simplifying payments with stripe
DESCRIPTION
If you need to accept payments online, there is no shortage of options to choose from. Stripe is a relatively new service that simplifies the whole process. You can be up and running in an evening. Stripe also makes it easy to setup recurring billing. All without storing sensitive credit card information on your server or emailing it around. This presentation will look at what you need to get started and explore the PHP bindings for working with the Stripe API. Oscar Merida, (@Omerida on Twitter) Founding Partner and Technical Lead at Musketeers.me, will be giving this talk. Check out their Kickstarter: http://kck.st/QjQZhoTRANSCRIPT
Simplify payments using Stripe
Oscar [email protected]
Early payment services painful
● Paylink & Payflow● Paypal
● Poorly Designed APIs● No API standard.● Documentation was
hard to find and use● Integration testing
cumbersome.
©2012 Oscar Merida@omerida
Processing payments is complicated
● Sign up for a merchant account or a payment gateway.
● Pay Fees - Setup, Monthly, Transaction● Secure your forms/site with SSL● Ensure PCI compliance
○ Firewall where card data is stored○ One function per server○ Deploy anti-virus software & keep it current○ Keep OS up to date
©2012 Oscar Merida@omerida
So we send customers away
©2012 Oscar Merida@omerida
Stripe simplifies payments
● No merchant account or gateway required.● Pay 2.9% + 30 cents per charge.● Available in the U.S. and Canada.● Well documented API with hooks for PHP, Javascript,
more● Pages w/payment forms must be HTTPS● Start accepting payments in minutes● Control the checkout & payment from start to finish.
©2012 Oscar Merida@omerida
Securely store customer data
● Can verify CVC and Address information.● Collect demographic and marketing data on
your site● Store sensitive card related data on Stripe
○ Certified PCI Level 1 Service Provider
©2012 Oscar Merida@omerida
Getting Started
● Sign up at http://stripe.com/● Provides two sets of API keys
○ One set for testing transactions○ One set for live transactions
● Download the PHP client library○ https://stripe.com/docs/libraries
● Initialize the client
require_once('./lib/Stripe.php');Stripe::setApiKey($my_public_key);
©2012 Oscar Merida@omerida
Creating a Charge// charge amount must be integer in cents and > 50
try {
$cents = (int) ($order->after_tax * 100);
$response = Stripe_Charge::create(array(
"amount" => $cents,
"currency" => "usd",
"card" => array(
'number' => $card,
'exp_month' => $month,
'exp_year' => $year,
'cvc' => $cvc,
'name' => $name,
'address_zip' => $zip,
),
"description" => sprintf("Submitting a payment")
));
} catch (\Stripe_CardError $ex) {
$errors = $ex->getMessage();
}
©2012 Oscar Merida@omerida
Catch exceptions on errors
Code Details
incorrect_number The card number is incorrect
invalid_number The card number is not a valid credit card number
invalid_expiry_month The card's expiration month is invalid
invalid_expiry_year The card's expiration year is invalid
invalid_cvc The card's security code is invalid
expired_card The card has expired
incorrect_cvc The card's security code is incorrect
card_declined The card was declined.
missing There is no card on a customer that is being charged.
processing_error An error occurred while processing the card.
©2012 Oscar Merida@omerida
Retrieve a successful charge
Response has a unique id associated with a sucessful charge. You can use this to pull up charge details within your app.Stripe_Charge::retrieve("ch_xuykedHrYF75sx");
©2012 Oscar Merida@omerida
Store & Retrieve Customers// create a new customer on stripe
$customer = Stripe_Customer::create(array(
"description" => "Customer for [email protected]",
"card" => array(
'number' => '4111111111111111',
'exp_month' => '03',
'exp_year' => '2015',
'cvc' => '123',
)));
// save stripe customer id for later
$customer_id = $customer->id;
// retrieve a customer from stripe
$customer = Stripe_Customer::retrieve($customer_id);
©2012 Oscar Merida@omerida
Creating subscription plans// create a "Pro Membership" plan
$plan = Stripe_Plan::create([
'amount' => '2500', // $25 in cents
'currency' => 'usd', // required
'trial_period_days' => 15, // first 15 days are free
'interval' => 'month', // billing frequency month|year
'name' => 'Pro Plan',
'id' => 'pro'
]);
// retrieve a plan
$pro = Stripe_Plan::retrieve('pro');
©2012 Oscar Merida@omerida
Subscribing customers to plans
Charge customers on a recurring basis$cupd = Stripe_Customer::retrieve($customer->stripe_id);
$cupd->updateSubscription([
'plan' => 'pro',
'prorate' => true, // prorate switching plans
'cancel_at_period_end' => false, // keep charging forever
'quantity' => 5 // bill them for 5 pro plan subscriptions
]);
// cancel a subcription
$cupd = Stripe_Customer::retrieve($customer->stripe_id);
$cupd->cancelSubscription();
©2012 Oscar Merida@omerida
Creating a coupon for customers
Coupons give a customer a percent off to subscriptions or invoices.
Stripe_Coupon::create([
'percent_off' => 20,
'duration' => 'repeating', // first three month discount
'duration_in_months' => 3,
'id' = '20DCPHP',
'max_redemptions' => 50, // limit usage to 50 people
'redeem_by' => strtotime('2012-12-31 23:59:59'), // UTC timestamp
]);
©2012 Oscar Merida@omerida
Apply a coupon to subscription$cupd = Stripe_Customer::retrieve($customer->stripe_id);
$cupd->updateSubscription([
'plan' => 'pro',
'prorate' => true, // prorate switching plans
'cancel_at_period_end' => false, // keep charging forever
'quantity' => 5 // bill them for 5 pro plan subscriptions,
'coupon' => '20DCPHP',
]);
©2012 Oscar Merida@omerida
Events to hook into your application
Stripe can send events to your application via a POST request with JSON data.You must respond with a 200 HTTP Status to indicate you received the webhook.● Send an email on charge.succeed events.● Notify user that a trial subscription will end.
©2012 Oscar Merida@omerida
Painless testing
● Stripe provides test numbers for testing cards and scenarios○ Test Visa, Mastercad, American Express numbers○ Test address, zip, cvc check failures○ Test card_declined, invalid expiration, invalid CVC○ See https://stripe.com/docs/testing
● View transaction logs on Stripe dashboard.
©2012 Oscar Merida@omerida
Other Stripe Features
● CRUD methods for any object● Create, retrieve, pay Invoices.● Integrates with Freshbooks
©2012 Oscar Merida@omerida