mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
breaking changes promisifying amazon payments
This commit is contained in:
@@ -92,7 +92,7 @@ describe('amazonPayments', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe.only('#executePayment', () => {
|
describe.only('#executePayment', () => {
|
||||||
it('succeeds', () => {
|
it('succeeds not as a gift', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('succeeds as a gift', () => {
|
it('succeeds as a gift', () => {
|
||||||
|
|||||||
11
test/api/v3/unit/libs/paymentsIndex.test.js
Normal file
11
test/api/v3/unit/libs/paymentsIndex.test.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
describe('payments/index', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#createSubscription', async () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#buyGems', async () => {
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
} from '../../../libs/api-v3/errors';
|
} from '../../../libs/api-v3/errors';
|
||||||
import amzLib from '../../../libs/api-v3/amazonPayments';
|
import amzLib from '../../../libs/api-v3/amazonPayments';
|
||||||
import { authWithHeaders } from '../../../middlewares/api-v3/auth';
|
import { authWithHeaders } from '../../../middlewares/api-v3/auth';
|
||||||
|
var payments = require('./index');
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
@@ -130,31 +131,22 @@ api.checkout = {
|
|||||||
|
|
||||||
await amzLib.closeOrderReference({ AmazonOrderReferenceId: orderReferenceId });
|
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);
|
res.respond(200);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
throw new BadRequest(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);
|
|
||||||
}, */
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ function revealMysteryItems (user) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: HEREHERE
|
||||||
|
api.createSubscription = async function createSubscription (data) {
|
||||||
|
}
|
||||||
api.createSubscription = function createSubscription (data, cb) {
|
api.createSubscription = function createSubscription (data, cb) {
|
||||||
let recipient = data.gift ? data.gift.member : data.user;
|
let recipient = data.gift ? data.gift.member : data.user;
|
||||||
let plan = recipient.purchased.plan;
|
let plan = recipient.purchased.plan;
|
||||||
@@ -150,6 +153,9 @@ api.cancelSubscription = function cancelSubscription (data, cb) {
|
|||||||
analytics.track('unsubscribe', analyticsData);
|
analytics.track('unsubscribe', analyticsData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// @TODO: HEREHERE
|
||||||
|
api.buyGems = async function buyGems (data) {
|
||||||
|
};
|
||||||
api.buyGems = function buyGems (data, cb) {
|
api.buyGems = function buyGems (data, cb) {
|
||||||
let amt = data.amount || 5;
|
let amt = data.amount || 5;
|
||||||
amt = data.gift ? data.gift.gems.amount / 4 : amt;
|
amt = data.gift ? data.gift.gems.amount / 4 : amt;
|
||||||
@@ -229,5 +235,4 @@ api.amazonSubscribeCancel = amazon.subscribeCancel;
|
|||||||
api.iapAndroidVerify = iap.androidVerify;
|
api.iapAndroidVerify = iap.androidVerify;
|
||||||
api.iapIosVerify = iap.iosVerify;
|
api.iapIosVerify = iap.iosVerify;
|
||||||
|
|
||||||
// module.exports = api;
|
module.exports = api;
|
||||||
module.exports = {}; // @TODO HEREHERE
|
|
||||||
|
|||||||
Reference in New Issue
Block a user