diff options
| author | Wes Bos <wesbos@gmail.com> | 2017-10-27 13:24:41 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2017-10-27 13:24:41 -0400 |
| commit | 0f1b9240bbd05b377e868faf78b89b509a3d7537 (patch) | |
| tree | 1974b4d5a59f1843f64789b5536c32606a097ba0 /functions/createCharge.js | |
| parent | acdfa2840f867e686471a8e9ac3f29353fab7dd1 (diff) | |
ayeee
Diffstat (limited to 'functions/createCharge.js')
| -rw-r--r-- | functions/createCharge.js | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/functions/createCharge.js b/functions/createCharge.js deleted file mode 100644 index 8dee76b..0000000 --- a/functions/createCharge.js +++ /dev/null @@ -1,51 +0,0 @@ -const stripe = require('stripe')('sk_ycLkGc2cAaBDSCKkHiKVBeT71CMxd') -; -const endpoint = 'https://api.graph.cool/simple/v1/cj5xz8szs28930145gct82bdj'; - -require('isomorphic-fetch'); - -const getPrice = itemId => { - const query = ` - query SingleItem { - Item(id: "${itemId}") { - price - } - } - `; - - return fetch(endpoint, { - method: 'post', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ query }), - }); -}; - -const createStripeCharge = (token, amount) => stripe.charges.create({ - amount, - currency: 'usd', - description: `a test charge`, - source: token - }); - -module.exports = function(event) { - return new Promise((resolve, reject) => { - // first find out the price of the item - getPrice(event.data.itemId) - .then(res => res.json()) - .then(res => { - console.log(`Back with the price ${res.data.Item.price}!`); - return createStripeCharge(event.data.token, res.data.Item.price); - }) - .then(res => { - console.log(`Back! charge ${res.id} for the amount ${res.amount}`); - event.data.charge = res.id; - event.data.amount = res.amount; - resolve(event); - }) - .catch(err => { - reject(err); - }); - }); -}; |
