SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
Simplify payments using
          Stripe
         Oscar Merida
     oscar@musketeers.me
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 test@example.com",
  "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

Contenu connexe

En vedette

Django Zebra Lightning Talk
Django Zebra Lightning TalkDjango Zebra Lightning Talk
Django Zebra Lightning TalkLee Trout
 
The #StartupStack
The #StartupStackThe #StartupStack
The #StartupStackStripe
 
Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)webhostingguy
 
New merchantapplication
New merchantapplicationNew merchantapplication
New merchantapplicationrgater
 
Android developer options & android sdk tools (for qa)
Android developer options & android sdk tools (for qa)Android developer options & android sdk tools (for qa)
Android developer options & android sdk tools (for qa)TechMagic
 
Peer-to-Peer lending: What is Lending Club?
Peer-to-Peer lending: What is Lending Club?Peer-to-Peer lending: What is Lending Club?
Peer-to-Peer lending: What is Lending Club?David Peat
 
Lending Club Case Study
Lending Club Case StudyLending Club Case Study
Lending Club Case Studyrgn216
 

En vedette (13)

Payment api basics
Payment api basicsPayment api basics
Payment api basics
 
Stripe
Stripe Stripe
Stripe
 
Django Zebra Lightning Talk
Django Zebra Lightning TalkDjango Zebra Lightning Talk
Django Zebra Lightning Talk
 
The #StartupStack
The #StartupStackThe #StartupStack
The #StartupStack
 
Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)Saferpay Checkout Page - PHP Sample (Hosting)
Saferpay Checkout Page - PHP Sample (Hosting)
 
Stripe in php
Stripe in phpStripe in php
Stripe in php
 
New merchantapplication
New merchantapplicationNew merchantapplication
New merchantapplication
 
Web payment system
Web payment system Web payment system
Web payment system
 
Android developer options & android sdk tools (for qa)
Android developer options & android sdk tools (for qa)Android developer options & android sdk tools (for qa)
Android developer options & android sdk tools (for qa)
 
FT Partners Research: Lending Club IPO: Post Quiet Period Review
FT Partners Research: Lending Club IPO: Post Quiet Period ReviewFT Partners Research: Lending Club IPO: Post Quiet Period Review
FT Partners Research: Lending Club IPO: Post Quiet Period Review
 
Peer-to-Peer lending: What is Lending Club?
Peer-to-Peer lending: What is Lending Club?Peer-to-Peer lending: What is Lending Club?
Peer-to-Peer lending: What is Lending Club?
 
Coaching
CoachingCoaching
Coaching
 
Lending Club Case Study
Lending Club Case StudyLending Club Case Study
Lending Club Case Study
 

Plus de Oscar Merida

Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeOscar Merida
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupalOscar Merida
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development EnvironmentsOscar Merida
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 
How to Evaluate your Technical Partner
How to Evaluate your Technical PartnerHow to Evaluate your Technical Partner
How to Evaluate your Technical PartnerOscar Merida
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development EnvironmentsOscar Merida
 
Publishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandocPublishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandocOscar Merida
 
Migrate without migranes
Migrate without migranesMigrate without migranes
Migrate without migranesOscar Merida
 

Plus de Oscar Merida (12)

PHP OOP
PHP OOPPHP OOP
PHP OOP
 
Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7
 
Symfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with easeSymfony console: build awesome command line scripts with ease
Symfony console: build awesome command line scripts with ease
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupal
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
How to Evaluate your Technical Partner
How to Evaluate your Technical PartnerHow to Evaluate your Technical Partner
How to Evaluate your Technical Partner
 
Building with Virtual Development Environments
Building with Virtual Development EnvironmentsBuilding with Virtual Development Environments
Building with Virtual Development Environments
 
Publishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandocPublishing alchemy with markdown and pandoc
Publishing alchemy with markdown and pandoc
 
Migrate without migranes
Migrate without migranesMigrate without migranes
Migrate without migranes
 
Hitch yourwagon
Hitch yourwagonHitch yourwagon
Hitch yourwagon
 

Simplifying payments with Stripe

  • 1. Simplify payments using Stripe Oscar Merida oscar@musketeers.me
  • 2. 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
  • 3. 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
  • 4. So we send customers away ©2012 Oscar Merida @omerida
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. Store & Retrieve Customers // create a new customer on stripe $customer = Stripe_Customer::create(array( "description" => "Customer for test@example.com", "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
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. Other Stripe Features ● CRUD methods for any object ● Create, retrieve, pay Invoices. ● Integrates with Freshbooks ©2012 Oscar Merida @omerida