传入的JSON请求不映射到API请求"通过PHP SDK回报和QUOT贝宝REST API; [英] PayPal REST API through PHP SDK return "Incoming JSON request does not map to API request"
问题描述
我试图创建和执行通过PHP SDK(沙箱环境)像下面的PayPal展示REST API付款。支付创建($费付款>创建),做工精细,但支付执行($费付款>执行)返回传入的JSON请求不映射到API请求。
JSON的请求被SDK创建的,那么什么可以是问题?
先谢谢了。
$付款人=新付款人();
$ payer-> setPaymentMethod(贝宝);$项目=新的项目();
$本期特价货品>的setName('任何名称')
- > setCurrency('欧元')
- > setQuantity(1)
- > setPrice(0.99);$ ITEMLIST =新ITEMLIST();
$ itemList-> setItems(数组($项目));$细节=新的细节();
$详情 - > setTax(0)
- > setSubtotal(0.99);$金额=新的金额();
$ amount-> setCurrency('欧元')
- > setTotal(0.99)
- > setDetails($详细信息);$交易=新交易();
$交易 - > setAmount($金额)
- > setItemList($ ITEMLIST)
- > setDescription('任何说明)
- > setInvoiceNumber(uniqid());$ redirectUrls =新RedirectUrls();
$ redirectUrls-> setReturnUrl(BASE_URL'/支付/成功=正确的?)。
- > setCancelUrl(BASE_URL'/支付/成功=假?');$支付=新的支付();
$费付款> setIntent(销售)
- > setPayer($付款人)
- > setRedirectUrls($ redirectUrls)
- > setTransactions(阵列($交易));尝试{
$费付款>创建($ apiContext); $执行=新PaymentExecution();
$结果= $费付款>执行($执行,$ apiContext);}赶上(例外$前){
//用于提取错误信息功能,
//错误信息可以与展示
//一个简单的var_dump($ EX)
$例外=自:: getException($前);
}
这足以把
$费付款> setIntent('授权')
而不是
$费付款> setIntent(销售)
和消除执行
$ =执行新PaymentExecution(); $结果= $费付款>执行($执行,$ apiContext);
接着,在
$费付款>创建
我用的href从
$费付款>链接
做重定向。一切都非常完美。谢谢大家。
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);
}
It was enough put
$payment->setIntent('authorize')
instead of
$payment->setIntent('sale')
and eliminate the execution
$execution = new PaymentExecution(); $result = $payment->execute($execution, $apiContext);
Then, after
$payment->create
I used the "href" from
$payment->links
to do the redirect. Everything went perfectly. Thank you all.
这篇关于传入的JSON请求不映射到API请求"通过PHP SDK回报和QUOT贝宝REST API;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!