diff --git a/website/client/src/components/admin/admin-panel/user-support/subscriptionAndPerks.vue b/website/client/src/components/admin/admin-panel/user-support/subscriptionAndPerks.vue index e8697f432e..ae02b4b089 100644 --- a/website/client/src/components/admin/admin-panel/user-support/subscriptionAndPerks.vue +++ b/website/client/src/components/admin/admin-panel/user-support/subscriptionAndPerks.vue @@ -474,6 +474,13 @@ :href="'https://www.paypal.com/billing/subscriptions/' + paymentDetails.customerId"> PayPal Dashboard + + Stripe Dashboard + diff --git a/website/server/controllers/api-v4/admin.js b/website/server/controllers/api-v4/admin.js index 9070483d1f..b34c98e3b2 100644 --- a/website/server/controllers/api-v4/admin.js +++ b/website/server/controllers/api-v4/admin.js @@ -12,6 +12,9 @@ import { import apple from '../../libs/payments/apple'; import google from '../../libs/payments/google'; import paypal from '../../libs/payments/paypal'; +import { + getSubscriptionPaymentDetails as getStripeSubscriptionPaymentDetails, +} from '../../libs/payments/stripe/subscriptions'; const api = {}; @@ -221,7 +224,7 @@ api.validateSubscriptionPaymentDetails = { } else if (user.purchased.plan.paymentMethod === 'Paypal') { paymentDetails = await paypal.getSubscriptionPaymentDetails({ user }); } else if (user.purchased.plan.paymentMethod === 'Stripe') { - throw new NotFound(res.t('stripeSubscriptionNotValidated')); + paymentDetails = await getStripeSubscriptionPaymentDetails(user); } else if (user.purchased.plan.paymentMethod === 'Amazon Payments') { throw new NotFound(res.t('amazonSubscriptionNotValidated')); } else if (user.purchased.plan.paymentMethod === 'Gift') { diff --git a/website/server/libs/payments/stripe/subscriptions.js b/website/server/libs/payments/stripe/subscriptions.js index 360ba64d8c..e18e310377 100644 --- a/website/server/libs/payments/stripe/subscriptions.js +++ b/website/server/libs/payments/stripe/subscriptions.js @@ -17,6 +17,7 @@ import { BadRequest, NotFound, } from '../../errors'; +import { payment } from 'paypal-rest-sdk'; export async function checkSubData (sub, isGroup = false, coupon) { if (!sub || !sub.canSubscribe) throw new BadRequest(shared.i18n.t('missingSubscriptionCode')); @@ -33,6 +34,26 @@ export async function checkSubData (sub, isGroup = false, coupon) { } } +export async function getSubscriptionPaymentDetails (user) { + const stripeApi = getStripeApi(); + + const { plan } = user.purchased; + const customer = await stripeApi.customers.retrieve(plan.customerId); + const paymentIntents = await stripeApi.paymentIntents.search({ + query: `customer:'${plan.customerId}'`, + }); + const lastPayment = paymentIntents.data.length > 0 + ? paymentIntents.data[0] + : null; + console.log(paymentIntents.data); + console.log(customer); + return { + customerId: customer.id, + originalPurchaseDate: new Date(Number(customer.created) * 1000), + lastPaymentDate: new Date(Number(lastPayment.created) * 1000), + }; +} + export async function applySubscription (session) { const { metadata, customer: customerId, subscription: subscriptionId } = session; const {