-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fixed Tips & Donations checkout error for sites with long titles
ref https://linear.app/tryghost/issue/ONC-296 Our `stripe_prices.nickname` field had a length of 50 chars which meant we could error out trying to save a donation Stripe price with a generated product nickname containing a long site title. - updated db schema and added a migration to change column length to 255 - added truncation to nickname generation to enforce a limit of 250 chars to match Stripe's limit
- Loading branch information
1 parent
b2d7922
commit 0130413
Showing
6 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...data/migrations/versions/5.93/2024-09-03-18-51-01-update-stripe-prices-nickname-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const logging = require('@tryghost/logging'); | ||
const {createNonTransactionalMigration} = require('../../utils'); | ||
const DatabaseInfo = require('@tryghost/database-info'); | ||
|
||
module.exports = createNonTransactionalMigration( | ||
async function up(knex) { | ||
if (DatabaseInfo.isSQLite(knex)) { | ||
logging.warn('Skipping migration for SQLite3'); | ||
return; | ||
} | ||
logging.info('Changing stripe_prices.nickname column from VARCHAR(50) to VARCHAR(255)'); | ||
await knex.schema.alterTable('stripe_prices', function (table) { | ||
table.string('nickname', 255).alter(); | ||
}); | ||
}, | ||
async function down() { | ||
logging.warn('Not changing stripe_prices.nickname column'); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,7 @@ describe('Create Stripe Checkout Session for Donations', function () { | |
assert.equal(lastDonation.get('attribution_type'), 'post'); | ||
assert.equal(lastDonation.get('attribution_url'), url); | ||
}); | ||
|
||
it('check if donation message is in email', async function () { | ||
const post = await getPost(fixtureManager.get('posts', 0).id); | ||
const url = urlService.getUrlByResourceId(post.id, {absolute: false}); | ||
|
@@ -281,4 +282,51 @@ describe('Create Stripe Checkout Session for Donations', function () { | |
text: /You are the best! Have a lovely day!/ | ||
}); | ||
}); | ||
|
||
// We had a bug where the stripe_prices.nickname column was too short for the site title | ||
// Stripe is also limited to 250 chars so we need to truncate the nickname | ||
it('can create a checkout session for a site with a long title', async function () { | ||
// Ensure site title is longer than 250 characters | ||
mockManager.mockSetting('title', 'a'.repeat(251)); | ||
|
||
// clear out existing prices to guarantee we're creating a new one | ||
await models.StripePrice.where('type', 'donation').destroy().catch((e) => { | ||
if (e.message !== 'No Rows Deleted') { | ||
throw e; | ||
} | ||
}); | ||
|
||
// Fake a visit to a post | ||
const post = await getPost(fixtureManager.get('posts', 0).id); | ||
const url = urlService.getUrlByResourceId(post.id, {absolute: false}); | ||
|
||
await membersAgent.post('/api/create-stripe-checkout-session/') | ||
.body({ | ||
customerEmail: '[email protected]', | ||
type: 'donation', | ||
successUrl: 'https://example.com/?type=success', | ||
cancelUrl: 'https://example.com/?type=cancel', | ||
metadata: { | ||
test: 'hello', | ||
urlHistory: [ | ||
{ | ||
path: url, | ||
time: Date.now(), | ||
referrerMedium: null, | ||
referrerSource: 'ghost-explore', | ||
referrerUrl: 'https://example.com/blog/' | ||
} | ||
] | ||
} | ||
}) | ||
.expectStatus(200) | ||
.matchBodySnapshot(); | ||
|
||
const latestStripePrice = await models.StripePrice | ||
.where('type', 'donation') | ||
.orderBy('created_at', 'DESC') | ||
.fetch({require: true}); | ||
|
||
latestStripePrice.get('nickname').should.have.length(250); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters