我正在使用PHP Paypal SDK:https://github.com/paypal/PayPal-PHP-SDK
参考PayPal REST API通过PHP SDK返回"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的基础上继续。
根据已有的Transaction Id,需要获取Payment 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技术支持的回复:
经过与开发团队的讨论和测试,他们确认您无法使用TransactionId检索PaymentId。 PaymentId是在初始REST API调用时生成的。而这仅适用于REST API。
Transaction id可以在REST API执行付款、Classic API [NVP/SOAP] DoEC API或普通按钮付款完成后生成。它永远不会起到反向搜索以查找Payment Id的作用。
目前,您唯一的解决方法是记录每个REST API请求,无论是否失败,以跟踪PaymentId。
需要实现的内容:一旦付款完成,它将被保留。 X天后将处理该付款。在处理时,将从客户帐户中扣除金额。