Skip to content

Commit

Permalink
Fix for needing to reenter CVV upon new payment
Browse files Browse the repository at this point in the history
  • Loading branch information
wjames111 committed Nov 25, 2024
1 parent 4204964 commit 22c3206
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}, {
Expand All @@ -37,6 +37,8 @@ describe('checkout', () => {
}
}
})
self.$window = $window
self.$window.sessionStorage.clear()
}))

describe('$onInit', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 22c3206

Please sign in to comment.