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
710
コミュニティ運営から 中の人に変わって感じたこと
hideokamoto
0
150
Developerが Developer Advocateになった話 / dev-rel-meetup-tokyo-71
hideokamoto
0
390
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 - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.1k
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
160
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
7.6k
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
710
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
190
Android CLI
fornewid
0
230
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
19k
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
120
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
590
Press start. Python's next generation.
willingc
PRO
2
100
バグを直したら useEffect が消えた
colorful12
3
690
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
500
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
270
The Invisible Side of Design
smashingmag
301
52k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
480
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Tell your own story through comics
letsgokoyo
1
1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Automating Front-end Workflow
addyosmani
1369
210k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
940
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
950
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