mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🐛 Fixed Stripe checkout session urls being invalid
refs https://github.com/TryGhost/Team/issues/1322 Since the Members service is no longer started when Stripe is reconfigured the url config used for checkout sessions was not updated. This moves all of the default Stripe urls into the Stripe service, where they will be updated as/when Stripe is connected/disconnected.
This commit is contained in:
parent
db6537fede
commit
f88b6bd02f
4 changed files with 48 additions and 39 deletions
|
@ -134,44 +134,18 @@ class MembersConfigProvider {
|
|||
return this.getActiveStripeKeys() !== null;
|
||||
}
|
||||
|
||||
getStripeUrlConfig() {
|
||||
const siteUrl = this._urlUtils.getSiteUrl();
|
||||
|
||||
const checkoutSuccessUrl = new URL(siteUrl);
|
||||
checkoutSuccessUrl.searchParams.set('stripe', 'success');
|
||||
const checkoutCancelUrl = new URL(siteUrl);
|
||||
checkoutCancelUrl.searchParams.set('stripe', 'cancel');
|
||||
|
||||
const billingSuccessUrl = new URL(siteUrl);
|
||||
billingSuccessUrl.searchParams.set('stripe', 'billing-update-success');
|
||||
const billingCancelUrl = new URL(siteUrl);
|
||||
billingCancelUrl.searchParams.set('stripe', 'billing-update-cancel');
|
||||
|
||||
return {
|
||||
checkoutSuccess: checkoutSuccessUrl.href,
|
||||
checkoutCancel: checkoutCancelUrl.href,
|
||||
billingSuccess: billingSuccessUrl.href,
|
||||
billingCancel: billingCancelUrl.href
|
||||
};
|
||||
}
|
||||
|
||||
getStripePaymentConfig() {
|
||||
if (!this.isStripeConnected()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const stripeApiKeys = this.getActiveStripeKeys();
|
||||
const urls = this.getStripeUrlConfig();
|
||||
|
||||
if (!stripeApiKeys) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
checkoutSuccessUrl: urls.checkoutSuccess,
|
||||
checkoutCancelUrl: urls.checkoutCancel,
|
||||
billingSuccessUrl: urls.billingSuccess,
|
||||
billingCancelUrl: urls.billingCancel,
|
||||
product: {
|
||||
name: this._settingsCache.get('stripe_product_name')
|
||||
},
|
||||
|
|
|
@ -6,8 +6,41 @@ const messages = {
|
|||
};
|
||||
|
||||
// @TODO Refactor to a class w/ constructor
|
||||
|
||||
/**
|
||||
* @typedef {object} StripeURLConfig
|
||||
* @prop {string} checkoutSessionSuccessUrl
|
||||
* @prop {string} checkoutSessionCancelUrl
|
||||
* @prop {string} checkoutSetupSessionSuccessUrl
|
||||
* @prop {string} checkoutSetupSessionCancelUrl
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
getConfig(settings, config, urlUtils) {
|
||||
/**
|
||||
* @returns {StripeURLConfig}
|
||||
*/
|
||||
function getStripeUrlConfig() {
|
||||
const siteUrl = urlUtils.getSiteUrl();
|
||||
|
||||
const checkoutSuccessUrl = new URL(siteUrl);
|
||||
checkoutSuccessUrl.searchParams.set('stripe', 'success');
|
||||
const checkoutCancelUrl = new URL(siteUrl);
|
||||
checkoutCancelUrl.searchParams.set('stripe', 'cancel');
|
||||
|
||||
const billingSuccessUrl = new URL(siteUrl);
|
||||
billingSuccessUrl.searchParams.set('stripe', 'billing-update-success');
|
||||
const billingCancelUrl = new URL(siteUrl);
|
||||
billingCancelUrl.searchParams.set('stripe', 'billing-update-cancel');
|
||||
|
||||
return {
|
||||
checkoutSessionSuccessUrl: checkoutSuccessUrl.href,
|
||||
checkoutSessionCancelUrl: checkoutCancelUrl.href,
|
||||
checkoutSetupSessionSuccessUrl: billingSuccessUrl.href,
|
||||
checkoutSetupSessionCancelUrl: billingCancelUrl.href
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {'direct' | 'connect'} type - The "type" of keys to fetch from settings
|
||||
* @returns {{publicKey: string, secretKey: string} | null}
|
||||
|
@ -61,9 +94,11 @@ module.exports = {
|
|||
|
||||
const webhookHandlerUrl = new URL('members/webhooks/stripe/', urlUtils.getSiteUrl());
|
||||
|
||||
const urls = getStripeUrlConfig();
|
||||
|
||||
return {
|
||||
secretKey: keys.secretKey,
|
||||
publicKey: keys.publicKey,
|
||||
...keys,
|
||||
...urls,
|
||||
enablePromoCodes: config.get('enableStripePromoCodes'),
|
||||
webhookSecret: webhookSecret,
|
||||
webhookHandlerUrl: webhookHandlerUrl.href
|
||||
|
|
|
@ -80,11 +80,11 @@
|
|||
"@tryghost/limit-service": "1.0.9",
|
||||
"@tryghost/logging": "2.0.3",
|
||||
"@tryghost/magic-link": "1.0.17",
|
||||
"@tryghost/members-api": "4.8.15",
|
||||
"@tryghost/members-api": "5.0.0",
|
||||
"@tryghost/members-importer": "0.5.0",
|
||||
"@tryghost/members-offers": "0.10.6",
|
||||
"@tryghost/members-ssr": "1.0.19",
|
||||
"@tryghost/members-stripe-service": "0.7.0",
|
||||
"@tryghost/members-stripe-service": "0.8.0",
|
||||
"@tryghost/metrics": "1.0.5",
|
||||
"@tryghost/minifier": "0.1.10",
|
||||
"@tryghost/mw-error-handler": "0.1.2",
|
||||
|
|
18
yarn.lock
18
yarn.lock
|
@ -1856,10 +1856,10 @@
|
|||
"@tryghost/domain-events" "^0.1.6"
|
||||
"@tryghost/member-events" "^0.3.4"
|
||||
|
||||
"@tryghost/members-api@4.8.15":
|
||||
version "4.8.15"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-4.8.15.tgz#75c2ad49ec93a73c50a2f8a6107084ba87df07cb"
|
||||
integrity sha512-yi2U6tJlAKFF2S1QXxlD2JI/xB7yYjtDswPIhsw9pL/zSVLSEWxv4Jbj8U84Oo6E+I6cR2jenn7qHE2yCXy84g==
|
||||
"@tryghost/members-api@5.0.0":
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-5.0.0.tgz#1726cc61726d6bc9cc55b702044b6e1dc4954481"
|
||||
integrity sha512-7U2Xd7VcRh3JCjyiE+qOFyx1LPLTdWpzt6oTrUOoyus33WolRKHbncu2lj1C98UYRsqrL3hxiPnuIghsOZXy5A==
|
||||
dependencies:
|
||||
"@nexes/nql" "^0.6.0"
|
||||
"@tryghost/debug" "^0.1.2"
|
||||
|
@ -1871,7 +1871,7 @@
|
|||
"@tryghost/member-events" "^0.3.4"
|
||||
"@tryghost/members-analytics-ingress" "^0.1.9"
|
||||
"@tryghost/members-payments" "^0.1.8"
|
||||
"@tryghost/members-stripe-service" "^0.7.0"
|
||||
"@tryghost/members-stripe-service" "^0.8.0"
|
||||
"@tryghost/tpl" "^0.1.2"
|
||||
"@types/jsonwebtoken" "^8.5.1"
|
||||
bluebird "^3.5.4"
|
||||
|
@ -1934,10 +1934,10 @@
|
|||
jsonwebtoken "^8.5.1"
|
||||
lodash "^4.17.11"
|
||||
|
||||
"@tryghost/members-stripe-service@0.7.0", "@tryghost/members-stripe-service@^0.7.0":
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/members-stripe-service/-/members-stripe-service-0.7.0.tgz#3e75d3fa554740ce639a4feda769a5563ae71ccf"
|
||||
integrity sha512-jBf56kG6vgBwTkA3wC2yIFblDPJ1J9D2iL3FUeyA1EOo6u5SYJixJu9y2xnAVD12rujzzuOx2A4vABTAPrcEfw==
|
||||
"@tryghost/members-stripe-service@0.8.0", "@tryghost/members-stripe-service@^0.8.0":
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@tryghost/members-stripe-service/-/members-stripe-service-0.8.0.tgz#a44e9af5dd577b9becacc2241a5fbd0043fd70fe"
|
||||
integrity sha512-7GZ+sTRxWomhNKzsvNwg5j3XUE4y062FZck7NKjWq4kZP7Vre7hAH3gMQl3E0qPEuqICcR9C4mM6lWE9zebkLA==
|
||||
dependencies:
|
||||
"@tryghost/debug" "^0.1.4"
|
||||
"@tryghost/errors" "1.2.0"
|
||||
|
|
Loading…
Reference in a new issue