我試圖通過PHP SDK(沙箱環境)創建並執行與PayPal REST API的支付,如下所示。付款創建($payment->create
)正常,但付款執行($payment->execute
)返回"Incoming JSON request does not map to API request"
。 JSON請求是由SDK創建的,那麼會出現什麼問題? 在此先感謝。PayPal REST API通過PHP SDK返回「傳入的JSON請求不映射到API請求」
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item = new Item();
$item->setName('Any name')
->setCurrency('EUR')
->setQuantity(1)
->setPrice(0.99);
$itemList = new ItemList();
$itemList->setItems(array($item));
$details = new Details();
$details->setTax(0)
->setSubtotal(0.99);
$amount = new Amount();
$amount->setCurrency('EUR')
->setTotal(0.99)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('Any description')
->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(BASE_URL.'/payment/?success=true')
->setCancelUrl(BASE_URL.'/payment/?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$payment->create($apiContext);
$execution = new PaymentExecution();
$result = $payment->execute($execution, $apiContext);
} catch (Exception $ex) {
//Function for extract the error message,
//the error message can be showing with
//a simple var_dump($ex)
$exception = self::getException($ex);
}
在谷歌上的一個快速搜索告訴我,這個錯誤通常是由你發送的json無效造成的。確保你已經閱讀過文檔,並且你所放的一切都是他們期望的。 –