mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Updated linkStripeCustomer to error rather than silently fail
no-issue This allows the importer to surface errors when linking members to customers
This commit is contained in:
parent
0a5f91f3d0
commit
d70aab83f6
@ -119,7 +119,8 @@ module.exports = function MembersApi({
|
|||||||
|
|
||||||
const users = Users({
|
const users = Users({
|
||||||
stripe,
|
stripe,
|
||||||
Member
|
Member,
|
||||||
|
StripeCustomer
|
||||||
});
|
});
|
||||||
|
|
||||||
async function sendEmailWithMagicLink({email, requestedType, tokenData, options = {forceEmailType: false}, requestSrc = ''}) {
|
async function sendEmailWithMagicLink({email, requestedType, tokenData, options = {forceEmailType: false}, requestSrc = ''}) {
|
||||||
|
@ -4,7 +4,8 @@ const common = require('../lib/common');
|
|||||||
|
|
||||||
module.exports = function ({
|
module.exports = function ({
|
||||||
stripe,
|
stripe,
|
||||||
Member
|
Member,
|
||||||
|
StripeCustomer
|
||||||
}) {
|
}) {
|
||||||
async function get(data, options) {
|
async function get(data, options) {
|
||||||
debug(`get id:${data.id} email:${data.email}`);
|
debug(`get id:${data.id} email:${data.email}`);
|
||||||
@ -127,6 +128,23 @@ module.exports = function ({
|
|||||||
await stripe.updateSubscriptionFromClient(subscriptionUpdate);
|
await stripe.updateSubscriptionFromClient(subscriptionUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function linkStripeCustomer(id, member, options) {
|
||||||
|
if (!stripe) {
|
||||||
|
throw new common.errors.BadRequestError({
|
||||||
|
message: 'Cannot link Stripe Customer without a Stripe connection'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const existingCustomer = await StripeCustomer.findOne({customer_id: id}, options);
|
||||||
|
|
||||||
|
if (existingCustomer) {
|
||||||
|
throw new common.errors.BadRequestError({
|
||||||
|
message: 'Cannot link Stripe Customer already associated with a member'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return stripe.linkStripeCustomer(id, member, options);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
create,
|
create,
|
||||||
update,
|
update,
|
||||||
@ -141,7 +159,7 @@ module.exports = function ({
|
|||||||
getStripeCustomer: safeStripe('getCustomer'),
|
getStripeCustomer: safeStripe('getCustomer'),
|
||||||
createStripeCustomer: safeStripe('createCustomer'),
|
createStripeCustomer: safeStripe('createCustomer'),
|
||||||
createComplimentarySubscription: safeStripe('createComplimentarySubscription'),
|
createComplimentarySubscription: safeStripe('createComplimentarySubscription'),
|
||||||
linkStripeCustomer: safeStripe('linkStripeCustomer'),
|
linkStripeCustomer,
|
||||||
linkStripeCustomerById
|
linkStripeCustomerById
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user