mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Updated the validateSettings method to check stripe_plans
refs #11765 This ensures that plans will always be set to 1 of the currency
This commit is contained in:
parent
38fce4efc5
commit
f3b4a538af
1 changed files with 16 additions and 4 deletions
|
@ -272,19 +272,31 @@ function validateSchema(tableName, model, options) {
|
||||||
// Validation for settings
|
// Validation for settings
|
||||||
// settings are checked against the validation objects
|
// settings are checked against the validation objects
|
||||||
// form default-settings.json
|
// form default-settings.json
|
||||||
function validateSettings(defaultSettings, model) {
|
async function validateSettings(defaultSettings, model) {
|
||||||
const values = model.toJSON();
|
const setting = model.toJSON();
|
||||||
let validationErrors = [];
|
let validationErrors = [];
|
||||||
const matchingDefault = defaultSettings[values.key];
|
const matchingDefault = defaultSettings[setting.key];
|
||||||
|
|
||||||
if (matchingDefault && matchingDefault.validations) {
|
if (matchingDefault && matchingDefault.validations) {
|
||||||
validationErrors = validationErrors.concat(validate(values.value, values.key, matchingDefault.validations, 'settings'));
|
validationErrors = validationErrors.concat(validate(setting.value, setting.key, matchingDefault.validations, 'settings'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validationErrors.length !== 0) {
|
if (validationErrors.length !== 0) {
|
||||||
return Promise.reject(validationErrors);
|
return Promise.reject(validationErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setting.key === 'stripe_plans') {
|
||||||
|
const plans = JSON.parse(setting.value);
|
||||||
|
for (const plan of plans) {
|
||||||
|
// We check 100, not 1, because amounts are in fractional units
|
||||||
|
if (plan.amount < 100 && plan.name !== 'Complimentary') {
|
||||||
|
throw new errors.ValidationError({
|
||||||
|
message: 'Plans cannot have an amount less than 1'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue