1
votes

I have an existing customer in Stripe and we plan to add a subscription to the customer. First I want to add an invoice item so the subscription picks it up when created and adds it to the pending invoice. The code below is run in order, however, the invoice item in stripe is shown as paid immediately as opposed to added to the pending invoice on the subscription. The docs say I have it correct as far as I can tell, any idea why the invoice item is not added to the pending invoice?

try {
    \Stripe\InvoiceItem::create(
        array(
            "customer" => $customer['stripe_customer_id'],
            "amount" => $invoice_item_amount,
            "currency" => "usd",
            "description" => $product['description']
        )
    );
} catch(Error $e) {
    // do something
}

try {
    $result = $stripe_customerObj->subscriptions->create(
        array(
            "coupon"    => $coupon,
            "plan"      => $plan_id,
            "quantity"  => $quantity,
            "trial_end" => $trial_end_timestamp,
            "metadata"  => $metadata
        )
    );
} catch(Error $e) {
    // do something
}

It worked when I moved the InvoiceItem::create to after the creation of the subscription.

1

1 Answers

1
votes

This is expected behaviour. The code you have creates an invoice item and then a subscription with a trial. That trial creates a $0 invoice that automatically picks up the invoice item(s) pending including the one you just created. This is the flow you'd use if you wanted to charge a fee for a trial period for example.

If you want the pending invoice item added to the next invoice, you'd create it after the subscription instead.