credit_card_generator 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -16
- data/lib/credit_card_generator/version.rb +5 -5
- data/lib/credit_card_generator.rb +31 -31
- metadata +3 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 273d5e8fb1d2339f62aa9a9e5cb389e57d9fea91d0abde50684f25232be15244
|
4
|
+
data.tar.gz: 9eeceec591e429bdd61c9dd391931630aa466056f8465fe9b26ce0bd246a6bd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c506bf1a22c7a3c8f5c88d4d0b3b0c19601e4748e3e647f2cb135cc5274f21276d6b5b0e5daa60305e0fd56486f38b8540d33c68536ded7649f699ea51ae1424
|
7
|
+
data.tar.gz: be0c5db66624ee58329e899519ee9d07f493319a78398d3d2f7ae324a056e8eac1c7f9fbc842290d4992f1f215a7d46d234a4f07977ed072ac7dbad21e3ce171
|
data/README.md
CHANGED
@@ -1,16 +1,37 @@
|
|
1
|
-
# CreditCard-Generator
|
2
|
-
CreditCardGenerator is a Ruby library designed to generate valid credit card numbers for testing purposes. Using the Luhn algorithm, this library creates credit card numbers that conform to the standard validation rules used by most payment processors.
|
3
|
-
|
4
|
-
## Purpose
|
5
|
-
The primary goal of CreditCardGenerator is to assist developers and testers in generating valid credit card numbers for use in test environments. These numbers are syntactically correct but cannot be used for real transactions, making them ideal for testing payment processing systems, form validations, and other use cases where valid card numbers are required.
|
6
|
-
|
7
|
-
## Features
|
8
|
-
Supports Multiple Card Types: Generate numbers for Visa, MasterCard, American Express, and other major card providers.
|
9
|
-
Customizable Lengths and Prefixes: Generate card numbers with specific lengths and prefixes to simulate different card types.
|
10
|
-
Batch Generation: Easily generate multiple card numbers in one go.
|
11
|
-
|
12
|
-
## Use Cases
|
13
|
-
Payment Gateway Testing: Simulate transactions with valid card numbers.
|
14
|
-
Form Validation: Ensure your forms correctly validate and accept credit card numbers.
|
15
|
-
Load Testing: Generate large quantities of card numbers to stress-test payment systems.
|
16
|
-
|
1
|
+
# CreditCard-Generator
|
2
|
+
CreditCardGenerator is a Ruby library designed to generate valid credit card numbers for testing purposes. Using the Luhn algorithm, this library creates credit card numbers that conform to the standard validation rules used by most payment processors.
|
3
|
+
|
4
|
+
## Purpose
|
5
|
+
The primary goal of CreditCardGenerator is to assist developers and testers in generating valid credit card numbers for use in test environments. These numbers are syntactically correct but cannot be used for real transactions, making them ideal for testing payment processing systems, form validations, and other use cases where valid card numbers are required.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
Supports Multiple Card Types: Generate numbers for Visa, MasterCard, American Express, and other major card providers.
|
9
|
+
Customizable Lengths and Prefixes: Generate card numbers with specific lengths and prefixes to simulate different card types.
|
10
|
+
Batch Generation: Easily generate multiple card numbers in one go.
|
11
|
+
|
12
|
+
## Use Cases
|
13
|
+
Payment Gateway Testing: Simulate transactions with valid card numbers.
|
14
|
+
Form Validation: Ensure your forms correctly validate and accept credit card numbers.
|
15
|
+
Load Testing: Generate large quantities of card numbers to stress-test payment systems.
|
16
|
+
|
17
|
+
## Other
|
18
|
+
To try it locally follow this steps
|
19
|
+
|
20
|
+
1. Build the Gem
|
21
|
+
First, you need to build the gem package from the .gemspec file:
|
22
|
+
```
|
23
|
+
gem build credit_card_generator.gemspec
|
24
|
+
```
|
25
|
+
This will generate a .gem file, such as credit_card_generator-0.1.0.gem.
|
26
|
+
|
27
|
+
2. Install the Gem Locally
|
28
|
+
After building the gem, install it on your local system using:
|
29
|
+
```
|
30
|
+
gem install ./credit_card_generator-0.1.0.gem
|
31
|
+
```
|
32
|
+
3. Run the Script
|
33
|
+
To test the gem, you can create a Ruby script or use an existing one. For example, if you have a main.rb script that uses this gem, run it with:
|
34
|
+
```
|
35
|
+
ruby main.rb
|
36
|
+
```
|
37
|
+
This will execute the script and demonstrate how the CreditCardGenerator library works in generating valid credit card numbers for testing purposes.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# lib/credit_card_generator/version.rb
|
2
|
-
|
3
|
-
module CreditCardGenerator
|
4
|
-
VERSION = "0.
|
5
|
-
end
|
1
|
+
# lib/credit_card_generator/version.rb
|
2
|
+
|
3
|
+
module CreditCardGenerator
|
4
|
+
VERSION = "0.2.0"
|
5
|
+
end
|
6
6
|
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module CreditCardGenerator
|
2
|
-
def self.luhn_checksum(card_number)
|
3
|
-
digits = card_number.chars.map(&:to_i)
|
4
|
-
checksum = 0
|
5
|
-
|
6
|
-
digits.reverse.each_with_index do |digit, index|
|
7
|
-
if index.odd?
|
8
|
-
digit *= 2
|
9
|
-
digit -= 9 if digit > 9
|
10
|
-
end
|
11
|
-
checksum += digit
|
12
|
-
end
|
13
|
-
|
14
|
-
checksum % 10
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.generate_card_number(prefix, length)
|
18
|
-
card_number = prefix.dup
|
19
|
-
|
20
|
-
while card_number.length < (length - 1)
|
21
|
-
card_number += rand(0..9).to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
checksum_digit = (10 - luhn_checksum(card_number + '0')) % 10
|
25
|
-
card_number + checksum_digit.to_s
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.generate(prefix, length, quantity)
|
29
|
-
(1..quantity).map { generate_card_number(prefix, length) }
|
30
|
-
end
|
31
|
-
end
|
1
|
+
module CreditCardGenerator
|
2
|
+
def self.luhn_checksum(card_number)
|
3
|
+
digits = card_number.chars.map(&:to_i)
|
4
|
+
checksum = 0
|
5
|
+
|
6
|
+
digits.reverse.each_with_index do |digit, index|
|
7
|
+
if index.odd?
|
8
|
+
digit *= 2
|
9
|
+
digit -= 9 if digit > 9
|
10
|
+
end
|
11
|
+
checksum += digit
|
12
|
+
end
|
13
|
+
|
14
|
+
checksum % 10
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.generate_card_number(prefix, length)
|
18
|
+
card_number = prefix.dup
|
19
|
+
|
20
|
+
while card_number.length < (length - 1)
|
21
|
+
card_number += rand(0..9).to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
checksum_digit = (10 - luhn_checksum(card_number + '0')) % 10
|
25
|
+
card_number + checksum_digit.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.generate(prefix, length, quantity)
|
29
|
+
(1..quantity).map { generate_card_number(prefix, length) }
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credit_card_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Oliveira
|
@@ -9,35 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-08-20 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: nokogiri
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: httparty
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
12
|
+
dependencies: []
|
41
13
|
description: This library generates credit card numbers using the Luhn algorithm,
|
42
14
|
suitable for testing payment systems and form validations.
|
43
15
|
email:
|
@@ -71,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
43
|
- !ruby/object:Gem::Version
|
72
44
|
version: '0'
|
73
45
|
requirements: []
|
74
|
-
rubygems_version: 3.5.
|
46
|
+
rubygems_version: 3.5.17
|
75
47
|
signing_key:
|
76
48
|
specification_version: 4
|
77
49
|
summary: A simple library for generating valid credit card numbers for testing purposes.
|