微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Paypal:PHP SDK错误传入的JSON请求未映射到API请求

我正在使用 PHP Paypal SDK: https://github.com/paypal/PayPal-PHP-SDK

提到PayPal REST API through PHP SDK return “Incoming JSON request does not map to API request”

继续https://stackoverflow.com/questions/39827032/paypal-how-to-get-payment-id-on-basis-of-transaction-id

根据已有的交易ID,需要获得付款ID

我试过下面的代码

require __DIR__ . '/bootstrap.PHP';

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
// Extra Code
use PayPal\Api\PaymentDetail;

$payer = new Payer();
$payer->setPaymentMethod('paypal');

$transaction = new PaymentDetail(
        '{
          "method" : "CASH","date" : "2014-07-06 03:30:00 PST","note" : "Cash received."
        }'
);

$transaction->setTransactionId("3NT32794KF4824703");

$payment = new Payment();
$payment->setIntent("sale")
        ->setPayer($payer)
        ->setTransactions(array($transaction));

// For Sample Purposes Only.
$request = clone $payment;

try {
    $payment->create($apiContext);
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
    echo $ex->getData();
}

echo "<pre>";
print_r($payment);
exit;

当我运行上面的代码时,它给出了以下类型的错误

{"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":"aa8bfa2a41f1f"}

PayPal\Api\Payment Object
(
    [_propMap:PayPal\Common\PayPalModel:private] => Array
        (
            [intent] => sale
            [payer] => PayPal\Api\Payer Object
                (
                    [_propMap:PayPal\Common\PayPalModel:private] => Array
                        (
                            [payment_method] => paypal
                        )

                )

            [transactions] => Array
                (
                    [0] => PayPal\Api\PaymentDetail Object
                        (
                            [_propMap:PayPal\Common\PayPalModel:private] => Array
                                (
                                    [method] => CASH
                                    [date] => 2014-07-06 03:30:00 PST
                                    [note] => Cash received.
                                    [transaction_id] => 3NT32794KF4824703
                                )

                        )

                )

        )

)

如何解决上述错误?请指导

来自Paypal技术支持回复

After discussion and testing with the dev teams,they confirmed that
you can’t use TransactionId to retrieve the PaymentId. PaymentId is
generated upon initial REST API call. And this happen to REST API
only.

Transaction id can be generated after REST API execute payment,
Classic API [NVP/SOAP] DoEC API or normal button payment completion.
It will never work to reverse the search to find the Payment Id.

As for Now,the only workaround for you is to log each of the REST API
request regardless if it Failed or not to trace the PaymentId.

需要实现:付款完成后,将保持不变. X天后,它将被处理.处理金额将从客户的账户中扣除.

解决方法

首先,您使用付款创建请求

$payment = new Payment();
    $payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));    
$payment->create($apiContext);

>在创建回复中,您将获得“apporval url”,此批准网址用于向用户付款.
>然后,您将通过“$redirectUrls”中的url发送来自paypal的通知.
>在这里,您将获得“付款ID”和“付款人ID”使用该付款执行付款.

$execution = new PaymentExecution();
$execution->setPayerId($da['PayerID']);
$apiContext=$this->apicontext();
$res = $payment->execute($execution,$apiContext);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