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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
680
コミュニティ運営から 中の人に変わって感じたこと
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.1k
Stripe & Next.js + AWS Amplify で会員 + 定期課金機能 / JP_Stripes20210903
hideokamoto
7
3.3k
Other Decks in Programming
See All in Programming
Oxlintのカスタムルールの現況
syumai
6
1k
OSもどきOS
arkw
0
470
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
140
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.8k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.5k
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
280
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.2k
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
450
A2UI という光を覗いてみる
satohjohn
1
110
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
340
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
The SEO identity crisis: Don't let AI make you average
varn
0
480
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
Accessibility Awareness
sabderemane
1
130
Git: the NoSQL Database
bkeepers
PRO
432
67k
Embracing the Ebb and Flow
colly
88
5.1k
The Cult of Friendly URLs
andyhume
79
6.9k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Rails Girls Zürich Keynote
gr2m
96
14k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
720
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