forked from stripe-archive/stripe-payments-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory.js
39 lines (33 loc) · 1.15 KB
/
inventory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* inventory.js
* Stripe Payments Demo. Created by Romain Huet (@romainhuet)
* and Thorsten Schaeff (@thorwebdev).
*
* Simple library to store and interact with products stored on Stripe.
* These methods are using the Stripe Products API, but we tried to abstract them
* from the main code if you'd like to use your own product management system instead.
*/
'use strict';
const config = require('./config');
const stripe = require('stripe')(config.stripe.secretKey);
// For product retrieval and listing set API version to 2018-02-28 so that skus are returned.
stripe.setApiVersion('2018-02-28');
// List all products.
const listProducts = async () => {
return await stripe.products.list({limit: 3, type: 'good'});
};
// Retrieve a product by ID.
const retrieveProduct = async productId => {
return await stripe.products.retrieve(productId);
};
// Get shipping cost from config based on selected shipping option.
const getShippingCost = shippingOption => {
return config.shippingOptions.filter(
option => option.id === shippingOption
)[0].amount;
};
exports.products = {
list: listProducts,
retrieve: retrieveProduct,
getShippingCost,
};