Skip to content

Commit

Permalink
fix: move GP url in config
Browse files Browse the repository at this point in the history
Closes: CXSPA-8059
  • Loading branch information
FollowTheFlo authored Nov 26, 2024
1 parent fc5e624 commit 0d33d02
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class OpfGooglePayComponent implements OnInit {
this.opfGooglePayService.loadResources().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,10 @@ import { OpfResourceLoaderService } from '@spartacus/opf/base/root';
import { OpfPaymentFacade } from '@spartacus/opf/payment/root';
import { OpfQuickBuyTransactionService } from '@spartacus/opf/quick-buy/core';
import {
OPF_GOOGLE_PAY_PROVIDER_NAME,
OPF_QUICK_BUY_ADDRESS_FIELD_PLACEHOLDER,
OpfQuickBuyConfig,
OpfQuickBuyGooglePayProvider,
OpfQuickBuyLocation,
OpfQuickBuyProviderType,
} from '@spartacus/opf/quick-buy/root';
Expand Down Expand Up @@ -47,6 +50,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 +88,14 @@ describe('OpfGooglePayService', () => {
['getQuickBuyProviderConfig']
);

mockOpfQuickBuyConfig = {
providers: {
[OPF_GOOGLE_PAY_PROVIDER_NAME]: {
resourceUrl: 'fakeUrl',
} as OpfQuickBuyGooglePayProvider,
},
};

const googlePayApiMock = {
payments: {
api: {
Expand Down Expand Up @@ -119,6 +131,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,9 +16,12 @@ import {
import { OpfPaymentFacade } from '@spartacus/opf/payment/root';
import { OpfQuickBuyTransactionService } from '@spartacus/opf/quick-buy/core';
import {
OPF_GOOGLE_PAY_PROVIDER_NAME,
OPF_QUICK_BUY_ADDRESS_FIELD_PLACEHOLDER,
OPF_QUICK_BUY_DEFAULT_MERCHANT_NAME,
OpfQuickBuyConfig,
OpfQuickBuyDeliveryType,
OpfQuickBuyGooglePayProvider,
OpfQuickBuyLocation,
OpfQuickBuyProviderType,
QuickBuyTransactionDetails,
Expand All @@ -39,9 +42,7 @@ export class OpfGooglePayService {
OpfQuickBuyTransactionService
);
protected opfQuickBuyButtonsService = inject(OpfQuickBuyButtonsService);

protected readonly GOOGLE_PAY_JS_URL =
'https://pay.google.com/gp/p/js/pay.js';
protected opfQuickBuyConfig = inject(OpfQuickBuyConfig);

private googlePaymentClient: google.payments.api.PaymentsClient;

Expand Down Expand Up @@ -138,8 +139,16 @@ export class OpfGooglePayService {
}

loadResources(): Promise<void> {
const opfGooglePayConfig: OpfQuickBuyGooglePayProvider | undefined =
this.opfQuickBuyConfig?.providers?.[OPF_GOOGLE_PAY_PROVIDER_NAME];

if (!opfGooglePayConfig?.resourceUrl?.length) {
return Promise.reject('Config not found');
}
return this.opfResourceLoaderService.loadResources([
{ url: this.GOOGLE_PAY_JS_URL },
{
url: opfGooglePayConfig.resourceUrl,
},
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com>
*
* SPDX-License-Identifier: Apache-2.0
*/

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

export const defaultOpfQuickBuyConfig: OpfQuickBuyConfig = {
providers: {
googlePay: {
resourceUrl: '',
},
},
};
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 <spartacus-team@sap.com>
*
* SPDX-License-Identifier: Apache-2.0
*/

export * from './default-opf-quick-buy-config';
export * from './opf-quick-buy-config';
20 changes: 20 additions & 0 deletions integration-libs/opf/quick-buy/root/config/opf-quick-buy-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2024 SAP Spartacus team <spartacus-team@sap.com>
*
* SPDX-License-Identifier: Apache-2.0
*/

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

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

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

export const OPF_GOOGLE_PAY_PROVIDER_NAME = 'googlePay';

export interface OpfQuickBuyGooglePayProvider {
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 @@ -3,7 +3,7 @@
exports[`Spartacus SAP OPF integration schematics: ng-add SAP OPF feature general setup should add the feature using the lazy loading syntax 1`] = `
"import { NgModule } from '@angular/core';
import { CmsConfig, provideConfig } from "@spartacus/core";
import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyRootModule } from "@spartacus/opf/quick-buy/root";
import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyConfig, OpfQuickBuyRootModule } from "@spartacus/opf/quick-buy/root";
@NgModule({
declarations: [],
Expand All @@ -17,7 +17,16 @@ import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyRootModule } from "@spartacus/opf/qui
import('@spartacus/opf/quick-buy').then((m) => m.OpfQuickBuyModule),
},
}
})]
}),
provideConfig(<OpfQuickBuyConfig>{
providers:
{
googlePay: {
resourceUrl: "PLACEHOLDER_GOOGLE_PAY_API_URL"
}
}
})
]
})
export class OpfFeatureModule { }
"
Expand All @@ -26,7 +35,7 @@ export class OpfFeatureModule { }
exports[`Spartacus SAP OPF integration schematics: ng-add SAP OPF feature general setup should add the feature using the lazy loading syntax 2`] = `
"import { NgModule } from '@angular/core';
import { CmsConfig, provideConfig } from "@spartacus/core";
import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyRootModule } from "@spartacus/opf/quick-buy/root";
import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyConfig, OpfQuickBuyRootModule } from "@spartacus/opf/quick-buy/root";
@NgModule({
declarations: [],
Expand All @@ -40,7 +49,16 @@ import { OPF_QUICK_BUY_FEATURE, OpfQuickBuyRootModule } from "@spartacus/opf/qui
import('@spartacus/opf/quick-buy').then((m) => m.OpfQuickBuyModule),
},
}
})]
}),
provideConfig(<OpfQuickBuyConfig>{
providers:
{
googlePay: {
resourceUrl: "PLACEHOLDER_GOOGLE_PAY_API_URL"
}
}
})
]
})
export class OpfFeatureModule { }
"
Expand Down
4 changes: 4 additions & 0 deletions integration-libs/opf/schematics/add-opf/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"commerceCloudPublicKey": {
"type": "string",
"description": "Commerce Clould public key required for authentication between OPF Cloud Commerce Adapter and Spartacus"
},
"opfGooglePayApiUrl": {
"type": "string",
"description": "GooglePay Api url required for Quick Buy Google Pay Integration."
}
},
"required": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import { ORDER_MODULE } from '../order-schematics-config';
export interface SpartacusOpfOptions extends LibraryOptions {
opfBaseUrl?: string;
commerceCloudPublicKey?: string;
opfGooglePayApiUrl?: string;
}

