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

定期料金と従量課金を組み合わせたサブ スクリプション型サービスを作る/jp-stripe-02

定期料金と従量課金を組み合わせたサブ スクリプション型サービスを作る/jp-stripe-02

Serverless Operations

June 09, 2021
Tweet

More Decks by Serverless Operations

Other Decks in Technology

Transcript

  1. ࣮ݱ͍ͨ͜͠ͱͷ֓ཁʢαϒεΫϦϓγϣϯʴैྔ՝ۚʣ &OUFSQSJTFϓϥϯ݄ "1*ݺͼग़͠ճ਺ ʢ"1*6TBHFʣ ຖ݄ܾ·ͬͨྉۚΛ੥ٻ "1*ͷݺͼग़͠ճ਺ʹԠͯ͡ ྉۚΛܭࢉͯ͠੥ٻ #BTJDϓϥϯ݄ "EWBODFEϓϥϯ݄ αϒεΫ͚ͩͰͳ͘ɺ

    ैྔ՝ۚ෼·Ͱूܭͯ͠ ੥ٻʹ൓өͤ͞ΔΑ͏ͳ ࣮૷ରԠ͕ඞཁʹͳͬͯ͘Δ αʔϏε։࢝·Ͱྉۚମܥ͕ ֬ఆ͠ͳ͍౳ɺޙ͔Βॊೈʹ ՝ۚϞσϧΛมߋͰ͖ΔΑ͏ʹ͍ͨ͠
  2. ࣮ݱ͍ͨ͜͠ͱͷ֓ཁʢαϒεΫϦϓγϣϯʴैྔ՝ۚʣ #BTJDϓϥϯ݄ "EWBODFEϓϥϯ݄ &OUFSQSJTFϓϥϯ݄ "1*ݺͼग़͠ճ਺ ʢ"1*6TBHFʣ ຖ݄ܾ·ͬͨྉۚΛ੥ٻ "1*ͷݺͼग़͠ճ਺ʹԠͯ͡ ྉۚΛܭࢉͯ͠੥ٻ  料金体系

    → ”継続” として商品登録 ・段階的/数量ベースの料金体系として商品登録 ・Stripeへ使用量を報告し、毎月の請求に反映させる
  3. ࢖༻ྔΛܭଌ͢ΔΦϓγϣϯΛ༗ޮԽ ᶄ4BOECPYr"1*6TBHFɿ"1*ݺͼग़͠ճ਺౳ɺैྔ՝ۚ޲͚ͷ঎඼Λొ࿥ 「Usage is metered(使用量が計測されます)」にチェック 「Charge for metered usage by(計測された使用量に基づく請求)」

    → 適宜システム仕様に合わせて選択 ˞ޙ΄Ͳઆ໌͢Δʮ࢖༻ྔͷใࠂʯ ͕Ͱ͖ΔΑ͏ʹͳΔ ˞࣮ࡍʹ֤Ϣʔβʔͷ࢖༻ྔΛTUSJQF ͷ"1*ܦ༝ͰϨϙʔτ͢Δ͚ͩͰɺ঎ ඼ొ࿥࣌ʹઃఆͨ͠ྉۚςʔϒϧʹ߹ Θͤͯ՝ֹ͕ۚ੥ٻॻʹ൓ө͞ΕΔ
  4. ސ٬ٴͼαϒεΫϦϓγϣϯͷొ࿥ ސ٬ɺࢧ෷৘ใɺαϒεΫϦϓγϣϯΛొ࿥ ˞͓ࢼ͠Ͱܾࡁొ࿥ը໘ͷσϞΛ࡞ͬͯΈ͍ͨ৔߹ɺެࣜͷ$IFDLPVUαϯϓϧ͕ศར e// https://github.com/stripe-samples/checkout-single-subscription e// server/node/server.js L.50 - econst

    session = await stripe.checkout.sessions.create({ mode: 'subscription', payment_method_types: [ 'card' ], line_items: [ { price: '{PRICE_ID_PLAN}', quantity: 1 }, { price: '{PRICE_ID_API_USAGE}' } ], // ...
  5. ैྔ՝ۚͷ࢖༻ྔΛใࠂ͢Δɹ e[request sample] ePOST /v1/subscription_items/:subscription_item_id/usage_records eauthorization: Bearer {SECRET_API_KEY} econtent-type: application/x-www-form-urlencoded

    etimestamp=1614752111&quantity=250&action=set e[response sample] e200 OK e{ e "subscription_item": "xxx", e "quantity": 250, e "timestamp": 1615097751, e // ... e} ैྔ՝ۚ .FUFSFE #JMMJOH ͷֹۚΛ൓өͤ͞ΔͨΊʹɺސ٬͕ར༻ͨ͠ྔ Ϣ χοτ Λ਺஋ͱͯ͠4USJQFʹૹ৴ʢ˞6TBHF3FDPSET"1*ʣ ˞1BUIύϥϝʔλʹސ٬ͷఆظࢧ෷ͷ μογϡϘʔυը໘͔ΒऔಘͰ͖Δ ʮαϒεΫϦϓγϣϯΞΠςϜ*% ʢTJ@YYYʣʯΛࢦఆͯ͠਺ྔΛૹ৴ ˞4USJQF"1*ʹ͸3BUF-JNJU͕͋ΔͷͰ஫ҙ ʢMJWFNPEFͰSFBE XSJUFQFSTFDPOEʣ  IUUQTTUSJQFDPNEPDTSBUFMJNJUT
  6. (FPMPOJB ΦϯϥΠϯ஍ਤαʔϏε ͷࣄྫ ྉۚମܥ͕ྲྀಈతͩͬͨΓɺैྔ՝ۚΛεΫϥονͰ։ൃ͢Δෛ୲͕͋ͬͨ ˠมߋՄೳͰॊೈͳ࢓૊Έͷ࣮ݱͱ࣮૷ෛ୲Λܰݮ ΧϜϯ΀ϲε ĖຌᲦό⑲τ ܭଌσʔλͷ&5-ॲཧΛܦͯ%ZOBNP%#΁อଘ ᑿᠭᅗΤᏄຓ -BNCEB

    "QQMJDBUJPO 4 "UIFOB 'BSHBUF %ZOBNP%# -BNCEB 4 %ZOBNP%# 4USFBNT e{ e “subject_id”: "...", e “subscription_item”: "...", e "quantity": 100, e "timestamp": 1615097751, e // … e} ˞ࣄྫ঺հهࣄ͸ͪ͜ΒIUUQTTFSWFSMFTTDPKQCMPH