From af25cfb619f7f1f1e4b27ad5186d73da399ca013 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 2 Oct 2019 18:10:19 +0700 Subject: [PATCH] Added interval, currency and last4 to stripe data no-issue This is attached to each "stripe item" belonging to a member --- ghost/members-api/lib/stripe/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ghost/members-api/lib/stripe/index.js b/ghost/members-api/lib/stripe/index.js index 58fe464197..145e80d0c9 100644 --- a/ghost/members-api/lib/stripe/index.js +++ b/ghost/members-api/lib/stripe/index.js @@ -127,7 +127,9 @@ module.exports = class StripePaymentProcessor { const customers = await Promise.all(metadata.map(async (data) => { try { - const customer = await this.getCustomer(data.customer_id); + const customer = await this.getCustomer(data.customer_id, { + expand: ['subscriptions.data.default_payment_method'] + }); return customer; } catch (err) { debug(`Ignoring Error getting customer for active subscriptions ${err.message}`); @@ -149,13 +151,17 @@ module.exports = class StripePaymentProcessor { return subscriptions; } + const payment = subscription.default_payment_method; return subscriptions.concat([{ customer: customer.id, status: subscription.status, subscription: subscription.id, plan: subscription.plan.id, name: subscription.plan.nickname, + interval: subscription.plan.interval, amount: subscription.plan.amount, + currency: subscription.plan.currency, + last4: payment && payment.card && payment.card.last4 || null, validUntil: subscription.current_period_end }]); }, [])); @@ -206,7 +212,7 @@ module.exports = class StripePaymentProcessor { return customer; } - async getCustomer(id) { - return retrieve(this._stripe, 'customers', id); + async getCustomer(id, options) { + return retrieve(this._stripe, 'customers', id, options); } };