Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe API v3: When to use Invoice vs PaymentIntent (Node SDK)

I've been reading Stripe's api documentation (v3) and it's not apparent to me when to use Stripe's Invoice vs PaymentIntent objects. From reading the documentation, here's what I understand:

  • Stripe sees payment intents being the primary way of facilitating payments through their API going forward and Charges will be deprecated at some point.

  • Processing an Invoice creates a PaymentIntent under the hood and and initiates payment right away. What I don't understand is why is there no destination account field for the Invoice? If the Invoice is defaulted to be sent to the platform's Stripe account (this is an assumption I am making since there is no destination field), why there is an application_fee_amount field which is essentially the platform's "cut" of the transaction?

  • A PaymentIntent allow you to specify a destination account while taking an "application" or "platform" fee so you don't have to generate a transfer yourself.

    • A PaymentIntent and Invoice can be processed at time of creation or deferred until later in your payment lifecycle.

My use case requires me to conduct payments between two parties and take a "platform fee" for each transaction. I have successfully done this by creating a PaymentIntent and using the connected Customer account's credit card on file and populating the transfer_data field with the amount to send to the 2nd party involved in the transaction.

I started looking into Stripe's invoicing api since I am planning on building an invoicing solution for my platform and thought it'd be best to leverage what Stripe has to offer, but I'm failing to see a benefit for me to leverage it since I also need to keep track of transaction ids for the payment intents and taxes based on zip code (it looks like Stripe doesn't do this automatically so I might be out of luck here).

I couldn't find a way to get a transactionId for processing an Invoice but I see that the chargeId gets returned as part of the response when you confirm a PaymentIntent (https://stripe.com/docs/api/payment_intents/confirm).

So the questions I have are:

  1. Why is there no destination account field for the Invoice? Does it automatically get send to the platform's Stripe account and require you to manually create a transfer?
  2. Is there an easy way to get a transactionId from an Invoice?
  3. Is there a way to get a transactionId when creating a PaymentIntent and setting the confirm=true so the PaymentIntent gets processed immediately?
  4. For a platform that will have an invoicing flow and facilitate transactions on behalf of two parties, is it recommended to use payment intents, invoicing, or both?
  5. What's the difference between a charge and transaction? When paying an Invoice, a charge id gets returned in the response but when paying a payment intent, a transaction id gets returned.

Thanks in advance!

like image 328
Scott Avatar asked Apr 04 '20 19:04

Scott


People also ask

What is PaymentIntent in stripe?

The PaymentIntent encapsulates details about the transaction, such as the supported payment methods, the amount to collect, and the desired currency.

What is clientSecret in stripe?

From Stripe Docs. clientSecret: The client secret of this PaymentIntent. Used for client-side retrieval using a publishable key. The client secret can be used to complete a payment from your frontend. It should not be stored, logged, embedded in URLs, or exposed to anyone other than the customer.

How does payment Intent work stripe?

Once required actions are handled, the PaymentIntent moves to processing . While for some payment methods (for example, cards) processing can be quick, other types of payment methods can take up to a few days to process. A PaymentIntent with a status of succeeded means that the payment flow it is driving is complete.


1 Answers

You can think of invoices as subsets of payment intent, kind of the same way subscriptions are subsets of invoices.

What I don't understand is why is there no destination account field for the Invoice?

Actually there is one, but the field is transfer_data[destination]. Also, note that whenever an invoice is finalized, it will contain a payment intent, which is expandable, and with which you should be able to solve most of the issues you rose in your question.
To sum up:

  1. Yes there is, as explained above.
  2. Expand the invoice's payment intent object.
  3. I'm not used to work with transactions, but I guess you could leverage their metadata to reference your invoice or vice verse to help you retrieve the need object in needed time.
  4. As explained above, their is not dichotomy between those, if your invoicing your clients, the you should use stripe's invoicing system.
  5. From what I see in the docs, transactions only concern purchase 'internal' to stripe, with issued cards. Charges are the attempts stripe will make to charge your bank account through the network, when a charge succeeds, the payment intent status is set to succeeded otherwise the payment intent might attempt more charges or stop trying at some point, and the payment intent will be set to canceled more about payment intent statuses here. In short payment intents are a subset of charges.

I hope this helped and didn't come too late, the answer might still be improve in the future, if others edit it or as I will learn more about stripe's issuing product.
like image 186
Alan Kersaudy Avatar answered Oct 18 '22 17:10

Alan Kersaudy