support for new billing and subscription endpoints

This commit is contained in:
Kyle Spearrin 2019-02-18 15:24:06 -05:00
parent 3e996ae9ad
commit 8b411de034
6 changed files with 119 additions and 115 deletions

View File

@ -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<ProfileResponse>;
getUserBilling: () => Promise<BillingResponse>;
getUserSubscription: () => Promise<SubscriptionResponse>;
putProfile: (request: UpdateProfileRequest) => Promise<ProfileResponse>;
postPrelogin: (request: PreloginRequest) => Promise<PreloginResponse>;
postEmailToken: (request: EmailTokenRequest) => Promise<any>;
@ -224,7 +226,8 @@ export abstract class ApiService {
postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise<any>;
getOrganization: (id: string) => Promise<OrganizationResponse>;
getOrganizationBilling: (id: string) => Promise<OrganizationBillingResponse>;
getOrganizationBilling: (id: string) => Promise<BillingResponse>;
getOrganizationSubscription: (id: string) => Promise<OrganizationSubscriptionResponse>;
getOrganizationLicense: (id: string, installationId: string) => Promise<any>;
postOrganization: (request: OrganizationCreateRequest) => Promise<OrganizationResponse>;
putOrganization: (id: string, request: OrganizationUpdateRequest) => Promise<OrganizationResponse>;

View File

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

View File

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

View File

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

View File

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

View File

@ -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<SubscriptionResponse> {
const r = await this.send('GET', '/accounts/subscription', null, true, true);
return new SubscriptionResponse(r);
}
async putProfile(request: UpdateProfileRequest): Promise<ProfileResponse> {
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<OrganizationBillingResponse> {
async getOrganizationBilling(id: string): Promise<BillingResponse> {
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<OrganizationSubscriptionResponse> {
const r = await this.send('GET', '/organizations/' + id + '/subscription', null, true, true);
return new OrganizationSubscriptionResponse(r);
}
async getOrganizationLicense(id: string, installationId: string): Promise<any> {