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.