Stripe Payment Gateway Integration in CakePHP 4

Reading Time: 8 minutes
7,945 Views

As we all know in most web application either in CakePHP 4 or any of the PHP Framework, we sometimes need to integrate payment gateway. Inside this article, we will see Stripe payment Integration in CakePHP 4. Stripe payment system settings in CakePHP 4. Easy and in complete detailed concept.

Let’s get started.


CakePHP 4 Installation

To create a CakePHP project, run this command into your shell or terminal. Make sure composer should be installed in your system.

$ composer create-project --prefer-dist cakephp/app:~4.0 mycakephp

Above command will creates a project with the name called mycakephp.


Stripe PHP Package Installation

We will install stripe package via composer into CakePHP 4 setup. Open CakePHP 4 project in terminal and hit this composer command.

$ composer require stripe/stripe-php

Set Stripe API Key and SECRET

Open up /config/paths.php file of CakePHP 4 application. Into the file, set few constants stripe api key, secret & vendor folder.

paths.php

This is our stripe sandbox detail, you can replace it with your own. If you are wondering to find stripe test account keys. Follow these steps –

  • You need to enable Viewing test data to use Test account details
  • Go to Developer >> Click on API keys

Create Routes

Next, we need to set CakePHP 4 stripe payment gateway application routes. To configure routes, open up /config/routes.php file.

routes.php

Create Controller File

Create application controller in setup. To create controller file, go to /src/Controller/StripesController.php and create this file. Open StripesController.php and paste the given code.

StripesController.php

Create Template File

Let’s create template file for setting the layout of payment details for user. Firstly we need to create a folder in /templates with the name as Stripes. Create a file stripe.php inside /templates/Stripes/stripe.php. Open file and paste the given code

stripe.php

Application Testing

Now, here you can test with these given test card details.

Open project in terminal and start development server

$ bin/cake server -p 8765

This is the Form when you open the route http://localhost:8765/stripe

Name: Sample
Number: 4242 4242 4242 4242
CSV: 123
Expiration Month: 04
Expiration Year: 2024

We hope this article helped you to learn about Stripe Payment Gateway Integration in CakePHP 4 in a very detailed way.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

2 thoughts on “Stripe Payment Gateway Integration in CakePHP 4”

Comments are closed.