rbi-learning / Today-I-Learned

1 stars 0 forks source link

Today I learned 08/17 #146

Open AlexandraCaplan opened 4 years ago

AlexandraCaplan commented 4 years ago

Today I learned about stripe

app.get('/products', async (_request, response) => {

const products = await stripe.products.list({ limit: 100, }); const prices = await stripe.prices.list({ limit: 100, });

prices.data.forEach(price => { const theAssociatedProduct = products.data.find( product => product.id === price.product ); theAssociatedProduct.price = price; });

const cleanedUpProducts = products.data.map(product => ({ name: product.name, description: product.description, image: product.images[0], category: product.metadata.category, currency: product.price.currency, price_cents: product.price.unit_amount, })); response.json(cleanedUpProducts); });

app.listen(3000, () => console.log(Server is on!));