From 578a768be2ed724e66a609051598e0dcb5852892 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Tue, 24 Dec 2019 11:56:34 -0800 Subject: [PATCH] Clarify async/await a bit --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f106c99a8..c41c213bc1 100644 --- a/README.md +++ b/README.md @@ -31,20 +31,30 @@ The package needs to be configured with your account's secret key which is available in your [Stripe Dashboard][api-keys]. Require it with the key's value: + ```js const stripe = require('stripe')('sk_test_...'); stripe.customers.create({ email: 'customer@example.com', -}); +}) + .then(customer => console.log(customer.id)) + .catch(error => console.error(error)); ``` -Or using ES modules, this looks more like: +Or using ES modules and `async`/`await`: ```js import Stripe from 'stripe'; const stripe = new Stripe('sk_test_...'); -//… + +(async () => { + const customer = await stripe.customers.create({ + email: 'customer@example.com', + }); + + console.log(customer.id); +})(); ``` ### Usage with TypeScript