Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Stripe CLIでWebhook APIを効率的に開発する/jp_stripes_deep...
Search
Hidetaka Okamoto
April 22, 2021
Programming
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Stripe CLIでWebhook APIを効率的に開発する/jp_stripes_deepdive_vol5
Hidetaka Okamoto
April 22, 2021
More Decks by Hidetaka Okamoto
See All by Hidetaka Okamoto
OpenAI APIで API Changelogを要約してみた話 / chatgpt-osaka-1
hideokamoto
0
690
コミュニティ運営から 中の人に変わって感じたこと
hideokamoto
0
140
Developerが Developer Advocateになった話 / dev-rel-meetup-tokyo-71
hideokamoto
0
380
Jamstack開発者のための App Runner入門
hideokamoto
1
540
WordPressでの webサイト制作2022 / ngk2022s
hideokamoto
0
490
JavaScript(TypeScript)で メディアサイトを インフラから構築する方法 / jsconf-jp-2021
hideokamoto
2
4.4k
AWS上でStripeを利用したアプリをより安全にデプロイする方法 /jaws-pankration-2021
hideokamoto
1
240
Shifter Headlessと Headless WordPressの紹介
hideokamoto
0
2.2k
Stripe & Next.js + AWS Amplify で会員 + 定期課金機能 / JP_Stripes20210903
hideokamoto
7
3.3k
Other Decks in Programming
See All in Programming
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
290
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
6.1k
Contextとはなにか
chiroruxx
1
360
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
670
OSもどきOS
arkw
0
580
技術的負債解消で開発者の未来を開く- AIの力でコード刷新
kmd2kmd
0
110
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
210
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Claspは野良GASの夢をみるか
takter00
0
200
Creating Composable Callables in Contemporary C++
rollbear
0
160
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.4k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
740
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
Done Done
chrislema
186
16k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
560
The Limits of Empathy - UXLibs8
cassininazir
1
370
Transcript
Stripe CLIͰ Webhook APIΛ ޮతʹ։ൃ͢Δ JP_Stripes Deep Dive vol.5 2021/04/22
Hidetaka Okamoto
TL;DR • Stripe Webhookͷಈ࡞ςετʹɺPublicͳAPI͕ඞཁ • Stripe CLIΛ͏͜ͱͰɺlocalhostͷAPIΛଓͰ͖Δ • trigger/listenͳͲɺWebhookͷςετ/σόοά͚ίϚϯυ͕๛ •
StripeΔͳΒWebhook -> WebhookΔͳΒStripe CLI -> StripeΔͳΒStripe CLIʂ
Agenda • Stripe WebhookΛ͏ϝϦοτ • Stripe Webhook APIͷ։ൃେมʁ • Stripe
CLIͰWebhook APIͷϩʔΧϧ։ൃΛޮԽ • σϓϩΠޙͷσόοάɾϞχλϦϯάʹStripe CLI
Agenda •Stripe WebhookΛ͏ϝϦοτ • Stripe Webhook APIͷ։ൃେมʁ • Stripe CLIͰWebhook
APIͷϩʔΧϧ։ൃΛޮԽ • σϓϩΠޙͷσόοάɾϞχλϦϯάʹStripe CLI
ΦϯϥΠϯܾࡁΠϕϯτۦಈ • ʮܾࡁʹޭͨ͠߹ʯಛఆͷϝʔϧૢ࡞Λ࣮ߦ͢Δ • ʮఆظ՝ۚͷٻ͕ࣦഊͨ͠ͷͰʯαʔϏε੍ݶͱϢʔβʔ௨ • ʮܾࡁֹۚ߹ܭ / ܖظ͕ؒҰఆΛ͑ͨͷͰʯಛయΛ༩ •
ʮෆ৹ͳܾࡁ͕ݟ͔ͭͬͨͷͰʯࣾSlackʹ௨ • etc…
Stripe্ͷग़དྷࣄΛ ಠࣗͷαʔϏεʹ࿈ܞ͢ΔΈ Ὃ Stripe Webhook
DigitalcubeͰͷWebhookར༻ྫʢҰ෦ʣ • ఆظ՝ۚͷܾࡁ͕ࣦഊͨ͠߹ɺαʔϏεʹ੍ݶΛઃఆ • FailedܥΠϕϯτ͕ൃੜͨ͠߹ɺSlackʹ௨ • ղ(subscriptions.delete)࣌ʹɺؔ࿈σʔλͷআ • ϓϥϯมߋޙɺαʔϏε্ݶͷ৮͕ͳ͍͔ͷ֬ೝ •
etc…
Agenda • Stripe WebhookΛ͏ϝϦοτ •Stripe Webhook APIͷ։ൃେมʁ • Stripe CLIͰWebhook
APIͷϩʔΧϧ։ൃΛޮԽ • σϓϩΠޙͷσόοάɾϞχλϦϯάʹStripe CLI
StripeͷαʔϏε͔Β HTTPSϦΫΤετΛ͛Δ Ὃ APIInternetʹ ެ։͞Ε͍ͯΔඞཁ͕͋Δ
Before Stripe CLI • APIαʔόʔΛςετ༻ʹσϓϩΠʢsls deploy -s webhookʣ • Stripe
Dashboard͔ΒWebhookΠϕϯτΛखಈͰൃՐ • αʔόʔͷϩάΛࢹͯ͠ɺҙਤͨ͠ಈ࡞ʹͳ͍ͬͯΔ͔֬ೝ • ͕͋ΕɺϩʔΧϧͰमਖ਼ͯ͠࠶σϓϩΠ • ʮ࣮ -> ςετʯʹ͕͔͔࣌ؒΔ
ngrokΛ͏ͱ͍͏ख͋Δʹ͋Δ • ϩʔΧϧʹཱͯͨAPIαʔόʔʹ֎෦͔ΒଓͰ͖ΔΑ͏ʹ͢ΔSaaS • ແྉ͕͋ΔͷͰɺϫʔΫγϣοϓνϡʔτϦΞϧͰΑ͘ొ͢Δ • ແྉ൛ଓ্ݶURL͕ຖճมΘΔͳͲͷ੍ݶ͕͋Δ • ʮStripe CLI͕͑ͳ͍ʯͳΒɺngrokΛ͏ͷͻͱͭ
Agenda • Stripe WebhookΛ͏ϝϦοτ • Stripe Webhook APIͷ։ൃେมʁ • Stripe
CLIͰWebhook APIͷϩʔΧϧ։ൃΛޮԽ • σϓϩΠޙͷσόοάɾϞχλϦϯάʹStripe CLI
stripe listenͰ ϩʔΧϧAPIʹ ϦΫΤετதܧ # ϩʔΧϧͷAPIαʔόʔΛىಈ % npm start #
ϩʔΧϧͷAPIαʔόʔ͕localhost:4242ͷ߹ % stripe listen \ -—forward-to localhost:4242/webhook > Ready! Your webhook signing secret is whsec_xxxxxxxxxxxxx (^C to quit) # Webhook༻ͷॺ໊γʔΫϨοτΛڥมʹઃఆ % export STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxx x • DashboardͰͷ Webhookొ • ઐ༻ॺ໊Secretͷൃߦ • HTTPSϦΫΤετͷதܧ
Stripe CLIͰWebhookΠϕϯτΛखಈൃՐ • ʮstripe trigger [WEBHOOK_EVENT_NAME]ʯͰൃՐՄೳ • testڥଆʹ࣮σʔλ͕࡞ΒΕɺWebhookΠϕϯτ͕ൃՐ͢Δܗ • productͷશ݅औಘͳͲΛ͍ͯ͠Δ߹ʹཁҙ
• ࡞͞ΕΔσʔλͷதઃఆෆՄೳ • stripe products createͳͲɺݸผίϚϯυͰ࡞͢͠
Before Stripe CLI • APIαʔόʔΛςετ༻ʹσϓϩΠʢsls deploy -s webhookʣ • Stripe
Dashboard͔ΒWebhookΠϕϯτΛखಈͰൃՐ • αʔόʔͷϩάΛࢹͯ͠ɺҙਤͨ͠ಈ࡞ʹͳ͍ͬͯΔ͔֬ೝ • ͕͋ΕɺϩʔΧϧͰमਖ਼ͯ͠࠶σϓϩΠ • ʮ࣮ -> ςετʯʹ͕͔͔࣌ؒΔ
After Stripe CLI • APIαʔόʔΛϩʔΧϧͰىಈ • stripe listen —forward-to localhost:XXXXͰStripeͱଓ
• whsec_xxxͷΛڥมʹอଘ(or ߋ৽) • stripe trigger [EVENT_NAME]ͰΠϕϯτΛൃՐͯ͠ಈ࡞֬ೝ • ϩʔΧϧ্ͰWebhook APIͷ࣮͕Ͱ͖Δ
Stripe CLIͰͷϩʔΧϧ։ൃͷҙ • listenσϑΥϧτͩͱCatch ALLʢશΠϕϯτड͚͚Δʣ • ʮఆ͍ͯ͠ͳ͍Πϕϯτʯ͕ૹΒΕͯ͘Δέʔε͕͋ΓಘΔ • testڥΛ͍ͬͯΔΞϓϦ͕Stripe APIʹϦΫΤετΛૹͬͨ߹
• DashboardͰ୭͔͕࡞ۀΛͨ͠߹ • ผͷ࡞ۀऀ͕stripe triggerίϚϯυΛ࣮ߦͨ͠߹ • —events EVENT_NAMEϑϥάͰड͚͚ΔΠϕϯτΛߜΖ͏
Agenda • Stripe WebhookΛ͏ϝϦοτ • Stripe Webhook APIͷ։ൃେมʁ • Stripe
CLIͰWebhook APIͷϩʔΧϧ։ൃΛޮԽ • σϓϩΠޙͷσόοάɾϞχλϦϯάʹStripe CLI
Stripe CLIͰWebhookΠϕϯτͷϩάࢹ • ʮstripe listenʯͰൃੜͨ͠ΠϕϯτͷϩάΛࢹͰ͖Δ • σϑΥϧτͰʮ͍ͭɺͲΜͳΠϕϯτ͕ɺͲͷIDͰʯͷΈग़ྗ • flagΛͬͯΠϕϯτͷߜΓࠐΈJSONग़ྗՄೳ •
Ϣχοτςετ / E2Eςετʹ͍͍ͨͳΒɺ—print-jsonϑϥά • —liveϑϥάͰຊ൪σϓϩΠޙͷΠϕϯτϩάࢹͰ͖Δ
্: σϑΥϧτ Լ: JSONग़ྗ % stripe --project-name test listen 2021-04-21
15:43:52 --> payment_intent.created [evt_1IiZmtDHnG67uihbHble0dMs] 2021-04-21 15:44:39 --> customer.created [evt_1IiZneDHnG67uihbz8CqDMXa] 2021-04-21 15:44:39 --> customer.deleted [evt_1IiZneDHnG67uihb1fkojgcc] % stripe --project-name test listen \ --print-json { "id": "evt_1IiZoVDHnG67uihb6NbbKShX", "object": "event", "api_version": "2020-03-02", "created": 1618987531, "data": { "object": { "id": "cus_JLGLsScTeXQ2Ve", "object": "customer", "address": null, "balance": 0, …
Appendix 1: ͬಘ Stripe CLI ίϚϯυ • stripe fixture: JSONͰෳͷAPIίʔϧΛॱংཱ࣮ͯͯߦࢦࣔͰ͖Δ
• stripe logs: StripeʹૹΒΕͨAPIίʔϧΛࢹʢonly test modeʣ • stripe open: DashboardDocumentϖʔδΛϒϥβͰ։͚Δ • stripe samples: github.com/stripe-samplesͷΞϓϦΛcloneͰ͖Δ
Appendix 2: Webhook ॺ໊ݕূͰ อޢ͠Α͏ • Stripe͔ΒͷϦΫΤετ ͷΈॲཧ͖͢ • webhooks.constructEventΛͬ
ͯϦΫΤετΛݕূ • whsec_xxxAWSͷ Secret ManagerͳͲͰอޢ͠Α͏
Need more information?
https://zenn.dev/hideokamoto/books/e961b4bad92429
Thanks! • Stripe WebhookΛ͏ϝϦοτ • Stripe Webhook APIͷ։ൃେมʁ • Stripe
CLIͰWebhook APIͷϩʔΧϧ։ൃΛޮԽ • σϓϩΠޙͷσόοάɾϞχλϦϯάʹStripe CLI