aliquot-pay 3.0.2 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/aliquot-pay.rb +64 -31
  3. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eca8987a342cb9d4c72a68b9c45ec9431f7aa383b5688e20dd85ef8a2ba267c0
4
- data.tar.gz: 4cf2a6489569dbe2edd79330aa74ac349ef1a765f954c6b1753cecda206bc006
3
+ metadata.gz: f0347fa0a06522e58ab9c2a9377c833cf362162eeb56d00ea1115282127d4a68
4
+ data.tar.gz: 15619eb5744be9d8e9dfe640ef61f75ed665ee4e036c8e0fc504df95ebac95d7
5
5
  SHA512:
6
- metadata.gz: 63cafaccc975cfb2f6b9d0986209f95c5aee30074392380008d573c1bcfa1400b9ef545434f6f62d511f8fe8f3f96132af2780891789bcc080f6c1496e6bf40f
7
- data.tar.gz: 145ce9d75ad93e496d98945af3f27964ddc46fb3723ef13951eda851bbf88a32ad0f27d353cc5ab5da2406055944aff8de93138cec7c9fb5674d94441d7dec28
6
+ metadata.gz: '0891095df48ec5fc8fb35705d369ff0504b75c41af817098155278c9dd61bbc1a53a1b4813b40bc48cb733cb1d8bb01e40680758d423c5112950e6d434ae939f'
7
+ data.tar.gz: 2daa9b11ae45383ebe4cd85a5f48cd394bed7e3f3a54ce212e566ef66359d01453cabbbc8c41b0231edb805fdfc62463645b05c097706117a1abacfa1bef0cb5
data/lib/aliquot-pay.rb CHANGED
@@ -25,10 +25,16 @@ class AliquotPay
25
25
  attr_accessor :recipient, :info, :root_key, :intermediate_key
26
26
  attr_writer :recipient_id, :shared_secret, :token, :signed_key_string
27
27
 
28
- def initialize(protocol_version = :ECv2, root_key = nil)
28
+ def initialize(protocol_version: :ECv2, root_key: nil, type: :browser)
29
29
  @protocol_version = protocol_version
30
- if root_key
31
- @root_key = root_key
30
+ @root_key = root_key
31
+ @type = type
32
+ if @type == :app
33
+ @auth_method = 'CRYPTOGRAM_3DS'
34
+ if @protocol_version == :ECv1
35
+ @auth_method = '3DS'
36
+ @payment_method = 'TOKENIZED_CARD'
37
+ end
32
38
  end
33
39
  end
34
40
 
@@ -39,10 +45,10 @@ class AliquotPay
39
45
  def extract_root_signing_keys
40
46
  key = Base64.strict_encode64(ensure_root_key.to_der)
41
47
  {
42
- 'keys' => [
48
+ 'keys' => [{
43
49
  'protocolVersion' => @protocol_version,
44
- 'keyValue' => key,
45
- ]
50
+ 'keyValue' => key
51
+ }]
46
52
  }.to_json
47
53
  end
48
54
 
@@ -68,7 +74,7 @@ class AliquotPay
68
74
  when :ECv2
69
75
  cipher = OpenSSL::Cipher::AES256.new(:CTR)
70
76
  else
71
- raise StandardError, "Invalid protocol_version #{protocol_version}"
77
+ raise StandardError, "Invalid protocol_version #{@protocol_version}"
72
78
  end
73
79
 
74
80
  keys = AliquotPay::Util.derive_keys(eph.public_key.to_bn.to_s(2), ss, @info, @protocol_version)
@@ -83,29 +89,54 @@ class AliquotPay
83
89
  {
84
90
  'encryptedMessage' => Base64.strict_encode64(encrypted_message),
85
91
  'ephemeralPublicKey' => Base64.strict_encode64(eph.public_key.to_bn.to_s(2)),
86
- 'tag' => Base64.strict_encode64(tag),
92
+ 'tag' => Base64.strict_encode64(tag)
87
93
  }
88
94
  end
89
95
 
90
96
  def build_payment_method_details
91
97
  return @payment_method_details if @payment_method_details
98
+
99
+ return build_payment_method_details_non_tokenized if @type == :browser
100
+
101
+ build_payment_method_details_tokenized
102
+ end
103
+
104
+ def build_payment_method_details_non_tokenized
92
105
  value = {
93
106
  'pan' => @pan || '4111111111111111',
94
107
  'expirationYear' => @expiration_year || Time.now.year + 1,
95
- 'expirationMonth' => @expiration_month || 12,
96
- 'authMethod' => @auth_method || 'PAN_ONLY',
108
+ 'expirationMonth' => @expiration_month || 12
97
109
  }
98
110
 
99
- if @auth_method == 'CRYPTOGRAM_3DS'
111
+ if @protocol_version == :ECv2 && @type == :browser
100
112
  value.merge!(
101
- 'cryptogram' => @cryptogram || 'SOME CRYPTOGRAM',
102
- 'eciIndicator' => @eci_indicator || '05'
113
+ 'authMethod' => @auth_method || 'PAN_ONLY'
103
114
  )
104
115
  end
105
-
106
116
  value
107
117
  end
108
118
 
