Laravel PayPal付款返还400 [英] Laravel PayPal payment return 400

查看:42
本文介绍了Laravel PayPal付款返还400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PayPal paypal/rest-api-sdk-php 作为我的laravel应用程序的付款网关.

I am using PayPal paypal/rest-api-sdk-php for payment gateway for my laravel application.

但是当单击链接进行确认时,访问https://api.sandbox.paypal.com/v1/payments/payment时,我得到 Got Http响应代码400.

But when the link is click for confirmation, I get Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.

以下是我在Laravel 5.1和AngularJS中的实现方法:

Following is my method of implementation in Laravel 5.1 and AngularJS:

angular.module('MyApp')
    .factory('Account', function($http){
        return {

            buyNow: function(pid){
                console.log(pid)
                return $http.put('/api/buynow',pid);
            }

        }   
    });

     public function buyNowAPI(Request $request)
        {
            $pid = $request->input('pid');
            $product = Product::find($pid);
            $baseUrl = url().'/#/app/product?orderId=$pid';     
            $payment = $this->makePaymentUsingPayPal($product->price,'MYR',$product->title,"$baseUrl&success=true", "$baseUrl&success=false");

            dd($payment->getLinks());
            return response()->json($pid);
        }

    public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl)
        {
            $payer = new Payer();
            $payer->setPaymentMethod("paypal");

            // Specify the payment amount.
            $amount = new Amount();
            $amount->setCurrency($currency);
            $amount->setTotal($total);

            $transaction = new Transaction();
            $transaction->setAmount($amount);
            $transaction->setDescription($paymentDesc);

            $redirectUrls = new RedirectUrls();
            $redirectUrls->setReturnUrl($returnUrl);
            $redirectUrls->setCancelUrl($cancelUrl);

            $payment = new Payment();
            $payment->setRedirectUrls($redirectUrls);
            $payment->setIntent("sale");
            $payment->setPayer($payer);
            $payment->setTransactions(array($transaction));
            $payment->create($this->getApiContext());
            return $payment;
        }

laravel代码实现基于git中可用于 paypal/rest-api-sdk-php 的示例的示例,该示例称为 The Pizza App

The laravel code implementation is based on example that available in git for paypal/rest-api-sdk-php based example called The Pizza App rest-api-sample-app . Thanks!!

推荐答案

您需要按照此处提到的说明进行操作:

You need to follow the instructions mentioned here:

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