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
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
720
コミュニティ運営から 中の人に変わって感じたこと
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
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
230
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
280
Deep dive into the select statement (GopherCon UK)
jespino
0
170
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
6
3.4k
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
280
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
470
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
910
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
130
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
2
260
Featured
See All Featured
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Visualization
eitanlees
152
17k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
510
The Spectacular Lies of Maps
axbom
PRO
1
990
Fireside Chat
paigeccino
43
4k
Done Done
chrislema
186
16k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
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