解析支付宝支付
Parsing Paypal payment
我正在使用贝宝结账。我已经为此工作了两天,但似乎无法弄清楚如何将付款详细信息放入我的数据库中
这是我在尝试 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
这是我的贝宝按钮脚本
<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 解析,我读过其他一些 Whosebug 的文章,指出使用 data.payID 之类的东西,但那些只会返回未定义的错误。
how to get the payment details to put into my DB
如果您需要在数据库中存储付款详细信息,则不应在客户端使用 actions.order.capture()
。
相反,切换到适当的服务器集成。
在您的服务器上创建两条路线,一条用于 'Create Order',一条用于 'Capture Order'、documented here。这些路由应该 return 只有 JSON 数据(没有 HTML 或文本)。后者应该(成功)在执行 return(特别是 purchase_units[0].payments.captures[0].id
、PayPal 交易 ID)
之前将付款详细信息存储在您的数据库中
将这两条路线与以下批准流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server
我正在使用贝宝结账。我已经为此工作了两天,但似乎无法弄清楚如何将付款详细信息放入我的数据库中
这是我在尝试 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
这是我的贝宝按钮脚本
<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 解析,我读过其他一些 Whosebug 的文章,指出使用 data.payID 之类的东西,但那些只会返回未定义的错误。
how to get the payment details to put into my DB
如果您需要在数据库中存储付款详细信息,则不应在客户端使用 actions.order.capture()
。
相反,切换到适当的服务器集成。
在您的服务器上创建两条路线,一条用于 'Create Order',一条用于 'Capture Order'、documented here。这些路由应该 return 只有 JSON 数据(没有 HTML 或文本)。后者应该(成功)在执行 return(特别是 purchase_units[0].payments.captures[0].id
、PayPal 交易 ID)
将这两条路线与以下批准流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server