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

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

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

JP_Stripes Online

Hidetaka Okamoto

June 09, 2021
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

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

    View full-size slide

  2. TL;DR
    • StripeͰैྔ՝ۚϓϥϯͷఏڙ͸ͱͯ΋؆୯
    • ঎඼ / ྉۚͷొ࿥ͱɺSubscriptionͷ࡞੒ɺ͋ͱ͸࢖༻ྔͷొ࿥
    • ෳ਺ͷIntervalʢظؒʣΛఏڙ͢Δ৔߹ɺैྔ՝ۚͷճऩ࣌ظʹ஫ҙ
    • Stripe BillingͷྉۚλΠϓ͕෯޿͍ͷͰɺϏδωεاըʹ͍͔ͦ͏
    #JP_Stripes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. ͳͥैྔ՝ۚʁ
    • σʔλసૹྔ͸ແݶʹ૿͑ΔՄೳੑ͕͋Δ
    • ࠷্Ґϓϥϯͷར༻࿮Ͱ΋௒ա͢ΔϢʔβʔ͕ొ৔
    • ͜Ε·Ͱ͸ʮXGB = $YʯͷΑ͏ͳݸผܾࡁΛ݄ຖʹ΍͍ͬͯͨ
    • ʮͲΕ͚ͩফඅ͢Δ͔ʯͷ༧ଌ͕Ϣʔβʔʹඞཁ
    • ʮ௒͔͑ͯΒܖ໿ʯͰ͸αΠτμ΢ϯ͕Ұ࣌తͰ΋ൃੜ͢Δ
    • ʮ࢖ͬͨ෼͚ͩ੥ٻʯͷΦϓγϣϯͰɺ
    ༧ଌͷखؒͱμ΢ϯϦεΫΛճආ #JP_Stripes

    View full-size slide

  8. શ෦ैྔ՝ۚʹ͠ͳ͍ͷʁ
    • Shifter͸ᴈ໌ظɺैྔ՝ۚͩͬͨ
    • Stripe Billing͕ैྔ՝ۚରԠલͷྗٕ࣮૷
    • ʮͲΕ͚ͩ੥ٻ͞ΕΔ͔Θ͔Βͳ͍ʯ͕ʮબ͹Εͳ͍ཧ༝ʯʹ
    • ʮ݄16υϧɺແྉϓϥϯ͋Γʯͷํ͕఻ΘΔࢢ৔ʹ͍ͨ
    • ैྔ՝ۚ => ύοέʔδՁ֨ => ύοέʔδ + ैྔ՝ۚ
    #JP_Stripes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  12. ैྔ՝ۚ͸
    Subscription create/update
    ͚ͩͰ͸1ԁ΋੥ٻͰ͖ͳ͍
    #JP_Stripes

    View full-size slide

  13. createUsageRecordͰʮ࢖ͬͨྔʯΛొ࿥͢Δ
    const usageRecord = await stripe.subscriptionItems
    .createUsageRecord(
    ‘si_XXXXX',
    {
    quantity: 100,
    timestamp: 1571252444,
    action: ‘set’
    }
    );
    #JP_Stripes

    View full-size slide

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

    View full-size slide

  15. ࢖༻ྔͷूܭํ๏
    1. Amazon EventBridgeͰAWS StepFunctionsΛݺͼग़͢Πϕϯτ࡞੒
    2. ର৅ͷpriceΛؚΉSubscriptionΛશऔಘ
    3. subscriptionຖʹฒྻͰूܭॲཧΛ࣮ࢪ
    4. ूܭ݁ՌΛAWS DynamoDBʹอଘ
    5. StripeͷUsageRecords APIʹར༻ྔΛొ࿥
    #JP_Stripes

    View full-size slide

  16. Price IDΛ࢖͑͹ʮର৅subscriptionʯ͚ͩҾ͚Δ
    const subscriptions = await stripe.subscriptions
    .list({
    price: ‘price_xxx’
    });
    #JP_Stripes

    View full-size slide

  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

    View full-size slide

  18. ࢖༻ྔ͸GBͰϢʔβʔʹදࣔ
    • ʮϕʔεϓϥϯͷ࢖༻ྔΛ௒͍͑ͯΔ࣌ʯ͚ͩ੥ٻ͞ΕΔੑ࣭
    • ʮԿGB࢖͍ͬͯΔ͔ʯ͕Φϓγϣϯͷ੥ٻൃੜલ͔ΒॏཁʹͳΔ
    • ୯Ձมߋ΍ෳ਺ྉۚͷఏڙ༧ఆ΋ͳ͍ͨΊɺ
    subscriptionItems.listUsageRecordSummaries͸࢖͍ͬͯͳ͍
    • DynamoDBʹه࿥ͨ͠࢖༻ྔGBΛදࣔ͠ɺ
    ඞཁͳΒ$0.18/GBΛϑϩϯτͰܭࢉ #JP_Stripes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  22. ͨͩ͠ɺ
    Intervalʢظؒʣͱ
    Currencyʢ௨՟ʣ͸
    ౷Ұ͠ͳ͍ͱμϝ
    #JP_Stripes

    View full-size slide

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

    View full-size slide

  24. ෳ਺ͷInterval͕ొ৔͢ΔͨΊɺ࢓༷ͱͯ͠ಠཱ
    • ຊདྷͳΒɺ1 Subscriptionʹ·ͱΊͨํָ͕
    • ֹ݄ͨͩ͠ <-> ೥ֹͷ੾Γସ͕͑೉͘͠ͳΔ
    • ೥ֹͷैྔ՝ۚΦϓγϣϯ͸ग़ͨ͘͠ͳ͔ͬͨ
    • ಠཱͨ͠Subscriptionʹ͢Δ͜ͱͰɺInterval ( Currency )ڝ߹Λճආ
    • DynamoDBʹattributeΛ1ͭ଍͚ͨͩ͠Ͱղܾ
    #JP_Stripes

    View full-size slide

  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

    View full-size slide

  26. ࠓఏڙ͍ͯ͠ΔSubscriptionʹ
    ैྔ՝ۚΛ௥Ճ͢Δʹ͸
    • Currency / Interval͕1ͭͳΒͦͷ··subscriptionʹ௥Ճָ͕
    • ෳ਺͋Δ৔߹͸ɺʮैྔ՝ۚͰग़͢currency / intervalʯΛܾΊΑ͏
    • ରԠͨ͠PriceΛશͯἧ͑ͳ͍ͳΒɺಠཱͨ͠Subscription͕ແ೉
    • ੥ٻλΠϛϯά͸ಉ͡λΠϛϯάʹἧ͓͑ͯ͘ͷ͕਌੾
    • ɾɾɾͱ͍͏͜ͱ͕͋ΔͷͰɺbilling_cycle_anchor͸࢖͓ͬͯ͜͏
    #JP_Stripes

    View full-size slide

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

    View full-size slide

  28. ஈ֊తͳՁ֨ઃఆ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  31. ࡞ΕΔྉۚମܥͷ
    छྨ͕૿͍͑ͯΔ

    ఏڙͰ͖ΔϏδωεͷछྨ͕
    ૿΍ͤΔΑ͏ʹͳΔ

    View full-size slide

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

    View full-size slide

  33. https://stripe.dev/

    View full-size slide

  34. StripeΛཧղ͢Δ
    StripeΛ࢖͍͜ͳ͢

    ఏҊɾ࣮૷Ͱ͖Δ
    ΦϯϥΠϯϏδωεͷ෯͕޿͕Δ

    View full-size slide

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

    View full-size slide

  36. Thanks!
    • StripeͰैྔ՝ۚϓϥϯͷఏڙ͸ͱͯ΋؆୯
    • ঎඼ / ྉۚͷొ࿥ͱɺSubscriptionͷ࡞੒ɺ͋ͱ͸࢖༻ྔͷొ࿥
    • ෳ਺ͷIntervalʢظؒʣΛఏڙ͢Δ৔߹ɺैྔ՝ۚͷճऩ࣌ظʹ஫ҙ
    • Stripe BillingͷྉۚλΠϓ͕෯޿͍ͷͰɺϏδωεاըʹ͍͔ͦ͏
    #JP_Stripes

    View full-size slide