我正在尝试使用服务器端的PayPal智能按钮设置交易。
在the PayPal docs中,我基于以下代码。我怀疑该问题是由于我在文档的以下行中的误解造成的:
return fetch('/my-server/create-paypal-transaction'
我在哪里使用
return fetch('http://127.0.0.1:8888/Waygook-Teacher/paypal/create-transaction.php'
form.php
paypal.Buttons({
// set up the transaction
createOrder: function() {
return fetch('http://127.0.0.1:8888/Waygook-Teacher/paypal/create-transaction.php', {
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.orderID;
});
},
creation-transaction.php
我已逐字复制from here。
请注意,我也为服务器端SDK设置了the config和the environment。
VM346:1 POST http://127.0.0.1:8888/Waygook-Teacher/paypal/create-transaction.php 500 (Internal Server Error)
(anonymous) @ VM346:1
createOrder @ profile.php?userID=28:113
(anonymous) @ js?client-id=sb¤cy=USD:1
n.try @ js?client-id=sb¤cy=USD:1
(anonymous) @ js?client-id=sb¤cy=USD:1
(anonymous) @ js?client-id=sb¤cy=USD:1
i @ js?client-id=sb¤cy=USD:1
e.dispatch @ js?client-id=sb¤cy=USD:1
e.then @ js?client-id=sb¤cy=USD:1
(anonymous) @ js?client-id=sb¤cy=USD:1
(anonymous) @ js?client-id=sb¤cy=USD:1
n.try @ js?client-id=sb¤cy=USD:1
Er.postrobot_message_request @ js?client-id=sb¤cy=USD:1
wr @ js?client-id=sb¤cy=USD:1
(anonymous) @ js?client-id=sb¤cy=USD:1
(anonymous) @ js?client-id=sb¤cy=USD:1
3js?client-id=sb¤cy=USD:1 Uncaught SyntaxError: Unexpected end of JSON input
Error: Unexpected end of JSON input
at Yt.(anonymous function) (https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:51517)
at Object.<anonymous> (https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:57776)
at JSON.parse (<anonymous>)
at o (https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:57636)
at ar (https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:57787)
at u.on (https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:62550)
at wr (https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:62739)
at https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:67176
at https://www.paypal.com/sdk/js?client-id=sb¤cy=USD:1:67222