Using PHP to set up and use setupIntents with the STRIPE payment gateway

This is a walk through of the PHP & Javascript code required for collecting a card payment method using to save the card details ready for collecting payments later.

The code here is using the STRIPE developers test environment and will not collect real funds.

As a pre-requisit for your own coding, you will need to have created a STRIPE account and acquired the public and secret keys from your STRIPE dashboard.
You will also have used composer to install the STRIPE API into your application vendor folders using the command line composer require stripe/stripe-php

The code is broken down into a few steps to set-up a customer on the STRIPE environment and then create a form to collect the credit card details that will be used by a background billing process later; use the STRIPE test cards listed below - or found on

Also see Sagepage checkout

Written: July-2022 PHP: 7+ STRIPE.js: v3

Step 1 Code:

Set up your STRIPE keys; these are provided to you from your STRIPE dashboard see for your own.
NOTE: These are best stored in config files that are different between dev and live environments.

No code found for //--//--Step1:start

Step 2 Code:

Search STRIPE for the customer

No code found for //--//--Step2:start

Step 2 Result:

  • checkpoint 1 : Searching STRIPE for name='customer X'.
      Found [cus_MCbYUK7GS6pCye] on STRIPE; attached email is []
  • Step 3 Code:

    Create the STRIPE customer if it does not already have one.

    In this case we are using customer name as the Unique Identifier, but you would need to consider this when implementing your own solution.

    No code found for //--//--Step3:start

    Step 3 Result:

  • checkpoint 2: customer found
  • Step 4 Code:

    Create a STRIPE customer intent by creating the <form> using the client-secret created using setupIntents->create, and then using this in the javascript that follows this will tell stripe.js to populate the empty form with some input fields.

    No code found for //--//--Step4:start

    Step 4 Result:

  • checkpoint 3: creating a setupintent
  • setupIntent Id=seti_1MBFkOESHvtQP0M8TH6pP9tk

  • HINT: Use the Test card options listed below (e.g. 4242424242424242 - expires 12/33, CVC 123

    expand_more Test card options:

  • See
  • Step 5 Code:

    After this - I want to charge the customer using a new process each month - but this is where I can't find any examples to proceed. 🙁

    No code found for //--//--Step5:start


    New Comment

    NOTE: (Put code blocks in [[[ and ]]] markup to be formatted.)

    (Posted comments will be checked by the administrator before being published)

    Sun Dec 04, 22 10:48:36