export const OPF_FOLDER_NAME = 'opf';
export const OPF_MODULE_NAME = 'Opf';
export const OPF_SCSS_FILE_NAME = 'opf.scss';
export const OPF_CONFIG = 'OpfConfig';
export const OPF_QUICKBUY_CONFIG = 'OpfQuickBuyConfig';

export const OPF_CHECKOUT_FEATURE_NAME_CONSTANT = 'OPF_CHECKOUT_FEATURE';
export const OPF_CHECKOUT_MODULE = 'OpfCheckoutModule';
Expand Down Expand Up @@ -262,6 +264,7 @@ export const OPF_QUICK_BUY_SCHEMATICS_CONFIG: SchematicConfig = {
scssFileName: OPF_SCSS_FILE_NAME,
importStyle: SPARTACUS_OPF,
},
customConfig: buildOpfQuickBuyConfig,
};

function buildOpfConfig(
Expand All @@ -287,3 +290,26 @@ function buildOpfConfig(
},
};
}

function buildOpfQuickBuyConfig(
options: SpartacusOpfOptions
): AdditionalFeatureConfiguration<SpartacusOpfOptions> {
return {
providers: {
import: [
{
moduleSpecifier: SPARTACUS_OPF_QUICK_BUY_ROOT,
namedImports: [OPF_QUICKBUY_CONFIG],
},
],
content: `<${OPF_QUICKBUY_CONFIG}>{
providers:
{
googlePay: {
resourceUrl: "${options.opfGooglePayApiUrl || 'PLACEHOLDER_GOOGLE_PAY_API_URL'}"
}
}
}`,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import {
OpfPaymentRootModule,
} from '@spartacus/opf/payment/root';
import {
OPF_GOOGLE_PAY_PROVIDER_NAME,
OPF_QUICK_BUY_FEATURE,
OpfQuickBuyConfig,
OpfQuickBuyGooglePayProvider,
OpfQuickBuyRootModule,
} from '@spartacus/opf/quick-buy/root';
import { environment } from '../../../../environments/environment';
Expand Down Expand Up @@ -109,6 +112,13 @@ if (environment.b2b) {
commerceCloudPublicKey: 'ab4RhYGZ+w5B0SALMPOPlepWk/kmDQjTy2FU5hrQoFg=',
},
}),
provideConfig(<OpfQuickBuyConfig>{
providers: {
[OPF_GOOGLE_PAY_PROVIDER_NAME]: {
resourceUrl: 'https://pay.google.com/gp/p/js/pay.js',
} as OpfQuickBuyGooglePayProvider,
},
}),
...extensionProviders,
],
})
Expand Down
2 changes: 2 additions & 0 deletions scripts/install/config.default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ EPD_VISUALIZATION_BASE_URL=
# The base URL and public key values are required for connection to Cloud Commerce Adapter (OPF)
OPF_BASE_URL=
OPF_CLIENT_PUBLIC_KEY=
# Google Pay Api url required for Quick Buy Google Pay integration.
OPF_QUICK_BUY_GOOGLE_PAY_RESOURCE_URL=

