From 7af74ff8988961c988f03c95961b70c2918521ae Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 25 Aug 2017 09:33:53 -0400 Subject: yay --- functions/createCharge.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'functions/createCharge.js') 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 => { -- cgit v1.3