wirecard_checkout_page 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/.gitignore +1 -0
- data/.travis.yml +2 -1
- data/Gemfile +2 -0
- data/README.md +4 -0
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/lib/wirecard_checkout_page.rb +6 -2
- data/lib/wirecard_checkout_page/errors.rb +2 -0
- data/lib/wirecard_checkout_page/fingerprint.rb +0 -0
- data/lib/wirecard_checkout_page/gateway.rb +26 -12
- data/lib/wirecard_checkout_page/init_request.rb +71 -0
- data/lib/wirecard_checkout_page/init_response.rb +12 -2
- data/lib/wirecard_checkout_page/request.rb +85 -0
- data/lib/wirecard_checkout_page/response_checksum.rb +15 -45
- data/lib/wirecard_checkout_page/toolkit/recur_payment.rb +66 -0
- data/lib/wirecard_checkout_page/toolkit/request.rb +55 -0
- data/lib/wirecard_checkout_page/toolkit/response.rb +50 -0
- data/lib/wirecard_checkout_page/version.rb +1 -1
- data/spec/spec_helper.rb +12 -8
- data/spec/wirecard_checkout_page/gateway_spec.rb +86 -28
- data/spec/wirecard_checkout_page/init_request_spec.rb +62 -0
- data/spec/wirecard_checkout_page/request_spec.rb +88 -0
- data/spec/wirecard_checkout_page/response_checksum_spec.rb +70 -116
- data/spec/wirecard_checkout_page/toolkit/recur_payment_spec.rb +125 -0
- data/spec/wirecard_checkout_page/toolkit/request_spec.rb +79 -0
- data/spec/wirecard_checkout_page/toolkit/response_spec.rb +36 -0
- data/wirecard_checkout_page.gemspec +9 -12
- metadata +40 -45
- data/lib/wirecard_checkout_page/request_checksum.rb +0 -88
- data/lib/wirecard_checkout_page/value_handling.rb +0 -19
- data/lib/wirecard_checkout_page/value_missing.rb +0 -1
- data/spec/wirecard_checkout_page/request_checksum_spec.rb +0 -96
- data/spec/wirecard_checkout_page/response_spec.rb +0 -42
@@ -0,0 +1,55 @@
|
|
1
|
+
# Official Wirecard Checkout Page Docs for Toolkit Requests:
|
2
|
+
# https://integration.wirecard.at/doku.php/wcp:toolkit_light:start?s[]=toolkit
|
3
|
+
module WirecardCheckoutPage
|
4
|
+
module Toolkit
|
5
|
+
class Request < WirecardCheckoutPage::Request
|
6
|
+
|
7
|
+
DEFAULT_URL = 'https://checkout.wirecard.com/page/toolkit.php'
|
8
|
+
|
9
|
+
# Which request parameters are required for all operations?
|
10
|
+
# To start an operation you have to set all required parameters to their corresponding values.
|
11
|
+
# If one or more of these required parameters are missing you will get an error message.
|
12
|
+
|
13
|
+
# Parameter Data type Short description
|
14
|
+
# customerId Alphanumeric with a fixed length of 7. Unique ID of merchant.
|
15
|
+
# shopId Alphanumeric with a variable length of 16. Unique ID of your online shop if several
|
16
|
+
# toolkitPassword Alphanumeric with special characters. Your password for Toolkit light operations.
|
17
|
+
# command Enumeration Operation to be executed.
|
18
|
+
# language Alphabetic with a fixed length of 2. Language for returned texts and error messages,
|
19
|
+
# currently only “en” is supported; we are able
|
20
|
+
# to integrate other languages upon request.
|
21
|
+
# requestFingerprint Alphanumeric with a fixed length of 32. Computed fingerprint of the parameter
|
22
|
+
# values and the secret.
|
23
|
+
# param :customerId, required: true
|
24
|
+
# param :shopId
|
25
|
+
# param :toolkitPassword, required: true
|
26
|
+
# param :command, required: true
|
27
|
+
# param :language, required: true
|
28
|
+
|
29
|
+
|
30
|
+
def initialize(url: nil, params: {})
|
31
|
+
super url: url || DEFAULT_URL, params: params
|
32
|
+
self.language = 'en'
|
33
|
+
end
|
34
|
+
|
35
|
+
def call
|
36
|
+
raise WirecardCheckoutPage::ValueMissing, errors.join(', ') unless valid?
|
37
|
+
WirecardCheckoutPage::Toolkit::Response.from_typhoeus_response Typhoeus.post(url, body: body, headers: headers)
|
38
|
+
end
|
39
|
+
|
40
|
+
# HTTP header parameter Description
|
41
|
+
# Host Domain name of server. Has to be set to the following value: secure.wirecard-cee.com
|
42
|
+
# User-Agent User agent string of client. (Should be set by the HTTP-Client lib)
|
43
|
+
# Content-Length Length of body in bytes. (Should be set by HTTP-Client lib)
|
44
|
+
# Content-Type MIME type of the body. Has to be set to the following value: application/x-www-form-urlencoded
|
45
|
+
# Connection Type of connection. Has to be set to the following value: close
|
46
|
+
def headers
|
47
|
+
{
|
48
|
+
'Host' => 'secure.wirecard-cee.com',
|
49
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
50
|
+
'Connection' => 'close',
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module WirecardCheckoutPage
|
4
|
+
module Toolkit
|
5
|
+
class Response
|
6
|
+
def self.from_typhoeus_response(response)
|
7
|
+
new(response.body, original_response: response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(body, original_response: nil)
|
11
|
+
@body = body
|
12
|
+
@original_response = original_response
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :original_response
|
16
|
+
|
17
|
+
attr_reader :body
|
18
|
+
|
19
|
+
def success?
|
20
|
+
status == '0'
|
21
|
+
end
|
22
|
+
|
23
|
+
def error_code
|
24
|
+
param('errorCode').to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def order_number
|
28
|
+
param('orderNumber').to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
def params
|
32
|
+
{ payment_url: original_response.headers['Location'] }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def status
|
38
|
+
param 'status'
|
39
|
+
end
|
40
|
+
|
41
|
+
def param(key)
|
42
|
+
parsed_body[key].last
|
43
|
+
end
|
44
|
+
|
45
|
+
def parsed_body
|
46
|
+
@parsed_body ||= CGI::parse(body)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
|
1
3
|
if ENV['START_SIMPLECOV'].to_i == 1
|
2
4
|
require 'simplecov'
|
3
5
|
SimpleCov.start do
|
@@ -15,13 +17,15 @@ if ENV.key?('CODECLIMATE_REPO_TOKEN')
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
require 'rspec'
|
19
|
-
require 'byebug'
|
20
|
-
require 'wirecard_checkout_page'
|
21
|
-
|
22
20
|
RSpec.configure do |config|
|
23
|
-
config.before
|
24
|
-
|
25
|
-
|
26
|
-
end
|
21
|
+
config.before :each do
|
22
|
+
Typhoeus::Expectation.clear
|
23
|
+
end
|
27
24
|
end
|
25
|
+
|
26
|
+
require 'rspec'
|
27
|
+
begin
|
28
|
+
require 'byebug'
|
29
|
+
rescue LoadError
|
30
|
+
end
|
31
|
+
require 'wirecard_checkout_page'
|
@@ -1,62 +1,120 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WirecardCheckoutPage::Gateway do
|
4
|
-
let(:
|
4
|
+
let(:credentials) do
|
5
|
+
{
|
6
|
+
customer_id: 'D200001',
|
7
|
+
secret: 'B8AKTPWBRMNBV455FG6M2DANE99WU2',
|
8
|
+
toolkit_password: 'jcv45z',
|
9
|
+
}
|
10
|
+
end
|
11
|
+
let(:gateway) { WirecardCheckoutPage::Gateway.new credentials }
|
5
12
|
|
6
13
|
describe '#initialize' do
|
7
14
|
it 'stores secret, customerId and init_url if given' do
|
8
|
-
gateway = WirecardCheckoutPage::Gateway.new(
|
9
|
-
|
15
|
+
gateway = WirecardCheckoutPage::Gateway.new(
|
16
|
+
customer_id: 'foo',
|
17
|
+
secret: 'bar',
|
18
|
+
toolkit_password: '123'
|
19
|
+
)
|
20
|
+
expect(gateway.customer_id).to eq 'foo'
|
10
21
|
expect(gateway.secret).to eq 'bar'
|
11
|
-
expect(gateway.
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'takes the default init url if none was given' do
|
15
|
-
gateway = WirecardCheckoutPage::Gateway.new
|
16
|
-
expect(gateway.init_url).to be_a String
|
17
|
-
expect(gateway.init_url).to eq WirecardCheckoutPage::Gateway::DEFAULT_INIT_URL
|
22
|
+
expect(gateway.toolkit_password).to eq '123'
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
26
|
describe '#init' do
|
27
|
+
let(:stubbed_response) do
|
28
|
+
Typhoeus::Response.new(code: 302, body: '', headers: { 'Location' => 'https://example.com/single_init' })
|
29
|
+
end
|
30
|
+
before { Typhoeus.stub('https://checkout.wirecard.com/page/init.php').and_return(stubbed_response) }
|
31
|
+
|
22
32
|
let(:valid_params) do
|
23
33
|
{
|
24
34
|
amount: '100.00',
|
35
|
+
currency: 'EUR',
|
25
36
|
orderDescription: 'order',
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
serviceUrl: 'https://foo.com/service',
|
38
|
+
successUrl: 'https://foo.com/success',
|
39
|
+
cancelUrl: 'https://foo.com/cancel',
|
40
|
+
failureUrl: 'https://foo.com/failure',
|
41
|
+
confirmUrl: 'https://foo.com/confirm',
|
31
42
|
orderReference: '123',
|
43
|
+
language: 'de',
|
44
|
+
paymentType: 'SELECT',
|
32
45
|
}
|
33
46
|
end
|
34
47
|
|
35
|
-
it 'builds
|
36
|
-
expect(WirecardCheckoutPage::
|
37
|
-
with(hash_including customerId: 'foo', secret: 'bar').and_call_original
|
48
|
+
it 'builds' do
|
49
|
+
expect(WirecardCheckoutPage::InitRequest).to receive(:new).and_call_original
|
38
50
|
gateway.init(valid_params)
|
39
51
|
end
|
40
52
|
|
41
53
|
it 'returns a InitResponse with the correct payment url' do
|
54
|
+
gateway = WirecardCheckoutPage::Gateway.new(
|
55
|
+
customer_id: 'D200001',
|
56
|
+
secret: 'B8AKTPWBRMNBV455FG6M2DANE99WU2',
|
57
|
+
)
|
42
58
|
response = gateway.init(valid_params)
|
43
59
|
expect(response).to be_a WirecardCheckoutPage::InitResponse
|
44
|
-
|
60
|
+
payment_url = response.params[:payment_url]
|
61
|
+
expect(payment_url).to match 'https://example.com/single_init'
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|
48
|
-
describe '#
|
65
|
+
describe '#recurring_init' do
|
66
|
+
let(:stubbed_response) do
|
67
|
+
Typhoeus::Response.new(code: 302, body: '', headers: { 'Location' => 'https://example.com/recurring_init' })
|
68
|
+
end
|
69
|
+
before { Typhoeus.stub('https://checkout.wirecard.com/page/init.php').and_return(stubbed_response) }
|
70
|
+
|
71
|
+
let(:valid_params) do
|
72
|
+
{
|
73
|
+
amount: '100.00',
|
74
|
+
currency: 'EUR',
|
75
|
+
paymentType: 'SELECT',
|
76
|
+
orderDescription: 'order',
|
77
|
+
serviceUrl: 'https://foo.com/service',
|
78
|
+
successUrl: 'https://foo.com/success',
|
79
|
+
cancelUrl: 'https://foo.com/cancel',
|
80
|
+
failureUrl: 'https://foo.com/failure',
|
81
|
+
confirmUrl: 'https://foo.com/confirm',
|
82
|
+
orderReference: '123',
|
83
|
+
language: 'de',
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
49
87
|
it 'builds a checksum with the authorization params' do
|
50
|
-
expect(WirecardCheckoutPage::
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
88
|
+
expect(WirecardCheckoutPage::InitRequest).to receive(:new).and_call_original
|
89
|
+
gateway.recurring_init(valid_params)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns a InitResponse with the correct payment url' do
|
93
|
+
response = gateway.recurring_init(valid_params)
|
94
|
+
expect(response).to be_a WirecardCheckoutPage::InitResponse
|
95
|
+
payment_url = response.params[:payment_url]
|
96
|
+
expect(payment_url).to match 'https://example.com/recurring_init'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#recurring_process' do
|
101
|
+
let(:stubbed_response) { Typhoeus::Response.new(code: 302, body: 'status=0&orderNumber=1') }
|
102
|
+
before { Typhoeus.stub('https://checkout.wirecard.com/page/toolkit.php').and_return(stubbed_response) }
|
103
|
+
|
104
|
+
let(:valid_params) do
|
105
|
+
{
|
106
|
+
sourceOrderNumber: '123',
|
107
|
+
orderDescription: 'orderDescription',
|
108
|
+
amount: '345',
|
109
|
+
currency: 'EUR'
|
110
|
+
}
|
55
111
|
end
|
56
112
|
|
57
|
-
it 'returns
|
58
|
-
|
59
|
-
expect(
|
113
|
+
it 'returns a successful ToolKit::Reponse' do
|
114
|
+
response = gateway.recurring_process(valid_params)
|
115
|
+
expect(response).to be_a WirecardCheckoutPage::Toolkit::Response
|
116
|
+
expect(response).to be_success
|
60
117
|
end
|
61
118
|
end
|
119
|
+
|
62
120
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WirecardCheckoutPage::InitRequest do
|
4
|
+
let(:valid_params) do
|
5
|
+
{
|
6
|
+
customerId: 'D200001',
|
7
|
+
secret: 'B8AKTPWBRMNBV455FG6M2DANE99WU2',
|
8
|
+
amount: '100.00',
|
9
|
+
currency: 'EUR',
|
10
|
+
orderDescription: 'order',
|
11
|
+
serviceUrl: 'https://foo.com/service',
|
12
|
+
successUrl: 'https://foo.com/success',
|
13
|
+
cancelUrl: 'https://foo.com/cancel',
|
14
|
+
failureUrl: 'https://foo.com/failure',
|
15
|
+
confirmUrl: 'https://foo.com/confirm',
|
16
|
+
orderReference: '123',
|
17
|
+
language: 'de',
|
18
|
+
paymentType: 'SELECT',
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#body' do
|
23
|
+
context 'with standard params' do
|
24
|
+
it 'has the right fingerprint' do
|
25
|
+
request = described_class.new params: valid_params
|
26
|
+
expected_request_fingerprint_order = 'secret,customerId,language,paymentType,amount,currency,orderDescription,successUrl,cancelUrl,failureUrl,serviceUrl,confirmUrl,orderReference,transactionIdentifier,requestFingerprintOrder'
|
27
|
+
expect(request.body['requestFingerprintOrder']).to eq expected_request_fingerprint_order
|
28
|
+
expect(request.body['requestFingerprint']).to eq Digest::MD5.hexdigest(
|
29
|
+
'B8AKTPWBRMNBV455FG6M2DANE99WU2''D200001''de''SELECT''100.00''EUR''order''https://foo.com/success''https://foo.com/cancel''https://foo.com/failure''https://foo.com/service''https://foo.com/confirm''123''SINGLE'"#{expected_request_fingerprint_order}"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with recurring init' do
|
35
|
+
it 'has the right fingerprint' do
|
36
|
+
request = described_class.new params: valid_params.merge(transactionIdentifier: 'INITIAL')
|
37
|
+
expected_request_fingerprint_order = 'secret,customerId,language,paymentType,amount,currency,orderDescription,successUrl,cancelUrl,failureUrl,serviceUrl,confirmUrl,orderReference,transactionIdentifier,requestFingerprintOrder'
|
38
|
+
expect(request.body['requestFingerprintOrder']).to eq expected_request_fingerprint_order
|
39
|
+
expect(request.body['requestFingerprint']).to eq Digest::MD5.hexdigest(
|
40
|
+
'B8AKTPWBRMNBV455FG6M2DANE99WU2''D200001''de''SELECT''100.00''EUR''order''https://foo.com/success''https://foo.com/cancel''https://foo.com/failure''https://foo.com/service''https://foo.com/confirm''123''INITIAL'"#{expected_request_fingerprint_order}"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'performing a request' do
|
47
|
+
let(:stubbed_response) do
|
48
|
+
Typhoeus::Response.new(code: 302, body: '', headers: { 'Location' => 'https://example.com/single_init' })
|
49
|
+
end
|
50
|
+
before { Typhoeus.stub('https://checkout.wirecard.com/page/init.php').and_return(stubbed_response) }
|
51
|
+
|
52
|
+
it 'makes a successful request' do
|
53
|
+
request = described_class.new params: valid_params
|
54
|
+
|
55
|
+
response = request.call
|
56
|
+
expect(response).to be_a WirecardCheckoutPage::InitResponse
|
57
|
+
expect(response).to be_success
|
58
|
+
payment_url = response.params[:payment_url]
|
59
|
+
expect(payment_url).to match 'https://example.com/single_init'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestRequest < WirecardCheckoutPage::Request
|
4
|
+
|
5
|
+
param :customerId, required: true
|
6
|
+
param :shopId
|
7
|
+
param :param1, required: true
|
8
|
+
param :secret, required: true
|
9
|
+
param :command, required: true
|
10
|
+
param :language, required: true
|
11
|
+
|
12
|
+
def initialize(params: {})
|
13
|
+
super params: params
|
14
|
+
self.command = 'test'
|
15
|
+
self.language = 'en'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe WirecardCheckoutPage::Request do
|
21
|
+
let(:valid_params) do
|
22
|
+
{
|
23
|
+
customerId: 'ABC',
|
24
|
+
secret: 'geheim',
|
25
|
+
param1: '345'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#request_params' do
|
30
|
+
subject { TestRequest.new params: valid_params }
|
31
|
+
|
32
|
+
it 'has the right request_params' do
|
33
|
+
expect(subject.request_params).to eq(
|
34
|
+
{
|
35
|
+
'command' => 'test',
|
36
|
+
'language' => 'en',
|
37
|
+
'customerId' => 'ABC',
|
38
|
+
'param1' => '345',
|
39
|
+
}
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#body' do
|
45
|
+
|
46
|
+
context 'with minimal params' do
|
47
|
+
subject { TestRequest.new(params: valid_params) }
|
48
|
+
|
49
|
+
it 'has correct fingerprinted params' do
|
50
|
+
expect(subject.body).to eq(
|
51
|
+
{
|
52
|
+
'command' => 'test',
|
53
|
+
'language' => 'en',
|
54
|
+
'customerId' => 'ABC',
|
55
|
+
'param1' => '345',
|
56
|
+
'requestFingerprint' => Digest::MD5.hexdigest('ABC''345''geheim''test''en'),
|
57
|
+
'requestFingerprintOrder' => 'customerId,param1,secret,command,language',
|
58
|
+
}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with optional params' do
|
64
|
+
subject { TestRequest.new(params: valid_params.merge(shopId: 'XYZ')) }
|
65
|
+
|
66
|
+
it 'has correct fingerprinted params' do
|
67
|
+
expect(subject.body).to eq(
|
68
|
+
{
|
69
|
+
'command' => 'test',
|
70
|
+
'language' => 'en',
|
71
|
+
'customerId' => 'ABC',
|
72
|
+
'param1' => '345',
|
73
|
+
'shopId' => 'XYZ',
|
74
|
+
'requestFingerprint' => Digest::MD5.hexdigest('ABC''XYZ''345''geheim''test''en'),
|
75
|
+
'requestFingerprintOrder' => 'customerId,shopId,param1,secret,command,language',
|
76
|
+
}
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#call' do
|
83
|
+
it 'raises ValueMissing' do
|
84
|
+
expect { TestRequest.new.call } .to raise_error WirecardCheckoutPage::NotImplementedError
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -2,127 +2,81 @@ require 'spec_helper'
|
|
2
2
|
require 'wirecard_checkout_page'
|
3
3
|
|
4
4
|
describe WirecardCheckoutPage::ResponseChecksum do
|
5
|
-
|
6
|
-
'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
'SOMECUSTOMERID'
|
11
|
-
end
|
5
|
+
describe '#valid?' do
|
6
|
+
context 'with valid parameters' do
|
7
|
+
it 'is valid' do
|
8
|
+
fingerprint_order = 'amount,currency,paymentType,financialInstitution,language,orderNumber,paymentState,authenticated,anonymousPan,expiry,maskedPan,gatewayReferenceNumber,gatewayContractNumber,secret,responseFingerprintOrder'
|
9
|
+
expected_fingerprint_string = '50.00''EUR''CCARD''Visa''de''8300664''SUCCESS''No''1122''06/2018''405911******1122''C101361143697423285286''000000316159CED9''SECRET'"#{fingerprint_order}"
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
params = {
|
12
|
+
secret: 'SECRET',
|
13
|
+
'amount' => '50.00',
|
14
|
+
'currency' => 'EUR',
|
15
|
+
'paymentType' => 'CCARD',
|
16
|
+
'financialInstitution' => 'Visa',
|
17
|
+
'language' => 'de',
|
18
|
+
'orderNumber' => '8300664',
|
19
|
+
'paymentState' => 'SUCCESS',
|
20
|
+
'authenticated' => 'No',
|
21
|
+
'anonymousPan' => '1122',
|
22
|
+
'expiry' => '06/2018',
|
23
|
+
'maskedPan' => '405911******1122',
|
24
|
+
'gatewayReferenceNumber' => 'C101361143697423285286',
|
25
|
+
'gatewayContractNumber' => '000000316159CED9',
|
26
|
+
'responseFingerprintOrder' => fingerprint_order,
|
27
|
+
'responseFingerprint' => 'd1e7ecba3980ca2da4954b9d154c1e1e',
|
28
|
+
}
|
29
|
+
checksum = described_class.new(params)
|
30
|
+
expect(checksum).to be_valid
|
31
|
+
end
|
32
|
+
end
|
16
33
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
customerId: customer_id,
|
22
|
-
shopId: shop_id,
|
23
|
-
"amount" => "28.95",
|
24
|
-
"currency" => "EUR",
|
25
|
-
"paymentType" => "CCARD",
|
26
|
-
"financialInstitution" => "MC",
|
27
|
-
"language" => "de",
|
28
|
-
"orderNumber" => "7739491",
|
29
|
-
"paymentState" => "SUCCESS",
|
30
|
-
"utf8" => "✓",
|
31
|
-
"authenticity_token" => "bnz1fHxcCYD9jdPiNIEl7yJExRetWWAOQPopmjYksFc=",
|
32
|
-
"commit" => "Bezahlen",
|
33
|
-
"authenticated" => "No",
|
34
|
-
"anonymousPan" => "0002",
|
35
|
-
"expiry" => "01/2013",
|
36
|
-
"cardholder" => "Foorian Bar",
|
37
|
-
"maskedPan" => "950000******0002",
|
38
|
-
"gatewayReferenceNumber" => "DGW_7739491_RN",
|
39
|
-
"gatewayContractNumber" => "DemoContractNumber123",
|
40
|
-
"responseFingerprintOrder"=>"amount,currency,paymentType,"\
|
41
|
-
"financialInstitution,language,orderNumber,paymentState,utf8,"\
|
42
|
-
"authenticity_token,commit,authenticated,anonymousPan,expiry,"\
|
43
|
-
"cardholder,maskedPan,gatewayReferenceNumber,gatewayContractNumber,"\
|
44
|
-
"secret,responseFingerprintOrder",
|
45
|
-
"responseFingerprint" => "8a1319b4a097d5a9157f479b11e8f5ae",
|
46
|
-
"challenge_offer_id" => "0dd916e49abd1935c2dc084bae2a57b8"
|
47
|
-
}
|
48
|
-
checksum = WirecardCheckoutPage::ResponseChecksum.new(response_params)
|
49
|
-
checksum.valid?
|
50
|
-
expect(checksum.computed_fingerprint).to eq '8a1319b4a097d5a9157f479b11e8f5ae'
|
51
|
-
expect(checksum).to be_valid
|
52
|
-
end
|
34
|
+
context 'with invalid parameters' do
|
35
|
+
it 'is not valid' do
|
36
|
+
fingerprint_order = 'amount,currency,paymentType,financialInstitution,language,orderNumber,paymentState,authenticated,anonymousPan,expiry,maskedPan,gatewayReferenceNumber,gatewayContractNumber,secret,responseFingerprintOrder'
|
37
|
+
expected_fingerprint_string = '50.00''EUR''CCARD''Visa''de''8300664''SUCCESS''No''1122''06/2018''405911******1122''C101361143697423285286''000000316159CED9''SECRET'"#{fingerprint_order}"
|
53
38
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
"gatewayContractNumber" => "DemoContractNumber123",
|
77
|
-
"responseFingerprintOrder"=>"amount,currency,paymentType,"\
|
78
|
-
"financialInstitution,language,orderNumber,paymentState,utf8,"\
|
79
|
-
"authenticity_token,commit,authenticated,anonymousPan,expiry,"\
|
80
|
-
"cardholder,maskedPan,gatewayReferenceNumber,gatewayContractNumber,"\
|
81
|
-
"secret,responseFingerprintOrder",
|
82
|
-
"responseFingerprint" => "666c9c80495703dabfc08434d2e99af0",
|
83
|
-
"challenge_offer_id" => "0dd916e49abd1935c2dc084bae2a57b8"
|
84
|
-
}
|
85
|
-
expect(WirecardCheckoutPage::ResponseChecksum.new(response_params)).
|
86
|
-
to_not be_valid
|
39
|
+
params = {
|
40
|
+
secret: 'SECRET',
|
41
|
+
'amount' => '21121221250.00',
|
42
|
+
'currency' => 'EUR',
|
43
|
+
'paymentType' => 'CCARD',
|
44
|
+
'financialInstitution' => 'Visa',
|
45
|
+
'language' => 'de',
|
46
|
+
'orderNumber' => '8300664',
|
47
|
+
'paymentState' => 'SUCCESS',
|
48
|
+
'authenticated' => 'No',
|
49
|
+
'anonymousPan' => '1122',
|
50
|
+
'expiry' => '06/2018',
|
51
|
+
'maskedPan' => '405911******1122',
|
52
|
+
'gatewayReferenceNumber' => 'C101361143697423285286',
|
53
|
+
'gatewayContractNumber' => '000000316159CED9',
|
54
|
+
'responseFingerprintOrder' => fingerprint_order,
|
55
|
+
'responseFingerprint' => 'd1e7ecba3980ca2da4954b9d154c1e1e',
|
56
|
+
}
|
57
|
+
checksum = described_class.new(params)
|
58
|
+
expect(checksum).to_not be_valid
|
59
|
+
end
|
60
|
+
end
|
87
61
|
end
|
88
62
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
"paymentState" => "SUCCESS",
|
101
|
-
"utf8" => "✓",
|
102
|
-
"authenticity_token" => "bnz1fHxcCYD9jdPiNIEl7yJExRetWWAOQPopmjYksFc=",
|
103
|
-
"commit" => "Bezahlen",
|
104
|
-
"authenticated" => "No",
|
105
|
-
"anonymousPan" => "0002",
|
106
|
-
"expiry" => "01/2013",
|
107
|
-
"cardholder" => "Foorian Bar",
|
108
|
-
"maskedPan" => "950000******0002",
|
109
|
-
"gatewayReferenceNumber" => "DGW_7739491_RN",
|
110
|
-
"gatewayContractNumber" => "DemoContractNumber123",
|
111
|
-
"responseFingerprintOrder"=>"amount,currency,paymentType,"\
|
112
|
-
"financialInstitution,language,orderNumber,paymentState,utf8,"\
|
113
|
-
"authenticity_token,commit,authenticated,anonymousPan,expiry,"\
|
114
|
-
"cardholder,maskedPan,gatewayReferenceNumber,gatewayContractNumber,"\
|
115
|
-
"secret,responseFingerprintOrder",
|
116
|
-
"responseFingerprint" => "666c9c80495703dabfc08434d2e99af0",
|
117
|
-
"challenge_offer_id" => "0dd916e49abd1935c2dc084bae2a57b8"
|
118
|
-
}
|
119
|
-
checksum = WirecardCheckoutPage::ResponseChecksum.new(response_params)
|
120
|
-
expect(checksum).to_not be_valid
|
121
|
-
expect(checksum).to be_missing_keys
|
122
|
-
expect(checksum.missing_keys?).to eq %w[amount]
|
123
|
-
end
|
63
|
+
describe '#initialize' do
|
64
|
+
context 'a probably crafted request without the secret key in the responseFingerprintOrder' do
|
65
|
+
let(:fingerprint_order) { 'amount,currency,responseFingerprintOrder' }
|
66
|
+
let(:params) do
|
67
|
+
{
|
68
|
+
'amount' => '10.00',
|
69
|
+
'currency' => 'EUR',
|
70
|
+
'responseFingerprint' => Digest::MD5.hexdigest('10.00''EUR'"#{fingerprint_order}"),
|
71
|
+
'responseFingerprintOrder' => fingerprint_order,
|
72
|
+
}
|
73
|
+
end
|
124
74
|
|
125
|
-
|
126
|
-
|
75
|
+
it 'raises InvalidResponseFingerprintOrder' do
|
76
|
+
expect {
|
77
|
+
described_class.new(params)
|
78
|
+
}.to raise_error WirecardCheckoutPage::InvalidResponseFingerPrintOrder
|
79
|
+
end
|
80
|
+
end
|
127
81
|
end
|
128
82
|
end
|