我正在使用paypal建立一个结帐。我已经为此工作了两天,似乎无法弄清楚如何将付款细节放入我的DB
这是我在尝试JSON解析时得到的错误:
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at https://######.com/######/quote.php?fname=######&lname=#####&email=########%40#########.com&tel=######&lot=7920&building=912&lotID=1:106:26
at e.n.dispatch (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:11814)
at e.n.resolve (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:10871)
at e.n.dispatch (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:12180)
at e.n.resolve (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:10871)
at https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:11681
at e.n.dispatch (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:11814)
at e.n.resolve (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:10871)
at e.n.dispatch (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:12180)
Error: Unexpected token o in JSON at position 1
at fr.error (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:62962)
at Object.<anonymous> (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:70732)
at JSON.parse (<anonymous>)
at o (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:70591)
at xr (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:70744)
at Fr.u.on (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:75415)
at Fr (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:75552)
at https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:81671
at Function.e.try (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:14344)
at https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:81468
Error: Unexpected token o in JSON at position 1
at fr.error (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:62962)
at Array.<anonymous> (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:70732)
at JSON.parse (<anonymous>)
at o (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:70591)
at xr (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:70744)
at Fr.u.on (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:75415)
at Fr (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:75552)
at https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:81671
at Function.e.try (https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:14344)
at https://www.paypal.com/sdk/js?client-id=AQ4DspGAAbWgC9Iw0KoI0kWjiEx5xM_gqpAmw1gxFIUha1YDtA_TTmMCaYJH6j58L3HvIlNkN4hD7Wdc&disable-funding=credit,card:2:81468
这是我的paypal按钮脚本
<script>
paypal.Buttons({
style:{
color:'blue',
shape:'pill'
},createOrder: function (data, actions) {
var cost = parseFloat(document.getElementsByClassName('totamount')[0].innerText.replace('$',''));
var address = document.getElementsByClassName('product-name')[0].innerText;
return actions.order.create({
purchase_units : [{
amount: {
name: '####### ######',
description: "##### #####at: " + address,
value: cost
}
}]
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
console.log(details)
var paydetails = JSON.parse(details);
var payee = paydetails.payer.name.given_name + " " + paydetails.payer.name.surname;
var payid = paydetails.id;
console.log(payee);
console.log(payid);
//document.getElementsByClassName('cart-total')[0].innerHTML= JSON.stringify(details)
//window.location.replace("https://######.com/######/paymentmade.php?uid=<?php echo $userid ?>")
})
},
onCancel: function (data) {
window.location.replace("https://#######.com/#######/quote.php?fname=<?php echo $fname ?> &lname=<?php echo $lname ?>&email=<?php echo $email ?>&tel=<?php echo $tel ?>&lot=<?php echo $lot ?>&building=<?php echo $building ?>&lotID=<?php echo $lotid ?>")
}
}).render('#paypal-payment-button');</script>
<script src="include/script.js"></script>
我试过Json解析,我读过一些其他的stackoverflow的指向使用数据之类的东西。payID之类的东西但这些只会返回未定义错误
如何获得付款细节放入我的DB
如果你需要在数据库中存储支付细节,你不应该在客户端使用actions.order.capture()
。
相反,切换到适当的服务器集成。
在你的服务器上创建两条路由,一条用于"创建订单",另一条用于"捕获订单",在这里记录。这些路由应该只返回JSON数据(不返回HTML或文本)。后者应该(如果成功)在返回之前将付款详细信息存储在数据库中(特别是purchase_units[0].payments.captures[0].id
, PayPal交易ID)
将这两个路由与以下审批流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server