アカウントでイベントが発生したときに通知を生成できます。これには Webhook を使用します。
これを行うためには、GeneXus で新しいプロシージャ―を作成します: メインプログラムと HTTP 呼び出しプロトコルです。
HTTPRequest 変数を使用して Stripe から送信されたデータを取得し、StripeEvent SDT にロードします。
ロードするとイベントタイプを取得できます。case コマンドを使用して通知を処理します。この例では、請求書に対する決済の成功と失敗をキャプチャして、処理します。 HTTPResponse を使用して String Response を追加できます。
&NotificationsLog.DateTime = now() &JSON = &HTTPRequest.ToString() &StripeEvent.FromJson(&JSON) ¶meters = &StripeEvent.type.SplitRegEx(!"\.") do case case ¶meters.Item(1) = "invoice" do case case ¶meters.Item(2) = "payment_succeeded" &StripeInvoice.FromJson(&StripeEvent.data.object) &NotificationsLog.Data = "Success: " + &StripeInvoice.ToJson()
case ¶meters.Item(2) = "payment_failed"
&StripeInvoice.FromJson(&StripeEvent.data.object)
&NotificationsLog.Data = "Failure: 「 + &StripeInvoice.ToJson()
endcase
endcase
&NotificationsLog.Insert()
commit
&Response = "OK"
&HTTPResponse.AddString(&Response)
重要な注記: Stripe が URL にアクセスできるように、クラウドにデプロイする必要があります。そうでない場合、Stripe にエラーコードが返され、通知は処理されません。
|