transbank-sdk 1.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +13 -0
- data/Dockerfile +6 -0
- data/Gemfile +6 -0
- data/LICENSE.md +11 -0
- data/Makefile +24 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +20 -0
- data/lib/transbank/sdk.rb +23 -0
- data/lib/transbank/sdk/onepay/base.rb +115 -0
- data/lib/transbank/sdk/onepay/errors/errors.rb +17 -0
- data/lib/transbank/sdk/onepay/errors/integration_type_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/invalid_options_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/item_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/refund_create_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/response_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/shopping_cart_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/signature_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/transaction_commit_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/transaction_create_error.rb +8 -0
- data/lib/transbank/sdk/onepay/errors/transbank_error.rb +9 -0
- data/lib/transbank/sdk/onepay/models/channels.rb +15 -0
- data/lib/transbank/sdk/onepay/models/item.rb +103 -0
- data/lib/transbank/sdk/onepay/models/models.rb +10 -0
- data/lib/transbank/sdk/onepay/models/refund.rb +51 -0
- data/lib/transbank/sdk/onepay/models/shopping_cart.rb +65 -0
- data/lib/transbank/sdk/onepay/models/transaction.rb +141 -0
- data/lib/transbank/sdk/onepay/requests/refund_create_request.rb +45 -0
- data/lib/transbank/sdk/onepay/requests/request.rb +18 -0
- data/lib/transbank/sdk/onepay/requests/requests.rb +9 -0
- data/lib/transbank/sdk/onepay/requests/transaction_commit_request.rb +48 -0
- data/lib/transbank/sdk/onepay/requests/transaction_create_request.rb +80 -0
- data/lib/transbank/sdk/onepay/responses/refund_create_response.rb +24 -0
- data/lib/transbank/sdk/onepay/responses/response.rb +18 -0
- data/lib/transbank/sdk/onepay/responses/responses.rb +9 -0
- data/lib/transbank/sdk/onepay/responses/transaction_commit_response.rb +39 -0
- data/lib/transbank/sdk/onepay/responses/transaction_create_response.rb +32 -0
- data/lib/transbank/sdk/onepay/utils/json_utils.rb +73 -0
- data/lib/transbank/sdk/onepay/utils/net_helper.rb +38 -0
- data/lib/transbank/sdk/onepay/utils/request_builder.rb +88 -0
- data/lib/transbank/sdk/onepay/utils/signature_utils.rb +49 -0
- data/lib/transbank/sdk/onepay/utils/utils.rb +9 -0
- data/lib/transbank/sdk/version.rb +5 -0
- data/sdk_test.sh +2 -0
- data/transbank-sdk.gemspec +33 -0
- metadata +220 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Onepay
|
3
|
+
module Utils
|
4
|
+
module RequestBuilder
|
5
|
+
# Create a [Transaction] request. Used internally by [Transaction]#create
|
6
|
+
# @param shopping_cart [ShoppingCart] the user's ShoppingCart, with [Item]s
|
7
|
+
# he/she intends to purchase
|
8
|
+
# @param channel [String] The channel the operation is made on. Valid values
|
9
|
+
# are on the [Channel] class
|
10
|
+
# @param external_unique_number [String, nil] a unique value (per Merchant, not global) that is used to identify a Transaction
|
11
|
+
# @param options [Hash, nil] a hash with config overrides
|
12
|
+
def create_transaction(shopping_cart:, channel:, external_unique_number: nil, options: nil)
|
13
|
+
channel = Base.default_channel if channel.nil?
|
14
|
+
external_unique_number = time_as_number if external_unique_number.nil?
|
15
|
+
options = complete_options(options)
|
16
|
+
issued_at = Time.now.to_i
|
17
|
+
|
18
|
+
request = TransactionCreateRequest.new(external_unique_number: external_unique_number,
|
19
|
+
total: shopping_cart.total,
|
20
|
+
items_quantity: shopping_cart.items_quantity,
|
21
|
+
issued_at: issued_at,
|
22
|
+
items: shopping_cart.items,
|
23
|
+
callback_url: Base.callback_url,
|
24
|
+
channel: channel,
|
25
|
+
app_scheme: Base.app_scheme)
|
26
|
+
request.set_keys_from_options(options)
|
27
|
+
request.app_key = Base::current_integration_type_app_key
|
28
|
+
request.sign(options.fetch(:shared_secret))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Used internally by [Transaction]#commit
|
32
|
+
# @param occ [String] Merchant purchase order
|
33
|
+
# @param external_unique_number [String] a unique value (per Merchant, not global) that is used to identify a Transaction
|
34
|
+
# @param options [Hash, nil] a hash with config overrides
|
35
|
+
def commit_transaction(occ:, external_unique_number:, options: nil)
|
36
|
+
options = complete_options(options)
|
37
|
+
issued_at = Time.now.to_i
|
38
|
+
request = TransactionCommitRequest.new(occ, external_unique_number, issued_at)
|
39
|
+
request.set_keys_from_options(options)
|
40
|
+
request.app_key = Base::current_integration_type_app_key
|
41
|
+
request.sign(options.fetch(:shared_secret))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Used internally by [Refund]#create
|
45
|
+
# @param refund_amount [Integer] the full amount of the [Transaction] to refund. No partial refunds allowed.
|
46
|
+
# @param occ [String] Merchant purchase order of the order to refund
|
47
|
+
# @param external_unique_number [String] external unique number of the [Transaction] to refund
|
48
|
+
# @param authorization_code [String] authorization code for the [Transaction] to refund.
|
49
|
+
# This is given when you successfully #commit a [Transaction]
|
50
|
+
# @param options [Hash, nil] a hash with config overrides
|
51
|
+
def refund_transaction(refund_amount:, occ:, external_unique_number:, authorization_code:, options: nil)
|
52
|
+
options = complete_options(options)
|
53
|
+
issued_at = Time.now.to_i
|
54
|
+
request = RefundCreateRequest.new(nullify_amount: refund_amount,
|
55
|
+
occ: occ,
|
56
|
+
external_unique_number: external_unique_number,
|
57
|
+
authorization_code: authorization_code,
|
58
|
+
issued_at: issued_at)
|
59
|
+
request.set_keys_from_options(options)
|
60
|
+
request.app_key = Base::current_integration_type_app_key
|
61
|
+
request.sign(options.fetch(:shared_secret))
|
62
|
+
end
|
63
|
+
|
64
|
+
def time_as_number
|
65
|
+
# Float#truncate(number_of_digits_to_leave) is from Ruby 2.4 onwards
|
66
|
+
number, decimals = Time.now.to_f.to_s.split('.')
|
67
|
+
(number + decimals[0..2]).to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
# Fill options with default values
|
71
|
+
def complete_options(options = {})
|
72
|
+
options = {} if options.nil?
|
73
|
+
default_options.merge(options)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Return the default options values:
|
77
|
+
# api_key: Base::api_key
|
78
|
+
# app_key: Base::current_integration_type_app_key
|
79
|
+
# shared_secret: Base::shared_secret
|
80
|
+
# @return [Hash] a hash with the aforementioned keys/values
|
81
|
+
def default_options
|
82
|
+
{ api_key: Base::api_key,
|
83
|
+
shared_secret: Base::shared_secret }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Onepay
|
3
|
+
module Utils
|
4
|
+
# Utils for creating signatures, included on classes that need to be signed
|
5
|
+
module SignatureUtils
|
6
|
+
# Transform the instance of the class that calls this method into a
|
7
|
+
# string in the format required for the signature, using the params defined
|
8
|
+
# in the class' SIGNATURE_PARAMS array constant
|
9
|
+
# @raise [RuntimeError] if self.class::SIGNATURE_PARAMS is nil or empty
|
10
|
+
def to_data
|
11
|
+
if self.class::SIGNATURE_PARAMS.nil? || self.class::SIGNATURE_PARAMS.empty?
|
12
|
+
raise RuntimeError, 'SIGNATURE_PARAMS is empty or nil!'
|
13
|
+
end
|
14
|
+
self.class::SIGNATURE_PARAMS.reduce('') do |data_string, current_value|
|
15
|
+
value_of_getter = send(current_value)
|
16
|
+
# Integer#digits is ruby 2.4 upwards :(
|
17
|
+
data_string + value_of_getter.to_s.length.to_s + value_of_getter.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Digest data and secret, creating a hashed string
|
22
|
+
# @param data [String] a string created from the signable, created using #to_data
|
23
|
+
# @param secret [String] the string to hash the data with.
|
24
|
+
# @return [String] the result of the hashing of data with secret.
|
25
|
+
def hmac_sha256(data, secret)
|
26
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, data)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return the base64 of the hmac_sha256'd data & secret
|
30
|
+
# @param data [String] a string created from the signable, created using #to_data
|
31
|
+
# @param secret [String] the string to hash the data with.
|
32
|
+
# @return [String] Base64 representation of the hmac_sha256 hashing of data & secret
|
33
|
+
def signature_for(data, secret)
|
34
|
+
Base64.encode64(hmac_sha256(data, secret)).strip
|
35
|
+
end
|
36
|
+
|
37
|
+
# Compare the @signature of self with the one recreated from self using
|
38
|
+
# the secret param. Return true if equal
|
39
|
+
# @param secret [String] the secret used to create the signature with.
|
40
|
+
# @return [boolean] return true if signatures match, false otherwise
|
41
|
+
def valid_signature?(secret)
|
42
|
+
# We should be able to recreate the same signature from the signable's data
|
43
|
+
# and the secret
|
44
|
+
self.signature == signature_for(self.to_data, secret)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/sdk_test.sh
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "transbank/sdk/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "transbank-sdk"
|
8
|
+
spec.version = Transbank::Sdk::VERSION
|
9
|
+
spec.authors = ["Transbank Developers"]
|
10
|
+
spec.email = ["transbankdevelopers@continuum.cl"]
|
11
|
+
|
12
|
+
spec.summary = %q{Transbank SDK for Ruby}
|
13
|
+
spec.homepage = "https://www.transbankdevelopers.cl/"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency "rubocop", "~> 0.59.2"
|
28
|
+
spec.add_development_dependency "pry", "~> 0.11.3"
|
29
|
+
spec.add_development_dependency 'minitest-reporters', '~> 1.1.9'
|
30
|
+
spec.add_development_dependency 'byebug'
|
31
|
+
spec.add_development_dependency 'pry-byebug'
|
32
|
+
spec.add_development_dependency 'webmock'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transbank-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Transbank Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.59.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.59.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.11.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.11.3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.1.9
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.1.9
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- transbankdevelopers@continuum.cl
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".built"
|
147
|
+
- ".bundled"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CHANGELOG.md
|
151
|
+
- Dockerfile
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.md
|
154
|
+
- Makefile
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- bin/console
|
158
|
+
- bin/setup
|
159
|
+
- docker-compose.yml
|
160
|
+
- lib/transbank/sdk.rb
|
161
|
+
- lib/transbank/sdk/onepay/base.rb
|
162
|
+
- lib/transbank/sdk/onepay/errors/errors.rb
|
163
|
+
- lib/transbank/sdk/onepay/errors/integration_type_error.rb
|
164
|
+
- lib/transbank/sdk/onepay/errors/invalid_options_error.rb
|
165
|
+
- lib/transbank/sdk/onepay/errors/item_error.rb
|
166
|
+
- lib/transbank/sdk/onepay/errors/refund_create_error.rb
|
167
|
+
- lib/transbank/sdk/onepay/errors/response_error.rb
|
168
|
+
- lib/transbank/sdk/onepay/errors/shopping_cart_error.rb
|
169
|
+
- lib/transbank/sdk/onepay/errors/signature_error.rb
|
170
|
+
- lib/transbank/sdk/onepay/errors/transaction_commit_error.rb
|
171
|
+
- lib/transbank/sdk/onepay/errors/transaction_create_error.rb
|
172
|
+
- lib/transbank/sdk/onepay/errors/transbank_error.rb
|
173
|
+
- lib/transbank/sdk/onepay/models/channels.rb
|
174
|
+
- lib/transbank/sdk/onepay/models/item.rb
|
175
|
+
- lib/transbank/sdk/onepay/models/models.rb
|
176
|
+
- lib/transbank/sdk/onepay/models/refund.rb
|
177
|
+
- lib/transbank/sdk/onepay/models/shopping_cart.rb
|
178
|
+
- lib/transbank/sdk/onepay/models/transaction.rb
|
179
|
+
- lib/transbank/sdk/onepay/requests/refund_create_request.rb
|
180
|
+
- lib/transbank/sdk/onepay/requests/request.rb
|
181
|
+
- lib/transbank/sdk/onepay/requests/requests.rb
|
182
|
+
- lib/transbank/sdk/onepay/requests/transaction_commit_request.rb
|
183
|
+
- lib/transbank/sdk/onepay/requests/transaction_create_request.rb
|
184
|
+
- lib/transbank/sdk/onepay/responses/refund_create_response.rb
|
185
|
+
- lib/transbank/sdk/onepay/responses/response.rb
|
186
|
+
- lib/transbank/sdk/onepay/responses/responses.rb
|
187
|
+
- lib/transbank/sdk/onepay/responses/transaction_commit_response.rb
|
188
|
+
- lib/transbank/sdk/onepay/responses/transaction_create_response.rb
|
189
|
+
- lib/transbank/sdk/onepay/utils/json_utils.rb
|
190
|
+
- lib/transbank/sdk/onepay/utils/net_helper.rb
|
191
|
+
- lib/transbank/sdk/onepay/utils/request_builder.rb
|
192
|
+
- lib/transbank/sdk/onepay/utils/signature_utils.rb
|
193
|
+
- lib/transbank/sdk/onepay/utils/utils.rb
|
194
|
+
- lib/transbank/sdk/version.rb
|
195
|
+
- sdk_test.sh
|
196
|
+
- transbank-sdk.gemspec
|
197
|
+
homepage: https://www.transbankdevelopers.cl/
|
198
|
+
licenses: []
|
199
|
+
metadata: {}
|
200
|
+
post_install_message:
|
201
|
+
rdoc_options: []
|
202
|
+
require_paths:
|
203
|
+
- lib
|
204
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
+
requirements:
|
211
|
+
- - ">="
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '0'
|
214
|
+
requirements: []
|
215
|
+
rubyforge_project:
|
216
|
+
rubygems_version: 2.7.7
|
217
|
+
signing_key:
|
218
|
+
specification_version: 4
|
219
|
+
summary: Transbank SDK for Ruby
|
220
|
+
test_files: []
|