1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-12 00:41:29 +01:00

billing invoices and transactions

This commit is contained in:
Kyle Spearrin 2019-02-09 00:19:46 -05:00
parent 98addd8ab5
commit 647b254a71
3 changed files with 68 additions and 5 deletions

View File

@ -0,0 +1,7 @@
export enum TransactionType {
Charge = 0,
Credit = 1,
PromotionalCredit = 2,
ReferralCredit = 3,
Refund = 4,
}

View File

@ -1,4 +1,5 @@
import { PaymentMethodType } from '../../enums/paymentMethodType';
import { TransactionType } from '../../enums/transactionType';
export class BillingResponse {
storageName: string;
@ -6,8 +7,10 @@ export class BillingResponse {
maxStorageGb: number;
paymentSource: BillingSourceResponse;
subscription: BillingSubscriptionResponse;
upcomingInvoice: BillingInvoiceResponse;
upcomingInvoice: BillingInvoiceInfoResponse;
charges: BillingChargeResponse[] = [];
invoices: BillingInvoiceResponse[] = [];
transactions: BillingTransactionResponse[] = [];
license: any;
expiration: string;
@ -19,10 +22,16 @@ export class BillingResponse {
this.subscription = response.Subscription == null ?
null : new BillingSubscriptionResponse(response.Subscription);
this.upcomingInvoice = response.UpcomingInvoice == null ?
null : new BillingInvoiceResponse(response.UpcomingInvoice);
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.license = response.License;
this.expiration = response.Expiration;
}
@ -82,7 +91,7 @@ export class BillingSubscriptionItemResponse {
}
}
export class BillingInvoiceResponse {
export class BillingInvoiceInfoResponse {
date: string;
amount: number;
@ -115,3 +124,40 @@ export class BillingChargeResponse {
this.invoiceId = response.InvoiceId;
}
}
export class BillingInvoiceResponse extends BillingInvoiceInfoResponse {
url: string;
pdfUrl: string;
number: string;
paid: boolean;
constructor(response: any) {
super(response);
this.url = response.Url;
this.pdfUrl = response.PdfUrl;
this.number = response.Number;
this.paid = response.Paid;
}
}
export class BillingTransactionResponse {
createdDate: string;
amount: number;
refunded: boolean;
partiallyRefunded: boolean;
refundedAmount: number;
type: TransactionType;
paymentMethodType: PaymentMethodType;
details: string;
constructor(response: any) {
this.createdDate = response.CreatedDate;
this.amount = response.Amount;
this.refunded = response.Refunded;
this.partiallyRefunded = response.PartiallyRefunded;
this.refundedAmount = response.RefundedAmount;
this.type = response.Type;
this.paymentMethodType = response.PaymentMethodType;
this.details = response.Details;
}
}

View File

@ -1,8 +1,10 @@
import {
BillingChargeResponse,
BillingInvoiceInfoResponse,
BillingInvoiceResponse,
BillingSourceResponse,
BillingSubscriptionResponse,
BillingTransactionResponse,
} from './billingResponse';
import { OrganizationResponse } from './organizationResponse';
@ -11,8 +13,10 @@ export class OrganizationBillingResponse extends OrganizationResponse {
storageGb: number;
paymentSource: BillingSourceResponse;
subscription: BillingSubscriptionResponse;
upcomingInvoice: BillingInvoiceResponse;
upcomingInvoice: BillingInvoiceInfoResponse;
charges: BillingChargeResponse[] = [];
invoices: BillingInvoiceResponse[] = [];
transactions: BillingTransactionResponse[] = [];
expiration: string;
constructor(response: any) {
@ -23,10 +27,16 @@ export class OrganizationBillingResponse extends OrganizationResponse {
this.subscription = response.Subscription == null ?
null : new BillingSubscriptionResponse(response.Subscription);
this.upcomingInvoice = response.UpcomingInvoice == null ?
null : new BillingInvoiceResponse(response.UpcomingInvoice);
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;
}
}