简体   繁体   English

如何解决此错误“访问 https://api.sandbox.paypal.com/v1/payments/payment 时收到 Http 响应代码 400。 ”

[英]How do I solve this error “Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment. ”

I am integrating PayPal payment in Laravel 7. I have followed this process and other questions including this , this and many more but I dont seem to get help.我在 Laravel 7 中集成 PayPal 付款。我已经遵循了这个过程和其他问题,包括这个这个等等,但我似乎没有得到帮助。 This is my create payment code这是我的创建付款代码

    <?php

namespace App\Http\Controllers;

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Api\PaymentExecution;
use Illuminate\Http\Request;
use App\Project;

class PaypalController extends Controller
{
    public function makePayment(){
        return view('paypal');
    }
    public function payForProject($id){
        $project = Project::find($id);
        return view('paypal',['project'=>$project]);
    }
    public function create(Request $request){
        
        // dd($request->all());
        // $project = Project::find($request->project_id);
        $apiContext = new \PayPal\Rest\ApiContext(
            new \PayPal\Auth\OAuthTokenCredential(
                '',//Client ID
                ''//Client Secret
            )
        );

        $payer = new Payer();
        $payer->setPaymentMethod("paypal");

        $item1 = new Item();
        $item1->setName("Project". $request->project_id)
                ->setCurrency('USD')
                ->setQuantity(1)
                ->setSku($request->project_id)
                ->setPrice($request->budget);

        $itemList = new ItemList();
        $itemList->setItems(array($item1));

        $details = new Details();
        $details->setShipping(0)
                ->setTax(0)
                ->setSubtotal($request->budget);


        $amount = new Amount();
        $amount->setCurrency("USD")
                ->setTotal($request->budget)
                ->setDetails($details);

        $transaction = new Transaction();
        $transaction->setAmount($amount)
                ->setItemList($itemList)
                ->setDescription("Payment for project No." .$request->project_id)
                ->setInvoiceNumber(uniqid());

        $redirectUrls = new RedirectUrls();
        $redirectUrls->setReturnUrl("http://localhost/execute-payment")
                ->setCancelUrl("http://localhost/cancel");


        $payment = new Payment();
        $payment->setIntent("deposit")
                ->setPayer($payer)
                ->setRedirectUrls($redirectUrls)
                ->setTransactions(array($transaction));

        // return $payment;// Tried this return statement which gave the below response.

        // try {
            // $payment->create($apiContext);
        // } catch (PayPal\Exception\PayPalConnectionException $ex) {
            // echo $ex->getCode(); // Prints the Error Code
         //    echo $ex->getData(); // Prints the detailed error message 
         //    die($ex);
            // echo $ex;
            // exit(1);
        // }
                // $payment->create($apiContext);
        try {
            $payment->create($apiContext);
        } catch (PayPal\Exception\PayPalConnectionException $ex) {
            echo $ex->getCode(); // Prints the Error Code
            echo $ex->getData(); // Prints the detailed error message 
            die($ex);
        } catch (Exception $ex) {
            die($ex);
        }
        // return 1;
        return redirect($payment->getApprovalLink());
         
    }
}

$payment->create($apiContext); $payment->create($apiContext); gives Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment .访问https://api.sandbox.paypal.com/v1/payments/payment时给出 Got Http 响应代码 400。

When I use return $payment I get the following response.当我使用return $payment时,我得到以下响应。

{ "intent": "deposit", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost/execute-payment", "cancel_url": "http://localhost/cancel" }, "transactions": [ { "amount": { "currency": "USD", "total": "9781", "details": { "shipping": "0", "tax": "0", "subtotal": "9781" } }, "item_list": { "items": [ { "name": "Project301", "currency": "USD", "quantity": 1, "sku": "301", "price": "9781" } ] }, "description": "Payment for project No.301", "invoice_number": "5f22a904096d7" } ] }

What am I doing wrong and how do I solve this issue?我做错了什么,我该如何解决这个问题? I have input the correct client and secret ID's.我输入了正确的客户和秘密 ID。

400 translates to bad request. 400 转换为错误请求。 Make sure your request params are well formatted and api key is valid.确保您的请求参数格式正确并且 api 密钥有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PayPal:错误:“访问https://api.sandbox.paypal.com/v1/payments/payment时的HTTP响应代码400。” - PayPal: Getting error: “Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.” 访问https://api.sandbox.paypal.com/v1/payments/billing-plans/时获得Http响应代码403 - Got Http response code 403 when accessing https://api.sandbox.paypal.com/v1/payments/billing-plans/ 访问 https://api.paypal.com/v1/payments/payment/ 时得到 Http 响应代码 400 - Got Http response code 400 when accessing https://api.paypal.com/v1/payments/payment/ 访问https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true时收到Http响应代码403 - Got Http response code 403 when accessing https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true 访问https://api.sandbox.paypal.com时获得Http响应代码400 - Got Http response code 400 when accessing https://api.sandbox.paypal.com 访问https://api-3t.sandbox.paypal.com/2.0时获得Http响应代码500 - Got Http response code 500 when accessing https://api-3t.sandbox.paypal.com/2.0 Got Http response code 400 When executing payment on PayPal Sandbox, using PayPal PHP SDK - Got Http response code 400 When executing payment on PayPal Sandbox, using PayPal PHP SDK 执行 paypal 付款时得到 Http 响应代码 400 - Got Http response code 400 when Execute the paypal Payments PayPal付款 - HTTP响应代码400 - PayPal Payments - HTTP Response code 400 访问paypal付款时,Http响应代码500 - Http response code 500 when accessing paypal payment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM