Skip to content

Commit

Permalink
feat(BankNameFromCard):added core method body
Browse files Browse the repository at this point in the history
  • Loading branch information
payam-zahedi committed Apr 19, 2021
1 parent 8839afe commit 378baa0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 0 additions & 1 deletion example/example_phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ void main() {
print(operatorDetail?.base); // کشوری
print(operatorDetail?.type); // SimCartType.both


/// you can also use this methods as String extension method
// phone number validator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import 'package:dart_persian_tools/src/constants/get_bank_name_from_card_number/constants.dart';

import 'models.dart';

/// checks the [cardNumber] is a valid bank card and returns the [Bank] info
/// if its not a valid card or not related to a bank
/// it will returns null
Bank? getBankNameFromCardNumber(String cardNumber) {
if (cardNumber.length == 16) {
/// split the card number and cut the init code from it
final initCode = cardNumber.substring(0, 6);

final findBank = bankInformation.firstWhere(
(element) => element?.initCode == initCode,
orElse: () => null,
);

if (findBank != null) return findBank;
}
return null;
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/core/phone_number/phone_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ String getPhonePrefix(String phoneNumber) {
return '';
}


/// find information such as province, type and model of [phoneNumber]
/// this function used the [getPhonePrefix] to find out the [phoneNumber] prefix number and
/// used the [phoneNumberValidator] function to validate the [phoneNumber].
Expand Down
3 changes: 2 additions & 1 deletion test/test_get_bank_name_from_card_number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import 'package:test/test.dart';
void main() {
group('test get_bank_name_from_card_number.dart', () {
test('test getBankNameFromCardNumber method', () {
expect(getBankNameFromCardNumber('6037701689095443')?.name, 'بانک کشاورزی');
expect(
getBankNameFromCardNumber('6037701689095443')?.name, 'بانک کشاورزی');
expect(getBankNameFromCardNumber('6219861034529007')?.name, 'بانک سامان');
expect(getBankNameFromCardNumber('6219861034529007')?.name, 'بانک سامان');

Expand Down

0 comments on commit 378baa0

Please sign in to comment.