This is a simple form demonstrating how you could integrate Stripe.js with Cheddar.
This example uses Stripe.js with Stripe Elements to collect credit card details and to send that information to Stripe from the client. If successful, Stripe responds with a token representing the payment information via Stripe.js.
The token received from Stripe.js can be passed to your servers and used to perform a charge or to save to a customer (in place of the actual payment information). In this example, an API call is made to Stripe to create a customer using their PHP library.
If successful, Stripe will return the customer object of the newly created customer. You can pull the id
field to pass as the subscription[gatewayToken]
when creating a customer in Cheddar. This example uses the Cheddar PHP library.
Note that it's possible to create a customer and an associated credit card in Stripe without collecting a name for either the customer or the credit card. However, Cheddar will require a first and last name for the both the customer and the credit card.
You can pass the credit card first and last name directly to Cheddar, or by including the name
attribute when you create a token in Stripe.js. If a name is included in the creation of a Stripe.js token, Cheddar will pull that information directly from Stripe. This example attaches a name
when creating a token with Stripe.js.
- Stripe.js and Elements Documentation
- Stripe API Reference
- Cheddar API Reference
- Cheddar PHP Client and docs
- Clone this repository
- e.g.,
git clone https://github.com/chdr/stripejs-example.git
- e.g.,
- Descend into the cloned directory
- e.g.,
cd stripejs-example
- e.g.,
- Install dependencies
- Install Composer if you don't have it
- Use Composer to install the dependencies for this example
- e.g.,
composer install
if globally installed orphp composer.phar install
- Set your configuration variables in
config/config.php
- The command
cp config/config.dist.php config/config.php
runs aftercomposer install
for convenience - Replace any variables representing API keys from Stripe with those from your own test accounts
- Replace any variables representing Cheddar credentials with those from a test product in Cheddar
- The command
- Run the PHP built-in server with the docroot set to
public/
- e.g.,
php -S localhost:8080 -t public/
- e.g.,