Skip to content

Commit

Permalink
fix: Absence of an email address during payment via Google Pay in OPF (
Browse files Browse the repository at this point in the history
  • Loading branch information
rmch91 authored Dec 16, 2024
1 parent 4d912da commit 77138fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class MockPaginationComponent {
@Output() viewPageEvent = new EventEmitter<string>();
}

@Component({
template: '',
selector: 'cx-opf-checkout-payment-wrapper',
})
class MockOpfCheckoutPaymentWrapperComponent {}

const mockActiveConfigurations: OpfActiveConfiguration[] = [
{
id: 1,
Expand Down Expand Up @@ -109,7 +115,11 @@ describe('OpfCheckoutPaymentsComponent', () => {
);
await TestBed.configureTestingModule({
imports: [I18nTestingModule, OpfCheckoutTermsAndConditionsAlertModule],
declarations: [OpfCheckoutPaymentsComponent, MockPaginationComponent],
declarations: [
OpfCheckoutPaymentsComponent,
MockOpfCheckoutPaymentWrapperComponent,
MockPaginationComponent,
],
providers: [
{
provide: OpfBaseFacade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('OpfGooglePayService', () => {
'getTransactionDeliveryInfo',
'getTransactionLocationContext',
'getMerchantName',
'updateCartGuestUserEmail',
]
);
mockPaymentFacade = jasmine.createSpyObj('OpfPaymentFacade', [
Expand Down Expand Up @@ -630,6 +631,7 @@ describe('OpfGooglePayService', () => {

describe('onPaymentAuthorized', () => {
it('should handle payment authorization', (done) => {
const mockEmail = '[email protected]';
const callbacks = service['handlePaymentCallbacks']();
const mockToken = 'mockToken';
const paymentDataResponse = {
Expand All @@ -638,6 +640,7 @@ describe('OpfGooglePayService', () => {
token: mockToken,
},
},
email: mockEmail,
} as google.payments.api.PaymentData;

mockPaymentFacade.submitPayment.and.returnValue(of(true));
Expand All @@ -647,6 +650,9 @@ describe('OpfGooglePayService', () => {
mockQuickBuyTransactionService.setDeliveryAddress.and.returnValue(
of('addressId')
);
mockQuickBuyTransactionService.updateCartGuestUserEmail.and.returnValue(
of(true)
);

if (callbacks.onPaymentAuthorized) {
(
Expand All @@ -657,6 +663,10 @@ describe('OpfGooglePayService', () => {

expect(result).toBeDefined();
expect(mockPaymentFacade.submitPayment).toHaveBeenCalled();
expect(
mockQuickBuyTransactionService.updateCartGuestUserEmail
).toHaveBeenCalledWith(mockEmail);

expect(Object.values(submitPaymentArgs.callbacks).length).toBe(3);
Object.values(submitPaymentArgs.callbacks).forEach((callback) => {
expect(typeof callback).toBe('function');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class OpfGooglePayService {
shippingAddressParameters: {
phoneNumberRequired: false,
},
emailRequired: true,
};

protected readonly defaultGooglePayCardParameters: any = {
Expand Down Expand Up @@ -378,6 +379,13 @@ export class OpfGooglePayService {
paymentDataResponse.paymentMethodData.info?.billingAddress
)
),
switchMap(() => {
return paymentDataResponse?.email
? this.opfQuickBuyTransactionService.updateCartGuestUserEmail(
paymentDataResponse.email
)
: of(true);
}),
switchMap(() => {
const encryptedToken = btoa(
paymentDataResponse.paymentMethodData.tokenizationData.token
Expand Down

0 comments on commit 77138fa

Please sign in to comment.