0

I am loading individual payments method under their own div container:

<br>
div id="paypal-button-container_paypal"<br>
div id=="paypal-button-container_card"<br>
div id=="paypal-button-container_sofort"<br>

    let FUNDING_SOURCES = [
        paypal.FUNDING.PAYPAL,
        paypal.FUNDING.CARD,
        paypal.FUNDING.SOFORT
    ];

    FUNDING_SOURCES.forEach(function (fundingSource) {
        var button = paypal.Buttons({
            fundingSource: fundingSource,
        })
        button.render('#paypal-button-container_'+fundingSource)
    });

How can I trigger the following functions,

createOrder onApprove onInit onClick onCancel

etc... in the above code?

If I do it within the loop, each of the actions will be repeated multiple times.

Do I have to do the following for each of the payment buttons: https://developer.paypal.com/docs/checkout/apm/sofort/#link-renderpaymentbutton (if so then, is not the same code repeating again & again?)

Need your help on this. Help would be appreciated. Thank you.

1 Answer 1

1

Put the callback functions (createOrder, onApprove, etc) inside paypal.Buttons({...}).

They will be called at the appropriate time, for example createOrder occurs after a button is clicked.

3
  • if I call those functions inside the paypal.Buttons({...}) will be looped multiple times. the same object will be created multiple times!
    – mrana
    Commented Jan 20, 2023 at 11:26
  • As a result, every function will be called multiple(as many payment methods as you have) times!!
    – mrana
    Commented Jan 20, 2023 at 11:32
  • No, they are callback functions. The callback occurs when it should. Commented Jan 20, 2023 at 15:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.