Skip to content

Commit

Permalink
- refactor Billing API
Browse files Browse the repository at this point in the history
  • Loading branch information
Valodya committed Jun 6, 2024
1 parent 21812e4 commit 19b4ed6
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 139 deletions.
8 changes: 0 additions & 8 deletions src/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,4 @@ export default req => ({
workers(appId, query) {
return req.get(`${urls.appConsole(appId)}/workers`).query(query)
},

scalePlanePricingEstimate(appId, query) {
return req.billing.get(`/${appId}/console/billing/application/tiers/price-estimation`).query(query)
},

scaleFixedPlanePricingEstimate(appId, tierId, query) {
return req.billing.get(`/${appId}/console/billing/application/tiers/price-estimation/${ tierId }`).query(query)
}
})
103 changes: 0 additions & 103 deletions src/billing.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/billing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { routes } from './routes'
import { billingPaymentsAPI } from './payments'
import { billingLimitsAPI } from './limits'
import { billingPlansAPI } from './plans'

export function billingAPI(req) {
return {
...billingPaymentsAPI(req),
...billingLimitsAPI(req),
...billingPlansAPI(req),

getBillingInfo(appId) {
return req.billing.get(routes.billingInfo(appId))
},

getSubscriptionStatus(appId) {
return req.billing.get(routes.subscriptionStatus(appId))
},

loadSubscriptionsInfo() {
return req.billing.get(routes.devSubscriptionsInfo())
},

getBillingPeriodInfo(appId) {
return req.billing.get(routes.billingPeriodInfo(appId))
},

// TODO: seems like we do not use the function
// getInviteCode(appId) {
// return req.billing.get(routes.inviteCode(appId))
// },

}
}
49 changes: 49 additions & 0 deletions src/billing/limits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { routes } from './routes'

export function billingLimitsAPI(req) {
return {
getPlanComponentsData(appId, planId, billingPeriod) {
return req.billing.get(routes.planComponentsData(appId, planId, billingPeriod))
},

getCurrentPlanComponentData(appId) {
return req.billing.get(routes.planComponentsData(appId, 'current', 'current'))
},

getComponentLimit(appId, componentId) {
return req.billing.get(routes.componentLimit(appId, componentId))
},

apiCallsBlocked(appId) {
return req.billing.get(routes.apiCallsBlocked(appId))
},

loadHiveUsage(appId, cached = true) {
return req.billing.get(routes.hiveUsage(appId)).query({ cached })
},

loadHiveLimit(appId) {
return req.billing.get(routes.hiveLimits(appId))
},

scalePlanePricingEstimate(appId, query) {
return req.billing.get(routes.tiersFloatPriceEstimation(appId)).query(query)
},

scaleFixedPlanePricingEstimate(appId, tierId, query) {
return req.billing.get(routes.tiersFloatPriceEstimation(appId, tierId)).query(query)
},

getMaxTier(appId) {
return req.billing.get(routes.maxTier(appId))
},

setMaxTier(appId, tierId) {
return req.billing.put(routes.maxTier(appId), { tierId })
},

getTiersList(appId) {
return req.billing.get(routes.tiers(appId))
},
}
}
39 changes: 39 additions & 0 deletions src/billing/payments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { routes } from './routes'

export function billingPaymentsAPI(req) {
return {
loadPaymentProfilesForCloneApp(appId) {
return req.billing.get(routes.paymentProfilesForCloneApp(appId))
},

confirmConsolidateApp(appId, { paymentProfileId, newBillingPlan, newBillingPeriod }) {
return req.billing.put(routes.consolidateApp(appId, paymentProfileId))
.query({ newBillingPlan, newBillingPeriod })
},

loadPaymentProfiles() {
return req.billing.get(routes.devPaymentProfile())
},

setPaymentProfile(appId, paymentProfileId) {
return req.billing.put(routes.devPaymentProfileCard(appId, paymentProfileId))
},

addPaymentProfile(data) {
return req.billing.post(routes.devPaymentProfile(), data)
},

updatePaymentProfile(id, data) {
return req.billing.put(routes.devPaymentProfileById(id), data)
},

deletePaymentProfile(id) {
return req.billing.delete(routes.devPaymentProfileById(id))
},

exchangeBBtoUSD(appId, bbAmount) {
return req.billing.post(routes.exchangeBB(appId), bbAmount)
.set({ 'Content-Type': 'application/json' })
},
}
}
17 changes: 17 additions & 0 deletions src/billing/plans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { routes } from './routes'

