I starting to check Stripe documentation to integrate the Stripe Billing Api in a Saas app. Things are not always the most straightforward, and it took a bit to understand that in the context of a Stripe subscription, the entity closest to a "transaction" is the Invoice, specifically the payment events associated with it—such as the Payment Intent and the resulting Charge. Here's why:
Subscription Lifecycle: A subscription in Stripe represents an ongoing agreement to charge a customer on a recurring basis. However, the subscription itself doesn't handle the actual financial transactions.
Invoice Generation: For each billing cycle of a subscription, Stripe generates an Invoice. The invoice details the amount owed, including subscription items, taxes, and discounts.
Payment Processing: When an invoice is finalized, Stripe creates a Payment Intent to process the payment. The Payment Intent encapsulates the payment flow and handles customer authentication if needed.
Charge Creation: Upon successful payment, a Charge object is created. This represents the actual transfer of funds from the customer account to application account.
In the JSON response provided in the stripe example, the latest_invoice field references the most recent invoice associated with the subscription:
"latest_invoice": "in_1MowQWLkdIwHu7ixuzkSPfKd"
To see the transaction details, we should retrieve this invoice and examine its payment_intent or charge:
Summary: In Stripe's subscription workflow, the Invoice—along with its associated Payment Intent and Charge—is the entity that most closely represents a transaction.
Example Workflow:
The above is the detailed content of How to retrieve the Transactions from Stripe. For more information, please follow other related articles on the PHP Chinese website!