简体   繁体   中英

Capture Stripe Payment Intent

I am trying to capture a payment intent I have previously created. The payment intent has been set up and confirmed and I am now looking to complete the payment intent with the final amount and transfer the money to a stripe connect user.

  const intent = await stripe.paymentIntents.capture({
    id: paymentIntentId,
    amount_to_capture: finalAmount,
    transfer_data:{destination: connectedAccountId,},
  });

The above code snippet is what I have so far, I know this is the correct method but I'm getting the following error:

Error: Stripe: Argument "intent" must be a string, but got: [object Object]

It must be to do with how I'm assigning the connect account id. reading the stripe api docs I need to pass the connect account id to the destination field of transfer data.

How should I be passing that in to the nested destination field. My syntax must be wrong.

Here is the stripe documentation for capturing a payment:

Stripe Capture Payment API Documentation

Any help is greatly appreciated.

Are you sure paymentIntentId is in fact an id as a string? From the error, it sounds like this might be a payment intent object and you'd need to use something like paymentIntent.id instead. ( paymentIntentId.id as a quick correction, but you should rename the variable to represent its contents).

Double check the value of paymentIntentId -- it's probably different than you expect.

Update : This is due to a misreading of the syntax. The payment intent id is the first argument as a string, with the options in an object as a second argument. So then this is what you need:

const intent = await stripe.paymentIntents.capture(
  paymentIntentId,
  {
    amount_to_capture: finalAmount,
    transfer_data: { destination: connectedAccountId, },
  }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM