Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Stripe CLIでWebhook APIを効率的に開発する/jp_stripes_deep...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
730
コミュニティ運営から 中の人に変わって感じたこと
hideokamoto
0
150
Developerが Developer Advocateになった話 / dev-rel-meetup-tokyo-71
hideokamoto
0
400
Jamstack開発者のための App Runner入門
hideokamoto
1
560
WordPressでの webサイト制作2022 / ngk2022s
hideokamoto
0
500
JavaScript(TypeScript)で メディアサイトを インフラから構築する方法 / jsconf-jp-2021
hideokamoto
2
4.4k
AWS上でStripeを利用したアプリをより安全にデプロイする方法 /jaws-pankration-2021
hideokamoto
1
250
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
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
6
4.8k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
Are APIs Still Relevant in the AI Era?
soyuka
0
310
Security issues being discussed on Web Platforms
petamoriken
0
1.2k
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
140
新卒PdEのリアル
ryu1013
1
520
FreeBSDでZabbixを動かす
kenkino
0
330
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
270
Agents on Rails - Rails at Scale 2026
irinanazarova
0
260
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
440
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
速習iPhone Duo対応
yuukiw00w
2
820
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
900
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Evolving SEO for Evolving Search Engines
ryanjones
0
300
Are puppies a ranking factor?
jonoalderson
2
3.9k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Designing for Timeless Needs
cassininazir
1
510
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Designing for Performance
lara
611
70k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
340
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
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