0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-18 02:21:47 -05:00

Removed superfluous stripe api modules

no-issue

This removes the subscription api as we are using stripe checkout to
generate those

This removes the customers api as we no longer need the deterministic
api for it
This commit is contained in:
Fabien O'Carroll 2019-09-24 12:59:12 +07:00
parent 216ab072b4
commit 4dc42709c3
5 changed files with 1 additions and 98 deletions

View file

@ -1,12 +0,0 @@
const createDeterministicApi = require('./createDeterministicApi');
const isNotDeleted = x => !x.deleted;
const getCustomerAttr = ({email}) => ({email});
const getCustomerHashSeed = member => member.email;
module.exports = createDeterministicApi(
'customers',
isNotDeleted,
getCustomerAttr,
getCustomerHashSeed
);

View file

@ -1,6 +1,4 @@
module.exports = {
customers: require('./customers'),
products: require('./products'),
plans: require('./plans'),
subscriptions: require('./subscriptions')
plans: require('./plans')
};

View file

@ -1,11 +1,5 @@
const createStripeRequest = require('./createStripeRequest');
const createSource = createStripeRequest(function (stripe, customerId, stripeToken) {
return stripe.customers.createSource(customerId, {
source: stripeToken
});
});
const retrieve = createStripeRequest(function (stripe, resource, id) {
return stripe[resource].retrieve(id);
});
@ -19,7 +13,6 @@ const del = createStripeRequest(function (stripe, resource, id) {
});
module.exports = {
createSource,
retrieve,
create,
del

View file

@ -1,64 +0,0 @@
const customers = require('./customers');
const {del, create, createSource} = require('./stripeRequests');
function removeSubscription(stripe, member) {
return customers.get(stripe, member, member.email).then((customer) => {
// CASE customer has no subscriptions
if (!customer.subscriptions || customer.subscriptions.total_count === 0) {
throw new Error('Cannot remove subscription');
}
const subscription = customer.subscriptions.data[0];
return del(stripe, 'subscriptions', subscription.id);
});
}
function getSubscription(stripe, member) {
return customers.get(stripe, member, member.email).then((customer) => {
// CASE customer has either none or multiple subscriptions
if (!customer.subscriptions || customer.subscriptions.total_count !== 1) {
return {};
}
const subscription = customer.subscriptions.data[0];
// CASE subscription has multiple plans
if (subscription.items.total_count !== 1) {
return {};
}
const plan = subscription.plan;
return {
validUntil: subscription.current_period_end,
plan: plan.nickname,
amount: plan.amount,
status: subscription.status
};
}).catch(() => {
return {};
});
}
function createSubscription(stripe, member, metadata) {
return customers.ensure(stripe, member, member.email).then((customer) => {
if (customer.subscriptions && customer.subscriptions.total_count !== 0) {
throw new Error('Customer already has a subscription');
}
return createSource(stripe, customer.id, metadata.stripeToken).then(() => {
return create(stripe, 'subscriptions', {
customer: customer.id,
items: [{plan: metadata.plan.id}],
coupon: metadata.coupon
});
});
});
}
module.exports = {
create: createSubscription,
get: getSubscription,
remove: removeSubscription
};

View file

@ -69,16 +69,4 @@ module.exports = class StripePaymentProcessor {
return session;
}
async getSubscription(member) {
return api.subscriptions.get(this._stripe, member);
}
async removeSubscription(member) {
return api.subscriptions.remove(this._stripe, member);
}
async removeCustomer(member) {
return api.customers.remove(this._stripe, member);
}
};