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="<?php echo $stripe['publishable_key']; ?>"
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
user972616
1,4043 gold badges21 silver badges38 bronze badges
-
If you view the page source, do you see the php code in there or the output from the php in there?Latheesan– Latheesan2014年05月19日 15:04:26 +00:00Commented 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.AbraCadaver– AbraCadaver2014年05月19日 15:04:59 +00:00Commented May 19, 2014 at 15:04
-
this one should get you moving - stackoverflow.com/questions/23740548/…EvilEpidemic– EvilEpidemic2014年05月19日 15:06:51 +00:00Commented May 19, 2014 at 15:06
-
Yes @LatheesanKanes I see php code, like this data-key="<?php echo $stripe['publishable_key']; ?>"user972616– user9726162014年05月19日 15:34:09 +00:00Commented May 19, 2014 at 15:34
-
@AbraCadaver Yes it's a tpl.php fileuser972616– user9726162014年05月19日 15:34:41 +00:00Commented May 19, 2014 at 15:34
default