From 22c32061b49a5aa90963525d456ab02944271536 Mon Sep 17 00:00:00 2001 From: wjames111 Date: Mon, 25 Nov 2024 14:50:04 -0500 Subject: [PATCH] Fix for needing to reenter CVV upon new payment --- .../existingPaymentMethods.component.js | 18 +++++++++++++++--- .../existingPaymentMethods.component.spec.js | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js index 93c52c8dd..ee8727bcd 100644 --- a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js +++ b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.js @@ -153,9 +153,21 @@ class ExistingPaymentMethodsController { switchPayment () { this.onPaymentChange({ selectedPaymentMethod: this.selectedPaymentMethod }) if (this.selectedPaymentMethod?.['card-type'] && this.creditCardPaymentForm?.securityCode) { - // Clear CVV when switching between payment credit card payment methods - this.creditCardPaymentForm.securityCode.$setViewValue('') - this.creditCardPaymentForm.securityCode.$render() + + const selectedUri = this.selectedPaymentMethod.self.uri + const storage = JSON.parse(this.sessionStorage.getItem('storedCvvs')) + // const storedUris = Object.keys(storage) + const getSelectedCvv = storage ? storage[Object.keys(storage).filter((item) => item === selectedUri)] : false; + + if (getSelectedCvv) { + // Set CVV to new credit card CVV + this.creditCardPaymentForm.securityCode.$setViewValue(getSelectedCvv) + } else { + // Clear CVV when switching between payment credit card payment methods + this.creditCardPaymentForm.securityCode.$setViewValue('') + } + + this.creditCardPaymentForm.securityCode.$render() } if (this.selectedPaymentMethod?.['bank-name']) { diff --git a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js index 93e0dfdbe..339d4bae1 100644 --- a/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js +++ b/src/app/checkout/step-2/existingPaymentMethods/existingPaymentMethods.component.spec.js @@ -16,7 +16,7 @@ describe('checkout', () => { beforeEach(angular.mock.module(module.name)) const self = {} - beforeEach(inject(($componentController, $timeout) => { + beforeEach(inject(($componentController, $timeout, $window) => { self.$timeout = $timeout self.controller = $componentController(module.name, {}, { @@ -37,6 +37,8 @@ describe('checkout', () => { } } }) + self.$window = $window + self.$window.sessionStorage.clear() })) describe('$onInit', () => { @@ -352,6 +354,18 @@ describe('checkout', () => { expect(self.controller.creditCardPaymentForm.securityCode.$setViewValue).toHaveBeenCalledWith('') expect(self.controller.creditCardPaymentForm.securityCode.$render).toHaveBeenCalled() }) + + it('should add securityCode viewValue from sessionStorage', () => { + self.controller.creditCardPaymentForm.securityCode.$viewValue = '123' + self.controller.selectedPaymentMethod = { 'card-type': 'Visa', self: { type: 'cru.creditcards.named-credit-card', uri: '/paymentmethods/crugive/giydsnjqgi=' }, selectAction: 'some uri' } + self.$window.sessionStorage.setItem('storedCvvs', '{"/paymentmethods/crugive/giydsnjqgi=":"456","/paymentmethods/crugive/giydsnjqgy=":"321"}') + console.log(self.$window.sessionStorage) + // self.controller.sessionStorage.setItem('storedCvvs', JSON.stringify({ 'selected uri': '456' })) + self.controller.switchPayment() + + expect(self.controller.creditCardPaymentForm.securityCode.$setViewValue).toHaveBeenCalledWith('456') + expect(self.controller.creditCardPaymentForm.securityCode.$render).toHaveBeenCalled() + }) }) describe('addCvvValidators', () => {