1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00
Files
browser/src/models/response/billingResponse.ts
2018-06-29 13:58:01 -04:00

118 lines
3.7 KiB
TypeScript

import { PaymentMethodType } from '../../enums/paymentMethodType';
export class BillingResponse {
storageName: string;
storageGb: number;
maxStorageGb: number;
paymentSource: BillingSourceResponse;
subscription: BillingSubscriptionResponse;
upcomingInvoice: BillingInvoiceResponse;
charges: BillingChargeResponse[] = [];
license: any;
expiration: Date;
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 BillingInvoiceResponse(response.UpcomingInvoice);
if (response.Charges != null) {
this.charges = response.Charges.map((c: any) => new BillingChargeResponse(c));
}
this.license = response.License;
this.expiration = response.Expiration;
}
}
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: any) => 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;
}
}