diff --git a/test/api/v3/unit/libs/amazonPayments.test.js b/test/api/v3/unit/libs/amazonPayments.test.js index 9529c3e985..b2bf480e01 100644 --- a/test/api/v3/unit/libs/amazonPayments.test.js +++ b/test/api/v3/unit/libs/amazonPayments.test.js @@ -92,7 +92,7 @@ describe('amazonPayments', () => { }); describe.only('#executePayment', () => { - it('succeeds', () => { + it('succeeds not as a gift', () => { }); it('succeeds as a gift', () => { diff --git a/test/api/v3/unit/libs/paymentsIndex.test.js b/test/api/v3/unit/libs/paymentsIndex.test.js new file mode 100644 index 0000000000..74b9d29273 --- /dev/null +++ b/test/api/v3/unit/libs/paymentsIndex.test.js @@ -0,0 +1,11 @@ + +describe('payments/index', () => { + beforeEach(() => { + }); + + describe('#createSubscription', async () => { + }); + + describe('#buyGems', async () => { + }); +}); diff --git a/website/src/controllers/top-level/payments/amazon.js b/website/src/controllers/top-level/payments/amazon.js index 16c835c2c3..785efb06b9 100644 --- a/website/src/controllers/top-level/payments/amazon.js +++ b/website/src/controllers/top-level/payments/amazon.js @@ -12,6 +12,7 @@ import { } from '../../../libs/api-v3/errors'; import amzLib from '../../../libs/api-v3/amazonPayments'; import { authWithHeaders } from '../../../middlewares/api-v3/auth'; +var payments = require('./index'); let api = {}; @@ -130,31 +131,22 @@ api.checkout = { await amzLib.closeOrderReference({ AmazonOrderReferenceId: orderReferenceId }); + // execute payment + let giftUser = await User.findById(gift ? gift.uuid : undefined); + let data = { giftUser, paymentMethod: 'Amazon Payments' }; + let method = 'buyGems'; + if (gift) { + if (gift.type === 'subscription') method = 'createSubscription'; + gift.member = giftUser; + data.gift = gift; + data.paymentMethod = 'Gift'; + } + await payments[method](data); + res.respond(200); } catch(error) { throw new BadRequest(error); } - - /* - executePayment (cb) { - async.waterfall([ - function findUser (cb2) { - User.findById(gift ? gift.uuid : undefined, cb2); - }, - function executeAmazonPayment (member, cb2) { - let data = {user, paymentMethod: 'Amazon Payments'}; - let method = 'buyGems'; - - if (gift) { - if (gift.type === 'subscription') method = 'createSubscription'; - gift.member = member; - data.gift = gift; - data.paymentMethod = 'Gift'; - } - - payments[method](data, cb2); - }, */ - }, }; diff --git a/website/src/controllers/top-level/payments/index.js b/website/src/controllers/top-level/payments/index.js index 6c9ddea60d..6ee56bf0d2 100644 --- a/website/src/controllers/top-level/payments/index.js +++ b/website/src/controllers/top-level/payments/index.js @@ -36,6 +36,9 @@ function revealMysteryItems (user) { }); } +// @TODO: HEREHERE +api.createSubscription = async function createSubscription (data) { +} api.createSubscription = function createSubscription (data, cb) { let recipient = data.gift ? data.gift.member : data.user; let plan = recipient.purchased.plan; @@ -150,6 +153,9 @@ api.cancelSubscription = function cancelSubscription (data, cb) { analytics.track('unsubscribe', analyticsData); }; +// @TODO: HEREHERE +api.buyGems = async function buyGems (data) { +}; api.buyGems = function buyGems (data, cb) { let amt = data.amount || 5; amt = data.gift ? data.gift.gems.amount / 4 : amt; @@ -229,5 +235,4 @@ api.amazonSubscribeCancel = amazon.subscribeCancel; api.iapAndroidVerify = iap.androidVerify; api.iapIosVerify = iap.iosVerify; -// module.exports = api; -module.exports = {}; // @TODO HEREHERE +module.exports = api;