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
@@ -0,0 +1,100 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Datatrans::JSON::Transaction::Authorize do
|
4
|
+
before do
|
5
|
+
@successful_response = {
|
6
|
+
"transactionId" => "230223022302230223"
|
7
|
+
}
|
8
|
+
|
9
|
+
@failed_response = {
|
10
|
+
"error" => {
|
11
|
+
"code" => "INVALID_PROPERTY",
|
12
|
+
"message" => "init.refno must not be null"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
@valid_params = {
|
17
|
+
currency: "CHF",
|
18
|
+
refno: "B4B4B4B4B",
|
19
|
+
amount: 1337,
|
20
|
+
payment_methods: ["ECA", "VIS"],
|
21
|
+
success_url: "https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp",
|
22
|
+
cancel_url: "https://pay.sandbox.datatrans.com/upp/merchant/cancelPage.jsp",
|
23
|
+
error_url: "https://pay.sandbox.datatrans.com/upp/merchant/errorPage.jsp"
|
24
|
+
}
|
25
|
+
|
26
|
+
@expected_request_body = {
|
27
|
+
currency: "CHF",
|
28
|
+
refno: "B4B4B4B4B",
|
29
|
+
amount: 1337,
|
30
|
+
autoSettle: true,
|
31
|
+
paymentMethods: ["ECA", "VIS"],
|
32
|
+
redirect: {
|
33
|
+
successUrl: "https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp",
|
34
|
+
cancelUrl: "https://pay.sandbox.datatrans.com/upp/merchant/cancelPage.jsp",
|
35
|
+
errorUrl: "https://pay.sandbox.datatrans.com/upp/merchant/errorPage.jsp"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
@invalid_params = {
|
40
|
+
currency: "CHF",
|
41
|
+
refno: nil,
|
42
|
+
amount: 1337,
|
43
|
+
payment_methods: ["ECA", "VIS"]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
context "successful response" do
|
48
|
+
before do
|
49
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Authorize).to receive(:process).and_return(@successful_response)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "generates correct request_body" do
|
53
|
+
request = Datatrans::JSON::Transaction::Authorize.new(@datatrans, @valid_params)
|
54
|
+
|
55
|
+
expect(request.request_body).to eq(@expected_request_body)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "#process handles a valid datatrans authorize response" do
|
59
|
+
@transaction = Datatrans::JSON::Transaction.new(@datatrans, @valid_params)
|
60
|
+
expect(@transaction.authorize).to be true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with autoSettle specified" do
|
65
|
+
it "uses autoSettle=false in request_body" do
|
66
|
+
params_with_auto_settle = @valid_params.merge(auto_settle: false)
|
67
|
+
request = Datatrans::JSON::Transaction::Authorize.new(@datatrans, params_with_auto_settle)
|
68
|
+
|
69
|
+
expected_request_body_without_auto_settle = @expected_request_body.merge(autoSettle: false)
|
70
|
+
expect(request.request_body).to eq(expected_request_body_without_auto_settle)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with option specified" do
|
75
|
+
it "uses option in request_body" do
|
76
|
+
params_with_option = @valid_params.merge(option: {createAlias: true})
|
77
|
+
request = Datatrans::JSON::Transaction::Authorize.new(@datatrans, params_with_option)
|
78
|
+
|
79
|
+
expected_request_body_with_option = @expected_request_body.merge("option" => {createAlias: true})
|
80
|
+
expect(request.request_body).to eq(expected_request_body_with_option)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "failed response" do
|
85
|
+
before do
|
86
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Authorize).to receive(:process).and_return(@failed_response)
|
87
|
+
@transaction = Datatrans::JSON::Transaction.new(@datatrans, @invalid_params)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "#process handles a failed datatrans authorize response" do
|
91
|
+
expect(@transaction.authorize).to be false
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns error details" do
|
95
|
+
@transaction.authorize
|
96
|
+
expect(@transaction.response.error_code).to eq "INVALID_PROPERTY"
|
97
|
+
expect(@transaction.response.error_message).to eq "init.refno must not be null"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Datatrans::JSON::Transaction::Init do
|
4
|
+
before do
|
5
|
+
@successful_response = {
|
6
|
+
"transactionId" => "230223022302230223"
|
7
|
+
}
|
8
|
+
|
9
|
+
@failed_response = {
|
10
|
+
"error" => {
|
11
|
+
"code" => "INVALID_PROPERTY",
|
12
|
+
"message" => "init.refno must not be null"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
@valid_params = {
|
17
|
+
currency: "CHF",
|
18
|
+
refno: "B4B4B4B4B",
|
19
|
+
amount: 1337,
|
20
|
+
payment_methods: ["ECA", "VIS"],
|
21
|
+
success_url: "https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp",
|
22
|
+
cancel_url: "https://pay.sandbox.datatrans.com/upp/merchant/cancelPage.jsp",
|
23
|
+
error_url: "https://pay.sandbox.datatrans.com/upp/merchant/errorPage.jsp"
|
24
|
+
}
|
25
|
+
|
26
|
+
@expected_request_body = {
|
27
|
+
currency: "CHF",
|
28
|
+
refno: "B4B4B4B4B",
|
29
|
+
amount: 1337,
|
30
|
+
autoSettle: true,
|
31
|
+
paymentMethods: ["ECA", "VIS"],
|
32
|
+
redirect: {
|
33
|
+
successUrl: "https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp",
|
34
|
+
cancelUrl: "https://pay.sandbox.datatrans.com/upp/merchant/cancelPage.jsp",
|
35
|
+
errorUrl: "https://pay.sandbox.datatrans.com/upp/merchant/errorPage.jsp"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
@invalid_params = {
|
40
|
+
currency: "CHF",
|
41
|
+
refno: nil,
|
42
|
+
amount: 1337,
|
43
|
+
payment_methods: ["ECA", "VIS"]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
context "successful response" do
|
48
|
+
before do
|
49
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Init).to receive(:process).and_return(@successful_response)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "generates correct request_body" do
|
53
|
+
request = Datatrans::JSON::Transaction::Init.new(@datatrans, @valid_params)
|
54
|
+
|
55
|
+
expect(request.request_body).to eq(@expected_request_body)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "#process handles a valid datatrans authorize response" do
|
59
|
+
@transaction = Datatrans::JSON::Transaction.new(@datatrans, @valid_params)
|
60
|
+
expect(@transaction.init).to be true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with autoSettle specified" do
|
65
|
+
it "uses autoSettle=false in request_body" do
|
66
|
+
params_with_auto_settle = @valid_params.merge(auto_settle: false)
|
67
|
+
request = Datatrans::JSON::Transaction::Init.new(@datatrans, params_with_auto_settle)
|
68
|
+
|
69
|
+
expected_request_body_without_auto_settle = @expected_request_body.merge(autoSettle: false)
|
70
|
+
expect(request.request_body).to eq(expected_request_body_without_auto_settle)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with option specified" do
|
75
|
+
it "uses option in request_body" do
|
76
|
+
params_with_option = @valid_params.merge(option: {createAlias: true})
|
77
|
+
request = Datatrans::JSON::Transaction::Init.new(@datatrans, params_with_option)
|
78
|
+
|
79
|
+
expected_request_body_with_option = @expected_request_body.merge("option" => {createAlias: true})
|
80
|
+
expect(request.request_body).to eq(expected_request_body_with_option)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "failed response" do
|
85
|
+
before do
|
86
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Init).to receive(:process).and_return(@failed_response)
|
87
|
+
@transaction = Datatrans::JSON::Transaction.new(@datatrans, @invalid_params)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "#process handles a failed datatrans authorize response" do
|
91
|
+
expect(@transaction.init).to be false
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns error details" do
|
95
|
+
@transaction.init
|
96
|
+
expect(@transaction.response.error_code).to eq "INVALID_PROPERTY"
|
97
|
+
expect(@transaction.response.error_message).to eq "init.refno must not be null"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Datatrans::JSON::Transaction::MerchantAuthorize do
|
4
|
+
before do
|
5
|
+
@successful_response = {
|
6
|
+
"transactionId" => "230223022302230223",
|
7
|
+
"acquirerAuthorizationCode" => "123456",
|
8
|
+
"card" => {
|
9
|
+
"masked" => "411111xxxxxx1111"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
@failed_response = {
|
14
|
+
"error" => {
|
15
|
+
"code" => "INVALID_PROPERTY",
|
16
|
+
"message" => "authorize.card.alias or number is mandatory"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
@valid_params = {
|
21
|
+
currency: "CHF",
|
22
|
+
refno: "B4B4B4B4B",
|
23
|
+
amount: 1000,
|
24
|
+
card: {
|
25
|
+
alias: "AAABcH0Bq92s3kgAESIAAbGj5NIsAHWC",
|
26
|
+
expiryMonth: "01",
|
27
|
+
expiryYear: "23"
|
28
|
+
},
|
29
|
+
auto_settle: true
|
30
|
+
}
|
31
|
+
|
32
|
+
@expected_request_body = {
|
33
|
+
currency: "CHF",
|
34
|
+
refno: "B4B4B4B4B",
|
35
|
+
amount: 1000,
|
36
|
+
card: {
|
37
|
+
alias: "AAABcH0Bq92s3kgAESIAAbGj5NIsAHWC",
|
38
|
+
expiryMonth: "01",
|
39
|
+
expiryYear: "23"
|
40
|
+
},
|
41
|
+
autoSettle: true
|
42
|
+
}
|
43
|
+
|
44
|
+
@invalid_params = {
|
45
|
+
currency: "CHF",
|
46
|
+
refno: "B4B4B4B4B",
|
47
|
+
amount: 1000,
|
48
|
+
card: {
|
49
|
+
expiryMonth: "01",
|
50
|
+
expiryYear: "23"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
context "successful response" do
|
56
|
+
before do
|
57
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::MerchantAuthorize).to receive(:process).and_return(@successful_response)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "generates correct request_body" do
|
61
|
+
request = Datatrans::JSON::Transaction::MerchantAuthorize.new(@datatrans, @valid_params)
|
62
|
+
expect(request.request_body).to eq(@expected_request_body)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "#process handles a valid datatrans merchant authorize response" do
|
66
|
+
transaction = Datatrans::JSON::Transaction.new(@datatrans, @valid_params)
|
67
|
+
expect(transaction.merchant_authorize).to be true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with autoSettle specified" do
|
72
|
+
it "handles autoSettle correctly in request_body" do
|
73
|
+
params_with_auto_settle = @valid_params.merge(auto_settle: false)
|
74
|
+
request = Datatrans::JSON::Transaction::MerchantAuthorize.new(@datatrans, params_with_auto_settle)
|
75
|
+
|
76
|
+
expected_request_body_without_auto_settle = @expected_request_body.merge(autoSettle: false)
|
77
|
+
expect(request.request_body).to eq(expected_request_body_without_auto_settle)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "failed response" do
|
82
|
+
before do
|
83
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::MerchantAuthorize).to receive(:process).and_return(@failed_response)
|
84
|
+
@transaction = Datatrans::JSON::Transaction.new(@datatrans, @invalid_params)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "#process handles a failed datatrans merchant authorize response" do
|
88
|
+
expect(@transaction.merchant_authorize).to be false
|
89
|
+
end
|
90
|
+
|
91
|
+
it "returns error details" do
|
92
|
+
@transaction.merchant_authorize
|
93
|
+
expect(@transaction.response.error_code).to eq "INVALID_PROPERTY"
|
94
|
+
expect(@transaction.response.error_message).to eq "authorize.card.alias or number is mandatory"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Datatrans::JSON::Transaction::Settle do
|
4
|
+
before do
|
5
|
+
@valid_params_authorize = {
|
6
|
+
currency: "CHF",
|
7
|
+
refno: "B4B4B4B4B",
|
8
|
+
amount: 1337,
|
9
|
+
payment_methods: ["ECA", "VIS"],
|
10
|
+
success_url: "https://pay.sandbox.datatrans.com/upp/merchant/successPage.jsp",
|
11
|
+
cancel_url: "https://pay.sandbox.datatrans.com/upp/merchant/cancelPage.jsp",
|
12
|
+
error_url: "https://pay.sandbox.datatrans.com/upp/merchant/errorPage.jsp"
|
13
|
+
}
|
14
|
+
|
15
|
+
@valid_params_settle = {
|
16
|
+
transaction_id: "230223022302230223",
|
17
|
+
amount: 1337,
|
18
|
+
currency: "CHF",
|
19
|
+
refno: "B4B4B4B4B"
|
20
|
+
}
|
21
|
+
|
22
|
+
@successful_response_settle = {} # Empty hash as 204 No Content is expected for successful settlement
|
23
|
+
|
24
|
+
@failed_response_settle = {
|
25
|
+
"error" => {
|
26
|
+
"code" => "INVALID_REQUEST",
|
27
|
+
"message" => "Invalid transaction ID or parameters"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
context "successful response" do
|
33
|
+
before do
|
34
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Settle).to receive(:process).and_return(@successful_response_settle)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "handles a successful settle request" do
|
38
|
+
transaction = Datatrans::JSON::Transaction.new(@datatrans, @valid_params_settle)
|
39
|
+
expect(transaction.settle).to be true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "failed response" do
|
44
|
+
before do
|
45
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Settle).to receive(:process).and_return(@failed_response_settle)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "handles a failed settle request" do
|
49
|
+
transaction = Datatrans::JSON::Transaction.new(@datatrans, @valid_params_settle)
|
50
|
+
expect(transaction.settle).to be false
|
51
|
+
expect(transaction.response.error_code).to eq "INVALID_REQUEST"
|
52
|
+
expect(transaction.response.error_message).to eq "Invalid transaction ID or parameters"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Datatrans::JSON::Transaction::Status do
|
4
|
+
before do
|
5
|
+
@successful_response = {
|
6
|
+
"transactionId" => "230223022302230223",
|
7
|
+
"merchantId" => "1100000000",
|
8
|
+
"type" => "payment",
|
9
|
+
"status" => "settled",
|
10
|
+
"currency" => "CHF",
|
11
|
+
"refno" => "B4B4B4B4B",
|
12
|
+
"paymentMethod" => "VIS",
|
13
|
+
"detail" => {
|
14
|
+
"authorize" => {}
|
15
|
+
},
|
16
|
+
"card" => {
|
17
|
+
"masked" => "424242xxxxxx4242",
|
18
|
+
"expiryMonth" => "06",
|
19
|
+
"expiryYear" => "25",
|
20
|
+
"info" => {}
|
21
|
+
},
|
22
|
+
"history" => [
|
23
|
+
{
|
24
|
+
"action" => "authorize",
|
25
|
+
"amount" => 1000,
|
26
|
+
"source" => "api",
|
27
|
+
"date" => "2023-02-08T14:25:24Z",
|
28
|
+
"success" => true,
|
29
|
+
"ip" => "8.8.8.8"
|
30
|
+
}
|
31
|
+
]
|
32
|
+
}
|
33
|
+
|
34
|
+
@failed_response = {
|
35
|
+
"error" => {
|
36
|
+
"code" => "INVALID_PROPERTY",
|
37
|
+
"message" => "status transactionId length must be 18 digits"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
@valid_params = {
|
42
|
+
transaction_id: "230223022302230223"
|
43
|
+
}
|
44
|
+
|
45
|
+
@invalid_params = {
|
46
|
+
transaction_id: "0208020802080208" # wrong number of digits in ID
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
context "successful response" do
|
51
|
+
before do
|
52
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Status).to receive(:process).and_return(@successful_response)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "#process handles a valid datatrans status response" do
|
56
|
+
transaction = Datatrans::JSON::Transaction.new(@datatrans, @valid_params)
|
57
|
+
expect(transaction.status).to be true
|
58
|
+
expect(transaction.response.params["refno"]).to eq "B4B4B4B4B"
|
59
|
+
expect(transaction.response.params["paymentMethod"]).to eq "VIS"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "failed response" do
|
64
|
+
before do
|
65
|
+
allow_any_instance_of(Datatrans::JSON::Transaction::Status).to receive(:process).and_return(@failed_response)
|
66
|
+
@transaction = Datatrans::JSON::Transaction.new(@datatrans, @invalid_params)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "handles a failed datatrans status response" do
|
70
|
+
expect(@transaction.status).to be false
|
71
|
+
expect(@transaction.response.error_code).to eq "INVALID_PROPERTY"
|
72
|
+
expect(@transaction.response.error_message).to eq "status transactionId length must be 18 digits"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Datatrans::JSON::Transaction do
|
4
|
+
it "returns correct trasaction_path" do
|
5
|
+
params = {transaction_id: "230223022302230223"}
|
6
|
+
transaction = Datatrans::JSON::Transaction.new(@datatrans, params)
|
7
|
+
|
8
|
+
expect(transaction.transaction_path).to eq "https://pay.sandbox.datatrans.com/v1/start/230223022302230223"
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "simplecov"
|
4
4
|
SimpleCov.start
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require "active_support"
|
7
|
+
require "datatrans"
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
|
-
config.filter_run :
|
11
|
-
config.filter_run_excluding :
|
10
|
+
config.filter_run focus: true
|
11
|
+
config.filter_run_excluding skip: true
|
12
12
|
config.run_all_when_everything_filtered = true
|
13
13
|
|
14
14
|
config.before(:each) do
|
15
15
|
@datatrans = Datatrans::Config.new(
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
16
|
+
merchant_id: "1100000000",
|
17
|
+
sign_key: "d777c17ba2010282c2d2350a68b441ca07a799d294bfaa630b7c8442207c0b69703cc55775b0ca5a4e455b818a9bb10a43669c0c20ce31f4a43f10e0cabb9525",
|
18
|
+
password: "basic_auth_password",
|
19
|
+
environment: :development
|
20
20
|
)
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require "action_controller"
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Datatrans::Web::Transaction do
|
5
|
+
before do
|
6
|
+
@successful_response = {
|
7
|
+
status: "success",
|
8
|
+
returnCustomerCountry: "CHE",
|
9
|
+
sign: "95f3111123e628eab6469c636e0d3f06",
|
10
|
+
aliasCC: "70323122544311173",
|
11
|
+
maskedCC: "520000xxxxxx0007",
|
12
|
+
responseMessage: "Authorized",
|
13
|
+
useAlias: "yes",
|
14
|
+
expm: "12",
|
15
|
+
responseCode: "01",
|
16
|
+
sign2: "a9571428be4d9d37b88988656984bfbf",
|
17
|
+
testOnly: "yes",
|
18
|
+
currency: "CHF",
|
19
|
+
amount: "1000",
|
20
|
+
hiddenMode: "yes",
|
21
|
+
expy: "15",
|
22
|
+
merchantId: "1100000000",
|
23
|
+
authorizationCode: "521029462",
|
24
|
+
uppTransactionId: "110808173520119430",
|
25
|
+
refno: "1",
|
26
|
+
uppMsgType: "web",
|
27
|
+
uppCustomerName: "",
|
28
|
+
pmethod: "ECA",
|
29
|
+
reqtype: "NOA",
|
30
|
+
uppCustomerEmail: "customer@email.com",
|
31
|
+
acqAuthorizationCode: "173520"
|
32
|
+
}
|
33
|
+
|
34
|
+
@successful_swisspost_response = @successful_response.merge({
|
35
|
+
pmethod: "PFC",
|
36
|
+
txtEp2TrxID: "7777777000000001",
|
37
|
+
responseMessage: "YellowPay transaction Ok"
|
38
|
+
})
|
39
|
+
|
40
|
+
@failed_response = {
|
41
|
+
status: "error",
|
42
|
+
returnCustomerCountry: "CHE",
|
43
|
+
sign: "95f3123246e628eab6469c636e0d3f06",
|
44
|
+
aliasCC: "70323122544311173",
|
45
|
+
maskedCC: "520000xxxxxx0007",
|
46
|
+
errorMessage: "declined",
|
47
|
+
useAlias: "yes",
|
48
|
+
expm: "12",
|
49
|
+
errorCode: "1403",
|
50
|
+
testOnly: "yes",
|
51
|
+
currency: "CHF",
|
52
|
+
amount: "1000",
|
53
|
+
hiddenMode: "yes",
|
54
|
+
expy: "14",
|
55
|
+
merchantId: "1100000000",
|
56
|
+
errorDetail: "Declined",
|
57
|
+
uppTransactionId: "110808173951050102",
|
58
|
+
refno: "1",
|
59
|
+
uppMsgType: "web",
|
60
|
+
uppCustomerName: "",
|
61
|
+
pmethod: "ECA",
|
62
|
+
reqtype: "NOA",
|
63
|
+
uppCustomerEmail: "customer@email.com"
|
64
|
+
}
|
65
|
+
|
66
|
+
@valid_params = {
|
67
|
+
refno: "ABCDEF",
|
68
|
+
amount: 1000,
|
69
|
+
currency: "CHF",
|
70
|
+
uppCustomerEmail: "customer@email.com"
|
71
|
+
# also params from view helper needed
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
context "rails form helper" do
|
76
|
+
before do
|
77
|
+
@transaction = Datatrans::Web::Transaction.new(@datatrans, @valid_params)
|
78
|
+
|
79
|
+
@view = if Gem.loaded_specs["activesupport"].version >= Gem::Version.create("6.0")
|
80
|
+
ActionView::Base.new(ActionController::Base.view_paths, {}, {})
|
81
|
+
else
|
82
|
+
ActionView::Base.new
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should generate valid form field string" do
|
87
|
+
expected_output = if Gem.loaded_specs["activesupport"].version >= Gem::Version.create("6.1")
|
88
|
+
'<input type="hidden" name="merchantId" id="merchantId" value="1100000000" autocomplete="off" /><input type="hidden" name="hiddenMode" id="hiddenMode" value="yes" autocomplete="off" /><input type="hidden" name="reqtype" id="reqtype" value="NOA" autocomplete="off" /><input type="hidden" name="amount" id="amount" value="1000" autocomplete="off" /><input type="hidden" name="currency" id="currency" value="CHF" autocomplete="off" /><input type="hidden" name="useAlias" id="useAlias" value="yes" autocomplete="off" /><input type="hidden" name="sign" id="sign" value="0402fb3fba8c6fcb40df9b7756e7e637" autocomplete="off" /><input type="hidden" name="refno" id="refno" value="ABCDEF" autocomplete="off" /><input type="hidden" name="uppCustomerDetails" id="uppCustomerDetails" autocomplete="off" /><input type="hidden" name="uppCustomerEmail" id="uppCustomerEmail" value="customer@email.com" autocomplete="off" />'
|
89
|
+
else
|
90
|
+
'<input type="hidden" name="merchantId" id="merchantId" value="1100000000" /><input type="hidden" name="hiddenMode" id="hiddenMode" value="yes" /><input type="hidden" name="reqtype" id="reqtype" value="NOA" /><input type="hidden" name="amount" id="amount" value="1000" /><input type="hidden" name="currency" id="currency" value="CHF" /><input type="hidden" name="useAlias" id="useAlias" value="yes" /><input type="hidden" name="sign" id="sign" value="0402fb3fba8c6fcb40df9b7756e7e637" /><input type="hidden" name="refno" id="refno" value="ABCDEF" /><input type="hidden" name="uppCustomerDetails" id="uppCustomerDetails" /><input type="hidden" name="uppCustomerEmail" id="uppCustomerEmail" value="customer@email.com" />'
|
91
|
+
end
|
92
|
+
|
93
|
+
expect(@view.datatrans_notification_request_hidden_fields(@datatrans, @transaction)).to eq expected_output
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "successful response" do
|
98
|
+
before do
|
99
|
+
allow_any_instance_of(Datatrans::Web::Transaction::AuthorizeResponse).to receive(:params).and_return(@successful_response)
|
100
|
+
end
|
101
|
+
|
102
|
+
context "process" do
|
103
|
+
it "handles a valid datatrans authorize response" do
|
104
|
+
@transaction = Datatrans::Web::Transaction.new(@datatrans, @valid_params)
|
105
|
+
expect(@transaction.authorize).to be true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "successful response (swiss post)" do
|
111
|
+
before do
|
112
|
+
allow_any_instance_of(Datatrans::Web::Transaction::AuthorizeResponse).to receive(:params).and_return(@successful_swisspost_response)
|
113
|
+
end
|
114
|
+
|
115
|
+
context "process" do
|
116
|
+
it "handles a valid datatrans authorize response" do
|
117
|
+
@transaction = Datatrans::Web::Transaction.new(@datatrans, @valid_params)
|
118
|
+
expect(@transaction.authorize).to be true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "compromised response" do
|
124
|
+
before do
|
125
|
+
fake_response = @successful_response
|
126
|
+
fake_response[:sign2] = "invalid"
|
127
|
+
allow_any_instance_of(Datatrans::Web::Transaction::AuthorizeResponse).to receive(:params).and_return(fake_response)
|
128
|
+
@transaction = Datatrans::Web::Transaction.new(@datatrans, @valid_params)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "raises an exception if sign2 is invalid" do
|
132
|
+
expect {
|
133
|
+
@transaction.authorize
|
134
|
+
}.to raise_error(Datatrans::InvalidSignatureError)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "failed response" do
|
139
|
+
before do
|
140
|
+
allow_any_instance_of(Datatrans::Web::Transaction::AuthorizeResponse).to receive(:params).and_return(@failed_response)
|
141
|
+
@transaction = Datatrans::Web::Transaction.new(@datatrans, @valid_params)
|
142
|
+
end
|
143
|
+
|
144
|
+
context "process" do
|
145
|
+
it "handles a failed datatrans authorize response" do
|
146
|
+
expect(@transaction.authorize).to be false
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns error details" do
|
150
|
+
@transaction.authorize
|
151
|
+
expect(@transaction.error_code.length).to be > 0
|
152
|
+
expect(@transaction.error_message.length).to be > 0
|
153
|
+
expect(@transaction.error_detail.length).to be > 0
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/spec/xml/capture_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Datatrans::XML::Transaction::CaptureRequest do
|
4
4
|
before do
|
@@ -54,10 +54,10 @@ describe Datatrans::XML::Transaction::CaptureRequest do
|
|
54
54
|
}
|
55
55
|
|
56
56
|
@valid_params = {
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
57
|
+
refno: "ABCDEF",
|
58
|
+
amount: 1000,
|
59
|
+
currency: "CHF",
|
60
|
+
transaction_id: "110808142256858007"
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Datatrans::XML::Transaction::AuthorizeRequest do
|
4
4
|
before do
|
@@ -63,12 +63,12 @@ describe Datatrans::XML::Transaction::AuthorizeRequest do
|
|
63
63
|
}
|
64
64
|
|
65
65
|
@valid_params = {
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
66
|
+
refno: "ABCDEF",
|
67
|
+
amount: 1000,
|
68
|
+
currency: "CHF",
|
69
|
+
aliasCC: "3784982984234",
|
70
|
+
expm: 12,
|
71
|
+
expy: 15
|
72
72
|
}
|
73
73
|
end
|
74
74
|
|