【发布时间】:2021-04-22 06:16:16
【问题描述】:
我正在开发一个 php 应用程序,我必须将 PayPal 智能按钮集成到我的应用程序中。在沙盒模式下一切正常。但是当我把它转到现场或生产环境时。它给出 JSON 错误。
PayPal Smart Buttons returns me JSON error
这个答案在为沙盒和其他所有东西设置环境时帮助了我很多,这真的很好。但仅适用于沙盒模式!
我检查了贝宝上的帐户,交易在那里创建,但没有响应发送到服务器进行进一步处理。说明 API 设置成功且密钥正常。但唯一的问题是我无法捕获响应并将其发送回服务器这是我的代码
创建-paypal-transaction.php
public static function createOrder($debug=false)
{
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = self::buildRequestBody();
// 3. Call PayPal to set up a transaction
$client = PayPalClient::client();
$response = $client->execute($request);
// 4. Return a successful response to the client.
$json_obj= array('id'=>$response->result->id);
$jsonstring = json_encode($json_obj);
echo $jsonstring;
}
在客户端
createOrder: function() {
return fetch('payments/create-paypal-transaction.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify($('#form_add').serializeObject())
}).then(function(res) {
console.log(res);
return res.json();
}).then(function(data) {
console.log(data);
return data.id;
});
我使用 console.log() 来调试服务器响应,但它总是
{
...
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
...
}
控制台也显示以下错误
create_order_error
click_initiate_payment_reject
Uncaught SyntaxError: Unexpected token < in JSON at position 0
任何帮助都将不胜感激:)
【问题讨论】:
标签: javascript php api paypal paypal-rest-sdk