PayPal 付款 - HTTP 响应代码 400
PayPal Payments - HTTP Response code 400
我在 PHP 从事 PayPal 支付方面的工作。一切都很好,直到出现此错误:
访问 https://api.sandbox.paypal.com/v1/payments/payment 时得到 Http 响应代码 400。
当我尝试为我的付款创建方法时抛出:$payment->create($api);
<?php
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Exception\PayPalConnectionException;
require '../src/start.php';
$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();
// Payer
$payer->setPaymentMethod('paypal');
// Details
$details->setShipping('2.00')
->setTax('0.00')
->setSubtotal('20.00');
// Amount
$amount->setCurrency('GBP')
->setTotal('22.00')
->setDetails($details);
// Transaction
$transaction->setAmount($amount)
->setDescription('Membership');
// Payment
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions($transaction);
// Redirect urls
$redirectUrls->setReturnUrl($myReturnUrl)
->setCancelUrl($myCancelUrl);
$payment->setRedirectUrls($redirectUrls);
try {
$payment->create($api);
} catch (Exception $e) {
echo $e->getMessage();
}
为什么会这样?我该如何解决?我最终如何才能获得更详细的异常消息?
$api = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential('Your Client ID',' Secret')
);
确保您提供了正确的值
// Amount
$amount->setCurrency('GBP')
->setTotal('22.00')
->setDetails($details);
并确保您的 PayPal 企业帐户在我的情况下是您的主要货币,它可以很好地将值从 'GBP' 更改为 'USA'
// Amount
$amount->setCurrency('USA')
->setTotal('22.00')
->setDetails($details);
我在 PHP 从事 PayPal 支付方面的工作。一切都很好,直到出现此错误:
访问 https://api.sandbox.paypal.com/v1/payments/payment 时得到 Http 响应代码 400。
当我尝试为我的付款创建方法时抛出:$payment->create($api);
<?php
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Exception\PayPalConnectionException;
require '../src/start.php';
$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();
// Payer
$payer->setPaymentMethod('paypal');
// Details
$details->setShipping('2.00')
->setTax('0.00')
->setSubtotal('20.00');
// Amount
$amount->setCurrency('GBP')
->setTotal('22.00')
->setDetails($details);
// Transaction
$transaction->setAmount($amount)
->setDescription('Membership');
// Payment
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions($transaction);
// Redirect urls
$redirectUrls->setReturnUrl($myReturnUrl)
->setCancelUrl($myCancelUrl);
$payment->setRedirectUrls($redirectUrls);
try {
$payment->create($api);
} catch (Exception $e) {
echo $e->getMessage();
}
为什么会这样?我该如何解决?我最终如何才能获得更详细的异常消息?
$api = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential('Your Client ID',' Secret')
);
确保您提供了正确的值
// Amount
$amount->setCurrency('GBP')
->setTotal('22.00')
->setDetails($details);
并确保您的 PayPal 企业帐户在我的情况下是您的主要货币,它可以很好地将值从 'GBP' 更改为 'USA'
// Amount
$amount->setCurrency('USA')
->setTotal('22.00')
->setDetails($details);