-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from p-fedyukovich/introduce-card-model
Introduce card model
- Loading branch information
Showing
11 changed files
with
120 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type RawCardBrand = | ||
| 'Visa' | ||
| 'MasterCard' | ||
| 'Amex' | ||
| 'Dankort' | ||
| 'Diners' | ||
| 'Finax' | ||
| 'Jcb' | ||
| 'IkanoFinansDK' | ||
| 'Maestro' | ||
|
||
export default RawCardBrand |
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
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,77 @@ | ||
import RawCardBrand from '../api/response/raw-card-brand' | ||
|
||
type CardBrand = | ||
| 'visa' | ||
| 'mastercard' | ||
| 'amex' | ||
| 'dankort' | ||
| 'diners' | ||
| 'finax' | ||
| 'jcb' | ||
| 'ikanofinansdk' | ||
| 'maestro' | ||
|
||
export default class Card { | ||
private readonly _rawCardBrand: RawCardBrand | ||
private readonly _maskedPan: string | ||
private readonly _expiryDate: string | ||
|
||
private constructor(rawCardBrand: RawCardBrand, maskedPan: string, expiryDate: string) { | ||
this._rawCardBrand = rawCardBrand | ||
this._maskedPan = maskedPan | ||
this._expiryDate = expiryDate | ||
} | ||
|
||
get rawCardBrand(): RawCardBrand { | ||
return this._rawCardBrand | ||
} | ||
|
||
get brand(): CardBrand { | ||
switch (this._rawCardBrand) { | ||
case 'Visa': | ||
return 'visa' | ||
case 'MasterCard': | ||
return 'mastercard' | ||
case 'Amex': | ||
return 'amex' | ||
case 'Dankort': | ||
return 'dankort' | ||
case 'Diners': | ||
return 'diners' | ||
case 'Finax': | ||
return 'finax' | ||
case 'Jcb': | ||
return 'jcb' | ||
case 'IkanoFinansDK': | ||
return 'ikanofinansdk' | ||
case 'Maestro': | ||
return 'maestro' | ||
default: | ||
throw new Error(`Card brand is not recognized: ${this._rawCardBrand}`) | ||
} | ||
} | ||
|
||
get expiryDate(): string { | ||
return this._expiryDate | ||
} | ||
|
||
get expMonth(): number { | ||
return Number(this._expiryDate.split('/')[0]) | ||
} | ||
|
||
get expYear(): number { | ||
return Number(this._expiryDate.split('/')[1]) | ||
} | ||
|
||
get maskedPan(): string { | ||
return this._maskedPan | ||
} | ||
|
||
get last4(): string { | ||
return this._maskedPan.slice(this.maskedPan.length - 4) | ||
} | ||
|
||
static generate(brand: RawCardBrand, maskedPan: string, expiryDate: string): Card { | ||
return new Card(brand, maskedPan, expiryDate) | ||
} | ||
} |
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