From 8b411de034569b36788239a5948d64f5029d6437 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 18 Feb 2019 15:24:06 -0500 Subject: [PATCH] support for new billing and subscription endpoints --- src/abstractions/api.service.ts | 7 +- src/models/response/billingResponse.ts | 73 ++----------------- .../response/organizationBillingResponse.ts | 42 ----------- .../organizationSubscriptionResponse.ts | 24 ++++++ src/models/response/subscriptionResponse.ts | 71 ++++++++++++++++++ src/services/api.service.ts | 17 ++++- 6 files changed, 119 insertions(+), 115 deletions(-) delete mode 100644 src/models/response/organizationBillingResponse.ts create mode 100644 src/models/response/organizationSubscriptionResponse.ts create mode 100644 src/models/response/subscriptionResponse.ts diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index 3fd8e0e430..ed77c77506 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -68,8 +68,8 @@ import { import { IdentityTokenResponse } from '../models/response/identityTokenResponse'; import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse'; import { ListResponse } from '../models/response/listResponse'; -import { OrganizationBillingResponse } from '../models/response/organizationBillingResponse'; import { OrganizationResponse } from '../models/response/organizationResponse'; +import { OrganizationSubscriptionResponse } from '../models/response/organizationSubscriptionResponse'; import { OrganizationUserDetailsResponse, OrganizationUserUserDetailsResponse, @@ -77,6 +77,7 @@ import { import { PreloginResponse } from '../models/response/preloginResponse'; import { ProfileResponse } from '../models/response/profileResponse'; import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; +import { SubscriptionResponse } from '../models/response/subscriptionResponse'; import { SyncResponse } from '../models/response/syncResponse'; import { TwoFactorAuthenticatorResponse } from '../models/response/twoFactorAuthenticatorResponse'; import { TwoFactorDuoResponse } from '../models/response/twoFactorDuoResponse'; @@ -101,6 +102,7 @@ export abstract class ApiService { getProfile: () => Promise; getUserBilling: () => Promise; + getUserSubscription: () => Promise; putProfile: (request: UpdateProfileRequest) => Promise; postPrelogin: (request: PreloginRequest) => Promise; postEmailToken: (request: EmailTokenRequest) => Promise; @@ -224,7 +226,8 @@ export abstract class ApiService { postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise; getOrganization: (id: string) => Promise; - getOrganizationBilling: (id: string) => Promise; + getOrganizationBilling: (id: string) => Promise; + getOrganizationSubscription: (id: string) => Promise; getOrganizationLicense: (id: string, installationId: string) => Promise; postOrganization: (request: OrganizationCreateRequest) => Promise; putOrganization: (id: string, request: OrganizationUpdateRequest) => Promise; diff --git a/src/models/response/billingResponse.ts b/src/models/response/billingResponse.ts index 2e32dfcb4b..48c797f3f6 100644 --- a/src/models/response/billingResponse.ts +++ b/src/models/response/billingResponse.ts @@ -2,27 +2,13 @@ import { PaymentMethodType } from '../../enums/paymentMethodType'; import { TransactionType } from '../../enums/transactionType'; export class BillingResponse { - storageName: string; - storageGb: number; - maxStorageGb: number; paymentSource: BillingSourceResponse; - subscription: BillingSubscriptionResponse; - upcomingInvoice: BillingInvoiceInfoResponse; charges: BillingChargeResponse[] = []; invoices: BillingInvoiceResponse[] = []; transactions: BillingTransactionResponse[] = []; - license: any; - expiration: string; constructor(response: any) { - this.storageName = response.StorageName; - this.storageGb = response.StorageGb; - this.maxStorageGb = response.MaxStorageGb; this.paymentSource = response.PaymentSource == null ? null : new BillingSourceResponse(response.PaymentSource); - this.subscription = response.Subscription == null ? - null : new BillingSubscriptionResponse(response.Subscription); - this.upcomingInvoice = response.UpcomingInvoice == null ? - null : new BillingInvoiceInfoResponse(response.UpcomingInvoice); if (response.Charges != null) { this.charges = response.Charges.map((c: any) => new BillingChargeResponse(c)); } @@ -32,8 +18,6 @@ export class BillingResponse { if (response.Invoices != null) { this.invoices = response.Invoices.map((i: any) => new BillingInvoiceResponse(i)); } - this.license = response.License; - this.expiration = response.Expiration; } } @@ -51,56 +35,6 @@ export class BillingSourceResponse { } } -export class BillingSubscriptionResponse { - trialStartDate: string; - trialEndDate: string; - periodStartDate: string; - periodEndDate: string; - cancelledDate: string; - cancelAtEndDate: boolean; - status: string; - cancelled: boolean; - items: BillingSubscriptionItemResponse[] = []; - - constructor(response: any) { - this.trialEndDate = response.TrialStartDate; - this.trialEndDate = response.TrialEndDate; - this.periodStartDate = response.PeriodStartDate; - this.periodEndDate = response.PeriodEndDate; - this.cancelledDate = response.CancelledDate; - this.cancelAtEndDate = response.CancelAtEndDate; - this.status = response.Status; - this.cancelled = response.Cancelled; - if (response.Items != null) { - this.items = response.Items.map((i: any) => new BillingSubscriptionItemResponse(i)); - } - } -} - -export class BillingSubscriptionItemResponse { - name: string; - amount: number; - quantity: number; - interval: string; - - constructor(response: any) { - this.name = response.Name; - this.amount = response.Amount; - this.quantity = response.Quantity; - this.interval = response.Interval; - } -} - -export class BillingInvoiceInfoResponse { - date: string; - amount: number; - - constructor(response: any) { - this.date = response.Date; - this.amount = response.Amount; - } -} - export class BillingChargeResponse { createdDate: string; amount: number; @@ -125,18 +59,21 @@ export class BillingChargeResponse { } } -export class BillingInvoiceResponse extends BillingInvoiceInfoResponse { +export class BillingInvoiceResponse { url: string; pdfUrl: string; number: string; paid: boolean; + date: string; + amount: number; constructor(response: any) { - super(response); this.url = response.Url; this.pdfUrl = response.PdfUrl; this.number = response.Number; this.paid = response.Paid; + this.date = response.Date; + this.amount = response.Amount; } } diff --git a/src/models/response/organizationBillingResponse.ts b/src/models/response/organizationBillingResponse.ts deleted file mode 100644 index 258da85b67..0000000000 --- a/src/models/response/organizationBillingResponse.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - BillingChargeResponse, - BillingInvoiceInfoResponse, - BillingInvoiceResponse, - BillingSourceResponse, - BillingSubscriptionResponse, - BillingTransactionResponse, -} from './billingResponse'; -import { OrganizationResponse } from './organizationResponse'; - -export class OrganizationBillingResponse extends OrganizationResponse { - storageName: string; - storageGb: number; - paymentSource: BillingSourceResponse; - subscription: BillingSubscriptionResponse; - upcomingInvoice: BillingInvoiceInfoResponse; - charges: BillingChargeResponse[] = []; - invoices: BillingInvoiceResponse[] = []; - transactions: BillingTransactionResponse[] = []; - expiration: string; - - constructor(response: any) { - super(response); - this.storageName = response.StorageName; - this.storageGb = response.StorageGb; - this.paymentSource = response.PaymentSource == null ? null : new BillingSourceResponse(response.PaymentSource); - this.subscription = response.Subscription == null ? - null : new BillingSubscriptionResponse(response.Subscription); - this.upcomingInvoice = response.UpcomingInvoice == null ? - null : new BillingInvoiceInfoResponse(response.UpcomingInvoice); - if (response.Charges != null) { - this.charges = response.Charges.map((c: any) => new BillingChargeResponse(c)); - } - if (response.Transactions != null) { - this.transactions = response.Transactions.map((t: any) => new BillingTransactionResponse(t)); - } - if (response.Invoices != null) { - this.invoices = response.Invoices.map((i: any) => new BillingInvoiceResponse(i)); - } - this.expiration = response.Expiration; - } -} diff --git a/src/models/response/organizationSubscriptionResponse.ts b/src/models/response/organizationSubscriptionResponse.ts new file mode 100644 index 0000000000..77cacaa68b --- /dev/null +++ b/src/models/response/organizationSubscriptionResponse.ts @@ -0,0 +1,24 @@ +import { OrganizationResponse } from './organizationResponse'; +import { + BillingSubscriptionResponse, + BillingSubscriptionUpcomingInvoiceResponse, +} from './subscriptionResponse'; + +export class OrganizationSubscriptionResponse extends OrganizationResponse { + storageName: string; + storageGb: number; + subscription: BillingSubscriptionResponse; + upcomingInvoice: BillingSubscriptionUpcomingInvoiceResponse; + expiration: string; + + constructor(response: any) { + super(response); + this.storageName = response.StorageName; + this.storageGb = response.StorageGb; + this.subscription = response.Subscription == null ? + null : new BillingSubscriptionResponse(response.Subscription); + this.upcomingInvoice = response.UpcomingInvoice == null ? + null : new BillingSubscriptionUpcomingInvoiceResponse(response.UpcomingInvoice); + this.expiration = response.Expiration; + } +} diff --git a/src/models/response/subscriptionResponse.ts b/src/models/response/subscriptionResponse.ts new file mode 100644 index 0000000000..86d3580307 --- /dev/null +++ b/src/models/response/subscriptionResponse.ts @@ -0,0 +1,71 @@ +export class SubscriptionResponse { + storageName: string; + storageGb: number; + maxStorageGb: number; + subscription: BillingSubscriptionResponse; + upcomingInvoice: BillingSubscriptionUpcomingInvoiceResponse; + license: any; + expiration: string; + + constructor(response: any) { + this.storageName = response.StorageName; + this.storageGb = response.StorageGb; + this.maxStorageGb = response.MaxStorageGb; + this.subscription = response.Subscription == null ? + null : new BillingSubscriptionResponse(response.Subscription); + this.upcomingInvoice = response.UpcomingInvoice == null ? + null : new BillingSubscriptionUpcomingInvoiceResponse(response.UpcomingInvoice); + this.license = response.License; + this.expiration = response.Expiration; + } +} + +export class BillingSubscriptionResponse { + trialStartDate: string; + trialEndDate: string; + periodStartDate: string; + periodEndDate: string; + cancelledDate: string; + cancelAtEndDate: boolean; + status: string; + cancelled: boolean; + items: BillingSubscriptionItemResponse[] = []; + + constructor(response: any) { + this.trialEndDate = response.TrialStartDate; + this.trialEndDate = response.TrialEndDate; + this.periodStartDate = response.PeriodStartDate; + this.periodEndDate = response.PeriodEndDate; + this.cancelledDate = response.CancelledDate; + this.cancelAtEndDate = response.CancelAtEndDate; + this.status = response.Status; + this.cancelled = response.Cancelled; + if (response.Items != null) { + this.items = response.Items.map((i: any) => new BillingSubscriptionItemResponse(i)); + } + } +} + +export class BillingSubscriptionItemResponse { + name: string; + amount: number; + quantity: number; + interval: string; + + constructor(response: any) { + this.name = response.Name; + this.amount = response.Amount; + this.quantity = response.Quantity; + this.interval = response.Interval; + } +} + +export class BillingSubscriptionUpcomingInvoiceResponse { + date: string; + amount: number; + + constructor(response: any) { + this.date = response.Date; + this.amount = response.Amount; + } +} diff --git a/src/services/api.service.ts b/src/services/api.service.ts index bb9f7faa55..692ac69dc5 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -75,8 +75,8 @@ import { import { IdentityTokenResponse } from '../models/response/identityTokenResponse'; import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorResponse'; import { ListResponse } from '../models/response/listResponse'; -import { OrganizationBillingResponse } from '../models/response/organizationBillingResponse'; import { OrganizationResponse } from '../models/response/organizationResponse'; +import { OrganizationSubscriptionResponse } from '../models/response/organizationSubscriptionResponse'; import { OrganizationUserDetailsResponse, OrganizationUserUserDetailsResponse, @@ -84,6 +84,7 @@ import { import { PreloginResponse } from '../models/response/preloginResponse'; import { ProfileResponse } from '../models/response/profileResponse'; import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; +import { SubscriptionResponse } from '../models/response/subscriptionResponse'; import { SyncResponse } from '../models/response/syncResponse'; import { TwoFactorAuthenticatorResponse } from '../models/response/twoFactorAuthenticatorResponse'; import { TwoFactorDuoResponse } from '../models/response/twoFactorDuoResponse'; @@ -200,6 +201,11 @@ export class ApiService implements ApiServiceAbstraction { return new BillingResponse(r); } + async getUserSubscription(): Promise { + const r = await this.send('GET', '/accounts/subscription', null, true, true); + return new SubscriptionResponse(r); + } + async putProfile(request: UpdateProfileRequest): Promise { const r = await this.send('PUT', '/accounts/profile', request, true, true); return new ProfileResponse(r); @@ -722,9 +728,14 @@ export class ApiService implements ApiServiceAbstraction { return new OrganizationResponse(r); } - async getOrganizationBilling(id: string): Promise { + async getOrganizationBilling(id: string): Promise { const r = await this.send('GET', '/organizations/' + id + '/billing', null, true, true); - return new OrganizationBillingResponse(r); + return new BillingResponse(r); + } + + async getOrganizationSubscription(id: string): Promise { + const r = await this.send('GET', '/organizations/' + id + '/subscription', null, true, true); + return new OrganizationSubscriptionResponse(r); } async getOrganizationLicense(id: string, installationId: string): Promise {