skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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"];
    

  2. When using JS SDK buttons that call your server, you can track which button on your site was clicked by passing an onClick function; its first parameter will be an object with fundingSource set to e.g. "paypal", "venmo", "card", "paylater". Have it store this to a global or w/e and then you can include this in the JSON body sent to your server when capturing an order from onApprove.

    However, the actual funding method that the payer ended up using might not correspond to that initial click selection, and is not returned; this and all other billing information is kept private to the payer in PayPal by design.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search