# 非同期キャプチャー 非同期キャプチャーを使用して PaymentIntent 確定の高速化を有効にします。 非同期キャプチャーは、キャプチャー操作をバックグラウンドで実行することで、PaymentIntent の確定の遅延を短縮します。キャプチャーリクエストを行うと、システムは成功のレスポンスを受け取り、Stripe はバックエンドで支払いのキャプチャーを完了します。この PaymentIntent キャプチャーの高速化を使用するには、PaymentIntent の確定時に `capture_method=automatic_async` パラメーターを設定します。 ## 非同期キャプチャーを選択する 既存の実装をアップグレードして非同期キャプチャーのサポートを追加するには、PaymentIntent を作成する際に、キャプチャー方法として `automatic_async` を使用します。Stripe は最新バージョンの API でその機能をデフォルトで有効にしているため、`capture_method=automatic_async` パラメーターの指定は必須ではありません。 #### curl ```bash curl https://api.stripe.com/v1/payment_intents \ -u <>: \ -d amount=2000 \ -d currency=usd \ -d "payment_method_types[]"=card \ -d payment_method=pm_card_visa \-d capture_method=automatic_async \ -d confirm=true ``` 非同期キャプチャーを選択すると、API レスポンスと一部の Webhook は他のキャプチャー方法とは動作が異なるため、追加の変更が必要になる場合があります。 すべての支払いで、以下のオブジェクトの [balance_transaction](https://docs.stripe.com/api/balance_transactions.md) は `null` です。Connect の支払いの場合は、以下のオブジェクトの [transfer](https://docs.stripe.com/api/charges/object.md#charge_object-transfer) と [application_fee](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-application_fee_amount) も `null` です。 - API レスポンスの関連付けられた [Charge](https://docs.stripe.com/api/charges/object.md) オブジェクト - [charge.succeeded](https://docs.stripe.com/api/events/types.md#event_types-charge.succeeded) Webhook - [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) Webhook [charge.succeeded](https://docs.stripe.com/api/events/types.md#event_types-charge.succeeded) Webhook の変更された Charge オブジェクト: ```json # Charge Object { "id": "ch_123", "object": "charge", "amount_captured": 1000, # the capture has happened "application_fee_amount": 100, "captured": true,"balance_transaction": null, # object might not be created yet, might be shown as nil. "transfer": null, # object might not be created yet, might be shown as nil. "application_fee": null, # object might not be created yet, might be shown as nil. ... } ``` 変更された API レスポインスと [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) Webhook: ([API バージョン](https://docs.stripe.com/upgrades.md)によって異なります) #### API バージョン 2022-11-15 以降 ```json # PaymentIntent Object { "id": "pi_123", "object": "payment_intent", "capture_method": "automatic_async", "status": "succeeded","latest_charge": "ch_**" # if expanded, this is the Modified Charge object above } ``` ## Webhook をリッスンして、追加データが利用可能になったときに通知を受け取ります > charge.updated Webhook の SLA は、PaymentIntent が正常に確定されてから 1 時間後です。 非同期キャプチャーを使用する場合は、Webhook をリッスンして、最初は `null` であったオブジェクトのステータスを確認できます。 - [balance_transaction](https://docs.stripe.com/api/balance_transactions.md) を取得するには、[charge.updated](https://docs.stripe.com/api/events/types.md#event_types-charge.created) Webhook イベントに登録します。 - [application_fee](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-application_fee_amount) を取得するには、[application_fee.created](https://docs.stripe.com/api/events/types.md#event_types-application_fee.created) Webhook イベントに登録します。 - [transfer](https://docs.stripe.com/api/charges/object.md#charge_object-transfer) を取得するには、[transfer.created](https://docs.stripe.com/api/events/types.md#event_types-transfer.created) Webhook イベントに登録します。 非同期キャプチャーの Webhook ```json # charge.updated events { "data": { "id": "ch_123", "object": "charge", "amount": 100,"balance_transaction": "txn_123", # applicable to all charges. "transfer": "tr_123", # applicable to destination charge only. "application_fee": "fee_123", # applicable to destination charge only. ... }, previous_attributes: { "balance_transaction": null, # applicable to all charges. "transfer": null, # applicable to destination charge only. "application_fee": null, # applicable to destination charge only. } } ``` ```json # transfer.created events { "data": { "id": "tr_123", "object": "transfer", "amount": 1000, ... } } ``` ```json # application_fee.created events { "data": { "id": "fee_123", "object": "application_fee", "amount": 100, ... } } ```