Can I drop Javascript onApprove if paypalcheckoutsdk.orders OrdersCreateRequest is used?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I largely appreciate all the different example regarding implementation. Currently I try to derive a optimized python solution from the provided examples.
However, I am a little confused at the moment.
I want to use the Javascript sdk PayPal.Buttons from this example: https://developer.paypal.com/docs/checkout/integrate/
<script>
paypal.Buttons({
createOrder: function(data, actions) { // This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({ purchase_units: [{ amount: { value: '0.01' } }] }); },
onApprove: function(data, actions) { // This function captures the funds from the transaction.
return actions.order.capture().then(function(details) { // This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name); }); } }
).render('#paypal-button-container'); //This function displays Smart Payment Buttons on your web page.
</script>
Additionally I want to handle the transaction on a flask server with OrdersCreateRequest from this example: https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
What I am confused about is the following. If I use the server side integration to set up a transaction with OrdersCreateRequest I already receive a response on the server side.
Does this mean I can drop the client site Javascript sdk onApprove handler?
<script>
paypal.Buttons(
createOrder: function() {
return fetch('/my-server/create-paypal-transaction', { method: 'post', headers: { 'content-type': 'application/json' }
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.id; // Use the key sent by your server's response, ex. 'id' or 'token' }); },
onApprove: function(data, actions) { // This function captures the funds from the transaction.
return actions.order.capture().then(function(details) { // This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name); }); } }
).render('#paypal-button-container'); //This function displays Smart Payment Buttons on your web page.
</script>
- Labels:
-
Mobile SDKs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Solved it myself now!
Short answer: onApprove is still necessary to capture the payment. For server side handling a similiar fetch is necessary like in createOrder.
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Change the button from Sandbox to Production in REST APIs
- Issue with Rendering Trustly Payment Button via PayPal JavaScript SDK in SDKs
- Enable Pay later without credit in SDKs
- When I do PayPal capture Order, I keep on getting Invalid Request Connection in REST APIs
- Error: "Unable to change shipping method. Please try again." in PayPal popup in REST APIs