0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Handled empty stripe price object in API

no refs

In case of Stripe disconnect, its possible that the product table still contains reference to monthly/price id while the object itself isn't present in the DB. In this scenario the stripe price returned is empty object instead of `null` , which then passes down empty object in the API that causes clients to fail if they just check existence of stripe price. The fix returns `null` value for monthly/yearly price in case it has no reference and is empty object.
This commit is contained in:
Rishabh 2021-06-08 20:59:21 +05:30
parent d2e4f30b5b
commit 413c1cc4ce

View file

@ -1,5 +1,6 @@
//@ts-check
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:output:products');
const _ = require('lodash');
const allowedIncludes = ['stripe_prices', 'monthly_price', 'yearly_price'];
@ -75,8 +76,8 @@ function serializeProduct(product, options, apiType) {
created_at: json.created_at,
updated_at: json.updated_at,
stripe_prices: json.stripePrices ? json.stripePrices.map(price => serializeStripePrice(price, hideStripeData)) : null,
monthly_price: json.monthlyPrice ? serializeStripePrice(json.monthlyPrice, hideStripeData) : null,
yearly_price: json.yearlyPrice ? serializeStripePrice(json.yearlyPrice, hideStripeData) : null
monthly_price: serializeStripePrice(json.monthlyPrice, hideStripeData),
yearly_price: serializeStripePrice(json.yearlyPrice, hideStripeData)
};
return serialized;
@ -89,6 +90,9 @@ function serializeProduct(product, options, apiType) {
* @returns {StripePrice}
*/
function serializeStripePrice(data, hideStripeData) {
if (_.isEmpty(data)) {
return null;
}
const price = {
id: data.id,
stripe_product_id: data.stripe_product_id,