Search code examples
pythonapistripe-paymentspayment

Stripe: batch multiple transactions from one customer into a single charge and optimise micropayments


My use case is the following, users have to buy items one by one in my app and at the end of the day I'll capture the payments of all transactions previously made.

Problem is that Stripe charge 2.9% + 30 cents for each transaction and I'd like to optimise that.

As written here https://support.stripe.com/questions/batch-multiple-transactions-from-one-customer-into-a-single-charge and here Batching Transactions in Stripe it seems like it's possible to batch the transactions from one customer into a single charge.

My question is what is the best way to implement it? I need each transaction to be confirmed so I can lock the amount to capture it later. Also one user can use different credit card for each transactions (as far as I understood if the card is different then it's not possible to batch the transactions). I tried creating a PaymentIntent and updating it after each transaction (same card same user) but I got this error:

This PaymentIntent's amount could not be updated because it has a status of requires_capture. You may only update the amount of a PaymentIntent with one of the following statuses: requires_payment_method, requires_confirmation, requires_action.

So since the PaymentIntent flow doesn't seem to be the answer to my problem the other option would be to create a subscription. But I don't really understand how I can make it act as a single charge without the recurring option and it seems like it would be limited to maximum 20 items (that I would have to create using Price and Product API) https://stripe.com/docs/api/subscriptions/create

Thank you in advance!


Solution

  • I tried creating a PaymentIntent and updating it after each transaction (same card same user) but I got this error:

    That's because you're updating it after you charged the customer(you must have confirmed the PaymentIntent — that charges the payment method attached for whatever the current amount is). After a charge is authorised you can't do anything more except create a new PaymentIntent (which is a new charge and new processing fee).

    I need each transaction to be confirmed so I can lock the amount to capture it later

    That's not possible on Stripe, if you 'confirm' (authorize) a charge on the customer's card, that incurs the processing fee. So the alternative is you just store up the amounts 'virtually' and then make one big authorisation, that's what the links are describing.

    Your idea is fine though, just update the amount of the PaymentIntent throughout the day. Once you are satisfied that you have counted all the transactions you want to charge for in your batch payment, call the confirm API to authorise the charge for that total amount.

    For the subscription case, there's no 20-item limit(that's something else, for the number of recurring items you bill for in a single invoice). Creating invoice items is just adding a dynamic line item for a specific amount and there's no limit on those.