Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Add READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Saikat Chakrabarti committed Nov 11, 2012
1 parent c289cb2 commit cb84cd8
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 9 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

Wilde Things is a website on which you can buy quotes Oscar Wilde. This is a PHP demo that demonstrates integrating Stripe, originally done for a General Assembly livestream tutorial on November 14, 2012.

The demo is 7 steps and goes from setting up a simple site for accepting one-time payments to a subscription-based service complete with webhook support.
The demo is 7 steps and goes from setting up a simple site for accepting one-time payments to a subscription-based service complete with webhook support.

## Getting started

To run any of the steps, you will first need to initialize the stripe submodule, which points to the stripe-php client library. To do this, first clone this project, then run:

`git submodule init`
`git submodule update`

Then, sign up for a Stripe account at https://stripe.com and replace every instance of <YOUR PUBLISHABLE STRIPE API KEY> and <YOUR SECRET STRIPE API KEY> with your publishable and secret API keys found at [https://manage.stripe.com/#account/apikeys](https://manage.stripe.com/#account/apikeys).
11 changes: 11 additions & 0 deletions Step1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Step 1: Get it running

In Step 1, we create a very checkout to purchase a single Oscare Wilde quote for $535.00. This demo uses the Stripe Button, which is a beta product but greatly simplifies creating your checkout.

Before trying to run the code, sign up a Stripe account at [https://stripe.com/signup](https://stripe.com/signup). Then, grab your API keys from [https://manage.stripe.com/#account/apikeys](https://manage.stripe.com/#account/apikeys) and replace the placeholders in the code with them.

Normally, you would then need to download the stripe-php client library from [https://stripe.com/docs/libraries](https://stripe.com/docs/libraries), but this source comes with the PHP library as a git submodule.

This demo then uses the instructions in [https://stripe.com/docs/guides/php](https://stripe.com/docs/guides/php) and [https://stripe.com/docs/button](https://stripe.com/docs/guides/php) to create a simple checkout page.

Once you get this demo running, make a payment, and then see your charge on your [dashboard](https://manage.stripe.com) to verify that it worked.
4 changes: 2 additions & 2 deletions Step1/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<?php
require_once('../stripe/lib/Stripe.php');
$stripe = array(
'secret_key' => 'sk_test_COES306BuVznThOZkMr8ibAa',
'publishable_key' => 'pk_test_fRASYtf5gVfnrjeNS6Z0aqLW'
'secret_key' => '<YOUR SECRET STRIPE API KEY>',
'publishable_key' => '<YOUR PUBLISHABLE STRIPE API KEY>'
);
Stripe::setApiKey($stripe['secret_key']);

Expand Down
16 changes: 16 additions & 0 deletions Step2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Step 2: To err is human

In this step, we add some simple error handling and show you how to debug the issue.

To start, try running the demo from Step1 and making a payment with the card "4000000000000002" -- this is one of many cards that are available on [https://stripe.com/docs/testing](https://stripe.com/docs/testing) to reproduce specific errors. You'll notice that your program will error.

To investigate the error, you have a couple of tools at your disposable.

First, you can look at your own PHP logs. If you are running PHP through the built-in Apache on OS X, you can find these at /private/var/log/apache2/error_log.

Second, you can look at the logs of requests you have made to Stripe. These are available in your Stripe dashboard at [https://manage.stripe.com/#logs](https://manage.stripe.com/#logs).

You can also take a look at [https://stripe.com/docs/api#errors](https://stripe.com/docs/api#errors) to get a sense of possible errors Stripe may return to you.

Once you get the code running in this tutorial, try making another purchase with a credit card with number "4000000000000002" -- you should get a nice message telling you your card was declined. Again, you can check your dashboard to see the failed payment.

4 changes: 2 additions & 2 deletions Step2/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<?php
require_once('../stripe/lib/Stripe.php');
$stripe = array(
'secret_key' => 'sk_test_COES306BuVznThOZkMr8ibAa',
'publishable_key' => 'pk_test_fRASYtf5gVfnrjeNS6Z0aqLW'
'secret_key' => '<YOUR SECRET STRIPE API KEY>',
'publishable_key' => '<YOUR PUBLISHABLE STRIPE API KEY>'
);
Stripe::setApiKey($stripe['secret_key']);

Expand Down
3 changes: 3 additions & 0 deletions Step3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Step 3: Factor in the refactoring

We don't do much in this step except to break up our site into a few component pieces. This will help keep our code organized for the next few steps.
4 changes: 2 additions & 2 deletions Step3/config.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require_once('../stripe/lib/Stripe.php');
$stripe = array(
'secret_key' => 'sk_test_COES306BuVznThOZkMr8ibAa',
'publishable_key' => 'pk_test_fRASYtf5gVfnrjeNS6Z0aqLW'
'secret_key' => '<YOUR SECRET STRIPE API KEY>',
'publishable_key' => '<YOUR PUBLISHABLE STRIPE API KEY>'
);
Stripe::setApiKey($stripe['secret_key']);
?>
11 changes: 11 additions & 0 deletions Step4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Step 4: Customers

Now that your Oscar Wilde quotes website is succeeding beyond your wildest dreams, you realize that the most avid Wilde fans keep coming back for quotes over and over again. Each time, they enter their credit card details in hopes of their next Wilde fix.

But you can make this simpler for them. In this step, we show you how to create a Stripe customer object for your users the first time they purchase a quote with their credit card. Then, in the future, they can simply log in and pay with the card they have on file.

In this step, we make a poor man's database in a text file located at /public/customers.txt. You should modify the code to save this elsewhere, or make sure that your PHP process can write to /public (and that that folder exists). To allow /public to be readable and writeable by any process (note: do this only if /public is only being used for the purposes of this demo), run:

`chmod 777 /public`

Once you get this code running, try purchasing a quote by signing up. Then, purchase another quote after logging in. You should see a customer in your Stripe dashboard with 2 payments.
4 changes: 2 additions & 2 deletions Step4/config.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
require_once('../stripe/lib/Stripe.php');
$stripe = array(
'secret_key' => 'sk_test_COES306BuVznThOZkMr8ibAa',
'publishable_key' => 'pk_test_fRASYtf5gVfnrjeNS6Z0aqLW'
'secret_key' => '<YOUR SECRET STRIPE API KEY>',
'publishable_key' => '<YOUR PUBLISHABLE STRIPE API KEY>'
);
Stripe::setApiKey($stripe['secret_key']);
?>

0 comments on commit cb84cd8

Please sign in to comment.