'Capture payment method used to pay with PayPal Checkout/Orders API
I'm using the Standard Integration of PayPal Checkout (via the Orders API), and want to capture the actual payment method - which I believe PayPal calls a "funding source" - that the customer paid with, so that I can pass this value to my server and persist it to my database.
What API object do I need to call to get this information?
Solution 1:[1]
This is a similar approach to the one that Preston outlines, and in the same way it has the limitation that it only returns the funding source of the button that's initially selected rather than the one that the user actually paid with (as this can be changed by the user from within the PayPal modal).
It seems that this is currently the closest that those using the Standard integration of PayPal Checkout can get to obtaining the payment method the user actually paid with because, for some reason, PayPal only sees it necessary to expose that information (which does exist in the API) to developers who have implemented the Advanced integration.
This is a disappointment if you're someone like me who's invested considerable time in integrating the Standard integration only to find out too late (thanks to poor documentation of both the integrations and the API) that the Standard integration can only access a crippled version of the API that has limited data.
In your client-side JavaScript, add fundingSource: fundingSource and any other variables you want to grab from the order data:
paypal.Buttons({
...
onApprove: function (data, actions) {
return fetch("/route/to/paypal/capture", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
fundingSource: fundingSource,
// Add any other variables you need here
}),
})
...
Then, when capturing the payment on your server, use:
$data = json_decode($request->getContent(), true);
...
$payment_method = $data["fundingSource"];
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 | Hashim Aziz |
