【问题标题】:Laravel 5 - PayPal not getting Price when calling APILaravel 5 - 调用 API 时 PayPal 没有获得价格
【发布时间】:2015-09-14 16:26:09
【问题描述】:

由于某种原因,PayPal 没有收到我为交易指定的总价格。

我正在使用 NetShell 的 PayPal 模块。

我的控制器看起来像这样:

class PayPalController extends Controller {

    private $_apiContext;
    public function __construct() {
        $this->_apiContext = PayPal::ApiContext(
            config('services.paypal.client_id'),
            config('services.paypal.secret'));

        $this->_apiContext->setConfig(array(
            'mode' => 'sandbox',
            'service.EndPoint' => 'https://api.sandbox.paypal.com',
            'http.ConnectionTimeOut' => 30,
            'log.LogEnabled' => true,
            'log.FileName' => storage_path('logs/paypal.log'),
            'log.LogLevel' => 'FINE'
        ));
    }

    public function getCheckout() {
        $payer = PayPal::Payer();
        $payer->setPaymentMethod('paypal');

        $amount = PayPal::Amount();
        $amount->setCurrency('USD');
        $amount->setTotal(42); // This is the simple way,
        // you can alternatively describe everything in the order separately;
        // Reference the PayPal PHP REST SDK for details.

        $transaction = PayPal::Transaction();
        $transaction->setAmount($amount);
        $transaction->setDescription('What are you selling?');

        $redirectUrls = PayPal::RedirectUrls();
        $redirectUrls->setReturnUrl(action('PayPalController@getDone'));
        $redirectUrls->setCancelUrl(action('PayPalController@getCancel'));

        $payment = PayPal::Payment();
        $payment->setIntent('sale');
        $payment->setPayer($payer);
        $payment->setRedirectUrls($redirectUrls);
        $payment->setTransactions(array($transaction));

        $response = $payment->create($this->_apiContext);
        $redirectUrl = $response->links[1]->href;

        return Redirect::to( $redirectUrl );
    }

    // Other functions here. Removed for question.

}

getCheckout() 在路由 `/paypal/checkout' 处被调用

当我去/paypal/checkout时没有价格。

我错过了什么吗?任何帮助,将不胜感激。

谢谢!

【问题讨论】:

    标签: laravel paypal laravel-5


    【解决方案1】:

    可能与价格类型有关。价格必须以浮点数声明。 试试吧,

    floatval($price)
    

    看看这个,我写了关于将 paypal express 集成到 laravel,

    Paypal express integration

    【讨论】:

    • 你做了 $transaction->setAmount(floatval($amount));正确的?如果您愿意,请尝试使用omnipay paypal 包?
    • Object of class PayPal\Api\Amount could not be converted to double
    • 因为您的金额是一个对象,请认真检查一下,developer.paypal.com/docs/api 它在该对象内有总参数,请使用它。
    • 我对此很陌生,并不真正了解那里的文档。我正在按照它所说的代码做,但它仍然给我那个错误。
    • 我写了一个例子,用在博客gist.github.com/metekabak/1281bc0e2d80b33f5666
    猜你喜欢
    • 2017-07-02
    • 2017-10-30
    • 2019-07-03
    • 2017-03-24
    • 2019-02-24
    • 2020-01-05
    • 2020-10-05
    • 2012-01-08
    相关资源
    最近更新 更多