mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
* content: add gems blocks * gemsBlocks: include ios and android identifiers * wip: promo code * split common constants into multiple files * add second promo part * geCurrentEvent, refactor promo * fix lint * fix exports, use world state api * start adding world state tests * remove console.log * use gems block for purchases * remove comments * fix most unit tests * restore comment * fix lint * prevent apple/google gift tests from breaking other tests when stub is not reset * fix unit tests, clarify tests names * iap: use gift object when gifting gems * allow gift object with less data * fix iap tests, remove findById stubs * iap: require less data from the mobile apps * apply discounts * add missing worldState file * fix lint * add test event * start removing 20 gems option for web * start adding support for all gems packages on web * fix unit tests for apple, stripe and google * amazon: support all gems blocks * paypal: support all gems blocks * fix payments unit tests, add tests for getGemsBlock * web: add gems plans with discounts, update stripe * fix amazon and paypal clients, payments success modals * amazon pay: disabled state * update icons, start abstracting payments buttons * begin redesign * redesign gems modal * fix buttons * fix hover color for gems modal close icon * add key to world state current event * extend test event length * implement gems modals designs * early test fall2020 * fix header banner position * add missing files * use iso 8601 for dates, minor ui fixes * fix time zones * events: fix ISO8601 format * fix css indentation * start abstracting banners * refactor payments buttons * test spooky, fix group plans box * implement gems promo banners, refactor banners, fixes * fix lint * fix dates * remove unused i18n strings * fix stripe integration test * fix world state integration tests * the current active event * add missing unit tests * add storybook story for payments buttons component * fix typo * fix(stripe): correct label when gifting subscriptions
105 lines
2.9 KiB
JavaScript
105 lines
2.9 KiB
JavaScript
import shared from '../../../../common';
|
|
import {
|
|
authWithHeaders,
|
|
} from '../../../middlewares/auth';
|
|
import stripePayments from '../../../libs/payments/stripe';
|
|
|
|
const api = {};
|
|
|
|
/**
|
|
* @apiIgnore Payments are considered part of the private API
|
|
* @api {post} /stripe/checkout Stripe checkout
|
|
* @apiName StripeCheckout
|
|
* @apiGroup Payments
|
|
*
|
|
* @apiParam {String} id Body parameter - The token
|
|
* @apiParam {String} email Body parameter - the customer email
|
|
* @apiParam {String} gift Query parameter - stringified json object, gift
|
|
* @apiParam {String} sub Query parameter - subscription, possible values are:
|
|
* basic_earned, basic_3mo, basic_6mo, google_6mo, basic_12mo
|
|
* @apiParam {String} coupon Query parameter - coupon for the matching subscription,
|
|
* required only for certain subscriptions
|
|
*
|
|
* @apiSuccess {Object} data Empty object
|
|
* */
|
|
api.checkout = {
|
|
method: 'POST',
|
|
url: '/stripe/checkout',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
// @TODO: These quer params need to be changed to body
|
|
const token = req.body.id;
|
|
const { user } = res.locals;
|
|
const gift = req.query.gift ? JSON.parse(req.query.gift) : undefined;
|
|
const sub = req.query.sub ? shared.content.subscriptionBlocks[req.query.sub] : false;
|
|
const { groupId, coupon, gemsBlock } = req.query;
|
|
|
|
await stripePayments.checkout({
|
|
token, user, gemsBlock, gift, sub, groupId, coupon,
|
|
});
|
|
|
|
res.respond(200, {});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @apiIgnore Payments are considered part of the private API
|
|
* @api {post} /stripe/subscribe/edit Edit Stripe subscription
|
|
* @apiName StripeSubscribeEdit
|
|
* @apiGroup Payments
|
|
*
|
|
* @apiParam {String} id Body parameter - The token
|
|
*
|
|
* @apiSuccess {Object} data Empty object
|
|
* */
|
|
api.subscribeEdit = {
|
|
method: 'POST',
|
|
url: '/stripe/subscribe/edit',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
const token = req.body.id;
|
|
const { groupId } = req.body;
|
|
const { user } = res.locals;
|
|
|
|
await stripePayments.editSubscription({ token, groupId, user });
|
|
|
|
res.respond(200, {});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* @apiIgnore Payments are considered part of the private API
|
|
* @api {get} /stripe/subscribe/cancel Cancel Stripe subscription
|
|
* @apiName StripeSubscribeCancel
|
|
* @apiGroup Payments
|
|
* */
|
|
api.subscribeCancel = {
|
|
method: 'GET',
|
|
url: '/stripe/subscribe/cancel',
|
|
middlewares: [authWithHeaders()],
|
|
async handler (req, res) {
|
|
const { user } = res.locals;
|
|
const { groupId } = req.query;
|
|
|
|
await stripePayments.cancelSubscription({ user, groupId });
|
|
|
|
if (req.query.noRedirect) {
|
|
res.respond(200);
|
|
} else {
|
|
res.redirect('/');
|
|
}
|
|
},
|
|
};
|
|
|
|
api.handleWebhooks = {
|
|
method: 'POST',
|
|
url: '/stripe/webhooks',
|
|
async handler (req, res) {
|
|
await stripePayments.handleWebhooks({ requestBody: req.body });
|
|
|
|
return res.respond(200, {});
|
|
},
|
|
};
|
|
|
|
export default api;
|