Walk through the basics of building a simple SCA compliant payment flow for saving cards and charging them later with the Stripe API and PHP following this guide.
Follow these instructions to spin-up a copy of this demo project up on your local machine for development and testing purposes. This is meant to be a guide to show you how to go about building an SCA ready payment flow for saving and charging cards later when the customer is off session. Additionally, there's an example of how to bring a customer back "on session" to complete authentication, if for some reason the off session payment failed for authentication required.
- Configure your keys
Copy the example .env
file and update those values with your Stripe API keys.
cp .env.example .env
Then, be sure to update the publishable key (pk_xxx) in client/index.html.
- Start the server
cd server/php
composer install
composer start
- Run the demo
Try using the test card 4000002760003184
which requires authentication for
every transaction, will demonstrate the entire flow. Also, experiment with other
cards like 4242424242424242
(no authentication required) and 4000002500003155
(authentication required to setup). For more test cards see https://stripe.com/docs/testing#cards.
Step 1: Saving card details
Browse as the customer to http://localhost:4242 and enter 4000002760003184 as the card number.
Step 2: Admin interface for charging later
Using the customer ID (cus_xxx) and payment method ID (pm_xxx) logged in Step 1, charge the customer from this admin interface: http://localhost:4242/admin
Step 3: Complete authentication
If off session payment fails because the transaction requires authentication, you'll want to bring the customer back on session to complete payment. Use the link from step 2 to view the "bring customer on session" page here: http://localhost:4242/complete?pi=pi_xxx&pm=pm_xxx