Issue
I'm trying to implement the latest version of stripe payment in a CakePHP project. I'm beginning in CakePHP.
I read the doc but the thing is that, I have to combine JavaScript and CakePHP controller.
My question is how to fetch client_secret in a Javacript function to make it look like stripe doc authorize.
Thanks
Solution
From the last comment what I understand is, you have a data lets say $secret_key which is available in controller and we need to use $secret_key in JavaScript. If I understand correctly, here are the two ways we can follow:
Set $secret_key in view: i.e $this->set(compact('secret_key')); in the controller method. Thus it will be available in view.
set $secret_key in a hidden input. like
<input type="hidden" name="secret_key" id="secret_key" value="< ?= $secret_key ?>"
then access it through JavaScript.
var secret_key = document.getElementById("secret_key").value;
- Set directly $secret_key directly in JavaScript variable.
var secret_key = '<?= $secret_key?>'
;
You should write no.2 code in view as in .js file php text is not workable.
Note: in input field value, I put an extra space before ? as Stack overflow somehow hiding it.Please remove that extra space on testing time.
Answered By - Kaiser Ahmed Tushar
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.