Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix checkmarx #19532

Open
wants to merge 10 commits into
base: epic/opf
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
OpfMetadataModel,
OpfMetadataStoreService,
} from '@spartacus/opf/base/root';
import { Subscription } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { tap } from 'rxjs/operators';

@Component({
Expand All @@ -33,23 +33,23 @@ import { tap } from 'rxjs/operators';
export class OpfCheckoutPaymentsComponent implements OnInit, OnDestroy {
protected subscription = new Subscription();

activeConfigurations$ = this.opfBaseService
.getActiveConfigurationsState()
.pipe(
tap((state: QueryState<OpfActiveConfiguration[] | undefined>) => {
if (state.error) {
this.displayError('loadActiveConfigurations');
} else if (!state.loading && !Boolean(state.data?.length)) {
this.displayError('noActiveConfigurations');
}
activeConfigurations$: Observable<
QueryState<OpfActiveConfiguration[] | undefined>
> = this.opfBaseService.getActiveConfigurationsState().pipe(
tap((state: QueryState<OpfActiveConfiguration[] | undefined>) => {
if (state.error) {
this.displayError('loadActiveConfigurations');
} else if (!state.loading && !Boolean(state.data?.length)) {
this.displayError('noActiveConfigurations');
}

if (state.data && !state.error && !state.loading) {
this.opfMetadataStoreService.updateOpfMetadata({
defaultSelectedPaymentOptionId: state?.data[0]?.id,
});
}
})
);
if (state.data && !state.error && !state.loading) {
this.opfMetadataStoreService.updateOpfMetadata({
defaultSelectedPaymentOptionId: state?.data[0]?.id,
});
}
})
);

@Input()
disabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class OpfGooglePayComponent implements OnInit {
this.opfGooglePayService.loadProviderResources().then(() => {
this.opfGooglePayService.initClient(this.activeConfiguration);
this.opfGooglePayService.isReadyToPay().then((response: any) => {
this.isReadyToPayState$.next(response?.result);
this.isReadyToPayState$.next(!!response?.result);
this.changeDetectionRef.detectChanges();
if (response.result && this.googlePayButtonContainer) {
this.opfGooglePayService.renderPaymentButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { OpfResourceLoaderService } from '@spartacus/opf/base/root';
import { OpfPaymentFacade } from '@spartacus/opf/payment/root';
import { OpfQuickBuyTransactionService } from '@spartacus/opf/quick-buy/core';
import {
GooglePayOpfQuickBuyProvider,
OPF_QUICK_BUY_ADDRESS_FIELD_PLACEHOLDER,
OpfQuickBuyConfig,
OpfQuickBuyLocation,
OpfQuickBuyProviderType,
} from '@spartacus/opf/quick-buy/root';
Expand Down Expand Up @@ -47,6 +49,7 @@ describe('OpfGooglePayService', () => {
let mockQuickBuyTransactionService: jasmine.SpyObj<OpfQuickBuyTransactionService>;
let mockPaymentFacade: jasmine.SpyObj<OpfPaymentFacade>;
let mockQuickBuyButtonsService: jasmine.SpyObj<OpfQuickBuyButtonsService>;
let mockOpfQuickBuyConfig: jasmine.SpyObj<OpfQuickBuyConfig>;

beforeEach(() => {
mockResourceLoaderService = jasmine.createSpyObj(
Expand Down Expand Up @@ -84,6 +87,16 @@ describe('OpfGooglePayService', () => {
['getQuickBuyProviderConfig']
);

mockOpfQuickBuyConfig = {
providers: [
{
googlePay: {
resourceUrl: 'fakeUrl',
},
} as GooglePayOpfQuickBuyProvider,
],
};

const googlePayApiMock = {
payments: {
api: {
Expand Down Expand Up @@ -119,6 +132,10 @@ describe('OpfGooglePayService', () => {
provide: OpfQuickBuyButtonsService,
useValue: mockQuickBuyButtonsService,
},
{
provide: OpfQuickBuyConfig,
useValue: mockOpfQuickBuyConfig,
},
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import {
import { OpfPaymentFacade } from '@spartacus/opf/payment/root';
import { OpfQuickBuyTransactionService } from '@spartacus/opf/quick-buy/core';
import {
GOOGLE_PAY_PROVIDER_NAME,
GooglePayOpfQuickBuyProvider,
OPF_QUICK_BUY_ADDRESS_FIELD_PLACEHOLDER,
OPF_QUICK_BUY_DEFAULT_MERCHANT_NAME,
OpfQuickBuyConfig,
OpfQuickBuyDeliveryType,
OpfQuickBuyLocation,
OpfQuickBuyProvider,
OpfQuickBuyProviderType,
QuickBuyTransactionDetails,
} from '@spartacus/opf/quick-buy/root';
Expand All @@ -38,11 +42,9 @@ export class OpfGooglePayService {
protected opfQuickBuyTransactionService = inject(
OpfQuickBuyTransactionService
);
protected opfQuickBuyConfig = inject(OpfQuickBuyConfig);
protected opfQuickBuyButtonsService = inject(OpfQuickBuyButtonsService);

protected readonly GOOGLE_PAY_JS_URL =
'https://pay.google.com/gp/p/js/pay.js';

private googlePaymentClient: google.payments.api.PaymentsClient;

private googlePaymentClientOptions: google.payments.api.PaymentOptions = {
Expand Down Expand Up @@ -138,8 +140,18 @@ export class OpfGooglePayService {
}

loadProviderResources(): Promise<void> {
const opfGooglePayConfig: OpfQuickBuyProvider | undefined =
this.opfQuickBuyConfig.providers?.find(
(provider) => provider[GOOGLE_PAY_PROVIDER_NAME]
);
if (!opfGooglePayConfig) {
return Promise.reject('Config not found');
}
return this.opfResourceLoaderService.loadProviderResources([
{ url: this.GOOGLE_PAY_JS_URL },
{
url: (opfGooglePayConfig as GooglePayOpfQuickBuyProvider).googlePay
.resourceUrl,
},
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { GooglePayOpfQuickBuyProvider } from '../model';
import { OpfQuickBuyConfig } from './opf-quick-buy-config';

export const defaultOpfQuickBuyConfig: OpfQuickBuyConfig = {
providers: [
{
googlePay: {
resourceUrl: '',
},
} as GooglePayOpfQuickBuyProvider,
],
};
8 changes: 8 additions & 0 deletions integration-libs/opf/quick-buy/root/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

export * from './default-opf-quick-buy-config';
export * from './opf-quick-buy-config';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { Injectable } from '@angular/core';
import { Config } from '@spartacus/core';
import { OpfQuickBuyProvider } from '../model';

@Injectable({
providedIn: 'root',
useExisting: Config,
})
export abstract class OpfQuickBuyConfig {
providers?: OpfQuickBuyProvider[];
}

declare module '@spartacus/core' {
interface Config extends OpfQuickBuyConfig {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ export enum OpfQuickBuyProviderType {
APPLE_PAY = 'APPLE_PAY',
GOOGLE_PAY = 'GOOGLE_PAY',
}

export interface OpfQuickBuyProvider {
[providerName: string]: {
[resource: string]: string;
};
}

export const GOOGLE_PAY_PROVIDER_NAME = 'googlePay';
export interface GooglePayOpfQuickBuyProvider extends OpfQuickBuyProvider {
[GOOGLE_PAY_PROVIDER_NAME]: {
resourceUrl: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
*/

import { NgModule } from '@angular/core';
import { CmsConfig, provideDefaultConfigFactory } from '@spartacus/core';
import {
CmsConfig,
provideDefaultConfig,
provideDefaultConfigFactory,
} from '@spartacus/core';
import { defaultOpfQuickBuyConfig } from './config';
import { OPF_QUICK_BUY_FEATURE } from './feature-name';

export function defaultOpfQuickBuyCmsComponentsConfig(): CmsConfig {
Expand All @@ -22,6 +27,7 @@ export function defaultOpfQuickBuyCmsComponentsConfig(): CmsConfig {
@NgModule({
providers: [
provideDefaultConfigFactory(defaultOpfQuickBuyCmsComponentsConfig),
provideDefaultConfig(defaultOpfQuickBuyConfig),
],
})
export class OpfQuickBuyRootModule {}
1 change: 1 addition & 0 deletions integration-libs/opf/quick-buy/root/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

export * from './config/index';
export * from './facade/index';
export * from './feature-name';
export * from './model/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
OpfPaymentRootModule,
} from '@spartacus/opf/payment/root';
import {
GooglePayOpfQuickBuyProvider,
OPF_QUICK_BUY_FEATURE,
OpfQuickBuyConfig,
OpfQuickBuyRootModule,
} from '@spartacus/opf/quick-buy/root';
import { environment } from '../../../../environments/environment';
Expand Down Expand Up @@ -122,6 +124,15 @@ if (environment.b2b) {
commerceCloudPublicKey: 'ab4RhYGZ+w5B0SALMPOPlepWk/kmDQjTy2FU5hrQoFg=',
},
}),
provideConfig(<OpfQuickBuyConfig>{
providers: [
{
googlePay: {
resourceUrl: 'https://pay.google.com/gp/p/js/pay.js',
},
} as GooglePayOpfQuickBuyProvider,
],
}),
...extensionProviders,
],
})
Expand Down
Loading