#NPM connection info
#NPM_URL must start by 'https://' and end with '/' char
Expand Down
5 changes: 2 additions & 3 deletions scripts/install/config.opf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ BASE_SITE="electronics-spa-standalone"
# The base URL and public key values are required for connection to Cloud Commerce Adapter (OPF)
OPF_BASE_URL="https://cp96avkh5f-integrati2-d2.opf.commerce.stage.context.cloud.sap/commerce-cloud-adapter-stage/storefront"
OPF_CLIENT_PUBLIC_KEY="k2N3m3TJPLragwia5ZUvS/qkIPVQoy5qjUkOAB6Db+U="

# TODO: Comment out the line below after OPF branch is merged into develop.
BRANCH="epic/opf"
# Google Pay Api url required for Quick Buy Google Pay integration.
OPF_QUICK_BUY_GOOGLE_PAY_RESOURCE_URL="https://pay.google.com/gp/p/js/pay.js"
2 changes: 1 addition & 1 deletion scripts/install/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function add_epd_visualization {

function add_opf {
if [ "$ADD_OPF" = true ] ; then
ng add @spartacus/opf@${SPARTACUS_VERSION} --opf-base-url ${OPF_BASE_URL} --commerce-cloud-public-key ${OPF_CLIENT_PUBLIC_KEY} --skip-confirmation --no-interactive
ng add @spartacus/opf@${SPARTACUS_VERSION} --opf-base-url ${OPF_BASE_URL} --commerce-cloud-public-key ${OPF_CLIENT_PUBLIC_KEY} --opf-google-pay-api-url ${OPF_QUICK_BUY_GOOGLE_PAY_RESOURCE_URL} --skip-confirmation --no-interactive
fi
}

Expand Down

0 comments on commit 0d33d02

Please sign in to comment.