0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

stripe apiのsubscription挙動確認ドキュメント

Last updated at Posted at 2021-05-18

このドキュメントの目的

stripe apiの挙動を調べてまとめたもの

subscriptionの決済の流れ

  • Stripe::Checkout::Session.createで決済ページと決済完了後のページを指定
  • 決済ページで決済が完了するとcheckout.session.completedイベントがwebhookで飛ばされる
    • ここではsubscriptionまでが生成されている
  • その後invoice.createdが飛ばされる
  • 更にその後invoice.paidが飛ばされる。ここでpayment_intent_idが飛ぶ

Stripe::Checkout::Session.create

stripeのcheckoutを使用する際にcheckoutページを作成するのに必要。これで下記を行っている。

  • 決済ページのsessionを作成。ここでjsonを返し、redirectToCheckoutにわたし、決済ページに行ける
  • この処理はページに飛ばすところまでなので決済の完了などは行ってない

checkout.session.completed

  • 決済完了のイベント
  • 継続課金の場合、subscription_idが飛ぶ
  • ここで支払い、invoiceまでは発生していない

返ってくるevent

返ってくるeventのjsonの情報が1回目と2回目で違う。subscription_idは一回目のみ発行で2回目は送られない

invoice.created

  • invoiceの作成でここではpayment_intent_idは送られない

invoice.paid

  • ここでpayment_intent_idが送られる
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?