1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-24 16:49:26 +01:00

add billing apis

This commit is contained in:
Kyle Spearrin 2018-06-29 11:29:24 -04:00
parent ac221d8867
commit 1565140024
4 changed files with 115 additions and 0 deletions

View File

@ -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<IdentityTokenResponse | IdentityTwoFactorResponse>;
refreshIdentityToken: () => Promise<any>;
getProfile: () => Promise<ProfileResponse>;
getUserBilling: () => Promise<BillingResponse>;
putProfile: (request: UpdateProfileRequest) => Promise<ProfileResponse>;
postEmailToken: (request: EmailTokenRequest) => Promise<any>;
postEmail: (request: EmailRequest) => Promise<any>;

View File

@ -0,0 +1,6 @@
export enum PaymentMethodType {
Card = 0,
BankAccount = 1,
PayPal = 2,
Bitcoin = 3,
}

View File

@ -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;
}
}

View File

@ -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<BillingResponse> {
const r = await this.send('GET', '/accounts/billing', null, true, true);
return new BillingResponse(r);
}
async putProfile(request: UpdateProfileRequest): Promise<ProfileResponse> {
const r = await this.send('PUT', '/accounts/profile', request, true, true);
return new ProfileResponse(r);