datatrans 5.0.0 → 5.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/.github/workflows/ci.yml +37 -4
- data/.github/workflows/release.yml +1 -1
- data/.gitignore +1 -1
- data/.ruby-version +1 -1
- data/Appraisals +16 -8
- data/CHANGELOG.md +22 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +151 -0
- data/README.markdown +183 -3
- data/Rakefile +2 -2
- data/datatrans.gemspec +20 -22
- data/gemfiles/rails_5_2.gemfile +2 -2
- data/gemfiles/rails_6_0.gemfile +2 -2
- data/gemfiles/rails_6_1.gemfile +2 -2
- data/gemfiles/rails_7_0.gemfile +2 -2
- data/gemfiles/rails_7_1.gemfile +12 -0
- data/lib/datatrans/common.rb +5 -5
- data/lib/datatrans/config.rb +41 -12
- data/lib/datatrans/json/transaction/authorize.rb +10 -0
- data/lib/datatrans/json/transaction/init.rb +61 -0
- data/lib/datatrans/json/transaction/merchant_authorize.rb +45 -0
- data/lib/datatrans/json/transaction/response.rb +26 -0
- data/lib/datatrans/json/transaction/settle.rb +41 -0
- data/lib/datatrans/json/transaction/status.rb +50 -0
- data/lib/datatrans/json/transaction.rb +54 -0
- data/lib/datatrans/version.rb +1 -1
- data/lib/datatrans/web/transaction/authorize.rb +46 -17
- data/lib/datatrans/web/transaction.rb +10 -4
- data/lib/datatrans/web/view_helper.rb +3 -1
- data/lib/datatrans/xml/transaction/authorize.rb +39 -19
- data/lib/datatrans/xml/transaction/capture.rb +29 -15
- data/lib/datatrans/xml/transaction/request.rb +10 -9
- data/lib/datatrans/xml/transaction/response.rb +4 -2
- data/lib/datatrans/xml/transaction/status.rb +41 -25
- data/lib/datatrans/xml/transaction/void.rb +30 -16
- data/lib/datatrans/xml/transaction.rb +18 -14
- data/lib/datatrans.rb +9 -8
- data/renovate.json +14 -0
- data/spec/common_spec.rb +6 -6
- data/spec/config_spec.rb +8 -2
- data/spec/json/authorize_spec.rb +100 -0
- data/spec/json/init_spec.rb +100 -0
- data/spec/json/merchant_authorize_spec.rb +97 -0
- data/spec/json/settle_spec.rb +55 -0
- data/spec/json/status_spec.rb +75 -0
- data/spec/json/transaction_spec.rb +10 -0
- data/spec/spec_helper.rb +11 -11
- data/spec/web/init_spec.rb +157 -0
- data/spec/xml/capture_spec.rb +5 -5
- data/spec/xml/{authorize_spec.rb → init_spec.rb} +7 -7
- data/spec/xml/request_spec.rb +21 -22
- data/spec/xml/status_spec.rb +4 -4
- data/spec/xml/void_spec.rb +5 -5
- metadata +20 -4
- data/spec/web/authorize_spec.rb +0 -157
data/gemfiles/rails_5_2.gemfile
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
5
|
gem "simplecov", group: :test, require: nil
|
6
|
-
gem "activesupport", "~> 5.2"
|
6
|
+
gem "activesupport", "~> 5.2.0"
|
7
7
|
|
8
8
|
group :development, :test do
|
9
|
-
gem "actionpack", "~> 5.2"
|
9
|
+
gem "actionpack", "~> 5.2.0"
|
10
10
|
end
|
11
11
|
|
12
12
|
gemspec path: "../"
|
data/gemfiles/rails_6_0.gemfile
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
5
|
gem "simplecov", group: :test, require: nil
|
6
|
-
gem "activesupport", "~> 6.0"
|
6
|
+
gem "activesupport", "~> 6.0.0"
|
7
7
|
|
8
8
|
group :development, :test do
|
9
|
-
gem "actionpack", "~> 6.0"
|
9
|
+
gem "actionpack", "~> 6.0.0"
|
10
10
|
end
|
11
11
|
|
12
12
|
gemspec path: "../"
|
data/gemfiles/rails_6_1.gemfile
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
5
|
gem "simplecov", group: :test, require: nil
|
6
|
-
gem "activesupport", "~> 6.1"
|
6
|
+
gem "activesupport", "~> 6.1.0"
|
7
7
|
|
8
8
|
group :development, :test do
|
9
|
-
gem "actionpack", "~> 6.1"
|
9
|
+
gem "actionpack", "~> 6.1.0"
|
10
10
|
end
|
11
11
|
|
12
12
|
gemspec path: "../"
|
data/gemfiles/rails_7_0.gemfile
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
5
|
gem "simplecov", group: :test, require: nil
|
6
|
-
gem "activesupport", "~> 7.0"
|
6
|
+
gem "activesupport", "~> 7.0.0"
|
7
7
|
|
8
8
|
group :development, :test do
|
9
|
-
gem "actionpack", "~> 7.0"
|
9
|
+
gem "actionpack", "~> 7.0.0"
|
10
10
|
end
|
11
11
|
|
12
12
|
gemspec path: "../"
|
data/lib/datatrans/common.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "openssl"
|
2
2
|
|
3
3
|
module Datatrans::Common
|
4
4
|
def sign(*fields)
|
5
|
-
return nil unless
|
6
|
-
key =
|
5
|
+
return nil unless datatrans.sign_key
|
6
|
+
key = datatrans.sign_key.split(/([a-f0-9][a-f0-9])/).reject(&:empty?)
|
7
7
|
key = key.pack("H*" * key.size)
|
8
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest
|
8
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("MD5"), key, fields.join)
|
9
9
|
end
|
10
|
-
end
|
10
|
+
end
|
data/lib/datatrans/config.rb
CHANGED
@@ -6,10 +6,10 @@ module Datatrans
|
|
6
6
|
DEFAULT_SIGN_KEY = false
|
7
7
|
|
8
8
|
SUBDOMAINS = {
|
9
|
-
payment_page:
|
10
|
-
server_to_server_api:
|
9
|
+
payment_page: "pay",
|
10
|
+
server_to_server_api: "api"
|
11
11
|
}
|
12
|
-
DOMAIN =
|
12
|
+
DOMAIN = "datatrans.com"
|
13
13
|
|
14
14
|
attr_reader :environment, :merchant_id, :sign_key, :password, :proxy
|
15
15
|
|
@@ -21,10 +21,10 @@ module Datatrans
|
|
21
21
|
# * :proxy (a hash containing :http_proxyaddr, :http_proxyport, :http_proxyuser, :http_proxypass)
|
22
22
|
def initialize(options = {})
|
23
23
|
@merchant_id = options[:merchant_id]
|
24
|
-
raise ArgumentError.new(":merchant_id is required") unless
|
24
|
+
raise ArgumentError.new(":merchant_id is required") unless merchant_id
|
25
25
|
self.environment = options[:environment] || DEFAULT_ENVIRONMENT
|
26
26
|
@password = options[:password]
|
27
|
-
raise ArgumentError.new(":password is required") unless
|
27
|
+
raise ArgumentError.new(":password is required") unless password
|
28
28
|
@sign_key = options[:sign_key] || DEFAULT_SIGN_KEY
|
29
29
|
@proxy = options[:proxy] || {}
|
30
30
|
end
|
@@ -34,29 +34,54 @@ module Datatrans
|
|
34
34
|
if ENVIRONMENTS.include?(environment)
|
35
35
|
@environment = environment
|
36
36
|
else
|
37
|
-
raise "Unknown environment '#{environment}'. Available: #{ENVIRONMENTS.join(
|
37
|
+
raise "Unknown environment '#{environment}'. Available: #{ENVIRONMENTS.join(", ")}"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
# Access a url, is automatically scoped to environment
|
42
|
-
def url(what)
|
42
|
+
def url(what, options = {})
|
43
43
|
case what
|
44
44
|
when :web_authorize_url
|
45
|
+
warn "DEPRECATION WARNING: Support for the payment page is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
46
|
+
|
45
47
|
subdomain = SUBDOMAINS[:payment_page]
|
46
|
-
path =
|
48
|
+
path = "/upp/jsp/upStart.jsp"
|
47
49
|
when :xml_authorize_url
|
50
|
+
warn "DEPRECATION WARNING: Support for the XML API is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
51
|
+
|
48
52
|
subdomain = SUBDOMAINS[:server_to_server_api]
|
49
|
-
path =
|
53
|
+
path = "/upp/jsp/XML_authorize.jsp"
|
50
54
|
when :xml_settlement_url
|
55
|
+
warn "DEPRECATION WARNING: Support for the XML API is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
56
|
+
|
51
57
|
subdomain = SUBDOMAINS[:server_to_server_api]
|
52
|
-
path =
|
58
|
+
path = "/upp/jsp/XML_processor.jsp"
|
53
59
|
when :xml_status_url
|
60
|
+
warn "DEPRECATION WARNING: Support for the XML API is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
61
|
+
|
62
|
+
subdomain = SUBDOMAINS[:server_to_server_api]
|
63
|
+
path = "/upp/jsp/XML_status.jsp"
|
64
|
+
when :init_transaction
|
65
|
+
subdomain = SUBDOMAINS[:server_to_server_api]
|
66
|
+
path = "/v1/transactions"
|
67
|
+
when :authorize_transaction
|
54
68
|
subdomain = SUBDOMAINS[:server_to_server_api]
|
55
|
-
path =
|
69
|
+
path = "/v1/transactions/authorize"
|
70
|
+
when :start_json_transaction
|
71
|
+
subdomain = SUBDOMAINS[:payment_page]
|
72
|
+
path = "/v1/start/#{options[:transaction_id]}"
|
73
|
+
when :json_status_url
|
74
|
+
# https://api.sandbox.datatrans.com/v1/transactions/{transactionId}
|
75
|
+
subdomain = SUBDOMAINS[:server_to_server_api]
|
76
|
+
path = "/v1/transactions/#{options[:transaction_id]}"
|
77
|
+
when :json_settle_url
|
78
|
+
# https://api.sandbox.datatrans.com/v1/transactions/{transactionId}/settle
|
79
|
+
subdomain = SUBDOMAINS[:server_to_server_api]
|
80
|
+
path = "/v1/transactions/#{options[:transaction_id]}/settle"
|
56
81
|
else
|
57
82
|
raise "Unknown wanted action '#{what}'."
|
58
83
|
end
|
59
|
-
subdomain +=
|
84
|
+
subdomain += ".sandbox" unless environment == :production
|
60
85
|
"https://#{subdomain}.#{DOMAIN}#{path}"
|
61
86
|
end
|
62
87
|
|
@@ -67,5 +92,9 @@ module Datatrans
|
|
67
92
|
def xml_transaction(*args)
|
68
93
|
XML::Transaction.new(self, *args)
|
69
94
|
end
|
95
|
+
|
96
|
+
def json_transaction(*args)
|
97
|
+
JSON::Transaction.new(self, *args)
|
98
|
+
end
|
70
99
|
end
|
71
100
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "init"
|
2
|
+
|
3
|
+
class Datatrans::JSON::Transaction
|
4
|
+
class Authorize < Init
|
5
|
+
def initialize(datatrans, params)
|
6
|
+
warn "[DEPRECATION] `Datatrans::JSON::Transaction::Authorize` is deprecated. Please use `Datatrans::JSON::Transaction::Init` instead."
|
7
|
+
super(datatrans, params)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "datatrans/json/transaction/response"
|
3
|
+
|
4
|
+
class Datatrans::JSON::Transaction
|
5
|
+
class Init
|
6
|
+
# class to initialize a new transaction https://api-reference.datatrans.ch/#tag/v1transactions/operation/init
|
7
|
+
attr_accessor :params, :datatrans
|
8
|
+
|
9
|
+
def initialize(datatrans, params)
|
10
|
+
@datatrans = datatrans
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(url, options = {})
|
15
|
+
options = options
|
16
|
+
.merge(datatrans.proxy)
|
17
|
+
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
|
18
|
+
HTTParty.post(url, **options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def process
|
22
|
+
post(datatrans.url(:init_transaction),
|
23
|
+
headers: {"Content-Type" => "application/json"},
|
24
|
+
body: request_body.to_json).parsed_response
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_body
|
28
|
+
auto_settle = params[:auto_settle].nil? ? true : params[:auto_settle]
|
29
|
+
|
30
|
+
body = {
|
31
|
+
currency: params[:currency],
|
32
|
+
refno: params[:refno],
|
33
|
+
amount: params[:amount],
|
34
|
+
autoSettle: auto_settle,
|
35
|
+
paymentMethods: params[:payment_methods],
|
36
|
+
redirect: {
|
37
|
+
successUrl: params[:success_url],
|
38
|
+
cancelUrl: params[:cancel_url],
|
39
|
+
errorUrl: params[:error_url]
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
body["option"] = params[:option] if params[:option].present?
|
44
|
+
|
45
|
+
body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class InitResponse < Response
|
50
|
+
def successful?
|
51
|
+
params["error"].blank? && params["transactionId"].present?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class AuthorizeResponse < InitResponse
|
56
|
+
def initialize(datatrans, params)
|
57
|
+
warn "[DEPRECATION] `Datatrans::JSON::Transaction::AuthorizeResponse` is deprecated. Please use `Datatrans::JSON::Transaction::InitResponse` instead."
|
58
|
+
super(datatrans, params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "datatrans/json/transaction/response"
|
3
|
+
|
4
|
+
class Datatrans::JSON::Transaction
|
5
|
+
class MerchantAuthorize
|
6
|
+
# class to authorize a transaction without user interaction https://api-reference.datatrans.ch/#tag/v1transactions/operation/authorize
|
7
|
+
attr_accessor :params, :datatrans
|
8
|
+
|
9
|
+
def initialize(datatrans, params)
|
10
|
+
@datatrans = datatrans
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(url, options = {})
|
15
|
+
options = options
|
16
|
+
.merge(datatrans.proxy)
|
17
|
+
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
|
18
|
+
HTTParty.post(url, **options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def process
|
22
|
+
post(datatrans.url(:authorize_transaction),
|
23
|
+
headers: {"Content-Type" => "application/json"},
|
24
|
+
body: request_body.to_json).parsed_response
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_body
|
28
|
+
auto_settle = params[:auto_settle].nil? ? true : params[:auto_settle]
|
29
|
+
|
30
|
+
{
|
31
|
+
currency: params[:currency],
|
32
|
+
refno: params[:refno],
|
33
|
+
amount: params[:amount],
|
34
|
+
card: params[:card],
|
35
|
+
autoSettle: auto_settle
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class MerchantAuthorizeResponse < Response
|
41
|
+
def successful?
|
42
|
+
params["error"].blank? && params["transactionId"].present?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Datatrans::JSON::Transaction
|
2
|
+
class Response
|
3
|
+
attr_accessor :params, :datatrans
|
4
|
+
|
5
|
+
def initialize(datatrans, params)
|
6
|
+
@datatrans = datatrans
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def successful?
|
11
|
+
raise "overwrite in subclass!"
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_code
|
15
|
+
params["error"]["code"]
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_message
|
21
|
+
params["error"]["message"]
|
22
|
+
rescue
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "datatrans/json/transaction/response"
|
3
|
+
|
4
|
+
class Datatrans::JSON::Transaction
|
5
|
+
class Settle
|
6
|
+
# Class to settle a transaction https://api-reference.datatrans.ch/#tag/v1transactions/operation/settle
|
7
|
+
attr_accessor :params, :datatrans
|
8
|
+
|
9
|
+
def initialize(datatrans, params)
|
10
|
+
@datatrans = datatrans
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(url, options = {})
|
15
|
+
options = options
|
16
|
+
.merge(datatrans.proxy)
|
17
|
+
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
|
18
|
+
HTTParty.post(url, **options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def process
|
22
|
+
post(datatrans.url(:json_settle_url, transaction_id: params[:transaction_id]),
|
23
|
+
headers: {"Content-Type" => "application/json"},
|
24
|
+
body: request_body.to_json).parsed_response
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_body
|
28
|
+
{
|
29
|
+
currency: params[:currency],
|
30
|
+
amount: params[:amount],
|
31
|
+
refno: params[:refno]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class SettleResponse < Response
|
37
|
+
def successful?
|
38
|
+
params["error"].blank?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "datatrans/json/transaction/response"
|
3
|
+
|
4
|
+
class Datatrans::JSON::Transaction
|
5
|
+
class Status
|
6
|
+
# class to check a transaction status and get a transaction info: https://api-reference.datatrans.ch/#tag/v1transactions/operation/status
|
7
|
+
attr_accessor :params, :datatrans
|
8
|
+
|
9
|
+
def initialize(datatrans, params)
|
10
|
+
@datatrans = datatrans
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(url, options = {})
|
15
|
+
options = options
|
16
|
+
.merge(datatrans.proxy)
|
17
|
+
.merge(basic_auth: {username: datatrans.merchant_id, password: datatrans.password})
|
18
|
+
HTTParty.get(url, **options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def process
|
22
|
+
get(datatrans.url(:json_status_url, transaction_id: params[:transaction_id]),
|
23
|
+
headers: {"Content-Type" => "application/json"}).parsed_response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class StatusResponse < Response
|
28
|
+
def successful?
|
29
|
+
params["error"].blank? && ["settled", "transmitted"].include?(response_code)
|
30
|
+
end
|
31
|
+
|
32
|
+
def response_code
|
33
|
+
params["status"]
|
34
|
+
rescue
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def reference_number
|
39
|
+
params["refno"]
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def amount
|
45
|
+
params["detail"]["settle"]["amount"]
|
46
|
+
rescue
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "active_support/core_ext/hash"
|
2
|
+
|
3
|
+
module Datatrans::JSON
|
4
|
+
class Transaction
|
5
|
+
attr_accessor :request
|
6
|
+
attr_reader :response, :params, :datatrans
|
7
|
+
|
8
|
+
def initialize(datatrans, params)
|
9
|
+
@datatrans = datatrans
|
10
|
+
@params = params
|
11
|
+
end
|
12
|
+
|
13
|
+
def authorize
|
14
|
+
warn "[DEPRECATION] `Datatrans::JSON::Transaction#authorize` is deprecated. Please use `Datatrans::JSON::Transaction#init` instead."
|
15
|
+
|
16
|
+
self.request = Authorize.new(datatrans, params)
|
17
|
+
@response = AuthorizeResponse.new(datatrans, request.process)
|
18
|
+
@response.successful?
|
19
|
+
end
|
20
|
+
|
21
|
+
def init
|
22
|
+
self.request = Init.new(datatrans, params)
|
23
|
+
@response = InitResponse.new(datatrans, request.process)
|
24
|
+
@response.successful?
|
25
|
+
end
|
26
|
+
|
27
|
+
def merchant_authorize
|
28
|
+
self.request = MerchantAuthorize.new(datatrans, params)
|
29
|
+
@response = MerchantAuthorizeResponse.new(datatrans, request.process)
|
30
|
+
@response.successful?
|
31
|
+
end
|
32
|
+
|
33
|
+
def status
|
34
|
+
self.request = Status.new(datatrans, params)
|
35
|
+
@response = StatusResponse.new(datatrans, request.process)
|
36
|
+
@response.successful?
|
37
|
+
end
|
38
|
+
|
39
|
+
def settle
|
40
|
+
self.request = Settle.new(datatrans, params)
|
41
|
+
@response = SettleResponse.new(datatrans, request.process)
|
42
|
+
@response.successful?
|
43
|
+
end
|
44
|
+
|
45
|
+
def transaction_path
|
46
|
+
datatrans.url(:start_json_transaction, transaction_id: params[:transaction_id])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
require "datatrans/json/transaction/authorize"
|
52
|
+
require "datatrans/json/transaction/merchant_authorize"
|
53
|
+
require "datatrans/json/transaction/status"
|
54
|
+
require "datatrans/json/transaction/settle"
|
data/lib/datatrans/version.rb
CHANGED
@@ -3,78 +3,107 @@ class Datatrans::Web::Transaction
|
|
3
3
|
attr_accessor :params, :datatrans
|
4
4
|
|
5
5
|
def initialize(datatrans, params)
|
6
|
+
warn "DEPRECATION WARNING: Support for the payment page is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
7
|
+
|
6
8
|
@datatrans = datatrans
|
7
9
|
@params = params
|
8
10
|
end
|
9
11
|
|
10
12
|
def successful?
|
11
13
|
raise Datatrans::InvalidSignatureError unless valid_signature?
|
12
|
-
response_code ==
|
14
|
+
response_code == "01" && status == "success" && !errors_occurred?
|
13
15
|
end
|
14
16
|
|
15
17
|
def valid_signature?
|
16
18
|
# TODO: does not make sense... true if errors?
|
17
19
|
return true if errors_occurred? # no sign2 sent on error
|
18
|
-
sign(
|
20
|
+
sign(datatrans.merchant_id, params[:amount], params[:currency], params[:uppTransactionId]) == params[:sign2]
|
19
21
|
end
|
20
22
|
|
21
23
|
def status
|
22
|
-
params[:status]
|
24
|
+
params[:status]
|
25
|
+
rescue
|
26
|
+
nil
|
23
27
|
end
|
24
28
|
|
25
29
|
def response_code
|
26
|
-
params[:responseCode]
|
30
|
+
params[:responseCode]
|
31
|
+
rescue
|
32
|
+
nil
|
27
33
|
end
|
28
34
|
|
29
35
|
def response_message
|
30
|
-
params[:responseMessage]
|
36
|
+
params[:responseMessage]
|
37
|
+
rescue
|
38
|
+
nil
|
31
39
|
end
|
32
40
|
|
33
41
|
def transaction_id
|
34
|
-
params[:uppTransactionId]
|
42
|
+
params[:uppTransactionId]
|
43
|
+
rescue
|
44
|
+
nil
|
35
45
|
end
|
36
46
|
|
37
47
|
def reference_number
|
38
|
-
params[:refno]
|
48
|
+
params[:refno]
|
49
|
+
rescue
|
50
|
+
nil
|
39
51
|
end
|
40
52
|
|
41
53
|
def authorization_code
|
42
|
-
params[:authorizationCode]
|
54
|
+
params[:authorizationCode]
|
55
|
+
rescue
|
56
|
+
nil
|
43
57
|
end
|
44
58
|
|
45
59
|
def payment_method
|
46
|
-
params[:pmethod]
|
60
|
+
params[:pmethod]
|
61
|
+
rescue
|
62
|
+
nil
|
47
63
|
end
|
48
64
|
|
49
65
|
def masked_cc
|
50
|
-
params[:maskedCC]
|
66
|
+
params[:maskedCC]
|
67
|
+
rescue
|
68
|
+
nil
|
51
69
|
end
|
52
70
|
|
53
71
|
def exp_year
|
54
|
-
params[:expy]
|
72
|
+
params[:expy]
|
73
|
+
rescue
|
74
|
+
nil
|
55
75
|
end
|
56
76
|
|
57
77
|
def exp_month
|
58
|
-
params[:expm]
|
78
|
+
params[:expm]
|
79
|
+
rescue
|
80
|
+
nil
|
59
81
|
end
|
60
82
|
|
61
83
|
def creditcard_alias
|
62
|
-
params[:aliasCC]
|
84
|
+
params[:aliasCC]
|
85
|
+
rescue
|
86
|
+
nil
|
63
87
|
end
|
64
88
|
|
65
89
|
def error_code
|
66
|
-
params[:errorCode]
|
90
|
+
params[:errorCode]
|
91
|
+
rescue
|
92
|
+
nil
|
67
93
|
end
|
68
94
|
|
69
95
|
def error_message
|
70
|
-
params[:errorMessage]
|
96
|
+
params[:errorMessage]
|
97
|
+
rescue
|
98
|
+
nil
|
71
99
|
end
|
72
100
|
|
73
101
|
def error_detail
|
74
|
-
params[:errorDetail]
|
102
|
+
params[:errorDetail]
|
103
|
+
rescue
|
104
|
+
nil
|
75
105
|
end
|
76
106
|
|
77
|
-
|
78
107
|
private
|
79
108
|
|
80
109
|
def errors_occurred?
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/core_ext/hash"
|
2
2
|
|
3
3
|
module Datatrans::Web
|
4
4
|
class Transaction
|
@@ -8,15 +8,17 @@ module Datatrans::Web
|
|
8
8
|
attr_reader :response, :params, :datatrans
|
9
9
|
|
10
10
|
def initialize(datatrans, params)
|
11
|
+
warn "DEPRECATION WARNING: Support for the payment page is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
12
|
+
|
11
13
|
@datatrans = datatrans
|
12
14
|
params = params.to_hash
|
13
15
|
params.symbolize_keys!
|
14
|
-
params.reverse_merge!(:
|
16
|
+
params.reverse_merge!(reqtype: "NOA", useAlias: "yes", hiddenMode: "yes")
|
15
17
|
@params = params
|
16
18
|
end
|
17
19
|
|
18
20
|
def signature
|
19
|
-
sign(
|
21
|
+
sign(datatrans.merchant_id, params[:amount], params[:currency], params[:refno])
|
20
22
|
end
|
21
23
|
|
22
24
|
def authorize
|
@@ -24,6 +26,10 @@ module Datatrans::Web
|
|
24
26
|
@response.successful?
|
25
27
|
end
|
26
28
|
|
29
|
+
def respond_to_missing?(method, *)
|
30
|
+
response.respond_to?(method.to_sym) || super
|
31
|
+
end
|
32
|
+
|
27
33
|
def method_missing(method, *args, &block)
|
28
34
|
if response.respond_to? method.to_sym
|
29
35
|
response.send(method)
|
@@ -34,4 +40,4 @@ module Datatrans::Web
|
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
|
-
require
|
43
|
+
require "datatrans/web/transaction/authorize"
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Datatrans::Web
|
2
2
|
module ViewHelper
|
3
3
|
def datatrans_notification_request_hidden_fields(datatrans, transaction)
|
4
|
+
warn "DEPRECATION WARNING: Support for the payment page is deprecated and will be removed in the next major version. Please use the JSON API instead."
|
5
|
+
|
4
6
|
fields = [
|
5
7
|
hidden_field_tag(:merchantId, datatrans.merchant_id),
|
6
8
|
hidden_field_tag(:hiddenMode, transaction.params[:hiddenMode]),
|
@@ -10,7 +12,7 @@ module Datatrans::Web
|
|
10
12
|
hidden_field_tag(:useAlias, transaction.params[:useAlias]),
|
11
13
|
hidden_field_tag(:sign, transaction.signature),
|
12
14
|
hidden_field_tag(:refno, transaction.params[:refno]),
|
13
|
-
hidden_field_tag(:uppCustomerDetails, transaction.params[:uppCustomerDetails])
|
15
|
+
hidden_field_tag(:uppCustomerDetails, transaction.params[:uppCustomerDetails])
|
14
16
|
]
|
15
17
|
|
16
18
|
[:uppCustomerName, :uppCustomerEmail].each do |field_name|
|