[web] mv PaymentService to modules
GitOrigin-RevId: 73d739f53d96ff9e9d51a535907dbdc878aa6624
This commit is contained in:
committed by
Copybot
parent
04d36122bd
commit
f8f2585164
@@ -1,81 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
const RecurlyClient = require('./RecurlyClient.js')
|
||||
const logger = require('@overleaf/logger')
|
||||
const { callbackify } = require('util')
|
||||
|
||||
/**
|
||||
* @import { PaymentProviderSubscription, PaymentProviderAccount, PaymentProviderCoupon } from "./PaymentProviderEntities.js"
|
||||
* @import { ObjectId } from 'mongodb'
|
||||
*/
|
||||
|
||||
/**
|
||||
* this represents a subset of the Mongo Subscription record
|
||||
*
|
||||
* @typedef {object} MongoSubscription
|
||||
* @property {ObjectId} admin_id
|
||||
* @property {string} [recurlySubscription_id]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} PaymentRecord
|
||||
* @property {PaymentProviderSubscription} subscription
|
||||
* @property {PaymentProviderAccount | null} account
|
||||
* @property {PaymentProviderCoupon[]} coupons
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get payment information from our Mongo record
|
||||
*
|
||||
* @param {MongoSubscription} subscription
|
||||
* @return {Promise<PaymentRecord | null>}
|
||||
*/
|
||||
async function getPaymentFromRecord(subscription) {
|
||||
if (subscription == null) {
|
||||
logger.debug('no subscription provided')
|
||||
return null
|
||||
}
|
||||
const userId = (subscription.admin_id._id || subscription.admin_id).toString()
|
||||
const recurlySubscriptionId = subscription.recurlySubscription_id
|
||||
|
||||
// TODO: handle non-recurly payment records
|
||||
if (recurlySubscriptionId == null || recurlySubscriptionId === '') {
|
||||
logger.debug(
|
||||
{ userId },
|
||||
"no recurly subscription id found for user's subscription"
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const subscriptionResponse = await RecurlyClient.promises.getSubscription(
|
||||
recurlySubscriptionId
|
||||
)
|
||||
if (!subscriptionResponse) {
|
||||
logger.debug(
|
||||
{ recurlySubscriptionId },
|
||||
'no recurly subscription found for subscription id'
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const accountResponse =
|
||||
await RecurlyClient.promises.getAccountForUserId(userId)
|
||||
const accountCoupons =
|
||||
await RecurlyClient.promises.getActiveCouponsForUserId(userId)
|
||||
|
||||
// TODO: include account and coupons in subscription class instead of separately here
|
||||
// if Recurly is removed (Recurly needs 2 extra requests to get account & coupon data)
|
||||
return {
|
||||
subscription: subscriptionResponse,
|
||||
account: accountResponse,
|
||||
coupons: accountCoupons,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPaymentFromRecord: callbackify(getPaymentFromRecord),
|
||||
|
||||
promises: {
|
||||
getPaymentFromRecord,
|
||||
},
|
||||
}
|
||||
@@ -23,8 +23,8 @@ const {
|
||||
V1ConnectionError,
|
||||
} = require('../Errors/Errors')
|
||||
const FeaturesHelper = require('./FeaturesHelper')
|
||||
const PaymentService = require('./PaymentService')
|
||||
const { formatCurrency } = require('../../util/currency')
|
||||
const Modules = require('../../infrastructure/Modules')
|
||||
|
||||
/**
|
||||
* @import { Subscription } from "../../../../types/project/dashboard/subscription"
|
||||
@@ -82,16 +82,16 @@ async function buildUsersSubscriptionViewModel(user, locale = 'en') {
|
||||
currentInstitutionsWithLicence,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
paymentRecord,
|
||||
fetchedPaymentRecord,
|
||||
plan,
|
||||
} = await async.auto({
|
||||
personalSubscription(cb) {
|
||||
SubscriptionLocator.getUsersSubscription(user, cb)
|
||||
},
|
||||
paymentRecord: [
|
||||
fetchedPaymentRecord: [
|
||||
'personalSubscription',
|
||||
({ personalSubscription }, cb) => {
|
||||
PaymentService.getPaymentFromRecord(personalSubscription, cb)
|
||||
Modules.hooks.fire('getPaymentFromRecord', personalSubscription, cb)
|
||||
},
|
||||
],
|
||||
plan: [
|
||||
@@ -138,6 +138,8 @@ async function buildUsersSubscriptionViewModel(user, locale = 'en') {
|
||||
},
|
||||
})
|
||||
|
||||
const paymentRecord = fetchedPaymentRecord && fetchedPaymentRecord[0]
|
||||
|
||||
if (memberGroupSubscriptions == null) {
|
||||
memberGroupSubscriptions = []
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user