diff --git a/integration-libs/opf/base/core/connectors/opf-payment.adapter.ts b/integration-libs/opf/base/core/connectors/opf-payment.adapter.ts index 1bc7003977c..bb42aeb5eec 100644 --- a/integration-libs/opf/base/core/connectors/opf-payment.adapter.ts +++ b/integration-libs/opf/base/core/connectors/opf-payment.adapter.ts @@ -7,6 +7,8 @@ import { OpfPaymentVerificationPayload, OpfPaymentVerificationResponse, + SubmitCompleteRequest, + SubmitCompleteResponse, SubmitRequest, SubmitResponse, } from '@spartacus/opf/base/root'; @@ -31,4 +33,14 @@ export abstract class OpfPaymentAdapter { otpKey: string, paymentSessionId: string ): Observable; + + /** + * Abstract method used to submit-complete payment for hosted-fields pattern + */ + + abstract submitCompletePayment( + submitRequest: SubmitCompleteRequest, + otpKey: string, + paymentSessionId: string + ): Observable; } diff --git a/integration-libs/opf/base/core/connectors/opf-payment.connector.ts b/integration-libs/opf/base/core/connectors/opf-payment.connector.ts index 400ee89fc31..f838b4390c8 100644 --- a/integration-libs/opf/base/core/connectors/opf-payment.connector.ts +++ b/integration-libs/opf/base/core/connectors/opf-payment.connector.ts @@ -8,6 +8,8 @@ import { Injectable } from '@angular/core'; import { OpfPaymentVerificationPayload, OpfPaymentVerificationResponse, + SubmitCompleteRequest, + SubmitCompleteResponse, SubmitRequest, SubmitResponse, } from '@spartacus/opf/base/root'; @@ -33,4 +35,16 @@ export class OpfPaymentConnector { ): Observable { return this.adapter.submitPayment(submitRequest, otpKey, paymentSessionId); } + + public submitCompletePayment( + submitCompleteRequest: SubmitCompleteRequest, + otpKey: string, + paymentSessionId: string + ): Observable { + return this.adapter.submitCompletePayment( + submitCompleteRequest, + otpKey, + paymentSessionId + ); + } } diff --git a/integration-libs/opf/base/core/facade/opf-global-functions.service.ts b/integration-libs/opf/base/core/facade/opf-global-functions.service.ts index a275a497f72..e6630c00318 100644 --- a/integration-libs/opf/base/core/facade/opf-global-functions.service.ts +++ b/integration-libs/opf/base/core/facade/opf-global-functions.service.ts @@ -39,6 +39,7 @@ export class OpfGlobalFunctionsService implements OpfGlobalFunctionsFacade { vcr?: ViewContainerRef ): void { this.registerSubmit(paymentSessionId, vcr); + this.registerSubmitComplete(paymentSessionId, vcr); this._isGlobalServiceInit = true; } @@ -62,6 +63,24 @@ export class OpfGlobalFunctionsService implements OpfGlobalFunctionsFacade { return window.Opf.payments; } + protected startLoaderSpinner(vcr: ViewContainerRef) { + return this.launchDialogService.launch( + LAUNCH_CALLER.PLACE_ORDER_SPINNER, + vcr + ); + } + + protected stopLoaderSpinner(overlayedSpinner: Observable>) { + overlayedSpinner + .subscribe((component) => { + this.launchDialogService.clear(LAUNCH_CALLER.PLACE_ORDER_SPINNER); + if (component) { + component.destroy(); + } + }) + .unsubscribe(); + } + protected registerSubmit( paymentSessionId: string, vcr?: ViewContainerRef @@ -90,10 +109,7 @@ export class OpfGlobalFunctionsService implements OpfGlobalFunctionsFacade { return this.ngZone.run(() => { let overlayedSpinner: void | Observable | undefined>; if (vcr) { - overlayedSpinner = this.launchDialogService.launch( - LAUNCH_CALLER.PLACE_ORDER_SPINNER, - vcr - ); + overlayedSpinner = this.startLoaderSpinner(vcr); } const callbackArray: [ MerchantCallback, @@ -113,16 +129,60 @@ export class OpfGlobalFunctionsService implements OpfGlobalFunctionsFacade { .pipe( finalize(() => { if (overlayedSpinner) { - overlayedSpinner - .subscribe((component) => { - this.launchDialogService.clear( - LAUNCH_CALLER.PLACE_ORDER_SPINNER - ); - if (component) { - component.destroy(); - } - }) - .unsubscribe(); + this.stopLoaderSpinner(overlayedSpinner); + } + }) + ) + .toPromise(); + }); + }; + } + + protected registerSubmitComplete( + paymentSessionId: string, + vcr?: ViewContainerRef + ): void { + this.getGlobalFunctionContainer().submitComplete = ({ + cartId, + additionalData, + submitSuccess = (): void => { + // this is intentional + }, + submitPending = (): void => { + // this is intentional + }, + submitFailure = (): void => { + // this is intentional + }, + }: { + cartId: string; + additionalData: Array; + submitSuccess: MerchantCallback; + submitPending: MerchantCallback; + submitFailure: MerchantCallback; + }): Promise => { + return this.ngZone.run(() => { + let overlayedSpinner: void | Observable | undefined>; + if (vcr) { + overlayedSpinner = this.startLoaderSpinner(vcr); + } + const callbackArray: [ + MerchantCallback, + MerchantCallback, + MerchantCallback + ] = [submitSuccess, submitPending, submitFailure]; + + return this.opfPaymentFacade + .submitCompletePayment({ + additionalData, + paymentSessionId, + cartId, + callbackArray, + }) + .pipe( + finalize(() => { + if (overlayedSpinner) { + this.stopLoaderSpinner(overlayedSpinner); } }) ) diff --git a/integration-libs/opf/base/core/facade/opf-payment.service.ts b/integration-libs/opf/base/core/facade/opf-payment.service.ts index 4b4bc0b5162..3c69627c4f0 100644 --- a/integration-libs/opf/base/core/facade/opf-payment.service.ts +++ b/integration-libs/opf/base/core/facade/opf-payment.service.ts @@ -5,46 +5,18 @@ */ import { Injectable } from '@angular/core'; +import { Command, CommandService, WindowRef } from '@spartacus/core'; import { - Command, - CommandService, - GlobalMessageService, - RoutingService, - UserIdService, - WindowRef, -} from '@spartacus/core'; -import { - MerchantCallback, - OpfOrderFacade, - OpfOtpFacade, - OpfPaymentError, OpfPaymentFacade, OpfPaymentVerificationPayload, OpfPaymentVerificationResponse, - PaymentErrorType, - PaymentMethod, + SubmitCompleteInput, SubmitInput, - SubmitRequest, - SubmitResponse, - SubmitStatus, - defaultError, } from '@spartacus/opf/base/root'; -import { ActiveCartFacade } from '@spartacus/cart/base/root'; -import { Order } from '@spartacus/order/root'; -import { EMPTY, Observable, combineLatest, from, throwError } from 'rxjs'; -import { - catchError, - concatMap, - filter, - map, - switchMap, - take, - tap, -} from 'rxjs/operators'; +import { Observable } from 'rxjs'; import { OpfPaymentConnector } from '../connectors/opf-payment.connector'; -import { OpfPaymentErrorHandlerService } from '../services/opf-payment-error-handler.service'; -import { getBrowserInfo } from '../utils/opf-payment-utils'; +import { OpfPaymentHostedFieldsService } from '../services/opf-payment-hosted-fields.service'; @Injectable() export class OpfPaymentService implements OpfPaymentFacade { @@ -67,115 +39,27 @@ export class OpfPaymentService implements OpfPaymentFacade { }, boolean > = this.commandService.create((payload) => { - const { - paymentMethod, - cartId, - additionalData, - paymentSessionId, - returnPath, - } = payload.submitInput; - - const submitRequest: SubmitRequest = { - paymentMethod, - cartId, - additionalData, - channel: 'BROWSER', - browserInfo: getBrowserInfo(this.winRef.nativeWindow), - }; - if (paymentMethod !== PaymentMethod.CREDIT_CARD) { - submitRequest.encryptedToken = ''; - } - - return combineLatest([ - this.userIdService.getUserId(), - this.activeCartFacade.getActiveCartId(), - ]).pipe( - switchMap(([userId, activeCartId]: [string, string]) => { - submitRequest.cartId = activeCartId; - return this.opfOtpFacade.generateOtpKey(userId, activeCartId); - }), - filter((response) => Boolean(response?.value)), - take(1), - concatMap(({ value: otpKey }) => - this.opfPaymentConnector.submitPayment( - submitRequest, - otpKey, - paymentSessionId - ) - ), - concatMap((response: SubmitResponse) => - this.submitPaymentResponseHandler( - response, - payload.submitInput.callbackArray - ) - ), - tap((order: Order) => { - if (order) { - this.routingService.go({ cxRoute: 'orderConfirmation' }); - } - }), - map((order: Order) => (order ? true : false)), - catchError((error: OpfPaymentError | undefined) => { - this.opfPaymentErrorHandlerService.handlePaymentError( - error, - returnPath - ); - return throwError(error); - }) + return this.opfPaymentHostedFieldsService.submitPayment( + payload.submitInput ); }); - protected submitPaymentResponseHandler( - response: SubmitResponse, - [submitSuccess, submitPending, submitFailure]: [ - MerchantCallback, - MerchantCallback, - MerchantCallback - ] - ) { - if ( - response.status === SubmitStatus.ACCEPTED || - response.status === SubmitStatus.DELAYED - ) { - return from(Promise.resolve(submitSuccess(response))).pipe( - concatMap(() => this.opfOrderFacade.placeOpfOrder(true)) - ); - } else if (response.status === SubmitStatus.PENDING) { - return from(Promise.resolve(submitPending(response))).pipe( - concatMap(() => EMPTY) - ); - } else if (response.status === SubmitStatus.REJECTED) { - return from(Promise.resolve(submitFailure(response))).pipe( - concatMap(() => - throwError({ - ...defaultError, - type: PaymentErrorType.PAYMENT_REJECTED, - }) - ) - ); - } else { - return from(Promise.resolve(submitFailure(response))).pipe( - concatMap(() => - throwError({ - ...defaultError, - type: PaymentErrorType.STATUS_NOT_RECOGNIZED, - }) - ) - ); - } - } + protected submitCompletePaymentCommand: Command< + { + submitCompleteInput: SubmitCompleteInput; + }, + boolean + > = this.commandService.create((payload) => { + return this.opfPaymentHostedFieldsService.submitCompletePayment( + payload.submitCompleteInput + ); + }); constructor( protected commandService: CommandService, protected opfPaymentConnector: OpfPaymentConnector, protected winRef: WindowRef, - protected opfOtpFacade: OpfOtpFacade, - protected activeCartFacade: ActiveCartFacade, - protected userIdService: UserIdService, - protected routingService: RoutingService, - protected opfOrderFacade: OpfOrderFacade, - protected globalMessageService: GlobalMessageService, - protected opfPaymentErrorHandlerService: OpfPaymentErrorHandlerService + protected opfPaymentHostedFieldsService: OpfPaymentHostedFieldsService ) {} verifyPayment( @@ -189,6 +73,14 @@ export class OpfPaymentService implements OpfPaymentFacade { } submitPayment(submitInput: SubmitInput): Observable { - return this.submitPaymentCommand.execute({ submitInput }); + return this.submitPaymentCommand.execute({ + submitInput, + }); + } + + submitCompletePayment( + submitCompleteInput: SubmitCompleteInput + ): Observable { + return this.submitCompletePaymentCommand.execute({ submitCompleteInput }); } } diff --git a/integration-libs/opf/base/core/services/index.ts b/integration-libs/opf/base/core/services/index.ts index e4834c348e0..5d2b219d88b 100644 --- a/integration-libs/opf/base/core/services/index.ts +++ b/integration-libs/opf/base/core/services/index.ts @@ -6,3 +6,4 @@ export * from './opf-endpoints.service'; export * from './opf-payment-error-handler.service'; +export * from './opf-payment-hosted-fields.service'; diff --git a/integration-libs/opf/base/core/services/opf-payment-hosted-fields.service.ts b/integration-libs/opf/base/core/services/opf-payment-hosted-fields.service.ts new file mode 100644 index 00000000000..c8cb176710d --- /dev/null +++ b/integration-libs/opf/base/core/services/opf-payment-hosted-fields.service.ts @@ -0,0 +1,203 @@ +/* + * SPDX-FileCopyrightText: 2023 SAP Spartacus team + * + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Injectable } from '@angular/core'; +import { ActiveCartFacade } from '@spartacus/cart/base/root'; +import { + CommandService, + GlobalMessageService, + RoutingService, + UserIdService, + WindowRef, +} from '@spartacus/core'; +import { Order } from '@spartacus/order/root'; + +import { EMPTY, Observable, combineLatest, from, throwError } from 'rxjs'; +import { + catchError, + concatMap, + filter, + map, + switchMap, + take, + tap, +} from 'rxjs/operators'; +import { OpfOrderFacade, OpfOtpFacade } from '../../root/facade'; +import { + MerchantCallback, + OpfPaymentError, + PaymentErrorType, + PaymentMethod, + SubmitCompleteInput, + SubmitCompleteRequest, + SubmitCompleteResponse, + SubmitInput, + SubmitRequest, + SubmitResponse, + SubmitStatus, + defaultError, +} from '../../root/model'; +import { OpfPaymentConnector } from '../connectors/opf-payment.connector'; +import { OpfPaymentErrorHandlerService } from '../services/opf-payment-error-handler.service'; +import { getBrowserInfo } from '../utils/opf-payment-utils'; + +@Injectable({ providedIn: 'root' }) +export class OpfPaymentHostedFieldsService { + constructor( + protected commandService: CommandService, + protected opfPaymentConnector: OpfPaymentConnector, + protected winRef: WindowRef, + protected opfOtpFacade: OpfOtpFacade, + protected activeCartFacade: ActiveCartFacade, + protected userIdService: UserIdService, + protected routingService: RoutingService, + protected opfOrderFacade: OpfOrderFacade, + protected globalMessageService: GlobalMessageService, + protected opfPaymentErrorHandlerService: OpfPaymentErrorHandlerService + ) {} + + submitPayment(submitInput: SubmitInput): Observable { + const { + paymentMethod, + cartId, + additionalData, + paymentSessionId, + returnPath, + } = submitInput; + + const submitRequest: SubmitRequest = { + paymentMethod, + cartId, + additionalData, + channel: 'BROWSER', + browserInfo: getBrowserInfo(this.winRef.nativeWindow), + }; + if (paymentMethod !== PaymentMethod.CREDIT_CARD) { + submitRequest.encryptedToken = ''; + } + + return combineLatest([ + this.userIdService.getUserId(), + this.activeCartFacade.getActiveCartId(), + ]).pipe( + switchMap(([userId, activeCartId]: [string, string]) => { + submitRequest.cartId = activeCartId; + return this.opfOtpFacade.generateOtpKey(userId, activeCartId); + }), + filter((response) => Boolean(response?.value)), + take(1), + concatMap(({ value: otpKey }) => + this.opfPaymentConnector.submitPayment( + submitRequest, + otpKey, + paymentSessionId + ) + ), + concatMap((response: SubmitResponse) => + this.paymentResponseHandler(response, submitInput.callbackArray) + ), + tap((order: Order) => { + if (order) { + this.routingService.go({ cxRoute: 'orderConfirmation' }); + } + }), + map((order: Order) => (order ? true : false)), + catchError((error: OpfPaymentError | undefined) => { + this.opfPaymentErrorHandlerService.handlePaymentError( + error, + returnPath + ); + return throwError(error); + }) + ); + } + + submitCompletePayment(submitCompleteInput: SubmitCompleteInput) { + const { cartId, additionalData, paymentSessionId, returnPath } = + submitCompleteInput; + + const submitCompleteRequest: SubmitCompleteRequest = { + cartId, + additionalData, + paymentSessionId, + }; + + return combineLatest([ + this.userIdService.getUserId(), + this.activeCartFacade.getActiveCartId(), + ]).pipe( + switchMap(([userId, activeCartId]: [string, string]) => { + submitCompleteRequest.cartId = activeCartId; + return this.opfOtpFacade.generateOtpKey(userId, activeCartId); + }), + filter((response) => Boolean(response?.value)), + take(1), + concatMap(({ value: otpKey }) => + this.opfPaymentConnector.submitCompletePayment( + submitCompleteRequest, + otpKey, + paymentSessionId + ) + ), + concatMap((response: SubmitCompleteResponse) => + this.paymentResponseHandler(response, submitCompleteInput.callbackArray) + ), + tap((order: Order) => { + if (order) { + this.routingService.go({ cxRoute: 'orderConfirmation' }); + } + }), + map((order: Order) => (order ? true : false)), + catchError((error: OpfPaymentError | undefined) => { + this.opfPaymentErrorHandlerService.handlePaymentError( + error, + returnPath + ); + return throwError(error); + }) + ); + } + + protected paymentResponseHandler( + response: SubmitResponse | SubmitCompleteResponse, + [submitSuccess, submitPending, submitFailure]: [ + MerchantCallback, + MerchantCallback, + MerchantCallback + ] + ) { + if ( + response.status === SubmitStatus.ACCEPTED || + response.status === SubmitStatus.DELAYED + ) { + return from(Promise.resolve(submitSuccess(response))).pipe( + concatMap(() => this.opfOrderFacade.placeOpfOrder(true)) + ); + } else if (response.status === SubmitStatus.PENDING) { + return from(Promise.resolve(submitPending(response))).pipe( + concatMap(() => EMPTY) + ); + } else if (response.status === SubmitStatus.REJECTED) { + return from(Promise.resolve(submitFailure(response))).pipe( + concatMap(() => + throwError({ + ...defaultError, + type: PaymentErrorType.PAYMENT_REJECTED, + }) + ) + ); + } else { + return from(Promise.resolve(submitFailure(response))).pipe( + concatMap(() => + throwError({ + ...defaultError, + type: PaymentErrorType.STATUS_NOT_RECOGNIZED, + }) + ) + ); + } + } +} diff --git a/integration-libs/opf/base/core/tokens/tokens.ts b/integration-libs/opf/base/core/tokens/tokens.ts index 3a57c6f6dfe..c325bac7e7a 100644 --- a/integration-libs/opf/base/core/tokens/tokens.ts +++ b/integration-libs/opf/base/core/tokens/tokens.ts @@ -8,6 +8,7 @@ import { InjectionToken } from '@angular/core'; import { Converter } from '@spartacus/core'; import { OpfPaymentVerificationResponse, + SubmitCompleteResponse, SubmitResponse, } from '@spartacus/opf/base/root'; @@ -18,3 +19,7 @@ export const OPF_PAYMENT_VERIFICATION_NORMALIZER = new InjectionToken< export const OPF_PAYMENT_SUBMIT_NORMALIZER = new InjectionToken< Converter >('OpfPaymentSubmitNormalizer'); + +export const OPF_PAYMENT_SUBMIT_COMPLETE_NORMALIZER = new InjectionToken< + Converter +>('OpfPaymentSubmitCompleteNormalizer'); diff --git a/integration-libs/opf/base/core/utils/opf-payment-utils.ts b/integration-libs/opf/base/core/utils/opf-payment-utils.ts index f398c31d5aa..430ce88c58c 100644 --- a/integration-libs/opf/base/core/utils/opf-payment-utils.ts +++ b/integration-libs/opf/base/core/utils/opf-payment-utils.ts @@ -19,6 +19,6 @@ export function getBrowserInfo( screenWidth: nativeWindow?.screen?.width, userAgent: nativeWindow?.navigator?.userAgent, originUrl: nativeWindow?.location?.origin, - timeZoneOffset: new Date().getTimezoneOffset(), + timezoneOffset: new Date().getTimezoneOffset(), }; } diff --git a/integration-libs/opf/base/occ/adapters/occ-opf.adapter.ts b/integration-libs/opf/base/occ/adapters/occ-opf.adapter.ts index 2fae11af438..141946904fb 100644 --- a/integration-libs/opf/base/occ/adapters/occ-opf.adapter.ts +++ b/integration-libs/opf/base/occ/adapters/occ-opf.adapter.ts @@ -8,6 +8,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { ConverterService, backOff, isJaloError } from '@spartacus/core'; import { + OPF_PAYMENT_SUBMIT_COMPLETE_NORMALIZER, OPF_PAYMENT_SUBMIT_NORMALIZER, OPF_PAYMENT_VERIFICATION_NORMALIZER, OpfEndpointsService, @@ -19,6 +20,8 @@ import { OpfConfig, OpfPaymentVerificationPayload, OpfPaymentVerificationResponse, + SubmitCompleteRequest, + SubmitCompleteResponse, SubmitRequest, SubmitResponse, } from '@spartacus/opf/base/root'; @@ -95,6 +98,32 @@ export class OccOpfPaymentAdapter implements OpfPaymentAdapter { ); } + submitCompletePayment( + submitCompleteRequest: SubmitCompleteRequest, + otpKey: string, + paymentSessionId: string + ): Observable { + const headers = new HttpHeaders(this.header) + .set(OPF_CC_PUBLIC_KEY, this.config.opf?.commerceCloudPublicKey || '') + .set(OPF_CC_OTP_KEY, otpKey || ''); + + const url = this.getSubmitCompletePaymentEndpoint(paymentSessionId); + + return this.http + .post(url, submitCompleteRequest, { headers }) + .pipe( + catchError((error) => throwError(error)), + backOff({ + shouldRetry: isJaloError, + }), + backOff({ + shouldRetry: isHttp500Error, + maxTries: 2, + }), + this.converter.pipeable(OPF_PAYMENT_SUBMIT_COMPLETE_NORMALIZER) + ); + } + protected verifyPaymentEndpoint(paymentSessionId: string): string { return this.opfEndpointsService.buildUrl('verifyPayment', { urlParams: { paymentSessionId }, @@ -106,4 +135,10 @@ export class OccOpfPaymentAdapter implements OpfPaymentAdapter { urlParams: { paymentSessionId }, }); } + + protected getSubmitCompletePaymentEndpoint(paymentSessionId: string): string { + return this.opfEndpointsService.buildUrl('submitCompletePayment', { + urlParams: { paymentSessionId }, + }); + } } diff --git a/integration-libs/opf/base/occ/config/default-occ-opf-config.ts b/integration-libs/opf/base/occ/config/default-occ-opf-config.ts index 64fc4b30035..eff76fe0557 100644 --- a/integration-libs/opf/base/occ/config/default-occ-opf-config.ts +++ b/integration-libs/opf/base/occ/config/default-occ-opf-config.ts @@ -12,6 +12,7 @@ export const defaultOccOpfConfig: OccConfig = { endpoints: { verifyPayment: 'payments/${paymentSessionId}/verify', submitPayment: 'payments/${paymentSessionId}/submit', + submitCompletePayment: 'payments/${paymentSessionId}/submit-complete', }, }, }, diff --git a/integration-libs/opf/base/occ/model/occ-opf-endpoints.model.ts b/integration-libs/opf/base/occ/model/occ-opf-endpoints.model.ts index 5be60ee957a..844d5b4fe9f 100644 --- a/integration-libs/opf/base/occ/model/occ-opf-endpoints.model.ts +++ b/integration-libs/opf/base/occ/model/occ-opf-endpoints.model.ts @@ -17,5 +17,9 @@ declare module '@spartacus/core' { * Endpoint to submit payment for Hosted Fields pattern. */ submitPayment?: string | OccEndpoint; + /** + * Endpoint to submit-complete payment for Hosted Fields pattern. + */ + submitCompletePayment?: string | OccEndpoint; } } diff --git a/integration-libs/opf/base/root/facade/opf-payment.facade.ts b/integration-libs/opf/base/root/facade/opf-payment.facade.ts index 6114ee47bc7..83a87f734c1 100644 --- a/integration-libs/opf/base/root/facade/opf-payment.facade.ts +++ b/integration-libs/opf/base/root/facade/opf-payment.facade.ts @@ -11,6 +11,7 @@ import { OPF_BASE_FEATURE } from '../feature-name'; import { OpfPaymentVerificationPayload, OpfPaymentVerificationResponse, + SubmitCompleteInput, SubmitInput, } from '../model'; @@ -41,4 +42,13 @@ export abstract class OpfPaymentFacade { * @param submitInput */ abstract submitPayment(submitInput: SubmitInput): Observable; + + /** + * abstract method to submit-complete payment for Hosted Fields pattern. + * + * @param submitInput + */ + abstract submitCompletePayment( + submitCompleteInput: SubmitCompleteInput + ): Observable; } diff --git a/integration-libs/opf/base/root/model/opf.model.ts b/integration-libs/opf/base/root/model/opf.model.ts index f295c4cf1d1..24ce761bc7d 100644 --- a/integration-libs/opf/base/root/model/opf.model.ts +++ b/integration-libs/opf/base/root/model/opf.model.ts @@ -28,7 +28,7 @@ export interface KeyValuePair { } export type MerchantCallback = ( - response?: SubmitResponse + response?: SubmitResponse | SubmitCompleteResponse ) => void | Promise; export interface GlobalOpfPaymentMethods { @@ -40,6 +40,13 @@ export interface GlobalOpfPaymentMethods { submitFailure: MerchantCallback; paymentMethod: PaymentMethod; }): Promise; + submitComplete?(options: { + cartId: string; + additionalData: Array; + submitSuccess: MerchantCallback; + submitPending: MerchantCallback; + submitFailure: MerchantCallback; + }): Promise; } export interface PaymentBrowserInfo { @@ -51,7 +58,7 @@ export interface PaymentBrowserInfo { screenHeight?: number; screenWidth?: number; userAgent?: string; - timeZoneOffset?: number; + timezoneOffset?: number; ipAddress?: string; originUrl?: string; } @@ -86,18 +93,30 @@ export enum PaymentMethod { GOOGLE_PAY = 'GOOGLE_PAY', } export interface SubmitResponse { - cartId?: string; - status?: SubmitStatus; - reasonCode?: string; + cartId: string; + status: SubmitStatus; + reasonCode: string; paymentMethod: PaymentMethod; - authorizedAmount?: number; + authorizedAmount: number; + customFields: Array; +} - customFields?: Array; +export interface SubmitCompleteResponse { + cartId: string; + status: SubmitStatus; + reasonCode: number; + customFields: Array; } export interface SubmitCompleteRequest { paymentSessionId?: string; additionalData?: Array; cartId?: string; - otpKey?: string; +} +export interface SubmitCompleteInput { + additionalData: Array; + paymentSessionId: string; + cartId: string; + callbackArray: [MerchantCallback, MerchantCallback, MerchantCallback]; + returnPath?: Array; }