adyen_client 0.0.1 → 0.1.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 +2 -2
- data/lib/adyen_client.rb +38 -14
- data/lib/adyen_client/configuration.rb +18 -22
- data/lib/adyen_client/response.rb +21 -25
- data/lib/adyen_client/utils.rb +21 -25
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cfdbe290375469bcc8fd26d9251665f60d1efcd
|
|
4
|
+
data.tar.gz: 67ff26eb4a0581b77e87ee650185faa17c896862
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fbd7f75937c17840214e66bca9ae2c2b72722315b594288e3f578ca7e4c179d4876a031e324682ba360fda4fbff893543364ed6e6e44e65431aeef6481ebfa1
|
|
7
|
+
data.tar.gz: 527cae7b474e4140c0a7c1584e397f468573aa69fdc952c4b9298d82cf7e6532f21ecc3f0e1e1105eb9b9329e43c060f524a8d297f4c44be6f0a807ed75e046e
|
data/README.md
CHANGED
|
@@ -33,7 +33,7 @@ AdyenClient.configure(environment: :test, username: "ws_123456@Company.FooBar",
|
|
|
33
33
|
# That comes in handy to configure the client from a YAML file
|
|
34
34
|
AdyenClient.configure(YAML.load_file(Rails.root.join("config", "adyen.yml"))[Rails.env.to_s])
|
|
35
35
|
|
|
36
|
-
# You can override all
|
|
36
|
+
# You can override all default_* options for each instance of a client
|
|
37
37
|
client = AdyenClient.new(merchant_account: "FooBarSubMerchant123")
|
|
38
38
|
eur_client = AdyenClient.new(currency: "EUR")
|
|
39
39
|
```
|
|
@@ -93,7 +93,7 @@ Also the default `AdyenClient::Response` class basically just wraps the JSON res
|
|
|
93
93
|
The only work it does is converting `camelCase` keys to `sneak_case`, removing unnecessary object nestings and providing you with a convenience `authorised?` method.
|
|
94
94
|
|
|
95
95
|
If you want a more sophisticated response class, you can easily hook up your own.
|
|
96
|
-
The only method you need to provide is `::
|
|
96
|
+
The only method you need to provide is `::parse`. It will receive one argument, the [`HTTParty::Response`](http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/Response) for the given request.
|
|
97
97
|
|
|
98
98
|
```ruby
|
|
99
99
|
class MyAdyenResponse
|
data/lib/adyen_client.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require "httparty"
|
|
2
|
-
require "adyen_client/utils"
|
|
3
|
-
require "adyen_client/response"
|
|
4
|
-
require "adyen_client/configuration"
|
|
5
2
|
|
|
3
|
+
# Public: Main class for interacting with the Adyen API
|
|
4
|
+
#
|
|
5
|
+
# Use an instance to configure for the situation and talk to the API.
|
|
6
6
|
class AdyenClient
|
|
7
7
|
include HTTParty
|
|
8
8
|
|
|
@@ -82,14 +82,17 @@ class AdyenClient
|
|
|
82
82
|
# :recurring_reference - Use when referencing a specific payment method stored for the user. (default: "LATEST")
|
|
83
83
|
# :merchant_account - Use a specific merchant account for this transaction. (default: set by the instance or configuration default merchant account)
|
|
84
84
|
# :currency - Use a specific 3-letter currency code. (default: set by the instance or configuration default currency)
|
|
85
|
+
# :statement - Supply a statement that should be shown on the customers credit card bill. (default: "")
|
|
86
|
+
# Note however that most card issues allow for not more than 22 characters.
|
|
85
87
|
#
|
|
86
88
|
# Returns an AdyenClient::Response or your specific response implementation.
|
|
87
|
-
def authorise_recurring_payment(reference:, shopper_reference:, amount:, recurring_reference: "LATEST", merchant_account: @merchant_account, currency: configuration.default_currency)
|
|
89
|
+
def authorise_recurring_payment(reference:, shopper_reference:, amount:, recurring_reference: "LATEST", merchant_account: @merchant_account, currency: configuration.default_currency, statement: "")
|
|
88
90
|
postJSON("/Payment/v12/authorise",
|
|
89
91
|
reference: reference,
|
|
90
92
|
amount: { value: amount, currency: currency },
|
|
91
93
|
merchantAccount: merchant_account,
|
|
92
94
|
shopperReference: shopper_reference,
|
|
95
|
+
shopperStatement: statement,
|
|
93
96
|
selectedRecurringDetailReference: recurring_reference,
|
|
94
97
|
selectedBrand: "",
|
|
95
98
|
recurring: { contract: "RECURRING" },
|
|
@@ -118,6 +121,8 @@ class AdyenClient
|
|
|
118
121
|
#
|
|
119
122
|
# :encrypted_card - The encrypted credit card information generated by the CSE (client side encryption) javascript integration.
|
|
120
123
|
# :reference - Your reference id for this transaction.
|
|
124
|
+
# Caveat: According to Adyen a hyphen "-" is treated as a separator for multiple references.
|
|
125
|
+
# If you are using something like `SecureRandom.uuid` be sure to replace "-" with something else.
|
|
121
126
|
# :shopper - The hash describing the shopper for this contract:
|
|
122
127
|
# :reference - Your reference id for this shopper/user. (mandatory)
|
|
123
128
|
# :email - The shoppers email address. (optional but recommended)
|
|
@@ -144,20 +149,28 @@ class AdyenClient
|
|
|
144
149
|
# :encrypted_card - The encrypted credit card information generated by the CSE (client side encryption) javascript integration.
|
|
145
150
|
# :amount - The integer amount in cents.
|
|
146
151
|
# :reference - Your reference id for this transaction.
|
|
152
|
+
# Caveat: According to Adyen a hyphen "-" is treated as a separator for multiple references.
|
|
153
|
+
# If you are using something like `SecureRandom.uuid` be sure to replace "-" with something else.
|
|
147
154
|
# :merchant_account - Use a specific merchant account for this transaction. (default: set by the instance or configuration default merchant account)
|
|
148
155
|
# :currency - Use a specific 3-letter currency code. (default: set by the instance or configuration default currency)
|
|
149
156
|
# :shopper - The hash describing the shopper for this transaction, optional but recommended (default: {}):
|
|
150
|
-
#
|
|
151
|
-
#
|
|
152
|
-
#
|
|
157
|
+
# :email - The shoppers email address (optional but recommended).
|
|
158
|
+
# :ip - The shoppers last known ip address (optional but recommended).
|
|
159
|
+
# :reference - Your reference id for this shopper/user (optional).
|
|
160
|
+
# :statement - Supply a statement that should be shown on the customers credit card bill. (default: "")
|
|
161
|
+
# Note however that most card issues allow for not more than 22 characters.
|
|
153
162
|
#
|
|
154
163
|
# Returns an AdyenClient::Response or your specific response implementation.
|
|
155
|
-
def authorise(encrypted_card:, amount:, reference:, merchant_account: @merchant_account, currency: @currency, shopper: {})
|
|
164
|
+
def authorise(encrypted_card:, amount:, reference:, merchant_account: @merchant_account, currency: @currency, shopper: {}, statement: "")
|
|
156
165
|
postJSON("/Payment/v12/authorise",
|
|
157
166
|
reference: reference,
|
|
158
167
|
amount: { value: amount, currency: currency },
|
|
159
168
|
merchantAccount: merchant_account,
|
|
160
|
-
additionalData: { "card.encrypted.json": encrypted_card }
|
|
169
|
+
additionalData: { "card.encrypted.json": encrypted_card },
|
|
170
|
+
shopperEmail: shopper[:email],
|
|
171
|
+
shopperIP: shopper[:ip],
|
|
172
|
+
shopperReference: shopper[:reference],
|
|
173
|
+
shopperStatement: statement
|
|
161
174
|
)
|
|
162
175
|
end
|
|
163
176
|
alias_method :authorize, :authorise
|
|
@@ -166,22 +179,30 @@ class AdyenClient
|
|
|
166
179
|
#
|
|
167
180
|
# :encrypted_card - The encrypted credit card information generated by the CSE (client side encryption) javascript integration.
|
|
168
181
|
# :reference - Your reference id for this transaction.
|
|
182
|
+
# Caveat: According to Adyen a hyphen "-" is treated as a separator for multiple references.
|
|
183
|
+
# If you are using something like `SecureRandom.uuid` be sure to replace "-" with something else.
|
|
169
184
|
# :amount - The integer amount in cents. Will not be charged on the card. (default: 0)
|
|
170
185
|
# :merchant_account - Use a specific merchant account for this transaction (default: set by the instance or configuration default merchant account).
|
|
171
186
|
# :currency - Use a specific 3-letter currency code (default: set by the instance or configuration default currency).
|
|
172
187
|
# :shopper - The hash describing the shopper for this transaction, optional but recommended (default: {}):
|
|
173
|
-
#
|
|
174
|
-
#
|
|
175
|
-
#
|
|
188
|
+
# :email - The shoppers email address (optional but recommended).
|
|
189
|
+
# :ip - The shoppers last known ip address (optional but recommended).
|
|
190
|
+
# :reference - Your reference id for this shopper/user (optional).
|
|
191
|
+
# :statement - Supply a statement that should be shown on the customers credit card bill. (default: "")
|
|
192
|
+
# Note however that most card issues allow for not more than 22 characters.
|
|
176
193
|
#
|
|
177
194
|
# Returns an AdyenClient::Response or your specific response implementation.
|
|
178
|
-
def verify(encrypted_card:, reference:, amount: 0, merchant_account: @merchant_account, currency: @currency, shopper: {})
|
|
195
|
+
def verify(encrypted_card:, reference:, amount: 0, merchant_account: @merchant_account, currency: @currency, shopper: {}, statement: "")
|
|
179
196
|
postJSON("/Payment/v12/authorise",
|
|
180
197
|
reference: reference,
|
|
181
198
|
amount: { value: 0, currency: currency },
|
|
182
199
|
additionalAmount: { value: amount, currency: currency },
|
|
183
200
|
merchantAccount: merchant_account,
|
|
184
|
-
additionalData: { "card.encrypted.json": encrypted_card }
|
|
201
|
+
additionalData: { "card.encrypted.json": encrypted_card },
|
|
202
|
+
shopperEmail: shopper[:email],
|
|
203
|
+
shopperIP: shopper[:ip],
|
|
204
|
+
shopperReference: shopper[:reference],
|
|
205
|
+
shopperStatement: statement
|
|
185
206
|
)
|
|
186
207
|
end
|
|
187
208
|
|
|
@@ -251,3 +272,6 @@ class AdyenClient
|
|
|
251
272
|
|
|
252
273
|
end
|
|
253
274
|
|
|
275
|
+
require "adyen_client/utils"
|
|
276
|
+
require "adyen_client/response"
|
|
277
|
+
require "adyen_client/configuration"
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
class AdyenClient
|
|
1
|
+
class AdyenClient::Configuration
|
|
2
|
+
BASE_URI = "https://pal-%s.adyen.com/pal/servlet"
|
|
3
|
+
attr_accessor :environment
|
|
4
|
+
attr_accessor :username
|
|
5
|
+
attr_accessor :password
|
|
6
|
+
attr_accessor :cse_public_key
|
|
7
|
+
attr_accessor :default_merchant_account
|
|
8
|
+
attr_accessor :default_currency
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
attr_accessor :environment
|
|
6
|
-
attr_accessor :username
|
|
7
|
-
attr_accessor :password
|
|
8
|
-
attr_accessor :cse_public_key
|
|
9
|
-
attr_accessor :default_merchant_account
|
|
10
|
-
attr_accessor :default_currency
|
|
11
|
-
|
|
12
|
-
def set(hash)
|
|
13
|
-
hash.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def apply(klass)
|
|
17
|
-
klass.base_uri(BASE_URI % environment)
|
|
18
|
-
klass.basic_auth(username, password)
|
|
19
|
-
# prevent following redirects and raise HTTParty::RedirectionTooDeep
|
|
20
|
-
klass.no_follow(true)
|
|
21
|
-
klass.format(:json)
|
|
22
|
-
klass.headers("Content-Type" => "application/json; charset=utf-8")
|
|
23
|
-
end
|
|
10
|
+
def set(hash)
|
|
11
|
+
hash.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
|
24
12
|
end
|
|
25
13
|
|
|
14
|
+
def apply(klass)
|
|
15
|
+
klass.base_uri(BASE_URI % environment)
|
|
16
|
+
klass.basic_auth(username, password)
|
|
17
|
+
# prevent following redirects and raise HTTParty::RedirectionTooDeep
|
|
18
|
+
klass.no_follow(true)
|
|
19
|
+
klass.format(:json)
|
|
20
|
+
klass.headers("Content-Type" => "application/json; charset=utf-8")
|
|
21
|
+
end
|
|
26
22
|
end
|
|
27
23
|
|
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
class AdyenClient
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
new(http_response.code, Utils.massage_response(http_response.parsed_response))
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
attr_reader :code, :data
|
|
9
|
-
alias_method :to_hash, :data
|
|
1
|
+
class AdyenClient::Response
|
|
2
|
+
def self.parse(http_response)
|
|
3
|
+
new(http_response.code, AdyenClient::Utils.massage_response(http_response.parsed_response))
|
|
4
|
+
end
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
6
|
+
attr_reader :code, :data
|
|
7
|
+
alias_method :to_hash, :data
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
def initialize(code, data)
|
|
10
|
+
@code, @data = code, data
|
|
11
|
+
end
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
alias_method :authorized?, :authorised? # for our friends abroad
|
|
13
|
+
def success?
|
|
14
|
+
code == 200
|
|
15
|
+
end
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
def authorised?
|
|
18
|
+
success? && result_code == "Authorised"
|
|
19
|
+
end
|
|
20
|
+
alias_method :authorized?, :authorised? # for our friends abroad
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
22
|
+
def respond_to_missing?(name, include_private = false)
|
|
23
|
+
@data.has_key?(name.to_s) || super
|
|
31
24
|
end
|
|
32
25
|
|
|
26
|
+
def method_missing(name, *args, &block)
|
|
27
|
+
@data.fetch(name.to_s) { super(name, *args, &block) }
|
|
28
|
+
end
|
|
33
29
|
end
|
|
34
30
|
|
data/lib/adyen_client/utils.rb
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_, v = value.first
|
|
11
|
-
massage_response(v, value)
|
|
12
|
-
else
|
|
13
|
-
Hash[value.map { |k, v| [snake_caseify(k), massage_response(v, value)] }]
|
|
14
|
-
end
|
|
1
|
+
module AdyenClient::Utils
|
|
2
|
+
def massage_response(value, parent = nil)
|
|
3
|
+
case value
|
|
4
|
+
when Array
|
|
5
|
+
value.map { |v| massage_response(v, value) }
|
|
6
|
+
when Hash
|
|
7
|
+
if parent.is_a?(Array) && value.count == 1
|
|
8
|
+
_, v = value.first
|
|
9
|
+
massage_response(v, value)
|
|
15
10
|
else
|
|
16
|
-
value
|
|
11
|
+
Hash[value.map { |k, v| [snake_caseify(k), massage_response(v, value)] }]
|
|
17
12
|
end
|
|
13
|
+
else
|
|
14
|
+
value
|
|
18
15
|
end
|
|
16
|
+
end
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
extend self
|
|
18
|
+
def snake_caseify(string)
|
|
19
|
+
string
|
|
20
|
+
.gsub("::", "/")
|
|
21
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
22
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
23
|
+
.tr("-", "_")
|
|
24
|
+
.downcase
|
|
30
25
|
end
|
|
31
26
|
|
|
27
|
+
extend self
|
|
32
28
|
end
|
|
33
29
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: adyen_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lukas Rieder
|
|
@@ -57,8 +57,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
57
57
|
version: '0'
|
|
58
58
|
requirements: []
|
|
59
59
|
rubyforge_project:
|
|
60
|
-
rubygems_version: 2.
|
|
60
|
+
rubygems_version: 2.5.1
|
|
61
61
|
signing_key:
|
|
62
62
|
specification_version: 4
|
|
63
63
|
summary: A simple client that talks to the Adyen API
|
|
64
64
|
test_files: []
|
|
65
|
+
has_rdoc:
|