Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Stripe Subscription

Stripe Subscription

This deck walks through the details behind the Drupal Stripe Subscription module.

Mike Milano

March 18, 2013
Tweet

Other Decks in Technology

Transcript

  1. SUBSCRIPTIONS WITH DRUPAL • Add/Remove roles based on subscription status

    • Optionally require subscription purchase at registration • Email templates for subscription and payment events • Optional upcoming payment notifications • Subscribers can easily update active card, subscription, and cancel • Stripe events are integrated into Drupal’s hook system Monday, March 18, 13
  2. PHILOSOPHY Let Stripe manage the payment data over there. It’s

    what they’re good at! Don’t try to be an ‘Everything to Everybody’ module; Embrace Stripe’s subscription architecture and do it well. Monday, March 18, 13
  3. WHY STRIPE? • Modern & User Friendly UI • Developer

    Friendly API and Documentation • No Merchant Account Required • Competitive Rates (2.9% + .30 per transaction) • Fields Required for Transactions are Minimal Monday, March 18, 13
  4. WHAT MAKES STRIPE GREAT FOR SUBSCRIPTIONS? • Subscription Plan Upgrade/Downgrade

    Paths • Optional Pro-Rated Subscription Upgrades • Trial Period Support (Other gateways frown on trials) • Built in Coupon Support Monday, March 18, 13
  5. STRIPE PLANS EXAMPLE Standard User Plans - Basic $9.95/mo -

    Premium $24.95/mo OK! (html dropdown) Monday, March 18, 13
  6. PROBLEM: STRIPE PLANS ARE A SINGLE DIMENSION =( Standard User

    Plans - Basic $9.95/mo - Premium $24.95/mo New Requirement: We need plans for advertisers now! Modified User Plans - Basic $9.95/mo - Premium $24.95/mo - Basic Advertiser $199.95/mo - Premium Advertiser $299.95/mo OK! Wait a minute! (html dropdown) (html dropdown) Monday, March 18, 13
  7. SOLUTION: PLAN GROUPS - Basic $9.95/mo - Premium $24.95/mo -

    Basic Advertiser $199.95/mo - Premium Advertiser $299.95/mo Plan Group: Default Plan Group: Advertiser Manage Plans and Plan Groups similar to the blocks UI Monday, March 18, 13
  8. PLAN GROUPS + CONTEXT The Stripe Plan Group reaction will

    restrict the subscription options to a particular plan group. When no reaction is in effect, the plans in the Default group will display. Monday, March 18, 13
  9. STRIPE WEBHOOKS Stripe sends requests containing event data to defined

    URLs. stripe/webhooks is the path you should use. Monday, March 18, 13
  10. HOOK FOR STRIPE EVENTS • charge.succeeded • charge.failed • charge.refunded

    • customer.updated • customer.subscription.created • customer.subscription.trial_will_ end • invoice.created • invoice.payment_succeeded • invoice.payment_failed function mymodule_stripe_webhook($event) { switch ($event->type) { case ‘invoice.payment_failed’: // Add custom payment failed functionality break ... Some other Event Types available Monday, March 18, 13
  11. WEBHOOK SECURITY When a webhook request is received, the Stripe

    module will only reference the event ID, then explicitly make a new request for that event. { "id": "evt_1SxOgpW6py97Aa", "created": 1363367941, "livemode": false, "type": "plan.created", "data": { "object": { "interval": "year", "name": "Subscriber", "amount": 1495, "currency": "usd", "id": "basic", "object": "plan", "livemode": false, "interval_count": 1, "trial_period_days": null } }, "object": "event", "pending_webhooks": 0 } Stripe Post to Drupal $event = Stripe_Event::retrieve("evt_1SxOgpW6py97Aa"); Explicit Event ID Request Monday, March 18, 13
  12. WEBHOOK PERSISTANCE • Stripe will re-send webhook events if it

    does not receive a status 200 • The Stripe module will send a 404 unless the event is successfully retrieved with light validation on the object. Monday, March 18, 13
  13. MODULE DEPENDENCIES • Stripe (Required) • Secure Pages (Optional) •

    Context (Optional for Plan Group reactions) • Profile2 Reg Path (Optional for Plan Group Registrations) Monday, March 18, 13