Situation:

One form of PayPal integration is through using their "Smart Buttons" mechanism.

So far I have managed to encapsulate their buttons in a framework component, and this is working, but I have a problem.

A part of that mechanism requires calling their SDK JavaScript, which is OK if placed in Index.html:
Code:
<script src="https://www.paypal.com/sdk/js?client-id=test"></script>
The issue is the URL query-string "?client-id=test", which for deployment the "test" should be replaced with your real client-id. (And even in testing should use a proper test client-id.)

Now I need to be able to dynamically set that client-id from values in the database. I have tried many, many different approaches, including:
  • Putting the script into the openHtml function in the component (the actual button rendering code is in the afterRender function there), which doesn't work (the script isn't loaded)
  • Dynamically creating the script on index.html after the WebApp is instaciated and I've retreived a value from it with a serverAction call - again, doesn't work reliably: sometimes works with the browser debugger open, fails the first time the page loads, although a refreash makes it work (but in any event, see the next one)
  • Using a web service to return a value from the WebApp, which I synchronously call in index.html and then building the script dynamically from that: which works, but of course that is before login, so the user is not known
  • Putting the script in an HTML box - again, the script doesn't seem to get executed


What I need it a way to have the script called and executed from within the component itself, but so far I have failed to find a way to do that.

Help!


Mike