DEV Community

Cover image for How to retrieve the Transactions from Stripe
websilvercraft
websilvercraft

Posted on β€’ Edited on

How to retrieve the Transactions from Stripe

Image description

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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"
Enter fullscreen mode Exit fullscreen mode

To see the transaction details, we should retrieve this invoice and examine its payment_intent or charge:

  • Payment Intent: Contains the payment flow information, including status, amount, and payment method.
  • Charge: Represents the finalized payment transaction and includes details like the amount, currency, and receipt URL.

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:

  1. Subscription (sub_...): Manages the recurring billing agreement.
  2. Invoice (in_...): Generated for each billing cycle; itemizes charges.
  3. Payment Intent (pi_...): Initiated to collect payment for the invoice.
  4. Charge (ch_...): Created upon successful payment; represents the transaction.

πŸš€ Interested to learn more πŸ› οΈπŸ€–πŸ’»? Then don't forget to πŸ“¬βœ‰οΈ, πŸ‘‡

πŸš€ If you are interested in learning more about programming, πŸ› οΈ building applications, or in general about AI πŸ€– and tech πŸ’», you can subscribe to my newsletter at websilvercraft.substack.com βœ‰οΈ to get the posts delivered directly to you as soon as I publish them! πŸ“¬
β €β €β € β €β €β €β € β €β € β €πŸ‘†πŸ‘†πŸ‘†πŸ‘†
β €β €β €β €β €β €β €β € πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†
β € β € πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†
πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (1)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay