PayPal REST API through PHP SDK return quot;Incoming JSON request does not map to API requestquot;(PayPal REST API 通过 PHP SDK 返回“传入的 JSON 请求未映射到 API 请求)
问题描述
我正在尝试通过 PHP SDK(沙盒环境)使用 PayPal REST API 创建和执行付款,如下所示.付款创建 ($payment->create
) 工作正常,但付款执行 ($payment->execute
) 返回 "传入的 JSON 请求未映射到 API 请求"
.JSON 请求是由 SDK 创建的,那么会出现什么问题呢?提前致谢.
I'm trying to create and execute a payment with PayPal REST API through PHP SDK (sandbox environment) like showing below. The payment creation ($payment->create
) work fine but the payment execution ($payment->execute
) return "Incoming JSON request does not map to API request"
.
The JSON request is created by the SDK, then what can be the problem?
Thanks in advance.
$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);
}
推荐答案
放够了
$payment->setIntent('authorize')
代替
$payment->setIntent('sale')
并消除执行
$execution = new PaymentExecution(); $result = $payment->execute($execution, $apiContext);
然后,之后
$payment->create
我使用了来自
$payment->links
进行重定向.一切都很顺利.谢谢大家.
to do the redirect. Everything went perfectly. Thank you all.
这篇关于PayPal REST API 通过 PHP SDK 返回“传入的 JSON 请求未映射到 API 请求"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PayPal REST API 通过 PHP SDK 返回“传入的 JSON 请求未映射到 API 请求"
基础教程推荐
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01