diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-01-30 12:41:01 -0500 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-01-30 12:41:01 -0500 |
| commit | cd0b07b3adb36fb5ec098f9e511ab45d774fee7b (patch) | |
| tree | a203e5010219ccea1acc6bbd2c0a4bcfa0a78615 /graphcool-old/src/createCharge.js | |
| parent | 0a1648bf47490b312169c531aeb51ef4725e8d2e (diff) | |
Move to Prisma Backend
Diffstat (limited to 'graphcool-old/src/createCharge.js')
| -rw-r--r-- | graphcool-old/src/createCharge.js | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/graphcool-old/src/createCharge.js b/graphcool-old/src/createCharge.js deleted file mode 100644 index ccf9c11..0000000 --- a/graphcool-old/src/createCharge.js +++ /dev/null @@ -1,52 +0,0 @@ -const stripe = require('stripe')('sk_ycLkGc2cAaBDSCKkHiKVBeT71CMxd'); - -const endpoint = 'https://api.graph.cool/simple/v1/cj99zm6ye06sb01325ic751ww'; - -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); - }); - }); -}; |
