Skip to content

Commit

Permalink
fix: set product variant items and subscription plans accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
opedromiranda committed Nov 21, 2023
1 parent ea6fd28 commit d55fe21
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,60 +385,62 @@ export async function createOrUpdateItem(
} else {
delete variant.components
}
}

if (jsonVariant.subscriptionPlans) {
variant.subscriptionPlans = jsonVariant.subscriptionPlans.map((sP) => {
const meteredVariables = getSubscriptionPlanMeteredVariables({
planIdentifier: sP.identifier,
context,
})
if (jsonVariant.images) {
variant.images = await createImagesInput({
images: jsonVariant.images,
language,
context,
onUpdate,
})
}

return {
identifier: sP.identifier,
periods: sP.periods.map((p) => {
const id = getSubscriptionPlanPeriodId({
planIdentifier: sP.identifier,
periodName: p.name,
context,
})
// This causes an internal error at the API right now. Setting the value to an empty
// array has the same outcome as setting it to null
if (variant.images === null) {
variant.images = []
}

if (!id) {
throw new Error('Plan period id is null')
}

return {
id,
...(p.initial && {
initial: subscriptionPlanPrincingJsonToInput(
if (jsonVariant.subscriptionPlans) {
variant.subscriptionPlans = jsonVariant.subscriptionPlans.map((sP) => {
const meteredVariables = getSubscriptionPlanMeteredVariables({
planIdentifier: sP.identifier,
context,
})

return {
identifier: sP.identifier,
periods: sP.periods.map((p) => {
const id = getSubscriptionPlanPeriodId({
planIdentifier: sP.identifier,
periodName: p.name,
context,
})

if (!id) {
throw new Error('Plan period id is null')
}

return {
id,
...(p.initial && {
initial: subscriptionPlanPrincingJsonToInput(
p.initial,
meteredVariables
),
}),
recurring: subscriptionPlanPrincingJsonToInput(
),
}),
recurring: subscriptionPlanPrincingJsonToInput(
p.recurring,
meteredVariables
),
}
}),
}
})
}

if (jsonVariant.images) {
variant.images = await createImagesInput({
images: jsonVariant.images,
language,
context,
onUpdate,
})
}

// This causes an internal error at the API right now. Setting the value to an empty
// array has the same outcome as setting it to null
if (variant.images === null) {
variant.images = []
}
),
}
}),
}
})
}

return variant
}

Expand Down

0 comments on commit d55fe21

Please sign in to comment.