diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/input/tiers.js b/ghost/core/core/server/api/endpoints/utils/serializers/input/tiers.js index 2572829ff1..8fee3393ce 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/input/tiers.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/input/tiers.js @@ -1,4 +1,5 @@ const localUtils = require('../../index'); +const labs = require('../../../../../../shared/labs'); const forceActiveFilter = (frame) => { if (frame.options.filter) { @@ -22,6 +23,10 @@ function convertTierInput(input) { visibility: input.visibility }; + if (labs.isSet('freeTrial')) { + converted.trial_days = input.trial_days; + } + if (input.monthly_price && input.currency) { converted.monthly_price = { amount: input.monthly_price, diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js b/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js index 076d1ac362..182a946d29 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/output/tiers.js @@ -4,6 +4,7 @@ const debug = require('@tryghost/debug')('api:endpoints:utils:serializers:output const allowedIncludes = ['monthly_price', 'yearly_price']; const localUtils = require('../../index'); const utils = require('../../../../shared/utils'); +const labs = require('../../../../../../shared/labs'); module.exports = { browse: createSerializer('browse', paginatedTiers), @@ -69,6 +70,10 @@ function serializeTier(tier, options, frame) { benefits: null }; + if (labs.isSet('freeTrial')) { + serialized.trial_days = json.trial_days; + } + if (Array.isArray(json.benefits)) { serialized.benefits = json.benefits.map(benefit => benefit.name); } else { diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/tiers.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/tiers.test.js.snap index c30686cb8d..77b3ff8db5 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/tiers.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/tiers.test.js.snap @@ -21,6 +21,7 @@ Object { "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, "name": "Free", "slug": "free", + "trial_days": 0, "type": "free", "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "visibility": "public", @@ -34,6 +35,7 @@ Object { "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, "name": "Default Product", "slug": "default-product", + "trial_days": 0, "type": "paid", "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "visibility": "public", diff --git a/ghost/core/test/e2e-api/content/__snapshots__/tiers.test.js.snap b/ghost/core/test/e2e-api/content/__snapshots__/tiers.test.js.snap index 4bc3d7caff..a999968eef 100644 --- a/ghost/core/test/e2e-api/content/__snapshots__/tiers.test.js.snap +++ b/ghost/core/test/e2e-api/content/__snapshots__/tiers.test.js.snap @@ -21,6 +21,7 @@ Object { "id": StringMatching /\\[a-f0-9\\]\\{24\\}/, "name": "Free", "slug": "free", + "trial_days": 0, "type": "free", "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/, "visibility": "public", @@ -36,6 +37,7 @@ Object { "monthly_price": 1200, "name": "Default Product", "slug": "default-product", + "trial_days": 0, "type": "paid", "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}/, "visibility": "public", @@ -50,7 +52,7 @@ exports[`Tiers Content API Can request only active tiers 2: [headers] 1`] = ` Object { "access-control-allow-origin": "*", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "700", + "content-length": "730", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Accept-Encoding",