habitica-self-host/website/server/libs/payments/stripe/index.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

Stripe: upgrade module and API, switch to Checkout (#12785) * upgrade stripe module * switch stripe api to latest version * fix api version in tests * start upgrading client and server * client: switch to redirect * implement checkout session creation for gems, start implementing webhooks * stripe: start refactoring one time payments * working gems and gift payments * start adding support for subscriptions * stripe: migrate subscriptions and fix cancelling sub * allow upgrading group plans * remove console.log statements * group plans: upgrade from static page / create new one * fix #11885, correct group plan modal title * silence more stripe webhooks * fix group plans redirects * implement editing payment method * start cleaning up code * fix(stripe): update in-code docs, fix eslint issues * subscriptions tests * remove and skip old tests * skip integration tests * fix client build * stripe webhooks: throw error if request fails * subscriptions: correctly pass groupId * remove console.log * stripe: add unit tests for one time payments * wip: stripe checkout tests * stripe createCheckoutSession unit tests * stripe createCheckoutSession unit tests * stripe createCheckoutSession unit tests (editing card) * fix existing webhooks tests * add new webhooks tests * add more webhooks tests * fix lint * stripe integration tests * better error handling when retrieving customer from stripe * client: remove unused strings and improve error handling * payments: limit gift message length (server) * payments: limit gift message length (client) * fix redirects when payment is cancelled * add back "subUpdateCard" string * fix redirects when editing a sub card, use proper names for products, check subs when gifting
2020-12-14 14:59:17 +00:00
import stripeConstants from './constants';
import { handleWebhooks } from './webhooks'; // eslint-disable-line import/no-cycle
import { // eslint-disable-line import/no-cycle
createCheckoutSession,
createEditCardCheckoutSession,
} from './checkout';
import { // eslint-disable-line import/no-cycle
chargeForAdditionalGroupMember,
cancelSubscription,
} from './subscriptions';
import { setStripeApi } from './api';
const api = {};
api.constants = { ...stripeConstants };
api.setStripeApi = setStripeApi;
/**
* Allows for purchasing a user subscription, group subscription or gems with Stripe
*
* @param options
* @param options.user The user object who is purchasing
* @param options.gift The gift details if any
* @param options.gift The gem block object, if any
* @param options.sub The subscription data to purchase
* @param options.groupId The id of the group purchasing a subscription
* @param options.coupon The coupon code, if any
*
* @return undefined
*/
api.createCheckoutSession = createCheckoutSession;
/**
* Create a Stripe checkout session to edit a subscription payment method
*
* @param options
* @param options.user The user object who is making the request
* @param options.groupId If editing a group plan, its id
*
* @return undefined
*/
api.createEditCardCheckoutSession = createEditCardCheckoutSession;
/**
* Cancels a subscription created by Stripe
*
* @param options
* @param options.user The user object who is purchasing
* @param options.groupId The id of the group purchasing a subscription
* @param options.cancellationReason A text string to control sending an email
*
* @return undefined
*/
api.cancelSubscription = cancelSubscription;
/**
* Update the quantity for a group plan subscription on Stripe
*
* @param grouo The affected group object
*
* @return undefined
*/
api.chargeForAdditionalGroupMember = chargeForAdditionalGroupMember;
/**
* Handle webhooks from stripes
*
* @param options
* @param options.body The raw request body
* @param options.groupId The request's headers
*
* @return undefined
*/
api.handleWebhooks = handleWebhooks;
export default api;