0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed handling for Stripe connected members import

no issue

- When stripe is disconnected and there are Stripe-connected records present in imported set they should not be processed and proper error should be thrown
This commit is contained in:
Nazar Gargol 2020-08-20 17:08:19 +12:00
parent 4498b4624a
commit 2e769e3122
2 changed files with 18 additions and 7 deletions

View file

@ -70,6 +70,24 @@ const sanitizeInput = async (members) => {
invalidCount += invalidValidationCount;
const stripeIsConnected = membersService.config.isStripeConnected();
const hasStripeConnectedMembers = members.find(member => (member.stripe_customer_id || member.comped));
if (!stripeIsConnected && hasStripeConnectedMembers) {
let nonFilteredMembersCount = members.length;
members = members.filter(member => !(member.stripe_customer_id || member.comped));
const stripeConnectedMembers = (nonFilteredMembersCount - members.length);
if (stripeConnectedMembers) {
invalidCount += stripeConnectedMembers;
validationErrors.push(new errors.ValidationError({
message: i18n.t('errors.api.members.stripeNotConnected.message'),
context: i18n.t('errors.api.members.stripeNotConnected.context'),
help: i18n.t('errors.api.members.stripeNotConnected.help')
}));
}
}
const customersMap = members.reduce((acc, member) => {
if (member.stripe_customer_id && member.stripe_customer_id !== 'undefined') {
if (acc[member.stripe_customer_id]) {

View file

@ -153,8 +153,6 @@ function getMemberData({members, allLabelModels, importSetLabels, createdBy}) {
const importedLabels = importSetLabels.map(label => label.name);
const stripeIsConnected = membersService.config.isStripeConnected();
const invalidMembers = [];
const membersToInsert = [];
const stripeCustomersToFetch = [];
@ -162,11 +160,6 @@ function getMemberData({members, allLabelModels, importSetLabels, createdBy}) {
const labelAssociationsToInsert = [];
members.forEach(function (member) {
if ((member.stripe_customer_id || member.comped) && !stripeIsConnected) {
invalidMembers.push(member);
return;
}
// @TODO This is expensive, maybe we can just error if we get shoddy data?
for (let key in member) {
if (member[key] === 'undefined') {