加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:27:05 所属栏目:PHP教程 来源:网络整理
导读:我正在使用 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-paymen
我正在使用 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 PayPalApiAmount;
use PayPalApiDetails;
use PayPalApiItem;
use PayPalApiItemList;
use PayPalApiCreditCard;
use PayPalApiPayer;
use PayPalApiPayment;
use PayPalApiFundingInstrument;
use PayPalApiTransaction;
// Extra Code
use PayPalApiPaymentDetail;

$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 (PayPalExceptionPayPalConnectionException $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"}

PayPalApiPayment Object
(
    [_propMap:PayPalCommonPayPalModel:private] => Array
        (
            [intent] => sale
            [payer] => PayPalApiPayer Object
                (
                    [_propMap:PayPalCommonPayPalModel:private] => Array
                        (
                            [payment_method] => paypal
                        )

                )

            [transactions] => Array
                (
                    [0] => PayPalApiPaymentDetail Object
                        (
                            [_propMap:PayPalCommonPayPalModel: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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读