119
+ def build_payment_method_details_tokenized
120
+ value = {
121
+ 'expirationYear' => @expiration_year || Time.now.year + 1,
122
+ 'expirationMonth' => @expiration_month || 12,
123
+ 'eciIndicator' => @eci_indicator || '05'
124
+ }
125
+ if @protocol_version == :ECv1
126
+ value.merge!(
127
+ 'dpan' => @pan || '4111111111111111',
128
+ 'authMethod' => @auth_method || '3DS',
129
+ '3dsCryptogram' => @cryptogram || Base64.strict_encode64(OpenSSL::Random.random_bytes(20))
130
+ )
131
+ else
132
+ value.merge!(
133
+ 'pan' => @pan || '4111111111111111',
134
+ 'authMethod' => @auth_method || 'CRYPTOGRAM_3DS',
135
+ 'cryptogram' => @cryptogram || Base64.strict_encode64(OpenSSL::Random.random_bytes(20))
136
+ )
137
+ end
138
+ end
139
+
109
140
  def build_cleartext_message
110
141
  return @cleartext_message if @cleartext_message
111
142
 
@@ -114,8 +145,8 @@ class AliquotPay
114
145
 
115
146
  @cleartext_message = {
116
147
  'messageExpiration' => @message_expiration || default_message_expiration,
117
- 'messageId' => @message_id || default_message_id,
118
- 'paymentMethod' => @payment_method || 'CARD',
148
+ 'messageId' => @message_id || default_message_id,
149
+ 'paymentMethod' => @payment_method || 'CARD',
119
150
  'paymentMethodDetails' => build_payment_method_details
120
151
  }
121
152
 
@@ -140,11 +171,12 @@ class AliquotPay
140
171
  end
141
172
 
142
173
  def signed_message_string
143
- @signed_message_string ||= build_signed_message.to_json
174
+ build_signed_message.to_json
144
175
  end
145
176
 
146
177
  def build_signed_key
147
178
  return @signed_key if @signed_key
179
+
148
180
  ensure_intermediate_key
149
181
 
150
182
  if !@intermediate_key.private_key? && !@intermediate_key.public_key?
@@ -156,7 +188,7 @@ class AliquotPay
156
188
 
157
189
  @signed_key = {
158
190
  'keyExpiration' => @key_expiration || default_key_expiration,
159
- 'keyValue' => @key_value || default_key_value,
191
+ 'keyValue' => @key_value || default_key_value
160
192
  }
161
193
  end
162
194
 
@@ -181,40 +213,41 @@ class AliquotPay
181
213
  ensure_intermediate_key
182
214
  end
183
215
 
184
- signature_string =
185
- signed_string_message = ['Google',
186
- recipient_id,
187
- @protocol_version.to_s,
188
- signed_message_string].map do |str|
189
- [str.length].pack('V') + str
190
- end.join
216
+ signature_elements = [
217
+ 'Google',
218
+ recipient_id,
219
+ @protocol_version.to_s,
220
+ signed_message_string
221
+ ]
222
+
223
+ signature_string = signature_elements.map { |e| [e.length].pack('V') + e }.join
191
224
  @signature = sign(key, signature_string)
192
225
  end
193
226
 
194
227
  def build_signatures
195
228
  return @signatures if @signatures
196
229
 
197
- signature_string =
198
- signed_key_signature = ['Google', 'ECv2', signed_key_string].map do |str|
199
- [str.to_s.length].pack('V') + str.to_s
200
- end.join
230
+ signature_string = ['Google', 'ECv2', signed_key_string].map do |str|
231
+ [str.to_s.length].pack('V') + str.to_s
232
+ end.join
201
233
 
202
234
  @signatures = [sign(ensure_root_key, signature_string)]
203
235
  end
204
236
 
205
237
  def build_token
206
238
  return @token if @token
239
+
207
240
  res = {
208
241
  'protocolVersion' => @protocol_version.to_s,
209
242
  'signedMessage' => @signed_message || signed_message_string,
210
- 'signature' => build_signature,
243
+ 'signature' => build_signature
211
244
  }
212
245
 
213
246
  if @protocol_version == :ECv2
214
247
  intermediate = {
215
248
  'intermediateSigningKey' => @intermediate_signing_key || {
216
249
  'signedKey' => signed_key_string,
217
- 'signatures' => build_signatures,
250
+ 'signatures' => build_signatures
218
251
  }
219
252
  }
220
253
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliquot-pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clearhaus
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-04 00:00:00.000000000 Z
11
+ date: 2024-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hkdf
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3'
55
- description:
55
+ description:
56
56
  email: hello@clearhaus.com
57
57
  executables: []
58
58
  extensions: []
@@ -64,7 +64,7 @@ homepage: https://github.com/clearhaus/aliquot-pay
64
64
  licenses:
65
65
  - MIT
66
66
  metadata: {}
67
- post_install_message:
67
+ post_install_message:
68
68
  rdoc_options: []
69
69
  require_paths:
70
70
  - lib
@@ -79,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.3.5
83
- signing_key:
82
+ rubygems_version: 3.3.26
83
+ signing_key:
84
84
  specification_version: 4
85
85
  summary: Generates Google Pay test dummy tokens
86
86
  test_files: []