From 34551d6435f4241d52131a948eb1bac75f6674ee Mon Sep 17 00:00:00 2001 From: JD Date: Fri, 27 Nov 2020 18:30:50 +0000 Subject: [PATCH] fixed promises example --- README.md | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7bc9779b06..9e47c98202 100644 --- a/README.md +++ b/README.md @@ -128,26 +128,29 @@ callback: // Create a new customer and then create an invoice item then invoice it: stripe.customers .create({ - email: 'foo-customer@example.com', + email: 'customer@example.com', }) .then((customer) => { - return stripe.invoiceItems.create({ - customer: 'cus_GcAjt5gZVAtChu', - amount: 2500, - currency: 'usd', - description: 'One-time setup fee', - }) - .then((invoiceItem) => { - return stripe.invoices.create({ - collection_method: 'send_invoice', - customer: invoiceItem.customer, - }); - }) - .then((invoice) => { - // New invoice created on a new customer - }) - .catch((err) => { - // Deal with an error + // have access to the customer object + return stripe.invoiceItems + .create({ + customer: customer.id, // set the customer id + amount: 2500, // 25 + currency: 'usd', + description: 'One-time setup fee', + }) + .then((invoiceItem) => { + return stripe.invoices.create({ + collection_method: 'send_invoice', + customer: invoiceItem.customer, + }); + }) + .then((invoice) => { + // New invoice created on a new customer + }) + .catch((err) => { + // Deal with an error + }); }); ```