Stripe -- A way to transfer using source_transaction with paymentIntents

Viewed 403

I am trying get customer payment using PaymentIntents and if the status is succeeded, create transfers to the correct stripe connect account while using source_transaction.

payment.id in this case was pi_1I7xsjL98Injb3kNT74IwMK8 and I got the error No such charge: pi_1I7xsjL98Injb3kNT74IwMK8 which led to the resource_missing error. It makes sense since I am passing in a paymentIntents Id, but is there a way I could use source_transaction while using paymentIntents?

A sample of what I am doing in my code is below!

return stripe.paymentIntents.create({
            amount: data.amount,
            currency: data.currency,
            customer: stripeCustomerId,
            payment_method: data.paymentMethodId,
            off_session: false,
            confirm: true,
            confirmation_method: 'manual',
            setup_future_usage: 'off_session',
            // transfer_group: idempotencyKey
        }, { idempotencyKey })
    }).then(payment => {
       
        if (payment.status == 'succeeded') {        
            let transferPromises = []
            transferPromises.push(
                stripe.transfers.create({
                    amount: Math.ceil(payment.amount_received * 0.9),
                    currency: 'usd',
                    destination: creator.data().stripeConnectId,
                    source_transaction: payment.id,
                    // transfer_group: idempotencyKey,
                })
            )
1 Answers

Ok Found the answer. "When you fetch a PaymentIntent, you automatically get the latest Charge in the charges collection so you can access it via pi.charges.data[0] for example. You can also use the List Charges API and then get all charges related to a given PaymentIntent".

https://github.com/stripe/stripe-ruby/issues/927

Related