diff options
| author | Wes Bos <wesbos@gmail.com> | 2017-08-25 09:33:53 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2017-08-25 09:33:53 -0400 |
| commit | 7af74ff8988961c988f03c95961b70c2918521ae (patch) | |
| tree | d73cd0dd94751b76595b7febcae4162811c2040b /functions | |
| parent | 416c2cbae0e69b724876d232bf813eefd7550174 (diff) | |
yay
Diffstat (limited to 'functions')
| -rw-r--r-- | functions/createCharge.js | 19 | ||||
| -rw-r--r-- | functions/createCharge.test.js | 5 | ||||
| -rw-r--r-- | functions/getPrice.js | 8 |
3 files changed, 15 insertions, 17 deletions
diff --git a/functions/createCharge.js b/functions/createCharge.js index ecd22a1..215f8de 100644 --- a/functions/createCharge.js +++ b/functions/createCharge.js @@ -3,15 +3,15 @@ const graphCoolEndpoint = 'https://api.graph.cool/simple/v1/cj5xz8szs28930145gct require('isomorphic-fetch') -const query = ` -query SingleItem { - Item(id: "cj64bs7vuuqgu0116ul5cm223") { - price - } -} -`; +const getPrice = (itemId) => { + const query = ` + query SingleItem { + Item(id: "${itemId}") { + price + } + } + `; -const getPrice = (id) => { return fetch('https://api.graph.cool/simple/v1/cj5xz8szs28930145gct82bdj', { method: 'post', headers: { @@ -33,7 +33,7 @@ const createStripeCharge = (token, amount) => { module.exports = function(event) { return new Promise((resolve, reject) => { // first find out the price of the item - getPrice() + getPrice(event.data.itemId) .then(res => res.json()) .then(res => { console.log(`Back with the price ${res.data.Item.price}!`); @@ -43,7 +43,6 @@ module.exports = function(event) { console.log(`Back! charge ${res.id} for the amount ${res.amount}`); event.data.charge = res.id; event.data.amount = res.amount; - console.log(event.data); resolve(event); }) .catch(err => { diff --git a/functions/createCharge.test.js b/functions/createCharge.test.js index 18e13ba..65dde47 100644 --- a/functions/createCharge.test.js +++ b/functions/createCharge.test.js @@ -2,11 +2,8 @@ const takeMoney = require('./createCharge'); const event = { "data": { - "amount": 5, - "createdAt": "2017-08-08T19:48:39.436Z", - "id": "cj6400x3g00003i5zufoucron", + "user": "cj6ntm8qic3260140vkuzif9d", "token": "tok_visa", - "updatedAt": "2017-08-08T19:48:39.436Z" }, "context": { "headers": {} diff --git a/functions/getPrice.js b/functions/getPrice.js index 61c29e6..7808a85 100644 --- a/functions/getPrice.js +++ b/functions/getPrice.js @@ -18,7 +18,9 @@ function getItem(id) { }) } -getItem().then(x => x.json()).then(res => { - console.log(res.data.Item.price); -}).catch(console.log) +module.exports = function(event) { + getItem().then(x => x.json()).then(res => { + console.log(res.data.Item.price); + }).catch(console.log) +} |
