Stripe
ts
import { Hibiki } from "@hibiki-js/core"
import { stripe } from "@hibiki-js/stripe"
const app = new Hibiki().use(stripe({
secret: process.env.STRIPE_WEBHOOK_SECRET!,
tolerance: 300,
}))署名検証は Web Crypto の HMAC-SHA256 を使い、Stripe SDK には依存しません。その他の Stripe イベントはデフォルトで 200(strictEvents: true なら 400)です。
data.objectを持つsnapshotイベントに対応しています。thinイベントは対象外です。型は構造の一部を定義したもので、完全なSDKの型や業務データの実行時検証は提供しません。Checkout Sessionの金額・決済状態・metadata・customer、PaymentIntentとCustomerの主要フィールドに型があります。古いpayloadや小さなテストデータも扱えるよう、追加フィールドは省略可能です。その他はunknownのため、業務に必要な値を明示的に検証してください。StripeのAPIバージョンは固定していません。イベントのapi_versionがpayloadのバージョンを表します。
stripeEventsから、導入したパッケージの対応イベント一覧を取得できます。対応範囲のJSONにもパッケージバージョンと形式を載せています。
対応イベント
Checkout
checkout.session.completedcheckout.session.expiredcheckout.session.async_payment_succeededcheckout.session.async_payment_failed
PaymentIntent
payment_intent.succeededpayment_intent.payment_failedpayment_intent.canceledpayment_intent.requires_actionpayment_intent.processingpayment_intent.partially_funded
Invoice
invoice.paidinvoice.payment_failedinvoice.payment_action_requiredinvoice.finalizedinvoice.upcominginvoice.created
Customer / Subscription
customer.createdcustomer.updatedcustomer.deletedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedcustomer.subscription.pausedcustomer.subscription.resumedcustomer.subscription.trial_will_end
Charge / Dispute / Refund / PaymentMethod
charge.succeededcharge.failedcharge.refundedcharge.dispute.createdcharge.dispute.updatedcharge.dispute.closedrefund.createdrefund.updatedrefund.failedpayment_method.attachedpayment_method.detached
SetupIntent
setup_intent.succeeded
ハンドラは stripe. プレフィックスで登録します。
ts
app.on("stripe.payment_intent.succeeded", async ({ event }) => {
console.log(event.data.object.id)
})オプションと型の詳細は API リファレンス を参照してください。
