繁体   English   中英

我可以在Paypal PHP REST API中使用$ transaction-> setReferenceId()吗?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM