simplifying payments with stripe

18
Simplify payments using Stripe Oscar Merida [email protected]

Upload: oscar-merida

Post on 15-Jan-2015

3.140 views

Category:

Documents


3 download

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/QjQZho

TRANSCRIPT

Page 1: Simplifying payments with Stripe

Simplify payments using Stripe

Oscar [email protected]

Page 2: Simplifying payments with Stripe

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

Page 3: Simplifying payments with Stripe

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

Page 4: Simplifying payments with Stripe

So we send customers away

©2012 Oscar Merida@omerida

Page 5: Simplifying payments with Stripe

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

Page 6: Simplifying payments with Stripe

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

Page 7: Simplifying payments with Stripe

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

Page 8: Simplifying payments with Stripe

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

Page 9: Simplifying payments with Stripe

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

Page 10: Simplifying payments with Stripe

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

Page 11: Simplifying payments with Stripe

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

Page 12: Simplifying payments with Stripe

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

Page 13: Simplifying payments with Stripe

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

Page 14: Simplifying payments with Stripe

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

Page 15: Simplifying payments with Stripe

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

Page 16: Simplifying payments with Stripe

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

Page 17: Simplifying payments with Stripe

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

Page 18: Simplifying payments with Stripe

Other Stripe Features

● CRUD methods for any object● Create, retrieve, pay Invoices.● Integrates with Freshbooks

©2012 Oscar Merida@omerida