-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67dc598
commit 4f063d5
Showing
19 changed files
with
116 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {isCardLengthValid, isCardNumberValid} from '@taiga-ui/addon-commerce/utils'; | ||
import {tuiIsCardLengthValid, tuiIsCardNumberValid} from '@taiga-ui/addon-commerce/utils'; | ||
import {TuiBooleanHandler} from '@taiga-ui/cdk'; | ||
|
||
export const tuiDefaultCardValidator: TuiBooleanHandler<string> = card => | ||
card.length > 11 && isCardLengthValid(card) && isCardNumberValid(card); | ||
card.length > 11 && tuiIsCardLengthValid(card) && tuiIsCardNumberValid(card); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './currency'; | ||
export * from './currency-code'; | ||
export * from './payment-system'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const enum TuiPaymentSystem { | ||
Visa = 'visa', | ||
Electron = 'electron', | ||
Mastercard = 'mastercard', | ||
Maestro = 'maestro', | ||
Mir = 'mir', | ||
} | ||
|
||
export type TuiPaymentSystemT = 'visa' | 'electron' | 'mastercard' | 'maestro' | 'mir'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './code-length'; | ||
export * from './currency-variants'; | ||
export * from './money-sign'; | ||
export * from './payment-system'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import {TuiPaymentSystem} from '@taiga-ui/addon-commerce/enums'; | ||
|
||
import {tuiGetPaymentSystem} from './get-payment-system'; | ||
|
||
/** | ||
* @deprecated: use {@link tuiIsCardLengthValid} instead | ||
* Validates card number length using payment system dictionary | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export function isCardLengthValid(cardNumber: string): boolean { | ||
export function tuiIsCardLengthValid(cardNumber: string): boolean { | ||
const {length} = cardNumber; | ||
const paymentSystem = tuiGetPaymentSystem(cardNumber); | ||
|
||
switch (paymentSystem) { | ||
case 'electron': | ||
case TuiPaymentSystem.Electron: | ||
return length === 16; | ||
case 'maestro': | ||
case TuiPaymentSystem.Maestro: | ||
return length > 11 && length < 20; | ||
case 'mastercard': | ||
case 'mir': | ||
case TuiPaymentSystem.Mastercard: | ||
case TuiPaymentSystem.Mir: | ||
return length > 15 && length < 20; | ||
case 'visa': | ||
case TuiPaymentSystem.Visa: | ||
return length > 12 && length < 20; | ||
default: | ||
return length > 8 && length < 20; | ||
} | ||
} | ||
|
||
export const tuiIsCardLengthValid = isCardLengthValid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 28 additions & 26 deletions
54
projects/addon-commerce/utils/test/get-payment-system.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,107 @@ | ||
import {TuiPaymentSystem} from '@taiga-ui/addon-commerce'; | ||
|
||
import {tuiGetPaymentSystem} from '../get-payment-system'; | ||
|
||
describe('getPaymentSystem', () => { | ||
describe('Visa', () => { | ||
it('4', () => { | ||
expect(tuiGetPaymentSystem('4000')).toBe('visa'); | ||
expect(tuiGetPaymentSystem('4000')).toBe(TuiPaymentSystem.Visa); | ||
}); | ||
}); | ||
|
||
describe('Electron', () => { | ||
describe(TuiPaymentSystem.Electron, () => { | ||
it('4026', () => { | ||
expect(tuiGetPaymentSystem('4026')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4026')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
|
||
it('4175', () => { | ||
expect(tuiGetPaymentSystem('4175')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4175')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
|
||
it('4405', () => { | ||
expect(tuiGetPaymentSystem('4405')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4405')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
|
||
it('4508', () => { | ||
expect(tuiGetPaymentSystem('4508')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4508')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
|
||
it('4844', () => { | ||
expect(tuiGetPaymentSystem('4844')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4844')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
|
||
it('4913', () => { | ||
expect(tuiGetPaymentSystem('4913')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4913')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
|
||
it('4917', () => { | ||
expect(tuiGetPaymentSystem('4917')).toBe('electron'); | ||
expect(tuiGetPaymentSystem('4917')).toBe(TuiPaymentSystem.Electron); | ||
}); | ||
}); | ||
|
||
describe('Mastercard', () => { | ||
describe(TuiPaymentSystem.Mastercard, () => { | ||
it('2221', () => { | ||
expect(tuiGetPaymentSystem('2221')).toBe('mastercard'); | ||
expect(tuiGetPaymentSystem('2221')).toBe(TuiPaymentSystem.Mastercard); | ||
}); | ||
|
||
it('2720', () => { | ||
expect(tuiGetPaymentSystem('2720')).toBe('mastercard'); | ||
expect(tuiGetPaymentSystem('2720')).toBe(TuiPaymentSystem.Mastercard); | ||
}); | ||
|
||
it('5100', () => { | ||
expect(tuiGetPaymentSystem('5100')).toBe('mastercard'); | ||
expect(tuiGetPaymentSystem('5100')).toBe(TuiPaymentSystem.Mastercard); | ||
}); | ||
|
||
it('5500', () => { | ||
expect(tuiGetPaymentSystem('5500')).toBe('mastercard'); | ||
expect(tuiGetPaymentSystem('5500')).toBe(TuiPaymentSystem.Mastercard); | ||
}); | ||
|
||
it('5', () => { | ||
expect(tuiGetPaymentSystem('5')).toBe('mastercard'); | ||
expect(tuiGetPaymentSystem('5')).toBe(TuiPaymentSystem.Mastercard); | ||
}); | ||
}); | ||
|
||
describe('Maestro', () => { | ||
describe(TuiPaymentSystem.Maestro, () => { | ||
it('5000', () => { | ||
expect(tuiGetPaymentSystem('5000')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('5000')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('5090', () => { | ||
expect(tuiGetPaymentSystem('5090')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('5090')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('5600', () => { | ||
expect(tuiGetPaymentSystem('5600')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('5600')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('5890', () => { | ||
expect(tuiGetPaymentSystem('5890')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('5890')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('6000', () => { | ||
expect(tuiGetPaymentSystem('6000')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('6000')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('50', () => { | ||
expect(tuiGetPaymentSystem('50')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('50')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('56', () => { | ||
expect(tuiGetPaymentSystem('56')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('56')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
|
||
it('58', () => { | ||
expect(tuiGetPaymentSystem('58')).toBe('maestro'); | ||
expect(tuiGetPaymentSystem('58')).toBe(TuiPaymentSystem.Maestro); | ||
}); | ||
}); | ||
|
||
describe('Mir', () => { | ||
it('2200', () => { | ||
expect(tuiGetPaymentSystem('2200')).toBe('mir'); | ||
expect(tuiGetPaymentSystem('2200')).toBe(TuiPaymentSystem.Mir); | ||
}); | ||
|
||
it('2204', () => { | ||
expect(tuiGetPaymentSystem('2204')).toBe('mir'); | ||
expect(tuiGetPaymentSystem('2204')).toBe(TuiPaymentSystem.Mir); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.