我正在尝试在事务中包含一个标识符,因此我知道从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);
}
这是结果(调用toJSON()):
{
"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"
}
]
}
我找到了reference_id in the API documentation,所以我想我可以使用它。