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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +2 -1
  4. data/Gemfile +2 -0
  5. data/README.md +4 -0
  6. data/Rakefile +1 -2
  7. data/VERSION +1 -1
  8. data/lib/wirecard_checkout_page.rb +6 -2
  9. data/lib/wirecard_checkout_page/errors.rb +2 -0
  10. data/lib/wirecard_checkout_page/fingerprint.rb +0 -0
  11. data/lib/wirecard_checkout_page/gateway.rb +26 -12
  12. data/lib/wirecard_checkout_page/init_request.rb +71 -0
  13. data/lib/wirecard_checkout_page/init_response.rb +12 -2
  14. data/lib/wirecard_checkout_page/request.rb +85 -0
  15. data/lib/wirecard_checkout_page/response_checksum.rb +15 -45
  16. data/lib/wirecard_checkout_page/toolkit/recur_payment.rb +66 -0
  17. data/lib/wirecard_checkout_page/toolkit/request.rb +55 -0
  18. data/lib/wirecard_checkout_page/toolkit/response.rb +50 -0
  19. data/lib/wirecard_checkout_page/version.rb +1 -1
  20. data/spec/spec_helper.rb +12 -8
  21. data/spec/wirecard_checkout_page/gateway_spec.rb +86 -28
  22. data/spec/wirecard_checkout_page/init_request_spec.rb +62 -0
  23. data/spec/wirecard_checkout_page/request_spec.rb +88 -0
  24. data/spec/wirecard_checkout_page/response_checksum_spec.rb +70 -116
  25. data/spec/wirecard_checkout_page/toolkit/recur_payment_spec.rb +125 -0
  26. data/spec/wirecard_checkout_page/toolkit/request_spec.rb +79 -0
  27. data/spec/wirecard_checkout_page/toolkit/response_spec.rb +36 -0
  28. data/wirecard_checkout_page.gemspec +9 -12
  29. metadata +40 -45
  30. data/lib/wirecard_checkout_page/request_checksum.rb +0 -88
  31. data/lib/wirecard_checkout_page/value_handling.rb +0 -19
  32. data/lib/wirecard_checkout_page/value_missing.rb +0 -1
  33. data/spec/wirecard_checkout_page/request_checksum_spec.rb +0 -96
  34. 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
@@ -1,6 +1,6 @@
1
1
  module WirecardCheckoutPage
2
2
  # WirecardCheckoutPage version
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -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(:all) do
24
- response = Typhoeus::Response.new(code: 302, body: "", headers: { 'Location' => 'payment-url' })
25
- Typhoeus.stub(/init/).and_return(response)
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(:gateway) { WirecardCheckoutPage::Gateway.new(customerId: 'foo', secret: 'bar') }
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(customerId: 'foo', secret: 'bar', init_url: 'foobar')
9
- expect(gateway.customerId).to eq 'foo'
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.init_url).to eq 'foobar'
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
- serviceURL: 'service',
27
- successURL: 'succes',
28
- cancelURL: 'cancel',
29
- failureURL: 'failure',
30
- confirmURL: 'confirm',
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 a checksum with the authorization params' do
36
- expect(WirecardCheckoutPage::RequestChecksum).to receive(:new).
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
- expect(response.params).to eq(payment_url: 'payment-url')
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 '#check_response' do
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::ResponseChecksum).to receive(:new).
51
- with(
52
- hash_including('customerId' => 'foo', 'secret' => 'bar')
53
- ).and_call_original
54
- gateway.check_response.valid?
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 true if the response was valid' do
58
- allow_any_instance_of(WirecardCheckoutPage::ResponseChecksum).to receive(:valid?).and_return(true)
59
- expect(gateway.check_response).to be_valid
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
- let :secret do
6
- 'SOMESECRET'
7
- end
8
-
9
- let :customer_id do
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
- let :shop_id do
14
- 'someshopid'
15
- end
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
- it "recognizes a correct response" do
18
- response_params = {
19
- secret: secret,
20
- fingerprint_keys: WirecardCheckoutPage::RequestChecksum::FINGERPRINT_KEYS + %w[shopId],
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" => "&#10003;",
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
- it "fails check on an incorrect response" do
55
- response_params = {
56
- secret: secret,
57
- fingerprint_keys: WirecardCheckoutPage::RequestChecksum::FINGERPRINT_KEYS + %w[shopId],
58
- customerId: customer_id,
59
- shopId: shop_id,
60
- "amount" => "28.95",
61
- "currency" => "EUR",
62
- "paymentType" => "CCARD",
63
- "financialInstitution" => "MC",
64
- "language" => "de",
65
- "orderNumber" => "7739491",
66
- "paymentState" => "SUCCESS",
67
- "utf8" => "&#10003;",
68
- "authenticity_token" => "bnz1fHxcCYD9jdPiNIEl7yJExRetWWAOQPopmjYksFc=",
69
- "commit" => "Bezahlen",
70
- "authenticated" => "No",
71
- "anonymousPan" => "0002",
72
- "expiry" => "01/2013",
73
- "cardholder" => "Foorian Bar",
74
- "maskedPan" => "950000******0002",
75
- "gatewayReferenceNumber" => "DGW_7739491_RN",
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
- it "fails check on a response with missing keys" do
90
- response_params = {
91
- secret: secret,
92
- fingerprint_keys: WirecardCheckoutPage::RequestChecksum::FINGERPRINT_KEYS + %w[shopId],
93
- customerId: customer_id,
94
- shopId: shop_id,
95
- "currency" => "EUR",
96
- "paymentType" => "CCARD",
97
- "financialInstitution" => "MC",
98
- "language" => "de",
99
- "orderNumber" => "7739491",
100
- "paymentState" => "SUCCESS",
101
- "utf8" => "&#10003;",
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
- it "fails check in an empty response" do
126
- expect(WirecardCheckoutPage::ResponseChecksum.new(secret: secret)).to_not be_valid
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