'Paypal validation payment done
I use paypal button in a spring boot web application with thymeleaf, that work fine.
In the js script of the paypal button there is an
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Full available details
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
// Show a success message within this page, e.g.
const element = document.getElementById('paypal-button-container');
element.innerHTML = '';
element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
},
I need to know if payment was ok to activate subscription of the user.
I could use this onApprove to send value to the backend but don't think is very secure.
I checked key paypal and it seem webhook exist. Maybe it's the way to go?
Don't know if I need to check PAYMENT.CAPTURE.COMPLETED or INVOICING.INVOICE.PAID
to know if the payment made by the user was ok
Solution 1:[1]
For regular one-time PayPal payments (not subscriptions), use a server integration. There is a full stack example in node at https://developer.paypal.com/docs/checkout/standard/ , but the server side of it can be implemented in any environment. You can use the Checkout-Java-SDK to communicate with the PayPal API from your server, or implement your own HTTPS functions for v2/checkout/orders create and capture.
On the client, the approval flow will use its JS functions to call those two routes on your server as needed: the first happens when the button is clicked, to create the order, and the second after a payer approves the payment, to capture the order. The capture route of your server in particular should check the API response received directly from PayPal and verify the totals are as expected before marking the payment as successful.
For PayPal Subscriptions (payment that recurs automatically), the webhook to listen for PAYMENT.SALE.COMPLETED.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Preston PHX |
