我正在使用 PayPal Rest API,但出现错误。这是我的代码:
function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl) {
// set billing address
$addr = new Address();
$addr->setLine1('fh52 N Main ST');
$addr->setCity('Johnstownfhf');
$addr->setCountry_code('UK');
$addr->setPostal_code('35345');
$addr->setState('DF');
// set credit card information
$card = new CreditCard();
$card->setNumber('4111111111111111');
$card->setType('visa');
$card->setExpire_month('12');
$card->setExpire_year('2015');
$card->setCvv2('123');
$card->setFirst_name('dgdg');
$card->setLast_name('dgdgdShopper');
$card->setBilling_address($addr);
$fi = new FundingInstrument();
$fi->setCredit_card($card);
$payer = new Payer();
$payer->setPaymentMethod("paypal");
//$payer = new Payer();
//$payer->setPayment_method('credit_card');
//$payer->setFunding_instruments(array($fi));
// Specify the payment amount.
$amountDetails = new Details();
$amountDetails->setSubtotal('57.41');
$amountDetails->setTax('0.06');
$amountDetails->setShipping('0.06');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('5.47');
$amount->setDetails($amountDetails);
// ###Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('sdgdfg This is the payment transaction description.');
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($returnUrl);
$redirectUrls->setCancelUrl($cancelUrl);
$payment = new Payment();
$payment->setRedirectUrls($redirectUrls);
$payment->setIntent("buy");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
//print_r($payment);exit;
$payment->create($apiContext);
// return $payment;
}
一切正常,直到我打电话$payment->create($apiContext);
然后它显示这个错误:
0 - 访问时得到 Http 响应代码 400https://api.sandbox.paypal.com/v1/ payments/ payment https://api.sandbox.paypal.com/v1/payments/payment.
如果将调用包装在 try/catch 块中并捕获 PPConnectionException,则可以检查数据以准确了解错误是什么:
// ...
try {
$response = $pp_payment->create();
} catch (PayPal\Exception\PPConnectionException $pce) {
// Don't spit out errors or use "exit" like this in production code
echo '<pre>';print_r(json_decode($pce->getData()));exit;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)