[英]Can I use $transaction->setReferenceId() with Paypal PHP REST API?
我正在嘗試在交易中包含標識符,因此我知道從Paypal返回時是哪個交易。 我嘗試使用reference_id,因為它就像更好的選擇(因為這是我分配給該事務的時間標識符)。
問題是,當我將其設置為事務時,Paypal拒絕接受json,它返回:
{
"name":"MALFORMED_REQUEST",
"message":"Incoming JSON request does not map to API request",
"information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
"debug_id":"6835f984b6735"
}
我或多或少地使用示例代碼:
// Create new payer and method
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// Set redirect urls
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($urlRetorno)
->setCancelUrl($urlCancelar);
// Set payment amount
$amount = new Amount();
$amount->setCurrency($moneda)
->setTotal($total);
// Set transaction object
$transaction = new Transaction();
$transaction->setAmount($amount)
->setDescription($descripcion);
// If I comment this line it runs ok.
$transaction->setReferenceId($referenceId);
// Create the full payment object
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
echo $payment->toJSON();
// Create payment with valid API context
try {
$payment->create($apiContext);
// Get PayPal redirect URL and redirect user
$approvalUrl = $payment->getApprovalLink();
// Finalmente le redirigimos a PayPal para que apruebe el pago
//redirige($approvalUrl, 'Intentando redirigir a PayPal.');
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
這是結果(調用JSON()):
{
"intent":"sale",
"payer":{
"payment_method":"paypal"
},
"redirect_urls":{
"return_url":"https://example.com/return.php",
"cancel_url":"https://example.com/cancel.php"
},
"transactions":[
{
"amount":{
"currency":"MXN",
"total":"1515"
},
"description":"Suscripci\u00f3n c\u00f3digo PP-19119",
"reference_id":"304171757041"
}
]
}
我已經在API文檔中找到了reference_id,因此我可以使用它。
在有關它的GitHub存儲庫上發布后,這里是結論。
reference_id
是只讀值,您應該使用invoice_number
進行跟蹤。
你可以看一下https://github.com/paypal/PayPal-PHP-SDK/issues/828 ,目前在跟蹤https://github.com/paypal/PayPal-REST-API-issues/issues/69 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.