diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index 8a4953f04e..5b45bd3a33 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -28,6 +28,7 @@ import { UpdateTwoFactorEmailRequest } from '../models/request/updateTwoFactorEm import { UpdateTwoFactorU2fRequest } from '../models/request/updateTwoFactorU2fRequest'; import { UpdateTwoFactorYubioOtpRequest } from '../models/request/updateTwoFactorYubioOtpRequest'; +import { BillingResponse } from '../models/response/billingResponse'; import { CipherResponse } from '../models/response/cipherResponse'; import { DomainsResponse } from '../models/response/domainsResponse'; import { FolderResponse } from '../models/response/folderResponse'; @@ -53,6 +54,7 @@ export abstract class ApiService { postIdentityToken: (request: TokenRequest) => Promise; refreshIdentityToken: () => Promise; getProfile: () => Promise; + getUserBilling: () => Promise; putProfile: (request: UpdateProfileRequest) => Promise; postEmailToken: (request: EmailTokenRequest) => Promise; postEmail: (request: EmailRequest) => Promise; diff --git a/src/enums/paymentMethodType.ts b/src/enums/paymentMethodType.ts new file mode 100644 index 0000000000..fcc50fa45e --- /dev/null +++ b/src/enums/paymentMethodType.ts @@ -0,0 +1,6 @@ +export enum PaymentMethodType { + Card = 0, + BankAccount = 1, + PayPal = 2, + Bitcoin = 3, +} diff --git a/src/models/response/billingResponse.ts b/src/models/response/billingResponse.ts new file mode 100644 index 0000000000..2bd97a9ba6 --- /dev/null +++ b/src/models/response/billingResponse.ts @@ -0,0 +1,101 @@ +import { PaymentMethodType } from '../../enums/paymentMethodType'; + +export class BillingResponse { + storageName: string; + storageGb: number; + maxStorageGb: number; + + constructor(response: any) { + this.storageName = response.StorageName; + this.storageGb = response.StorageGb; + this.maxStorageGb = response.MaxStorageGb; + } +} + +export class BillingSourceResponse { + type: PaymentMethodType; + cardBrand: string; + description: string; + needsVerification: boolean; + + constructor(response: any) { + this.type = response.Type; + this.cardBrand = response.CardBrand; + this.description = response.Description; + this.needsVerification = response.NeedsVerification; + } +} + +export class BillingSubscriptionResponse { + trialStartDate: Date; + trialEndDate: Date; + periodStartDate: Date; + periodEndDate: Date; + cancelledDate: Date; + 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) => new BillingSubscriptionItemResponse(i)); + } + } +} + +export class BillingSubscriptionItemResponse { + name: string; + amount: number; + quantity: number; + internal: string; + + constructor(response: any) { + this.name = response.Name; + this.amount = response.Amount; + this.quantity = response.Quantity; + this.internal = response.Internal; + } +} + +export class BillingInvoiceResponse { + date: Date; + amount: number; + + constructor(response: any) { + this.date = response.Date; + this.amount = response.Amount; + } +} + +export class BillingChargeResponse { + createdDate: Date; + amount: number; + paymentSource: BillingSourceResponse; + status: string; + failureMessage: string; + refunded: boolean; + partiallyRefunded: boolean; + refundedAmount: number; + invoiceId: string; + + constructor(response: any) { + this.createdDate = response.CreatedDate; + this.amount = response.Amount; + this.paymentSource = response.PaymentSource != null ? new BillingSourceResponse(response.PaymentSource) : null; + this.status = response.Status; + this.failureMessage = response.FailureMessage; + this.refunded = response.Refunded; + this.partiallyRefunded = response.PartiallyRefunded; + this.refundedAmount = response.RefundedAmount; + this.invoiceId = response.InvoiceId; + } +} diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 6574eb4d4f..01a08e7802 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -34,6 +34,7 @@ import { UpdateTwoFactorEmailRequest } from '../models/request/updateTwoFactorEm import { UpdateTwoFactorU2fRequest } from '../models/request/updateTwoFactorU2fRequest'; import { UpdateTwoFactorYubioOtpRequest } from '../models/request/updateTwoFactorYubioOtpRequest'; +import { BillingResponse } from '../models/response/billingResponse'; import { CipherResponse } from '../models/response/cipherResponse'; import { DomainsResponse } from '../models/response/domainsResponse'; import { ErrorResponse } from '../models/response/errorResponse'; @@ -146,6 +147,11 @@ export class ApiService implements ApiServiceAbstraction { return new ProfileResponse(r); } + async getUserBilling(): Promise { + const r = await this.send('GET', '/accounts/billing', null, true, true); + return new BillingResponse(r); + } + async putProfile(request: UpdateProfileRequest): Promise { const r = await this.send('PUT', '/accounts/profile', request, true, true); return new ProfileResponse(r);