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

後付けで 従量課金プランの 提供を開始した話 / 20210609-jp_stripes

後付けで 従量課金プランの 提供を開始した話 / 20210609-jp_stripes

JP_Stripes Online

75486cbfd37125f121cf4a6c5614601c?s=128

Hidetaka Okamoto
PRO

June 09, 2021
Tweet

Transcript

  1. ޙ෇͚Ͱ ैྔ՝ۚϓϥϯͷ ఏڙΛ։࢝ͨ͠࿩ JP_Stripes Online Hidetaka Okamoto #JP_Stripes

  2. TL;DR • StripeͰैྔ՝ۚϓϥϯͷఏڙ͸ͱͯ΋؆୯ • ঎඼ / ྉۚͷొ࿥ͱɺSubscriptionͷ࡞੒ɺ͋ͱ͸࢖༻ྔͷొ࿥ • ෳ਺ͷIntervalʢظؒʣΛఏڙ͢Δ৔߹ɺैྔ՝ۚͷճऩ࣌ظʹ஫ҙ •

    Stripe BillingͷྉۚλΠϓ͕෯޿͍ͷͰɺϏδωεاըʹ͍͔ͦ͏ #JP_Stripes
  3. Agenda • ैྔ՝ۚͰͷΦϓγϣϯαʔϏεͷఏڙ։࢝ • ैྔ՝ۚϓϥϯΛఏڙ͢ΔͨΊʹ΍ͬͨ͜ͱ • Ϗδωε্ͷ൑அͰSubscriptionମܥΛม͑ͨ࿩ • ʢؾ͔ͮ͵ؒʹʣStripe Billingͷྉۚମܥ͕૿͑ͯͨ࿩

    #JP_Stripes
  4. Agenda • ैྔ՝ۚͰͷΦϓγϣϯαʔϏεͷఏڙ։࢝ • ैྔ՝ۚϓϥϯΛఏڙ͢ΔͨΊʹ΍ͬͨ͜ͱ • Ϗδωε্ͷ൑அͰSubscriptionମܥΛม͑ͨ࿩ • ʢؾ͔ͮ͵ؒʹʣStripe Billingͷྉۚମܥ͕૿͑ͯͨ࿩

    #JP_Stripes
  5. CDNసૹྔͷ ैྔ՝ۚΦϓγϣϯఏڙ։࢝ #JP_Stripes https://www.getshifter.io/ja/cdn-pay-as- you-go-option-is-available/

  6. #JP_Stripes • ֹ݄Ͱͷ੥ٻ • 1GB͋ͨΓ0.18 USD • UIͰ͸ʮΦϯɾΦϑʯͷΈ

  7. ͳͥैྔ՝ۚʁ • σʔλసૹྔ͸ແݶʹ૿͑ΔՄೳੑ͕͋Δ • ࠷্Ґϓϥϯͷར༻࿮Ͱ΋௒ա͢ΔϢʔβʔ͕ొ৔ • ͜Ε·Ͱ͸ʮXGB = $YʯͷΑ͏ͳݸผܾࡁΛ݄ຖʹ΍͍ͬͯͨ •

    ʮͲΕ͚ͩফඅ͢Δ͔ʯͷ༧ଌ͕Ϣʔβʔʹඞཁ • ʮ௒͔͑ͯΒܖ໿ʯͰ͸αΠτμ΢ϯ͕Ұ࣌తͰ΋ൃੜ͢Δ • ʮ࢖ͬͨ෼͚ͩ੥ٻʯͷΦϓγϣϯͰɺ ༧ଌͷखؒͱμ΢ϯϦεΫΛճආ #JP_Stripes
  8. શ෦ैྔ՝ۚʹ͠ͳ͍ͷʁ • Shifter͸ᴈ໌ظɺैྔ՝ۚͩͬͨ • Stripe Billing͕ैྔ՝ۚରԠલͷྗٕ࣮૷ • ʮͲΕ͚ͩ੥ٻ͞ΕΔ͔Θ͔Βͳ͍ʯ͕ʮબ͹Εͳ͍ཧ༝ʯʹ • ʮ݄16υϧɺແྉϓϥϯ͋Γʯͷํ͕఻ΘΔࢢ৔ʹ͍ͨ

    • ैྔ՝ۚ => ύοέʔδՁ֨ => ύοέʔδ + ैྔ՝ۚ #JP_Stripes
  9. Agenda • ैྔ՝ۚͰͷΦϓγϣϯαʔϏεͷఏڙ։࢝ • ैྔ՝ۚϓϥϯΛఏڙ͢ΔͨΊʹ΍ͬͨ͜ͱ • Ϗδωε্ͷ൑அͰSubscriptionମܥΛม͑ͨ࿩ • ʢؾ͔ͮ͵ؒʹʣStripe Billingͷྉۚମܥ͕૿͑ͯͨ࿩

    #JP_Stripes
  10. #JP_Stripes • plan(price)Ͱొ࿥ • 1୯Ґ = 1GBʹઃఆ • ૯ܭ͸ʮ࠷େ஋ʯΛར༻

  11. Subscriptionͷૢ࡞͸ී௨ͷPriceͱશ͘ಉ͡ const subscription = await stripe.subscriptions.create({ customer: 'cus_XXXXX', items: [

    {price: 'price_XXXXXXXX'}, ], }); const subscription = await stripe.subscriptions.update(‘sub_xxxx’, { items: [ {price: 'price_XXXXXXXX'}, ], }); #JP_Stripes
  12. ैྔ՝ۚ͸ Subscription create/update ͚ͩͰ͸1ԁ΋੥ٻͰ͖ͳ͍ #JP_Stripes

  13. createUsageRecordͰʮ࢖ͬͨྔʯΛొ࿥͢Δ const usageRecord = await stripe.subscriptionItems .createUsageRecord( ‘si_XXXXX', { quantity:

    100, timestamp: 1571252444, action: ‘set’ } ); #JP_Stripes
  14. setͩͱ૯ྔɺincrementͩͱՃࢉͰॲཧ͞ΕΔ const usageRecord = await stripe.subscriptionItems .createUsageRecord( ‘si_XXXXX', { quantity:

    100, timestamp: 1571252444, action: ‘set’ } ); #JP_Stripes
  15. ࢖༻ྔͷूܭํ๏ 1. Amazon EventBridgeͰAWS StepFunctionsΛݺͼग़͢Πϕϯτ࡞੒ 2. ର৅ͷpriceΛؚΉSubscriptionΛશऔಘ 3. subscriptionຖʹฒྻͰूܭॲཧΛ࣮ࢪ 4.

    ूܭ݁ՌΛAWS DynamoDBʹอଘ 5. StripeͷUsageRecords APIʹར༻ྔΛొ࿥ #JP_Stripes
  16. Price IDΛ࢖͑͹ʮର৅subscriptionʯ͚ͩҾ͚Δ const subscriptions = await stripe.subscriptions .list({ price: ‘price_xxx’

    }); #JP_Stripes
  17. 100݅௒͑ΔͷͰɺ࣮ࡍʹ͸࠶ؼతͳ࣮૷ʹ async listSubscriptionRecuecive(priceId, items = [], startingAfter) { const {data:

    subscriptions} = await stripe.subscriptions .list({ starting_after: startingAfter, price: priceId, }) const mergedSubscriptions = [...items, ...subscriptions] if (subscriptions.length < 1) { return mergedSubscriptions } const lastSubscriptionId = subscriptions[subscriptions.length - 1].id return listSubscriptionRecuecive(planId, mergedSubscriptions, lastSubscriptionId) } #JP_Stripes
  18. ࢖༻ྔ͸GBͰϢʔβʔʹදࣔ • ʮϕʔεϓϥϯͷ࢖༻ྔΛ௒͍͑ͯΔ࣌ʯ͚ͩ੥ٻ͞ΕΔੑ࣭ • ʮԿGB࢖͍ͬͯΔ͔ʯ͕Φϓγϣϯͷ੥ٻൃੜલ͔ΒॏཁʹͳΔ • ୯Ձมߋ΍ෳ਺ྉۚͷఏڙ༧ఆ΋ͳ͍ͨΊɺ subscriptionItems.listUsageRecordSummaries͸࢖͍ͬͯͳ͍ • DynamoDBʹه࿥ͨ͠࢖༻ྔGBΛදࣔ͠ɺ

    ඞཁͳΒ$0.18/GBΛϑϩϯτͰܭࢉ #JP_Stripes
  19. Agenda • ैྔ՝ۚͰͷΦϓγϣϯαʔϏεͷఏڙ։࢝ • ैྔ՝ۚϓϥϯΛఏڙ͢ΔͨΊʹ΍ͬͨ͜ͱ • Ϗδωε্ͷ൑அͰSubscriptionମܥΛม͑ͨ࿩ • ʢؾ͔ͮ͵ؒʹʣStripe Billingͷྉۚମܥ͕૿͑ͯͨ࿩

    #JP_Stripes
  20. ैྔ՝ۚΦϓγϣϯ͸ɺ ϗεςΟϯάͷSubscriptionͱ ผʹSubscriptionΛ࡞੒ #JP_Stripes

  21. ैྔ՝ۚͩΖ͏͕Stripe BillingͰͷѻ͍͸ಉ͡ const subscription = await stripe.subscriptions.create({ customer: 'cus_XXXXX', items:

    [ {price: 'price_XXXXXXXX'}, ], }); const subscription = await stripe.subscriptions.update(‘sub_xxxx’, { items: [ {price: 'price_XXXXXXXX'}, ], }); #JP_Stripes
  22. ͨͩ͠ɺ Intervalʢظؒʣͱ Currencyʢ௨՟ʣ͸ ౷Ұ͠ͳ͍ͱμϝ #JP_Stripes

  23. FYI: ଟ௨՟Subscription͸΋͔͢͠Δͱɾɾɾʁ https://stripe.com/docs/invoicing/additional-features/multiple-currencies

  24. ෳ਺ͷInterval͕ొ৔͢ΔͨΊɺ࢓༷ͱͯ͠ಠཱ • ຊདྷͳΒɺ1 Subscriptionʹ·ͱΊͨํָ͕ • ֹ݄ͨͩ͠ <-> ೥ֹͷ੾Γସ͕͑೉͘͠ͳΔ • ೥ֹͷैྔ՝ۚΦϓγϣϯ͸ग़ͨ͘͠ͳ͔ͬͨ

    • ಠཱͨ͠Subscriptionʹ͢Δ͜ͱͰɺInterval ( Currency )ڝ߹Λճආ • DynamoDBʹattributeΛ1ͭ଍͚ͨͩ͠Ͱղܾ #JP_Stripes
  25. ੥ٻλΠϛϯάΛἧ͑ΔͨΊͷ billing_cycle_anchor await stripe.subscriptions.create({ customer: customerId, items: [{ price: priceId,

    }], billing_cycle_anchor: moment().add(1, ‘month’) .startOf('month').unix() }) #JP_Stripes
  26. ࠓఏڙ͍ͯ͠ΔSubscriptionʹ ैྔ՝ۚΛ௥Ճ͢Δʹ͸ • Currency / Interval͕1ͭͳΒͦͷ··subscriptionʹ௥Ճָ͕ • ෳ਺͋Δ৔߹͸ɺʮैྔ՝ۚͰग़͢currency / intervalʯΛܾΊΑ͏

    • ରԠͨ͠PriceΛશͯἧ͑ͳ͍ͳΒɺಠཱͨ͠Subscription͕ແ೉ • ੥ٻλΠϛϯά͸ಉ͡λΠϛϯάʹἧ͓͑ͯ͘ͷ͕਌੾ • ɾɾɾͱ͍͏͜ͱ͕͋ΔͷͰɺbilling_cycle_anchor͸࢖͓ͬͯ͜͏ #JP_Stripes
  27. Agenda • ैྔ՝ۚͰͷΦϓγϣϯαʔϏεͷఏڙ։࢝ • ैྔ՝ۚϓϥϯΛఏڙ͢ΔͨΊʹ΍ͬͨ͜ͱ • Ϗδωε্ͷ൑அͰSubscriptionମܥΛม͑ͨ࿩ • ʢؾ͔ͮ͵ؒʹʣStripe Billingͷྉۚମܥ͕૿͑

    ͯͨ࿩ #JP_Stripes
  28. ஈ֊తͳՁ֨ઃఆ

  29. ਺ྔϕʔεͷՁ֨ઃఆ

  30. ύοέʔδ୯Ґͷྉۚମܥ 10Ϣχοτ·Ͱ͸$10 #JP_Stripes

  31. ࡞ΕΔྉۚମܥͷ छྨ͕૿͍͑ͯΔ ↓ ఏڙͰ͖ΔϏδωεͷछྨ͕ ૿΍ͤΔΑ͏ʹͳΔ

  32. ϝʔϧͰߋ৽৘ใΛ ͬ͟ͱݟͰ͖Δ Developer Digest #JP_Stripes

  33. https://stripe.dev/

  34. StripeΛཧղ͢Δ StripeΛ࢖͍͜ͳ͢ ↓ ఏҊɾ࣮૷Ͱ͖Δ ΦϯϥΠϯϏδωεͷ෯͕޿͕Δ

  35. [એ఻] 6/26 WordCamp Japan 2021ͰWP with SaaS https://japan.wordcamp.org/2021/session/autumn02/

  36. Thanks! • StripeͰैྔ՝ۚϓϥϯͷఏڙ͸ͱͯ΋؆୯ • ঎඼ / ྉۚͷొ࿥ͱɺSubscriptionͷ࡞੒ɺ͋ͱ͸࢖༻ྔͷొ࿥ • ෳ਺ͷIntervalʢظؒʣΛఏڙ͢Δ৔߹ɺैྔ՝ۚͷճऩ࣌ظʹ஫ҙ •

    Stripe BillingͷྉۚλΠϓ͕෯޿͍ͷͰɺϏδωεاըʹ͍͔ͦ͏ #JP_Stripes