Amazon EventBridge で Stripe のイベントを受信させてみた
こんにちは、森田です。
はじめに
re:Invent 2023 で Amazon EventBridge の SaaS 統合で Stripe がサポートされていました。
以前までは、Stripe の SaaS 統合は、プライベートベータでの提供となっており、試すことができませんでした。
現在確認したところ、一般提供されているようでしたので、本記事では、実際に Stripe のイベントを EventBridge で受信できるところまで確認してみます。
やってみた
前提条件
Stripe側
今回は Stripe のサンドボックス環境を利用します。

サンドボックス環境は、既存の環境から切り離して Stripe 機能をテストする際に便利です。
AWS側
動作確認用のSNSトピックを準備します。

サブスクリプションには、メールアドレスを登録します。

ワークベンチの有効化
Stripe のダッシュボードの開発者ページからワークベンチの有効化を行います。

送信先の追加
ワークベンチの有効化を行うと、以下のような開発者用のページが開きます。

Webhookから「送信先を追加する」をクリックします。

送信するイベントを選択します。今回は、「checkout.session.completed」を選択します。

イベントの送信先には、「Amazon EventBridge」を選択します。

送信先の「AWSアカウントID」と「リージョン」を入力します。

作成完了後は、7日以内にAWSアカウント側で関連付けの作業が必要となります。

AWS マネジメントコンソールの確認
AWS マネジメントコンソールの EventBridgeのページから Stripe の関連付けを完了させます。
表示されているパートナーイベントソースをクリックします。

「イベントバスと関連付ける」をクリックします。

このアカウントのみで利用するため何も変更せずに、「関連付ける」をクリックします。

Stripeダッシュボードを確認すると、イベント送信先のイベントソースのステータスがActiveになります。

EventBridge ルールの作成
マネジメントコンソールから EventBridge ルールを作成します。
イベントバスには Stripe のパートナーイベントバスを選択します。

イベントパターンは、「すべてのイベント」とします。

ターゲットには、SNSトピックを選択して、ルールの作成を完了させます。

動作確認
Checkout URL の作成
Stripe のダッシュボードから「支払いを作成」をクリックします。

商品を追加して、「リンクを作成」をクリックします。

支払いを完了させる
作成したリンクを新しいタブで開きます。テストカードの番号を入力して、商品の支払いを完了させます。

メールの確認
SNSトピックに登録したメールアドレスにイベント情報が送信されます。

イベント(JSON)
{
"version": "0",
"id": "c20f530e-****-****-****-**********",
"detail-type": "checkout.session.completed",
"source": "aws.partner/stripe.com/ed_test_******************",
"account": "************",
"time": "2024-12-27T11:19:22Z",
"region": "ap-northeast-1",
"resources": [
"arn:aws:events:ap-northeast-1::event-source/aws.partner/stripe.com/ed_test_******************"
],
"detail": {
"id": "evt_******************",
"object": "event",
"api_version": "2024-12-18.acacia",
"created": 1735298361,
"data": {
"object": {
"id": "cs_test_**********************************",
"object": "checkout.session",
"adaptive_pricing": {
"enabled": true
},
"after_expiration": null,
"allow_promotion_codes": false,
"amount_subtotal": 120,
"amount_total": 120,
"automatic_tax": {
"enabled": false,
"liability": null,
"status": null
},
"billing_address_collection": "auto",
"cancel_url": "https://stripe.com",
"client_reference_id": null,
"client_secret": null,
"consent": null,
"consent_collection": {
"payment_method_reuse_agreement": null,
"promotions": "none",
"terms_of_service": "none"
},
"created": 1735298336,
"currency": "jpy",
"currency_conversion": null,
"custom_fields": [],
"custom_text": {
"after_submit": null,
"shipping_address": null,
"submit": null,
"terms_of_service_acceptance": null
},
"customer": null,
"customer_creation": "if_required",
"customer_details": {
"address": {
"city": null,
"country": "JP",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "*********",
"name": "******",
"phone": null,
"tax_exempt": "none",
"tax_ids": []
},
"customer_email": null,
"expires_at": 1735384735,
"invoice": null,
"invoice_creation": {
"enabled": false,
"invoice_data": {
"account_tax_ids": null,
"custom_fields": null,
"description": null,
"footer": null,
"issuer": null,
"metadata": {},
"rendering_options": null
}
},
"livemode": false,
"locale": "auto",
"metadata": {},
"mode": "payment",
"payment_intent": "pi_************************",
"payment_link": "plink_********************",
"payment_method_collection": "if_required",
"payment_method_configuration_details": {
"id": "pmc_*************************",
"parent": null
},
"payment_method_options": {
"card": {
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card",
"link"
],
"payment_status": "paid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"saved_payment_method_options": null,
"setup_intent": null,
"shipping_address_collection": null,
"shipping_cost": null,
"shipping_details": null,
"shipping_options": [],
"status": "complete",
"submit_type": "auto",
"subscription": null,
"success_url": "https://stripe.com",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"ui_mode": "hosted",
"url": null
}
},
"livemode": false,
"pending_webhooks": 0,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}
}
detail内は、Stripe側のイベントと同じ情報となっていそうですね。
さいごに
Stripe のイベントの送信先として EventBridge が利用できるのは非常に便利だと思っています。
例えば、AWSサービスと連携したいようなケースでは、EventBridgeにイベント情報を送信して、EventBridgeからStep Functions呼び出してAWSサービスを呼び出すようなこともできそうです。
そのため、従来であれば、Webhook イベントの受信には、コード・エンドポイントの作成が必須でしたが、EventBridgeに置き換えることでノーコード・ローコードで同様の処理が実現できるかもしれません。







