<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return fetch('payPalPayment.html', {
method: 'post',
body: JSON.stringify( {
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": 100.00
}
}]
})
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.paypalToken;
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return fetch('paypalGetExpressCheckout.html', {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
this above code does not show the amount when I login
我遇到了类似的问题,对我有用的是我使用了 createOrder
的基本集成,因为我需要的东西驻留在客户端中。
https://developer.paypal.com/docs/checkout/integrate/#4-set-up-the-transaction
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
currency_code: "USD",
value: '100.00'
}
}]
});
},
onApprove: function(data, actions) {
return fetch('paypalGetExpressCheckout.html', {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
我是一名优秀的程序员,十分优秀!