From 01042a8ccb1bae2c7db2f56a5d8c5d7b83381e88 Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Wed, 15 Apr 2026 16:35:01 +0530 Subject: [PATCH 1/7] support multiple payment gateway --- .../apple-pay/apple-pay.component.spec.ts | 54 +++++++-------- .../apple-pay/apple-pay.component.ts | 10 +-- .../google-pay/google-pay.component.spec.ts | 2 +- .../google-pay/google-pay.component.ts | 2 +- .../google-pay/google-pay.service.spec.ts | 13 ++-- .../google-pay/google-pay.service.ts | 14 ++-- .../opf-quick-buy-buttons.component.spec.ts | 5 +- .../opf-quick-buy-buttons.component.ts | 4 +- .../opf-quick-buy-buttons.service.spec.ts | 69 +++++++++++-------- .../opf-quick-buy-buttons.service.ts | 48 ++++++------- 10 files changed, 119 insertions(+), 102 deletions(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts index dfadf77bca5..0e315cb743b 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts @@ -7,7 +7,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { Cart } from '@spartacus/cart/base/root'; import { Product } from '@spartacus/core'; -import { OpfActiveConfiguration } from '@spartacus/opf/base/root'; import { OpfPaymentErrorHandlerService } from '@spartacus/opf/payment/core'; import { OpfQuickBuyTransactionService } from '@spartacus/opf/quick-buy/core'; import { @@ -33,17 +32,6 @@ const mockCart: Cart = { code: '123', }; -const mockActiveConfiguration: OpfActiveConfiguration = { - digitalWalletQuickBuy: [ - { - merchantId: 'merchant.com.adyen.upscale.test', - provider: OpfQuickBuyProviderType.APPLE_PAY, - countryCode: 'US', - }, - { merchantId: 'merchant.test.example' }, - ], -}; - describe('ApplePayComponent', () => { let component: ApplePayComponent; let fixture: ComponentFixture; @@ -110,14 +98,17 @@ describe('ApplePayComponent', () => { provider: OpfQuickBuyProviderType.APPLE_PAY, countryCode: mockCountryCode, merchantId: 'merchant.com.adyen.upscale.test', + enabled: true, }; - component.activeConfiguration = { digitalWalletQuickBuy: [digitalWallet] }; + component.activeConfiguration = [ + { digitalWalletQuickBuy: [digitalWallet] } as any, + ]; const mockObservable = of(true); mockApplePayService.isApplePaySupported.and.returnValue(mockObservable); fixture.detectChanges(); - expect(component.isApplePaySupported$).toBe(mockObservable); + expect(component.isApplePaySupported$).toEqual(mockObservable); }); it('should not initialize isApplePaySupported$ provider is not Apple pay', () => { @@ -125,13 +116,14 @@ describe('ApplePayComponent', () => { provider: OpfQuickBuyProviderType.GOOGLE_PAY, countryCode: mockCountryCode, merchantId: 'merchant.com.adyen.upscale.test', + enabled: true, }; - component.activeConfiguration = { digitalWalletQuickBuy: [digitalWallet] }; - - const mockObservable = of(true); - mockApplePayService.isApplePaySupported.and.returnValue(mockObservable); + component.activeConfiguration = [ + { digitalWalletQuickBuy: [digitalWallet] } as any, + ]; fixture.detectChanges(); + expect(component.isApplePaySupported$).toBeUndefined(); expect(mockApplePayService.isApplePaySupported).not.toHaveBeenCalled(); }); @@ -139,21 +131,23 @@ describe('ApplePayComponent', () => { mockApplePayService.start.and.returnValue( of({ status: 1 }) ); - component.activeConfiguration = { - digitalWalletQuickBuy: [ - { - provider: OpfQuickBuyProviderType.APPLE_PAY, - countryCode: mockCountryCode, - merchantId: 'merchant.com.adyen.upscale.test', - }, - ], + + const digitalWallet: OpfQuickBuyDigitalWallet = { + provider: OpfQuickBuyProviderType.APPLE_PAY, + countryCode: mockCountryCode, + merchantId: 'merchant.com.adyen.upscale.test', + enabled: true, }; - component.activeConfiguration = mockActiveConfiguration; + + component.activeConfiguration = [ + { + digitalWalletQuickBuy: [digitalWallet], + } as any, + ]; + fixture.detectChanges(); component.initTransaction(); - expect( - mockOpfPaymentErrorHandlerService.handlePaymentError - ).not.toHaveBeenCalled(); + expect(mockApplePayService.start).toHaveBeenCalled(); }); }); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts index 8e23008e6c5..be21ed53d9a 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts @@ -31,7 +31,7 @@ import { ApplePayService } from './apple-pay.service'; imports: [NgIf, AsyncPipe], }) export class ApplePayComponent implements OnInit { - @Input() activeConfiguration: OpfActiveConfiguration; + @Input() activeConfiguration: OpfActiveConfiguration[]; protected applePayService = inject(ApplePayService); protected currentProductService = inject(CurrentProductService); @@ -43,10 +43,12 @@ export class ApplePayComponent implements OnInit { applePayDigitalWallet?: OpfQuickBuyDigitalWallet; ngOnInit(): void { - this.applePayDigitalWallet = - this.activeConfiguration?.digitalWalletQuickBuy?.find( + this.applePayDigitalWallet = this.activeConfiguration + ?.flatMap((config) => config.digitalWalletQuickBuy || []) + .find( (digitalWallet) => - digitalWallet.provider === OpfQuickBuyProviderType.APPLE_PAY + digitalWallet.provider === OpfQuickBuyProviderType.APPLE_PAY && + digitalWallet.enabled ); if ( !this.applePayDigitalWallet?.merchantId || diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts index 2f0df53a7dc..5b32ddd3ed3 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts @@ -48,7 +48,7 @@ describe('OpfGooglePayComponent', () => { fixture = TestBed.createComponent(OpfGooglePayComponent); component = fixture.componentInstance; - component.activeConfiguration = {}; + component.activeConfiguration = []; }); async function detectChanges() { diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts index 35eddd31506..bb10fb7fbdf 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts @@ -29,7 +29,7 @@ export class OpfGooglePayComponent implements OnInit { protected opfGooglePayService = inject(OpfGooglePayService); protected changeDetectionRef = inject(ChangeDetectorRef); - @Input() activeConfiguration: OpfActiveConfiguration; + @Input() activeConfiguration: OpfActiveConfiguration[]; @ViewChild('googlePayButtonContainer') googlePayButtonContainer: ElementRef; diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts index 1c567313dfe..9053b98a652 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts @@ -8,7 +8,10 @@ import { ElementRef } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { Cart } from '@spartacus/cart/base/root'; import { Address, PriceType } from '@spartacus/core'; -import { OpfResourceLoaderService } from '@spartacus/opf/base/root'; +import { + OpfActiveConfiguration, + OpfResourceLoaderService, +} from '@spartacus/opf/base/root'; import { OpfPaymentFacade } from '@spartacus/opf/payment/root'; import { OpfQuickBuyTransactionService } from '@spartacus/opf/quick-buy/core'; import { @@ -86,7 +89,7 @@ describe('OpfGooglePayService', () => { ]); mockQuickBuyButtonsService = jasmine.createSpyObj( 'OpfQuickBuyButtonsService', - ['getQuickBuyProviderConfig'] + ['getQuickBuyProviderConfig', 'getActiveConfigurationForProvider'] ); mockOpfQuickBuyConfig = { @@ -145,7 +148,7 @@ describe('OpfGooglePayService', () => { describe('getClient', () => { it('should return the Google Payment client instance', () => { - const activeConfiguration = {}; + const activeConfiguration: OpfActiveConfiguration[] = []; service.initClient(activeConfiguration); const client = service['getClient'](); @@ -225,7 +228,7 @@ describe('OpfGooglePayService', () => { describe('isReadyToPay', () => { it('should return info about readiness to pay from the Google Pay API', async () => { - const activeConfiguration = {}; + const activeConfiguration: OpfActiveConfiguration[] = []; service.initClient(activeConfiguration); @@ -247,7 +250,7 @@ describe('OpfGooglePayService', () => { describe('initClient', () => { it('should initialize the Google Payment client with configurations', () => { - const activeConfiguration = {}; + const activeConfiguration: any[] = []; service.initClient(activeConfiguration); const client = service['googlePaymentClient']; diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts index 8b3802da025..beb23d96a42 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts @@ -169,8 +169,15 @@ export class OpfGooglePayService { ]); } - initClient(activeConfiguration: OpfActiveConfiguration): void { - this.setAllowedPaymentMethodsConfig(activeConfiguration); + initClient(activeConfigurations: OpfActiveConfiguration[]): void { + const googlePayGateway = + this.opfQuickBuyButtonsService.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.GOOGLE_PAY, + activeConfigurations + ); + if (googlePayGateway) { + this.setAllowedPaymentMethodsConfig(googlePayGateway); + } this.updateGooglePaymentClient(); } @@ -498,9 +505,8 @@ export class OpfGooglePayService { const googlePayConfig = this.opfQuickBuyButtonsService.getQuickBuyProviderConfig( OpfQuickBuyProviderType.GOOGLE_PAY, - activeConfiguration + [activeConfiguration] ); - this.googlePaymentRequest.allowedPaymentMethods = [ { parameters: { diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.spec.ts index 474d3a636a9..d7878cb33ff 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.spec.ts @@ -11,6 +11,7 @@ import { OpfQuickBuyProviderType } from '../../root/model'; import { OpfQuickBuyButtonsComponent } from './opf-quick-buy-buttons.component'; import { OpfQuickBuyButtonsService } from './opf-quick-buy-buttons.service'; import createSpy = jasmine.createSpy; +import { OpfActiveConfiguration } from '@spartacus/opf/base/root'; const routerStateSubject = new BehaviorSubject({ state: { @@ -33,6 +34,8 @@ describe('OpfQuickBuyButtonsComponent', () => { opfQuickBuyButtonsServiceMock = jasmine.createSpyObj('OpfQuickBuyService', [ 'getPaymentGatewayConfiguration', 'isQuickBuyProviderEnabled', + 'getQuickBuyProviderConfig', + 'getActiveConfigurationForProvider', ]); await TestBed.configureTestingModule({ @@ -70,7 +73,7 @@ describe('OpfQuickBuyButtonsComponent', () => { it('should determine if a payment method is enabled', () => { const provider = OpfQuickBuyProviderType.APPLE_PAY; - const activeConfiguration = {}; + const activeConfiguration: OpfActiveConfiguration[] = []; opfQuickBuyButtonsServiceMock.isQuickBuyProviderEnabled.and.returnValue( true ); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts index 0130fe61636..ec110222df4 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts @@ -26,7 +26,7 @@ import { OpfQuickBuyButtonsService } from './opf-quick-buy-buttons.service'; }) export class OpfQuickBuyButtonsComponent implements OnInit { protected opfQuickBuyButtonsService = inject(OpfQuickBuyButtonsService); - protected paymentGatewayConfig$: Observable; + protected paymentGatewayConfig$: Observable; PAYMENT_METHODS = OpfQuickBuyProviderType; @@ -37,7 +37,7 @@ export class OpfQuickBuyButtonsComponent implements OnInit { isPaymentMethodEnabled( provider: OpfQuickBuyProviderType, - activeConfiguration: OpfActiveConfiguration + activeConfiguration: OpfActiveConfiguration[] ): boolean { return this.opfQuickBuyButtonsService.isQuickBuyProviderEnabled( provider, diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts index 774eab36a26..e425e12777e 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts @@ -52,7 +52,7 @@ describe('OpfQuickBuyButtonsService', () => { }); describe('getPaymentGatewayConfiguration', () => { - it('should return the first PAYMENT_GATEWAY configuration when available', () => { + it('should return all PAYMENT_GATEWAY configurations when available', () => { const mockConfigurations = [ { providerType: OpfPaymentProviderType.PAYMENT_METHOD }, { providerType: OpfPaymentProviderType.PAYMENT_GATEWAY }, @@ -65,7 +65,10 @@ describe('OpfQuickBuyButtonsService', () => { ); service.getPaymentGatewayConfiguration().subscribe((result) => { - expect(result).toEqual(mockConfigurations[1]); + expect(result).toEqual([ + mockConfigurations[1], + mockConfigurations[2], + ] as any); }); }); @@ -77,7 +80,7 @@ describe('OpfQuickBuyButtonsService', () => { ); service.getPaymentGatewayConfiguration().subscribe((result) => { - expect(result).toBeUndefined(); + expect(result).toEqual([]); }); }); @@ -90,7 +93,7 @@ describe('OpfQuickBuyButtonsService', () => { ); service.getPaymentGatewayConfiguration().subscribe((result) => { - expect(result).toBeUndefined(); + expect(result).toEqual([]); }); }); @@ -111,11 +114,13 @@ describe('OpfQuickBuyButtonsService', () => { const provider = OpfQuickBuyProviderType.APPLE_PAY; it('should return true when the provider is enabled', () => { - const activeConfiguration = { - digitalWalletQuickBuy: [ - { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, - ], - }; + const activeConfiguration = [ + { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, + ], + } as any, + ]; const result = service.isQuickBuyProviderEnabled( provider, @@ -125,11 +130,13 @@ describe('OpfQuickBuyButtonsService', () => { }); it('should return false when the provider is disabled', () => { - const activeConfiguration = { - digitalWalletQuickBuy: [ - { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: false }, - ], - }; + const activeConfiguration = [ + { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: false }, + ], + } as any, + ]; const result = service.isQuickBuyProviderEnabled( provider, @@ -139,11 +146,13 @@ describe('OpfQuickBuyButtonsService', () => { }); it('should return false when the provider is not found', () => { - const activeConfiguration = { - digitalWalletQuickBuy: [ - { provider: 'otherProvider' as any, enabled: true }, - ], - }; + const activeConfiguration = [ + { + digitalWalletQuickBuy: [ + { provider: 'otherProvider' as any, enabled: true }, + ], + } as any, + ]; const result = service.isQuickBuyProviderEnabled( provider, @@ -167,9 +176,11 @@ describe('OpfQuickBuyButtonsService', () => { it('should return false when digitalWalletQuickBuy is null or empty', () => { const provider = OpfQuickBuyProviderType.APPLE_PAY; - const activeConfiguration = { - digitalWalletQuickBuy: null as any, - }; + const activeConfiguration = [ + { + digitalWalletQuickBuy: null as any, + } as any, + ]; const result = service.isQuickBuyProviderEnabled( provider, @@ -189,12 +200,14 @@ describe('OpfQuickBuyButtonsService', () => { }; it('should return config for specific provider', () => { - const activeConfiguration = { - digitalWalletQuickBuy: [ - { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, - config, - ], - }; + const activeConfiguration = [ + { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, + config, + ], + } as any, + ]; const result = service.getQuickBuyProviderConfig( OpfQuickBuyProviderType.GOOGLE_PAY, diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts index e1b48996e83..66734b699a1 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts @@ -34,47 +34,43 @@ export class OpfQuickBuyButtonsService { protected activeCartFacade = inject(ActiveCartFacade); protected multiCartFacade = inject(MultiCartFacade); - getPaymentGatewayConfiguration(): Observable { + getPaymentGatewayConfiguration(): Observable { return this.opfBaseFacade .getActiveConfigurationsState() .pipe( - map( - (config) => - (config?.data?.value || []).filter( - (item) => - item?.providerType === OpfPaymentProviderType.PAYMENT_GATEWAY - )[0] + map((config) => + (config?.data?.value || []).filter( + (item) => + item?.providerType === OpfPaymentProviderType.PAYMENT_GATEWAY + ) ) ); } getQuickBuyProviderConfig( provider: OpfQuickBuyProviderType, - activeConfiguration: OpfActiveConfiguration + activeConfigurations: OpfActiveConfiguration[] ): OpfQuickBuyDigitalWallet | undefined { - let config; - if (activeConfiguration && activeConfiguration.digitalWalletQuickBuy) { - config = activeConfiguration?.digitalWalletQuickBuy.find( - (item) => item.provider === provider - ); - } - - return config; + return activeConfigurations + ?.flatMap((config) => config.digitalWalletQuickBuy ?? []) + .find((item) => item.provider === provider && item.enabled); } isQuickBuyProviderEnabled( provider: OpfQuickBuyProviderType, - activeConfiguration: OpfActiveConfiguration + activeConfigurations: OpfActiveConfiguration[] ): boolean { - let isEnabled = false; - if (activeConfiguration && activeConfiguration.digitalWalletQuickBuy) { - isEnabled = Boolean( - activeConfiguration?.digitalWalletQuickBuy.find( - (item) => item.provider === provider - )?.enabled - ); - } + return !!this.getQuickBuyProviderConfig(provider, activeConfigurations); + } - return isEnabled; + getActiveConfigurationForProvider( + provider: OpfQuickBuyProviderType, + activeConfigurations: OpfActiveConfiguration[] + ): OpfActiveConfiguration | undefined { + return activeConfigurations?.find((config) => + config.digitalWalletQuickBuy?.some( + (item) => item.provider === provider && item.enabled + ) + ); } } From ed2bec5fc88416bfad7b39df9543c5d03aeff82c Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Thu, 23 Apr 2026 17:40:28 +0530 Subject: [PATCH 2/7] address review comments --- .../apple-pay/apple-pay.component.ts | 11 +++++++++-- .../google-pay/google-pay.component.ts | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts index be21ed53d9a..67be25a9e18 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts @@ -31,7 +31,9 @@ import { ApplePayService } from './apple-pay.service'; imports: [NgIf, AsyncPipe], }) export class ApplePayComponent implements OnInit { - @Input() activeConfiguration: OpfActiveConfiguration[]; + @Input() activeConfiguration: + | OpfActiveConfiguration + | OpfActiveConfiguration[]; protected applePayService = inject(ApplePayService); protected currentProductService = inject(CurrentProductService); @@ -42,8 +44,13 @@ export class ApplePayComponent implements OnInit { isApplePaySupported$: Observable; applePayDigitalWallet?: OpfQuickBuyDigitalWallet; + get activeConfigurations(): OpfActiveConfiguration[] { + const value = this.activeConfiguration; + return Array.isArray(value) ? value : value ? [value] : []; + } + ngOnInit(): void { - this.applePayDigitalWallet = this.activeConfiguration + this.applePayDigitalWallet = this.activeConfigurations ?.flatMap((config) => config.digitalWalletQuickBuy || []) .find( (digitalWallet) => diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts index bb10fb7fbdf..0627b59a295 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts @@ -29,15 +29,21 @@ export class OpfGooglePayComponent implements OnInit { protected opfGooglePayService = inject(OpfGooglePayService); protected changeDetectionRef = inject(ChangeDetectorRef); - @Input() activeConfiguration: OpfActiveConfiguration[]; + @Input() activeConfiguration: + | OpfActiveConfiguration + | OpfActiveConfiguration[]; @ViewChild('googlePayButtonContainer') googlePayButtonContainer: ElementRef; isReadyToPayState$: BehaviorSubject = new BehaviorSubject(false); + get activeConfigurations(): OpfActiveConfiguration[] { + const value = this.activeConfiguration; + return Array.isArray(value) ? value : value ? [value] : []; + } ngOnInit(): void { this.opfGooglePayService.loadResources().then(() => { - this.opfGooglePayService.initClient(this.activeConfiguration); + this.opfGooglePayService.initClient(this.activeConfigurations); this.opfGooglePayService.isReadyToPay().then((response: any) => { this.isReadyToPayState$.next(!!response?.result); this.changeDetectionRef.detectChanges(); From de3262068bf288fdb661e1dc055268be3ee0db98 Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Thu, 23 Apr 2026 18:01:28 +0530 Subject: [PATCH 3/7] fix: sonar issue --- .../opf-quick-buy-buttons/apple-pay/apple-pay.component.ts | 5 +++-- .../opf-quick-buy-buttons/google-pay/google-pay.component.ts | 3 ++- .../opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts index 67be25a9e18..d506b8efe39 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts @@ -46,9 +46,10 @@ export class ApplePayComponent implements OnInit { get activeConfigurations(): OpfActiveConfiguration[] { const value = this.activeConfiguration; - return Array.isArray(value) ? value : value ? [value] : []; + if (!value) return []; + return Array.isArray(value) ? value : [value]; } - + ngOnInit(): void { this.applePayDigitalWallet = this.activeConfigurations ?.flatMap((config) => config.digitalWalletQuickBuy || []) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts index 0627b59a295..fddd1e9c2d0 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts @@ -39,7 +39,8 @@ export class OpfGooglePayComponent implements OnInit { get activeConfigurations(): OpfActiveConfiguration[] { const value = this.activeConfiguration; - return Array.isArray(value) ? value : value ? [value] : []; + if (!value) return []; + return Array.isArray(value) ? value : [value]; } ngOnInit(): void { this.opfGooglePayService.loadResources().then(() => { diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts index ec110222df4..4f656f2fe0f 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts @@ -37,11 +37,11 @@ export class OpfQuickBuyButtonsComponent implements OnInit { isPaymentMethodEnabled( provider: OpfQuickBuyProviderType, - activeConfiguration: OpfActiveConfiguration[] + activeConfigurations: OpfActiveConfiguration[] ): boolean { return this.opfQuickBuyButtonsService.isQuickBuyProviderEnabled( provider, - activeConfiguration + activeConfigurations ); } } From 28abef4dadb8a82f959666dae7cf7e2da3b58a1d Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Thu, 23 Apr 2026 18:15:48 +0530 Subject: [PATCH 4/7] revert it & use normalizer --- .../opf-quick-buy-buttons/apple-pay/apple-pay.component.ts | 4 +--- .../opf-quick-buy-buttons/google-pay/google-pay.component.ts | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts index d506b8efe39..c0b4370acfe 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts @@ -31,9 +31,7 @@ import { ApplePayService } from './apple-pay.service'; imports: [NgIf, AsyncPipe], }) export class ApplePayComponent implements OnInit { - @Input() activeConfiguration: - | OpfActiveConfiguration - | OpfActiveConfiguration[]; + @Input() activeConfiguration: OpfActiveConfiguration; protected applePayService = inject(ApplePayService); protected currentProductService = inject(CurrentProductService); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts index fddd1e9c2d0..eb779f6ed0c 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts @@ -29,9 +29,7 @@ export class OpfGooglePayComponent implements OnInit { protected opfGooglePayService = inject(OpfGooglePayService); protected changeDetectionRef = inject(ChangeDetectorRef); - @Input() activeConfiguration: - | OpfActiveConfiguration - | OpfActiveConfiguration[]; + @Input() activeConfiguration: OpfActiveConfiguration; @ViewChild('googlePayButtonContainer') googlePayButtonContainer: ElementRef; From ef2ff54cb4f4210812839043e629b8c1e7ab83d4 Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Thu, 23 Apr 2026 22:16:49 +0530 Subject: [PATCH 5/7] fix: unit test cases & build error --- .../apple-pay/apple-pay.component.spec.ts | 20 +++++++++---------- .../apple-pay/apple-pay.component.ts | 4 +++- .../google-pay/google-pay.component.spec.ts | 5 +++-- .../google-pay/google-pay.component.ts | 4 +++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts index 0e315cb743b..a529bd7369e 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.spec.ts @@ -100,9 +100,9 @@ describe('ApplePayComponent', () => { merchantId: 'merchant.com.adyen.upscale.test', enabled: true, }; - component.activeConfiguration = [ - { digitalWalletQuickBuy: [digitalWallet] } as any, - ]; + component.activeConfiguration = { + digitalWalletQuickBuy: [digitalWallet], + }; const mockObservable = of(true); mockApplePayService.isApplePaySupported.and.returnValue(mockObservable); @@ -118,9 +118,9 @@ describe('ApplePayComponent', () => { merchantId: 'merchant.com.adyen.upscale.test', enabled: true, }; - component.activeConfiguration = [ - { digitalWalletQuickBuy: [digitalWallet] } as any, - ]; + component.activeConfiguration = { + digitalWalletQuickBuy: [digitalWallet], + }; fixture.detectChanges(); expect(component.isApplePaySupported$).toBeUndefined(); @@ -139,11 +139,9 @@ describe('ApplePayComponent', () => { enabled: true, }; - component.activeConfiguration = [ - { - digitalWalletQuickBuy: [digitalWallet], - } as any, - ]; + component.activeConfiguration = { + digitalWalletQuickBuy: [digitalWallet], + }; fixture.detectChanges(); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts index c0b4370acfe..d506b8efe39 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts @@ -31,7 +31,9 @@ import { ApplePayService } from './apple-pay.service'; imports: [NgIf, AsyncPipe], }) export class ApplePayComponent implements OnInit { - @Input() activeConfiguration: OpfActiveConfiguration; + @Input() activeConfiguration: + | OpfActiveConfiguration + | OpfActiveConfiguration[]; protected applePayService = inject(ApplePayService); protected currentProductService = inject(CurrentProductService); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts index 5b32ddd3ed3..40da53495b1 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts @@ -10,6 +10,7 @@ import { ElementRef, } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; + import { OpfGooglePayComponent } from './google-pay.component'; import { OpfGooglePayService } from './google-pay.service'; @@ -48,7 +49,7 @@ describe('OpfGooglePayComponent', () => { fixture = TestBed.createComponent(OpfGooglePayComponent); component = fixture.componentInstance; - component.activeConfiguration = []; + component.activeConfiguration = {}; }); async function detectChanges() { @@ -65,7 +66,7 @@ describe('OpfGooglePayComponent', () => { expect(mockOpfGooglePayService.loadResources).toHaveBeenCalled(); expect(mockOpfGooglePayService.initClient).toHaveBeenCalledWith( - component.activeConfiguration + component.activeConfigurations ); }); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts index eb779f6ed0c..fddd1e9c2d0 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts @@ -29,7 +29,9 @@ export class OpfGooglePayComponent implements OnInit { protected opfGooglePayService = inject(OpfGooglePayService); protected changeDetectionRef = inject(ChangeDetectorRef); - @Input() activeConfiguration: OpfActiveConfiguration; + @Input() activeConfiguration: + | OpfActiveConfiguration + | OpfActiveConfiguration[]; @ViewChild('googlePayButtonContainer') googlePayButtonContainer: ElementRef; From 47c549b94dda03c5c267c732c84eeeb79f194298 Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Mon, 27 Apr 2026 09:22:54 +0530 Subject: [PATCH 6/7] review comments --- .../apple-pay/apple-pay.component.ts | 11 +- .../google-pay/google-pay.component.spec.ts | 6 +- .../google-pay/google-pay.component.ts | 10 +- .../google-pay/google-pay.service.spec.ts | 15 ++- .../google-pay/google-pay.service.ts | 7 +- .../opf-quick-buy-buttons.component.ts | 8 +- .../opf-quick-buy-buttons.service.spec.ts | 123 +++++++++++++++++- .../opf-quick-buy-buttons.service.ts | 37 ++++-- 8 files changed, 185 insertions(+), 32 deletions(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts index d506b8efe39..11a7dd25690 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/apple-pay/apple-pay.component.ts @@ -44,14 +44,11 @@ export class ApplePayComponent implements OnInit { isApplePaySupported$: Observable; applePayDigitalWallet?: OpfQuickBuyDigitalWallet; - get activeConfigurations(): OpfActiveConfiguration[] { - const value = this.activeConfiguration; - if (!value) return []; - return Array.isArray(value) ? value : [value]; - } - ngOnInit(): void { - this.applePayDigitalWallet = this.activeConfigurations + const activeConfigurations = Array.isArray(this.activeConfiguration) + ? this.activeConfiguration + : [this.activeConfiguration]; + this.applePayDigitalWallet = activeConfigurations ?.flatMap((config) => config.digitalWalletQuickBuy || []) .find( (digitalWallet) => diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts index 40da53495b1..ed06a707d46 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.spec.ts @@ -65,9 +65,9 @@ describe('OpfGooglePayComponent', () => { await detectChanges(); expect(mockOpfGooglePayService.loadResources).toHaveBeenCalled(); - expect(mockOpfGooglePayService.initClient).toHaveBeenCalledWith( - component.activeConfigurations - ); + expect(mockOpfGooglePayService.initClient).toHaveBeenCalledWith([ + component.activeConfiguration, + ]); }); it('should update ready to pay state when Google Pay is ready', async () => { diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts index fddd1e9c2d0..17a5343a033 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.component.ts @@ -37,14 +37,12 @@ export class OpfGooglePayComponent implements OnInit { isReadyToPayState$: BehaviorSubject = new BehaviorSubject(false); - get activeConfigurations(): OpfActiveConfiguration[] { - const value = this.activeConfiguration; - if (!value) return []; - return Array.isArray(value) ? value : [value]; - } ngOnInit(): void { + const activeConfigurations = Array.isArray(this.activeConfiguration) + ? this.activeConfiguration + : [this.activeConfiguration]; this.opfGooglePayService.loadResources().then(() => { - this.opfGooglePayService.initClient(this.activeConfigurations); + this.opfGooglePayService.initClient(activeConfigurations); this.opfGooglePayService.isReadyToPay().then((response: any) => { this.isReadyToPayState$.next(!!response?.result); this.changeDetectionRef.detectChanges(); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts index 9053b98a652..bca5e28ea74 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.spec.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +/// import { ElementRef } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { Cart } from '@spartacus/cart/base/root'; @@ -249,7 +250,7 @@ describe('OpfGooglePayService', () => { }); describe('initClient', () => { - it('should initialize the Google Payment client with configurations', () => { + it('should initialize the Google Payment client with configurations (array)', () => { const activeConfiguration: any[] = []; service.initClient(activeConfiguration); @@ -257,6 +258,18 @@ describe('OpfGooglePayService', () => { expect(client).toBeDefined(); }); + + it('should initialize the Google Payment client with single configuration', () => { + const activeConfiguration: OpfActiveConfiguration = { + merchantId: 'test-merchant', + providerType: 'PAYMENT_GATEWAY', + } as any; + service.initClient(activeConfiguration); + + const client = service['googlePaymentClient']; + + expect(client).toBeDefined(); + }); }); describe('updateTransactionInfo', () => { diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts index beb23d96a42..dcb8afa3115 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/google-pay/google-pay.service.ts @@ -169,7 +169,12 @@ export class OpfGooglePayService { ]); } - initClient(activeConfigurations: OpfActiveConfiguration[]): void { + initClient( + activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] + ): void { + const activeConfigurations = Array.isArray(activeConfiguration) + ? activeConfiguration + : [activeConfiguration]; const googlePayGateway = this.opfQuickBuyButtonsService.getActiveConfigurationForProvider( OpfQuickBuyProviderType.GOOGLE_PAY, diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts index 4f656f2fe0f..daa5c221ded 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.component.ts @@ -26,7 +26,9 @@ import { OpfQuickBuyButtonsService } from './opf-quick-buy-buttons.service'; }) export class OpfQuickBuyButtonsComponent implements OnInit { protected opfQuickBuyButtonsService = inject(OpfQuickBuyButtonsService); - protected paymentGatewayConfig$: Observable; + protected paymentGatewayConfig$: Observable< + OpfActiveConfiguration | OpfActiveConfiguration[] + >; PAYMENT_METHODS = OpfQuickBuyProviderType; @@ -37,11 +39,11 @@ export class OpfQuickBuyButtonsComponent implements OnInit { isPaymentMethodEnabled( provider: OpfQuickBuyProviderType, - activeConfigurations: OpfActiveConfiguration[] + activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] ): boolean { return this.opfQuickBuyButtonsService.isQuickBuyProviderEnabled( provider, - activeConfigurations + activeConfiguration ); } } diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts index e425e12777e..4ce9cc2d771 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.spec.ts @@ -113,7 +113,7 @@ describe('OpfQuickBuyButtonsService', () => { describe('isQuickBuyProviderEnabled', () => { const provider = OpfQuickBuyProviderType.APPLE_PAY; - it('should return true when the provider is enabled', () => { + it('should return true when the provider is enabled (array)', () => { const activeConfiguration = [ { digitalWalletQuickBuy: [ @@ -129,6 +129,20 @@ describe('OpfQuickBuyButtonsService', () => { expect(result).toBeTruthy(); }); + it('should return true when the provider is enabled (single object)', () => { + const activeConfiguration = { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, + ], + } as any; + + const result = service.isQuickBuyProviderEnabled( + provider, + activeConfiguration + ); + expect(result).toBeTruthy(); + }); + it('should return false when the provider is disabled', () => { const activeConfiguration = [ { @@ -199,7 +213,7 @@ describe('OpfQuickBuyButtonsService', () => { enabled: true, }; - it('should return config for specific provider', () => { + it('should return config for specific provider (array)', () => { const activeConfiguration = [ { digitalWalletQuickBuy: [ @@ -215,5 +229,110 @@ describe('OpfQuickBuyButtonsService', () => { ); expect(result).toBe(config); }); + + it('should return config for specific provider (single object)', () => { + const activeConfiguration = { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, + config, + ], + } as any; + + const result = service.getQuickBuyProviderConfig( + OpfQuickBuyProviderType.GOOGLE_PAY, + activeConfiguration + ); + expect(result).toBe(config); + }); + + it('should return undefined when activeConfiguration is null', () => { + const result = service.getQuickBuyProviderConfig( + OpfQuickBuyProviderType.GOOGLE_PAY, + null as any + ); + expect(result).toBeUndefined(); + }); + + it('should return undefined when activeConfiguration is undefined', () => { + const result = service.getQuickBuyProviderConfig( + OpfQuickBuyProviderType.GOOGLE_PAY, + undefined as any + ); + expect(result).toBeUndefined(); + }); + }); + + describe('getActiveConfigurationForProvider', () => { + const mockConfig = { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: true }, + ], + } as any; + + it('should return configuration for specific provider (array)', () => { + const activeConfigurations = [mockConfig]; + + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.APPLE_PAY, + activeConfigurations + ); + expect(result).toBe(mockConfig); + }); + + it('should return configuration for specific provider (single object)', () => { + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.APPLE_PAY, + mockConfig + ); + expect(result).toBe(mockConfig); + }); + + it('should return undefined when provider is not found (array)', () => { + const activeConfigurations = [mockConfig]; + + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.GOOGLE_PAY, + activeConfigurations + ); + expect(result).toBeUndefined(); + }); + + it('should return undefined when provider is not found (single object)', () => { + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.GOOGLE_PAY, + mockConfig + ); + expect(result).toBeUndefined(); + }); + + it('should return undefined when activeConfiguration is null', () => { + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.APPLE_PAY, + null as any + ); + expect(result).toBeUndefined(); + }); + + it('should return undefined when activeConfiguration is undefined', () => { + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.APPLE_PAY, + undefined as any + ); + expect(result).toBeUndefined(); + }); + + it('should return undefined when provider is disabled', () => { + const disabledConfig = { + digitalWalletQuickBuy: [ + { provider: OpfQuickBuyProviderType.APPLE_PAY, enabled: false }, + ], + } as any; + + const result = service.getActiveConfigurationForProvider( + OpfQuickBuyProviderType.APPLE_PAY, + disabledConfig + ); + expect(result).toBeUndefined(); + }); }); }); diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts index 66734b699a1..a2114b35aed 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts @@ -34,7 +34,9 @@ export class OpfQuickBuyButtonsService { protected activeCartFacade = inject(ActiveCartFacade); protected multiCartFacade = inject(MultiCartFacade); - getPaymentGatewayConfiguration(): Observable { + getPaymentGatewayConfiguration(): Observable< + OpfActiveConfiguration | OpfActiveConfiguration[] + > { return this.opfBaseFacade .getActiveConfigurationsState() .pipe( @@ -49,28 +51,45 @@ export class OpfQuickBuyButtonsService { getQuickBuyProviderConfig( provider: OpfQuickBuyProviderType, - activeConfigurations: OpfActiveConfiguration[] + activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] ): OpfQuickBuyDigitalWallet | undefined { - return activeConfigurations - ?.flatMap((config) => config.digitalWalletQuickBuy ?? []) + const configs = this.normalizeConfigurations(activeConfiguration); + return configs + ?.flatMap((config) => config?.digitalWalletQuickBuy ?? []) .find((item) => item.provider === provider && item.enabled); } isQuickBuyProviderEnabled( provider: OpfQuickBuyProviderType, - activeConfigurations: OpfActiveConfiguration[] + activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] ): boolean { - return !!this.getQuickBuyProviderConfig(provider, activeConfigurations); + return !!this.getQuickBuyProviderConfig(provider, activeConfiguration); } getActiveConfigurationForProvider( provider: OpfQuickBuyProviderType, - activeConfigurations: OpfActiveConfiguration[] + activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] ): OpfActiveConfiguration | undefined { - return activeConfigurations?.find((config) => - config.digitalWalletQuickBuy?.some( + const configs = this.normalizeConfigurations(activeConfiguration); + return configs?.find((config) => + config?.digitalWalletQuickBuy?.some( (item) => item.provider === provider && item.enabled ) ); } + + /** + * Normalizes ActiveConfiguration to always return an array. + * Returns empty array if configurations are null/undefined. + */ + private normalizeConfigurations( + activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] + ): OpfActiveConfiguration[] | undefined { + if (!activeConfiguration) { + return undefined; + } + return Array.isArray(activeConfiguration) + ? activeConfiguration + : [activeConfiguration]; + } } From 03a6cd926c5d0f1f9822846a188483025629db52 Mon Sep 17 00:00:00 2001 From: ijitendrasap Date: Mon, 27 Apr 2026 13:21:04 +0530 Subject: [PATCH 7/7] review comments --- .../opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts index a2114b35aed..e731310e5ca 100644 --- a/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts +++ b/integration-libs/opf/quick-buy/components/opf-quick-buy-buttons/opf-quick-buy-buttons.service.ts @@ -82,7 +82,7 @@ export class OpfQuickBuyButtonsService { * Normalizes ActiveConfiguration to always return an array. * Returns empty array if configurations are null/undefined. */ - private normalizeConfigurations( + protected normalizeConfigurations( activeConfiguration: OpfActiveConfiguration | OpfActiveConfiguration[] ): OpfActiveConfiguration[] | undefined { if (!activeConfiguration) {