Search code examples
paypalpaypal-sandbox

How are the payment events attached to standalone PayPal button in the JS SDK versus rendering all available payment buttons?


I am transitioning from the simple paypal buttons that had the copy-and-paste code with the multiple screens in which the taxes and shipping options could be configure for each button to their JS SDK. I have it working in the sandbox so long as the paypal.Buttons({...}).render('#paypal-button-container'); setup is used to display all the available payment buttons. This is all on the client; not processing it from the server.

When I try to employ the method to limit the funding sources as described in the these paypal instructions, the correct buttons are rendered but they are no longer connected to the events. Every tests purchase in the sandbox is for one penny only. If the code is returned to render all the paypal buttons, it all works fine.

I'm sure it's a stupid question because I'm using the same paypal.Buttons({...}).render('#paypal-button-container'); method except without the .render('#paypal-button-container') and then adding the code below.

Would you please explain how to get the event code added when each button is in FUNDING_SOURCES array is processed separately? I'm attempting only two: [paypal.FUNDING.PAYPAL, paypal.FUNDING.CARD].forEach( function (fundingSource) {...

Thank you. By the way, I know that paypal recommended showing every available funding option but there is only one product and it is very nominally priced; so, the deferred payment options are a bit ridiculous in this case. Thank you.

// Loop over each funding source/payment method

FUNDING_SOURCES.forEach(function(fundingSource) {
    // Initialize the buttons
    var button = paypal.Buttons({
        fundingSource: fundingSource
    });

    // Check if the button is eligible
    if (button.isEligible()) {
        // Render the standalone button for that funding source
        button.render('#paypal-button-container');
    }
});

Solution

  • I hope I understand your issue correctly. Otherwise please rephrase...

    Instead of looping through the options, your best shot is enabling what you need / disabling what you don't need in the script initialization.

    See https://developer.paypal.com/sdk/js/configuration/

    All parameters are listed under "query parameters".

    What you need is disable-funding / enable-funding.

    enter image description here