export function billingPlansAPI(req) {
return {
getPlans(appId) {
return req.billing.get(routes.billingPlans(appId))
},

switchToPlan(appId, planId, billingPeriod) {
return req.billing.put(routes.switchPlan(appId, planId, billingPeriod))
},

unlockPlan(appId, planId) {
return req.billing.put(routes.unlockPlan(appId, planId))
},
}
}
31 changes: 31 additions & 0 deletions src/billing/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { prepareRoutes } from '../utils/routes'

export const routes = prepareRoutes({
billingInfo : '/:appId/console/billing/application/accountinfo',
billingPlans : '/:appId/console/billing/application/plans',
planComponentsData : '/:appId/console/billing/application/plans/:planId/:billingPeriod/components',
switchPlan : '/:appId/console/billing/application/subscriptions/:planId/:billingPeriod',
componentLimit : '/:appId/console/billing/application/limits/:componentId',
billingPeriodInfo : '/:appId/console/billing/application/billing-period-info',
exchangeBB : '/:appId/console/billing/application/bb/exchange',
consolidateApp : '/:appId/console/billing/application/consolidate/:paymentProfileId',
tiers : '/:appId/console/billing/application/tiers',
maxTier : '/:appId/console/billing/application/tiers/max',
tiersFloatPriceEstimation : '/:appId/console/billing/application/tiers/price-estimation',
tiersFixedPriceEstimation : '/:appId/console/billing/application/tiers/price-estimation/:tierId',
paymentProfilesForCloneApp: '/:appId/console/billing/application/payment-profiles-for-clone-operation',
devPaymentProfileCard : '/:appId/console/billing/application/creditcard/:paymentProfileId',

apiCallsBlocked: '/:appId/console/billing/apicalls/blocked',
// inviteCode : '/:appId/console/billing/refcode',

devSubscriptionsInfo : '/console/billing/developer/subscriptions-info',
devPaymentProfile : '/console/billing/developer/payment-profile',
devPaymentProfileById: '/console/billing/developer/payment-profile/:id',

subscriptionStatus: '/:appId/billing/subscriptions/status',
unlockPlan : '/:appId/billing/plan/:planId/unlock',

hiveLimits: '/:appId/billing/limits/hive',
hiveUsage : '/:appId/service/billing/usage/hive',
})
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import analytics from './analytics'
import apiDocs from './api-docs'
import apps from './apps'
import automation from './automation'
import billing from './billing'
import { billingAPI } from './billing'
import bl from './bl'
import cloudCode from './cloud-code'
import blueprints from './blueprints'
Expand Down Expand Up @@ -168,7 +168,7 @@ const createClient = (serverUrl, authKey, options) => {
apiDocs : apiDocs(request),
apps : apps(request),
automation : automation(request),
billing : billing(request),
billing : billingAPI(request),
bl : bl(request),
cloudCode : cloudCode(request),
blueprints : blueprints(request),
Expand Down
7 changes: 5 additions & 2 deletions src/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ export const mobileSettings = appId =>
export const mobileSettingsAndroid = (appId, id) =>
`${mobileSettings(appId)}/android${optional(id)}`

export const billing = appId =>
`${appConsole(appId)}/billing`
export const billing = appId => {
console.warn('DO NOT USE THE FUNCTION')

return `${appConsole(appId)}/billing`
}

export const marketplace = (appId, name) => `${appConsole(appId)}/marketplace/${name}`

Expand Down
24 changes: 0 additions & 24 deletions src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,6 @@ export default (req, context) => ({
return req.get(`${urls.appConsole(appId)}/my-permissions`)
},

loadSubscriptionsInfo() {
return req.billing.get('/console/billing/developer/subscriptions-info')
},

loadPaymentProfiles() {
return req.get('/console/billing/developer/payment-profile')
},

setPaymentProfile(appId, paymentProfileId) {
return req.billing.put(`${urls.appConsole(appId)}/billing/application/creditcard/${paymentProfileId}`)
},

addPaymentProfile(data) {
return req.post('/console/billing/developer/payment-profile', data)
},

updatePaymentProfile(id, data) {
return req.put(`/console/billing/developer/payment-profile/${id}`, data)
},

deletePaymentProfile(id) {
return req.delete(`/console/billing/developer/payment-profile/${id}`)
},

completeStripeConnection(data) {
return req.post('/console/community/marketplace/stripe-connect/auth', data)
},
Expand Down

0 comments on commit 19b4ed6

Please sign in to comment.