Subscription and Smart Buttons on Same Page - Need to load different SDKs

breels
New Community Member

I am building a custom Wordpress theme and I have a Donate page that that contains multiple donation types - one-time payments and automatic monthly payments (subscriptions).  When the user clicks the Continue button for a donation type, it calls one of the two javascript functions specific to that payment type and then renders the appropriate PayPal buttons to complete the payment process. 

 

The issue I'm running into is that I need to use two different PayPal SDK scripts depending on the payment type:

https://www.paypal.com/sdk/js?client-id=ID-OMITTED&currency=USD&commit=false&debug=true

or

https://www.paypal.com/sdk/js?client-id=ID-OMITTED&vault=true&intent=subscription

 

Since the one-time payment button is the first on the page, when I call the function to render the paypal buttons it works as expected.  The problem comes in when I try to test the subscription option. Since the one-time SDK was loaded first, it will call that and the PayPal buttons won't render.

 

I am trying to figure out how to choose which script to load.  I have tried appending the correct SDK src to the head after an onclick event and even though I can see that it's there it still give me a "paypal is not defined" error.  

 

I am hoping someone has come across this and can make some suggestions.  I'm using PHP and Javascript and I can provide code examples if necessary, thanks.

Login to Me Too
1 REPLY 1

drakaria
Contributor
Contributor

The only way I was able to solve this was with https://github.com/paypal/paypal-js and the example at https://codepen.io/gregjopa/pen/RwagNWR?editors=1010 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.