diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index 13b424dea4..c00fb72b5c 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -78,6 +78,7 @@ import { OrganizationUserDetailsResponse, OrganizationUserUserDetailsResponse, } from '../models/response/organizationUserResponse'; +import { PaymentResponse } from '../models/response/paymentResponse'; import { PreloginResponse } from '../models/response/preloginResponse'; import { ProfileResponse } from '../models/response/profileResponse'; import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; @@ -118,7 +119,7 @@ export abstract class ApiService { getAccountRevisionDate: () => Promise; postPasswordHint: (request: PasswordHintRequest) => Promise; postRegister: (request: RegisterRequest) => Promise; - postPremium: (data: FormData) => Promise; + postPremium: (data: FormData) => Promise; postReinstatePremium: () => Promise; postCancelPremium: () => Promise; postAccountStorage: (request: StorageRequest) => Promise; @@ -241,7 +242,7 @@ export abstract class ApiService { postOrganizationLicenseUpdate: (id: string, data: FormData) => Promise; postOrganizationApiKey: (id: string, request: PasswordVerificationRequest) => Promise; postOrganizationRotateApiKey: (id: string, request: PasswordVerificationRequest) => Promise; - postOrganizationUpgrade: (id: string, request: OrganizationUpgradeRequest) => Promise; + postOrganizationUpgrade: (id: string, request: OrganizationUpgradeRequest) => Promise; postOrganizationSeat: (id: string, request: SeatRequest) => Promise; postOrganizationStorage: (id: string, request: StorageRequest) => Promise; postOrganizationPayment: (id: string, request: PaymentRequest) => Promise; @@ -263,6 +264,7 @@ export abstract class ApiService { getHibpBreach: (username: string) => Promise; postBitPayInvoice: (request: BitPayInvoiceRequest) => Promise; + postSetupPayment: () => Promise; getActiveBearerToken: () => Promise; fetch: (request: Request) => Promise; diff --git a/src/models/response/paymentResponse.ts b/src/models/response/paymentResponse.ts new file mode 100644 index 0000000000..f4cc67452a --- /dev/null +++ b/src/models/response/paymentResponse.ts @@ -0,0 +1,18 @@ +import { BaseResponse } from './baseResponse'; +import { ProfileResponse } from './profileResponse'; + +export class PaymentResponse extends BaseResponse { + userProfile: ProfileResponse; + paymentIntentClientSecret: string; + success: boolean; + + constructor(response: any) { + super(response); + const userProfile = this.getResponseProperty('UserProfile'); + if (userProfile != null) { + this.userProfile = new ProfileResponse(userProfile); + } + this.paymentIntentClientSecret = this.getResponseProperty('PaymentIntentClientSecret'); + this.success = this.getResponseProperty('Success'); + } +} diff --git a/src/services/api.service.ts b/src/services/api.service.ts index ab840ca5a6..911af209b4 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -85,6 +85,7 @@ import { OrganizationUserDetailsResponse, OrganizationUserUserDetailsResponse, } from '../models/response/organizationUserResponse'; +import { PaymentResponse } from '../models/response/paymentResponse'; import { PreloginResponse } from '../models/response/preloginResponse'; import { ProfileResponse } from '../models/response/profileResponse'; import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; @@ -253,8 +254,9 @@ export class ApiService implements ApiServiceAbstraction { return this.send('POST', '/accounts/register', request, false, false); } - postPremium(data: FormData): Promise { - return this.send('POST', '/accounts/premium', data, true, false); + async postPremium(data: FormData): Promise { + const r = await this.send('POST', '/accounts/premium', data, true, true); + return new PaymentResponse(r); } postReinstatePremium(): Promise { @@ -780,8 +782,9 @@ export class ApiService implements ApiServiceAbstraction { return new ApiKeyResponse(r); } - postOrganizationUpgrade(id: string, request: OrganizationUpgradeRequest): Promise { - return this.send('POST', '/organizations/' + id + '/upgrade', request, true, false); + async postOrganizationUpgrade(id: string, request: OrganizationUpgradeRequest): Promise { + const r = await this.send('POST', '/organizations/' + id + '/upgrade', request, true, true); + return new PaymentResponse(r); } postOrganizationSeat(id: string, request: SeatRequest): Promise { @@ -881,6 +884,11 @@ export class ApiService implements ApiServiceAbstraction { return r as string; } + async postSetupPayment(): Promise { + const r = await this.send('POST', '/setup-payment', null, true, true); + return r as string; + } + // Helpers async getActiveBearerToken(): Promise {