#svetidamir
1 messages · Page 1 of 1 (latest)
Hi, how can I help?
Hi, well I'm creating an app and I'm using the Stripe API.
I register the user, and then when he pays for the subscription on my application he is stored as a customer on Stripe.
In my app the user will be able also to buy additional items, and I created an product, price, retrieved my customer id, created an invoice, and an invoiceItem.
In my invoice i put collection_method: 'charge_automatically',
And when I check my stripe payment when I test it fails
It puts the invoince on incomplete
Could you please share the Invoice ID? in_xxx
But Invoice doesn't have a status of incomplete, maybe you're looking at a payment/PaymentIntent object?
in_1OPPNWJQTk4jQVYG7w12KYvG
Yes the payment is incomplete not the invoice it is my bad
ps. Maybe my code will help you to understand it better
export async function createInvoice(
customerId: string,
item: { description: string; amount: number; currency: string }
) {
try {
//Create Stripe Price
const price = await stripe.prices.create({
currency: 'usd',
unit_amount: item.amount,
product_data: {
name: 'Additional Gems',
},
});
// Create invoice for the customer with pending invoice items
const invoice = await stripe.invoices.create({
customer: customerId,
collection_method: 'charge_automatically',
});
const invoiceItem = await stripe.invoiceItems.create({
customer: customerId,
price: price.id,
invoice: invoice.id,
});
// Finalize the invoice to make it ready for payment
const finalizedInvoice = await stripe.invoices.finalizeInvoice(invoice.id);
return finalizedInvoice;
} catch (error) {
console.error(error);
throw error; // Propagate the error for the calling function to handle
}
}
I think it won't try to pay it automatically, unless you set auto_advance: true: https://stripe.com/docs/api/invoices/update#update_invoice-auto_advance
You can just call this method to pay it: https://stripe.com/docs/api/invoices/pay
oooh, didn't see that. I will try to setup the invoce-auto_advance
charge_automatically just says that we won't send the Invoice to the customer by email and wait until they pay it.
I see, thx for the help I successfully made the payment and get the return that the payment is successful
Happy to help.