mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Mapped Stripe Product name to Product name
closes https://github.com/TryGhost/Team/issues/682 This ensures that the Stripe Product name is updated during the migrations of an existing site and any future updates to the Product name.
This commit is contained in:
parent
15b535fd45
commit
d32e44c73b
3 changed files with 27 additions and 4 deletions
|
@ -127,11 +127,11 @@ module.exports = class StripeMigrations {
|
||||||
|
|
||||||
if (!defaultStripeProduct) {
|
if (!defaultStripeProduct) {
|
||||||
this._logging.info('Could not find Stripe Product - creating one');
|
this._logging.info('Could not find Stripe Product - creating one');
|
||||||
const stripeProduct = await this._stripeAPIService.createProduct({
|
|
||||||
name: 'Ghost Product'
|
|
||||||
});
|
|
||||||
const productsPage = await this._Product.findPage({limit: 1});
|
const productsPage = await this._Product.findPage({limit: 1});
|
||||||
const defaultProduct = productsPage.data[0];
|
const defaultProduct = productsPage.data[0];
|
||||||
|
const stripeProduct = await this._stripeAPIService.createProduct({
|
||||||
|
name: defaultProduct.get('name')
|
||||||
|
});
|
||||||
if (!defaultProduct) {
|
if (!defaultProduct) {
|
||||||
this._logging.error('Could not find Product - skipping stripe_plans -> stripe_prices migration');
|
this._logging.error('Could not find Product - skipping stripe_plans -> stripe_prices migration');
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -176,7 +176,7 @@ class ProductRepository {
|
||||||
|
|
||||||
if (!product.related('stripeProducts').first()) {
|
if (!product.related('stripeProducts').first()) {
|
||||||
const stripeProduct = await this._stripeAPIService.createProduct({
|
const stripeProduct = await this._stripeAPIService.createProduct({
|
||||||
name: productData.name
|
name: product.get('name')
|
||||||
});
|
});
|
||||||
|
|
||||||
await this._StripeProduct.add({
|
await this._StripeProduct.add({
|
||||||
|
@ -185,6 +185,13 @@ class ProductRepository {
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
await product.related('stripeProducts').fetch(options);
|
await product.related('stripeProducts').fetch(options);
|
||||||
|
} else {
|
||||||
|
if (product.attributes.name !== product._previousAttributes.name) {
|
||||||
|
const stripeProduct = product.related('stripeProducts').first();
|
||||||
|
await this._stripeAPIService.updateProduct(stripeProduct.get('stripe_product_id'), {
|
||||||
|
name: product.get('name')
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultStripeProduct = product.related('stripeProducts').first();
|
const defaultStripeProduct = product.related('stripeProducts').first();
|
||||||
|
|
|
@ -136,6 +136,22 @@ module.exports = class StripeAPIService {
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} id
|
||||||
|
* @param {object} options
|
||||||
|
* @param {string} options.name
|
||||||
|
*
|
||||||
|
* @returns {Promise<IProduct>}
|
||||||
|
*/
|
||||||
|
async updateProduct(id, options) {
|
||||||
|
await this._rateLimitBucket.throttle();
|
||||||
|
const product = await this._stripe.products.update(id, {
|
||||||
|
name: options.name
|
||||||
|
});
|
||||||
|
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ensureProduct.
|
* ensureProduct.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue