luhn_credit_card_verificator 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -2
- data/README.md +44 -2
- data/lib/enum.rb +12 -0
- data/lib/helper.rb +1 -2
- data/lib/luhn_credit_card_verificator/version.rb +1 -1
- data/lib/luhn_credit_card_verificator.rb +71 -27
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b989811ccdd8fa467ad84f4d2f87e0b3e5323f784f396118fc093143a42134f1
|
4
|
+
data.tar.gz: 6e9493d322d24163e1f3b496b050db8b13137d00adaebda70a552f27e91d8170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42cc8d2f7aab7ea92236f2bbaaf4b5b45c8c7ef285c47a80d7fede19b9991c3d2953bff2dc5fba3a8c5595855239a148834197baa36a7084f51d36d53da02ffe
|
7
|
+
data.tar.gz: 7fa7991e97c1331f26031f54ffed7e204132fa289feb77b052d01af4e8abf318dffae09d50bc6a9c14db975a0a2fe51b729d48ee840f94ddd904299a33e1ee54
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [
|
4
|
-
|
3
|
+
## [1.0.0] - 2022-06-02
|
5
4
|
- Initial release
|
5
|
+
|
6
|
+
## [1.0.1] - 2022-06-02
|
7
|
+
- Change the home page url
|
8
|
+
|
9
|
+
## [2.0.0] - 2022-06-02
|
10
|
+
- Fix major bug to verify card numbers
|
11
|
+
- add functionalities to get more information about the credit card
|
data/README.md
CHANGED
@@ -16,8 +16,16 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
16
|
$ gem install luhn_credit_card_verificator
|
17
17
|
|
18
18
|
## Usage
|
19
|
-
Very easy to use with the method : is_verif_card(numbers_of_credit_cards) : return a boolean
|
20
19
|
|
20
|
+
#### 3 functions you can use :
|
21
|
+
|
22
|
+
----
|
23
|
+
|
24
|
+
#### 1) Verify if the numbers of the credit card are ok
|
25
|
+
```
|
26
|
+
is_verif_card(credit_card_number)
|
27
|
+
```
|
28
|
+
Example :
|
21
29
|
```
|
22
30
|
require 'luhn_credit_card_verificator';
|
23
31
|
|
@@ -27,6 +35,40 @@ puts result
|
|
27
35
|
|
28
36
|
>> return true or false
|
29
37
|
```
|
38
|
+
---
|
39
|
+
|
40
|
+
#### 2) Get the issuing bank information (AMEX, VISA or MASTERCARD)
|
41
|
+
```
|
42
|
+
get_issuing_bank(credit_card_number)
|
43
|
+
```
|
44
|
+
Example :
|
45
|
+
```
|
46
|
+
require 'luhn_credit_card_verificator';
|
47
|
+
|
48
|
+
card_number_from_user = 4556737586899855
|
49
|
+
result = LuhnCreditCardVerificator.get_issuing_bank(card_number_from_user);
|
50
|
+
puts result
|
51
|
+
|
52
|
+
>> return VISA
|
53
|
+
```
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
#### 2) Get the both (If credit card number are ok and issuing bank)
|
58
|
+
|
59
|
+
```
|
60
|
+
get_all_credit_card_information(credit_card_number);
|
61
|
+
```
|
62
|
+
Example :
|
63
|
+
```
|
64
|
+
require 'luhn_credit_card_verificator';
|
65
|
+
|
66
|
+
card_number_from_user = 4556737586899855
|
67
|
+
result = LuhnCreditCardVerificator.get_all_credit_card_information(card_number_from_user);
|
68
|
+
puts result
|
69
|
+
|
70
|
+
>> return {valid => true, "bank" => VISA}
|
71
|
+
```
|
30
72
|
|
31
73
|
__If result is `True` so the card is OK.__
|
32
74
|
|
@@ -45,7 +87,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
45
87
|
|
46
88
|
## Contributing
|
47
89
|
|
48
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
90
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SarahBourgeois/luhn_credit_card_verificator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/luhn_credit_card_verificator/blob/master/CODE_OF_CONDUCT.md).
|
49
91
|
|
50
92
|
## Code of Conduct
|
51
93
|
|
data/lib/enum.rb
ADDED
data/lib/helper.rb
CHANGED
@@ -2,37 +2,81 @@
|
|
2
2
|
|
3
3
|
require_relative "luhn_credit_card_verificator/version"
|
4
4
|
require "Helper"
|
5
|
+
require "enum"
|
5
6
|
|
6
7
|
module LuhnCreditCardVerificator
|
7
8
|
|
8
9
|
class Error < StandardError; end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
11
|
+
|
12
|
+
# Verify if numbers of a credit card are valid
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# >> is_card_valid(4556737586899855)
|
16
|
+
# >> is_card_valid("4556 7375 8689 9855")
|
17
|
+
# => true
|
18
|
+
#
|
19
|
+
# Arguments:
|
20
|
+
# credit_card_number: (String) or (Integer)
|
21
|
+
def self.is_card_valid(card_number)
|
22
|
+
card_array_pair = Array.new;
|
23
|
+
card_array_impair = Array.new;
|
24
|
+
i =0;
|
25
|
+
|
26
|
+
begin
|
27
|
+
format_card = Helper::format_input(card_number.to_s);
|
28
|
+
format_card.each { |item|
|
29
|
+
number_to_push = Helper::double_number(item);
|
30
|
+
card_array_pair.push(item.to_i) if i%2 == 0;
|
31
|
+
card_array_impair.push(number_to_push) if i%2 != 0;
|
32
|
+
i = i +1
|
33
|
+
}
|
34
|
+
sum_pair = card_array_pair.sum
|
35
|
+
sum_impair = card_array_impair.sum
|
36
|
+
result = Helper::check_card_validity(sum_pair, sum_impair);
|
37
|
+
return result;
|
38
|
+
rescue
|
39
|
+
return false;
|
37
40
|
end
|
38
41
|
end
|
42
|
+
|
43
|
+
# Get the issuing bank of a credit card
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
# >> get_issuing_bank(4556737586899855)
|
47
|
+
# >> get_issuing_bank("4556 7375 8689 9855")
|
48
|
+
# => VISA
|
49
|
+
#
|
50
|
+
# Arguments:
|
51
|
+
# credit_card_number: (String) or (Integer)
|
52
|
+
def self.get_issuing_bank(credit_card_number)
|
53
|
+
card = credit_card_number.to_s
|
54
|
+
return BANK_TYPE::AMEX if card[0..1] == BANK_NUMBER::AMEX_NUMBER[0] or card[0..1] == BANK_NUMBER::AMEX_NUMBER[1];
|
55
|
+
return BANK_TYPE::VISA if card[0] == BANK_NUMBER::VISA_NUMBER;
|
56
|
+
return BANK_TYPE::MASTERCARD if card[0..1].to_i.between?(BANK_NUMBER::MASTERCARD_NUMBER[0], BANK_NUMBER::MASTERCARD_NUMBER[4]);
|
57
|
+
return BANK_TYPE::UNKNOWN;
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# Verify if credit card numbers are valid and the issuing bank at the same time
|
62
|
+
#
|
63
|
+
# Example:
|
64
|
+
# >> get_all_credit_card_information(4556737586899855)
|
65
|
+
# >> get_all_credit_card_information("4556 7375 8689 9855")
|
66
|
+
# => {valid => true, "bank" => VISA}
|
67
|
+
#
|
68
|
+
# Arguments:
|
69
|
+
# credit_card_number: (String) or (Integer)
|
70
|
+
def self.get_all_credit_card_information(credit_card_number)
|
71
|
+
begin
|
72
|
+
is_valid = is_card_valid(credit_card_number);
|
73
|
+
issuing_bank = get_issuing_bank(credit_card_number);
|
74
|
+
return {"valid" => is_valid, "bank" => issuing_bank}
|
75
|
+
rescue => error
|
76
|
+
return {"response" => "an error occurs during the verification of the credit card numbers #{error.message}"}
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luhn_credit_card_verificator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SarahBourgeois
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- LICENSE
|
31
31
|
- README.md
|
32
32
|
- Rakefile
|
33
|
+
- lib/enum.rb
|
33
34
|
- lib/helper.rb
|
34
35
|
- lib/luhn_credit_card_verificator.rb
|
35
36
|
- lib/luhn_credit_card_verificator/version.rb
|