您好我正在尝试为使用PayPal PHP SDK创建的订单创建多个授权 我只是在PayPal官方文档中提供了这个案例
例如,当商家从多个配送中心运送物品时,每个货物需要单独的授权。另一个例子是延迟装运没有库存的物品。
https://developer.paypal.com/docs/integration/direct/create-process-order/#create-the-order
根据这个,我每个订单有10个授权,但不是我得到的......
我可以创建一个20美元的订单,之后我为此订单创建一个autorization以阻止部分金额(10美元)一切都好,但是当我尝试使用相同的方式为任何金额创建另一个授权时我创建了第一个我收到此错误MAXIMUM_AUTHORIZATION_ALLOWED_REACHED_FOR_ORDER ...我不知道为什么因为只是第二个授权所以我不知道是否有一些我缺少的东西。
这是代码
创建订单
// Amount
$amount = new Amount();
$amount->setCurrency("USD")->setTotal(20);
// Transaction
$transaction = new Transaction();
$transaction
->setAmount($amount)
->setInvoiceNumber(uniqid())
;
// Payer
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// Redirect urls
$redirectUrls = new RedirectUrls();
$redirectUrls
->setReturnUrl($successUrl)
->setCancelUrl($cancelUrl)
;
// Payment
$payment = new Payment();
$payment
->setIntent("order")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction))
;
try {
$paymentResponse = $payment->create($apiContext);
} catch (Exception $ex) {
dump($ex);
exit(1);
}
超越订单
// Get Payment
$payment = Payment::get('PAY-3FL894366A430123HK6H765A', $apiContext);
$transactions = $payment->getTransactions();
// Create execution
$execution = new PaymentExecution();
$execution->setPayerId('DW4YPSRV6HRDS');
$execution->addTransaction($transactions[0]);
try {
// Execute to hold payer's balance
$result = $payment->execute($execution, $apiContext);
// Get payment's autorization
$resultTransaction = $result->getTransactions()[0];
$authorization = $resultTransaction->getRelatedResources()[0]->getAuthorization();
} catch (PayPalConnectionException $e) {
dump($e);
die;
}
创建授权
$authorization = new Authorization();
$authorization->setAmount(new Amount(
'{
"total": "1.00",
"currency": "USD"
}'
));
try {
$result = $order->authorize($authorization, $apiContext);
} catch (PayPalConnectionException $e) {
dump($e);
}