adyen-cse-ruby 0.1.5 → 1.0.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 +18 -9
- data/lib/adyen_cse/encrypter.rb +20 -25
- data/lib/adyen_cse/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9816514bfde8a7e82bc80437fadc0ebc0bd8b6
|
4
|
+
data.tar.gz: 7cd1f25ceeba3b576e42bdbd78949c30312583c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 476aa8acce591d1db06253e9c3579775a520d5343b32b4f51422d0ed6587b0853285316d72828429afe8e7284775a51b8e653af4d35d61884f0e94aedb6afe10
|
7
|
+
data.tar.gz: 0c695bf5902c7d6323b49f6f4e6bc23b4c03e54033e97e6ab3987a9cd6479e92cb3c3d4966f336340501ea0e9f05b4be2695d2d7efe0af72154c96842ca971b1
|
data/README.md
CHANGED
@@ -29,13 +29,22 @@ Or install it yourself as:
|
|
29
29
|
```ruby
|
30
30
|
require 'adyen_cse'
|
31
31
|
|
32
|
-
cse = AdyenCse::Encrypter.new(public_key)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
cse = AdyenCse::Encrypter.new(public_key)
|
33
|
+
|
34
|
+
encrypted_card = cse.encrypt!(
|
35
|
+
holder_name: "Adyen Shopper",
|
36
|
+
number: 4111_1111_1111_1111.to_s,
|
37
|
+
expiry_month: "08",
|
38
|
+
expiry_year: "2018",
|
39
|
+
cvc: "737"
|
40
|
+
)
|
41
|
+
```
|
42
|
+
|
43
|
+
Optionally, you may pass a custom `generation_time` to mock expired data.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
encrypted_card = cse.encrypt!(
|
47
|
+
...,
|
48
|
+
generation_time: Time.new(2015, 10, 21)
|
49
|
+
)
|
41
50
|
```
|
data/lib/adyen_cse/encrypter.rb
CHANGED
@@ -5,27 +5,34 @@ require "json"
|
|
5
5
|
|
6
6
|
module AdyenCse
|
7
7
|
class Encrypter
|
8
|
-
PREFIX
|
9
|
-
VERSION
|
8
|
+
PREFIX = "adyenrb"
|
9
|
+
VERSION = "0_1_1"
|
10
10
|
|
11
|
-
attr_reader
|
12
|
-
attr_accessor :holder_name, :number, :expiry_month, :expiry_year, :cvc, :generation_time
|
11
|
+
attr_reader :public_key
|
13
12
|
|
14
13
|
def initialize(public_key)
|
15
14
|
@public_key = public_key
|
16
|
-
yield self rescue nil
|
17
|
-
self.generation_time ||= Time.now
|
18
15
|
end
|
19
16
|
|
20
|
-
def encrypt!
|
21
|
-
validate!
|
17
|
+
def encrypt!(params = {})
|
18
|
+
validate!(params.keys)
|
22
19
|
|
23
20
|
key = SecureRandom.random_bytes(32)
|
24
21
|
nonce = SecureRandom.random_bytes(12)
|
25
|
-
|
22
|
+
generation_time = params.fetch(:generation_time, Time.now)
|
23
|
+
|
24
|
+
# keys sorted alphabetically
|
25
|
+
json_data = {
|
26
|
+
"cvc" => params[:cvc],
|
27
|
+
"expiryMonth" => params[:expiry_month],
|
28
|
+
"expiryYear" => params[:expiry_year],
|
29
|
+
"generationtime" => generation_time.utc.strftime("%FT%T.%LZ"),
|
30
|
+
"holderName" => params[:holder_name],
|
31
|
+
"number" => params[:number],
|
32
|
+
}.to_json
|
26
33
|
|
27
34
|
ccm = OpenSSL::CCM.new("AES", key, 8)
|
28
|
-
encrypted_card = ccm.encrypt(
|
35
|
+
encrypted_card = ccm.encrypt(json_data, nonce)
|
29
36
|
|
30
37
|
rsa = self.class.parse_public_key(public_key)
|
31
38
|
encrypted_aes_key = rsa.public_encrypt(key)
|
@@ -35,18 +42,6 @@ module AdyenCse
|
|
35
42
|
[PREFIX, VERSION, "$", Base64.strict_encode64(encrypted_aes_key), "$", Base64.strict_encode64(encrypted_card_component)].join
|
36
43
|
end
|
37
44
|
|
38
|
-
def card_data
|
39
|
-
# keys sorted alphabetically
|
40
|
-
{
|
41
|
-
"cvc" => cvc,
|
42
|
-
"expiryMonth" => expiry_month,
|
43
|
-
"expiryYear" => expiry_year,
|
44
|
-
"generationtime" => generation_time.utc.strftime("%FT%T.%LZ"),
|
45
|
-
"holderName" => holder_name,
|
46
|
-
"number" => number,
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
45
|
def self.parse_public_key(public_key)
|
51
46
|
exponent, modulus = public_key.split("|").map { |n| n.to_i(16) }
|
52
47
|
|
@@ -58,9 +53,9 @@ module AdyenCse
|
|
58
53
|
|
59
54
|
private
|
60
55
|
|
61
|
-
def validate!
|
62
|
-
%
|
63
|
-
raise ArgumentError, "param `#{param}' is required"
|
56
|
+
def validate!(params)
|
57
|
+
%i(holder_name number expiry_month expiry_year cvc).each do |param|
|
58
|
+
raise ArgumentError, "param `#{param}' is required" unless params.include?(param)
|
64
59
|
end
|
65
60
|
end
|
66
61
|
end
|
data/lib/adyen_cse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen-cse-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joey Cheng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl-ccm
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.6.13
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Adyen Client-side encryption library for Ruby
|