PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 31, 2021

[FIXED] Stripe implementaion in CakePHP3

 December 31, 2021     cakephp, cakephp-3.0, stripe-payments     No comments   

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.

  1. 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;
  1. 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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing