summaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions/createCharge.js51
-rw-r--r--functions/createCharge.test.js23
-rw-r--r--functions/getPrice.js26
-rw-r--r--functions/index.js2
4 files changed, 0 insertions, 102 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);
- });
- });
-};
diff --git a/functions/createCharge.test.js b/functions/createCharge.test.js
deleted file mode 100644
index 65dde47..0000000
--- a/functions/createCharge.test.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const takeMoney = require('./createCharge');
-
-const event = {
- "data": {
- "user": "cj6ntm8qic3260140vkuzif9d",
- "token": "tok_visa",
- },
- "context": {
- "headers": {}
- }
-}
-
-
-describe('Take Money', () => {
-
- test('A charge has come back', async () => {
- const res = await takeMoney(event);
- console.log(res);
- expect(res.data.amount).toBeGreaterThanOrEqual(0);
- });
-
-});
-
diff --git a/functions/getPrice.js b/functions/getPrice.js
deleted file mode 100644
index 7808a85..0000000
--- a/functions/getPrice.js
+++ /dev/null
@@ -1,26 +0,0 @@
-require('isomorphic-fetch')
-
-const query = `
-query SingleItem {
- Item(id: "cj64bs7vuuqgu0116ul5cm223") {
- price
- }
-}
-`;
-
-function getItem(id) {
- return fetch('https://api.graph.cool/simple/v1/cj5xz8szs28930145gct82bdj', {
- method: 'post',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ query }),
- })
-}
-
-
-module.exports = function(event) {
- getItem().then(x => x.json()).then(res => {
- console.log(res.data.Item.price);
- }).catch(console.log)
-}
diff --git a/functions/index.js b/functions/index.js
deleted file mode 100644
index ee451f6..0000000
--- a/functions/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-module.exports = () => 'Welcome to Micro'
-exports.what = () => 'What'