0

I am trying to place a stripe checkout button on a form with a dynamic amount to be charged based on the user's selection. The checkout button is rendered from Javascript as described here.

I am adding the script dynamically like so and used the answer to the following question to execute it.

 var script = document.createElement("script");
 script.setAttribute('src','https://checkout.stripe.com/v2/checkout.js');
 script.setAttribute('class','stripe-button');
 script.setAttribute('data-key',"<?php echo $stripe['publishable_key']; ?>");
 script.setAttribute('data-amount',parseFloat(jQuery('#totalCost').html())*100);
 script.setAttribute('data-description','Monthly subscription for ' + package_enabled);
 if(!document._write) document._write = document.write;
 document.write = function (str) {
 document.getElementById('paymentForm').innerHTML += str;
 };
 document.getElementById('paymentForm').appendChild(script);

The issue I am having is that the script does not render the php variable in this line

script.setAttribute('data-key',"<?php echo $stripe['publishable_key']; ?>");

and just prints it out as string like so

data-key="&lt;?php echo $stripe['publishable_key']; ?&gt;" 

As a hack, I can enter the key directly but I'd rather not. Is there any other solution?

asked May 19, 2014 at 15:01
5
  • If you view the page source, do you see the php code in there or the output from the php in there? Commented May 19, 2014 at 15:04
  • That file would need to be parsed by PHP. If the extension is .js or .html then probably not. Commented May 19, 2014 at 15:04
  • this one should get you moving - stackoverflow.com/questions/23740548/… Commented May 19, 2014 at 15:06
  • Yes @LatheesanKanes I see php code, like this data-key="&lt;?php echo $stripe['publishable_key']; ?&gt;" Commented May 19, 2014 at 15:34
  • @AbraCadaver Yes it's a tpl.php file Commented May 19, 2014 at 15:34

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.