Stan Bondi
Stan Bondi

Reputation: 4616

Adding shipping to first subscription invoice using stripe

I am integrating stripe to enable the user to subscribe to a physical product shipping to the US and Canada.

I want to use the invoice.created webhook to modify the invoice and add a shipping charge depending on the delivery address.

The problem according to stripe docs is that the first invoice is charged immediately, implying that I cannot modify it prior to the first charge as I could with the subsequent.

If this is so, then the only way around this I believe is to add plans for us and canada for each of the subscription intervals e.g product-weekly-us, product-monthly-us, product-weekly-ca, product-monthly-ca instead of just product-monthly, product-weekly

The shipping would then be static (no line item) and part of the total.

Edit

So looking into invoices from koopajah's answer, here is what I can work out (please confirm):

  1. Create the invoice items for your customer (pending invoice items) - does this exclude the line item for the subscription?
  2. Create the subscription for the customer (which adds those pending invoice items to the new invoice for the subscription) - this will fire invoice.created webhook, which you would have to inspect and ignore - would you have to track the invoice numbers? **edit: oh wait! It would be closed, so you can just check that :D **
  3. All subsequent invoices are modified with the invoice.created webhook for open invoices

Upvotes: 2

Views: 1722

Answers (1)

koopajah
koopajah

Reputation: 25622

If you want to keep using Invoice Items you just have to create one for the first cycle before creating your user subscription. Then once the subscription is created the first invoice will be created and automatically pick up the Invoice Item for your current customer.

You can then create the next Invoice Items in the webhook as you planned to do.

EDIT: The steps would be something like that:

  1. Create a Customer with the Stripe token
  2. Create an Invoice Item for this customer for the shipping amount (not the subscription one)
  3. Create the subscription for this customer which will automatically add the Invoice Item created at step 2 to the total charge
    1. 6.... In the webhook "invoice.created" check whether the invoice is closed and if not repeat step 2 also adding the current invoice identifier to the invoice parameter

Upvotes: 7

Related Questions