Dahamsta
Dahamsta

Reputation: 127

How to combine a subscription and single payments in one charge [Stripe API]?

In a purchase there might be a situation where a user may be purchasing both a subscription and some single payment items. If possible, I would like to process them as a single charge to avoid a potential situation, where the subscription succeeds and the single item purchase fails and other issues like that.

From what research I have done on this, there is no specific endpoint in the Stripe API for combining a subscription. The idea is to combine all the initial subscription and single purchase payments into a single payment intent and, once paid, to create subscriptions with trials and process individual payment items? Is this the approach to use currently or is there something newer / better, that I have missed?

Upvotes: 5

Views: 2531

Answers (1)

Nolan H
Nolan H

Reputation: 7409

You can do this be leveraging add_invoice_items when creating the Subscription:

curl https://api.stripe.com/v1/subscriptions \
  -u sk_test_123: \
  -d customer="{{ CUSTOMER_ID }}" \
  -d "items[0][price]={{ RECURRING_PRICE_ID }}" \
  -d "add_invoice_items[0][price]={{ PRICE_ID }}"

If you want to add extra one-time charge to future renewal invoices, you can create additional invoice items for that Customer (and Subscription).

Upvotes: 6

Related Questions