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

    ʮͲΕ͚ͩফඅ͢Δ͔ʯͷ༧ଌ͕Ϣʔβʔʹඞཁ • ʮ௒͔͑ͯΒܖ໿ʯͰ͸αΠτμ΢ϯ͕Ұ࣌తͰ΋ൃੜ͢Δ • ʮ࢖ͬͨ෼͚ͩ੥ٻʯͷΦϓγϣϯͰɺ ༧ଌͷखؒͱμ΢ϯϦεΫΛճආ #JP_Stripes
  2. 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
  3. 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
  4. ैྔ՝ۚͩΖ͏͕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
  5. ੥ٻλΠϛϯάΛἧ͑ΔͨΊͷ billing_cycle_anchor await stripe.subscriptions.create({ customer: customerId, items: [{ price: priceId,

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

    • ରԠͨ͠PriceΛશͯἧ͑ͳ͍ͳΒɺಠཱͨ͠Subscription͕ແ೉ • ੥ٻλΠϛϯά͸ಉ͡λΠϛϯάʹἧ͓͑ͯ͘ͷ͕਌੾ • ɾɾɾͱ͍͏͜ͱ͕͋ΔͷͰɺbilling_cycle_anchor͸࢖͓ͬͯ͜͏ #JP_Stripes