Ene*_*y40 8 javascript paypal laravel
我已将 Paypal 智能按钮集成到我的页面中并且可以正常工作。3天前 Do not pass Pay-xxx 直接给出了错误并告诉我改为发送令牌。这次,当我引用它时,它给出了一个错误:期望传递一个订单 ID。我应该怎么办?
以下代码引发错误:期望传递订单 ID
var CREATE_PAYMENT_URL = '/api/create-payment';
var checkBox = document.getElementById("ship_to_different");
var note = $("#ordernote").val();
if (checkBox.checked == true) {
var body = $("#checkoutt, #data").serializeArray();
} else {
$('input[name=note]').val(note);
var body = $("#data").serializeArray();
}
$("#wait").show();
return fetch(CREATE_PAYMENT_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
body: body
})
}).then(function (res) {
return res.json();
}).then(function (data) {
console.log(data);
let token;
for (let link of data.links) {
if (link.rel === 'approval_url') {
token = link.href.match(/EC-\w+/)[0];
}
}
return data.token;
});
Run Code Online (Sandbox Code Playgroud)
以下代码会引发错误:不要将 PAY-XXX 或 PAYID-XXX 直接传递到 createOrder 中。改为传递 EC-XXX 令牌
var CREATE_PAYMENT_URL = '/api/create-payment';
var checkBox = document.getElementById("ship_to_different");
var note = $("#ordernote").val();
if (checkBox.checked == true) {
var body = $("#checkoutt, #data").serializeArray();
} else {
$('input[name=note]').val(note);
var body = $("#data").serializeArray();
}
$("#wait").show();
return fetch(CREATE_PAYMENT_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
body: body
})
}).then(function (res) {
return res.json();
}).then(function (data) {
console.log(data);
let token;
for (let link of data.links) {
if (link.rel === 'approval_url') {
token = link.href.match(/EC-\w+/)[0];
}
}
return data.id;
});
Run Code Online (Sandbox Code Playgroud)
我无法理解发生了什么事。
小智 0
您需要发送支付的Token,而不是支付的ID。如果您使用 php,请使用以下命令:
// Instance of your ApiPayment
$payment = new ApiPayment();
$payment->getToken();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16523 次 |
| 最近记录: |