wirecard_checkout_page 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0470456a38f7276de6c835212ff32c0a23030f7
4
+ data.tar.gz: 65230a1899c686c624e02675bc7e428084906fef
5
+ SHA512:
6
+ metadata.gz: e93187a873b162d0bfb29829fb65b674ec018e9e5fb30698da7f0a0b97d80ec3a470d0990998a2c42795fb612c489202484ae33ce423ffd3b1923b860f2987af
7
+ data.tar.gz: 60e3f3db0ca60f7cea0f44fffd0d549de38d2ebbad9c4fadff422cf11252dd3c0edc89fce807a8abd8e1b2c4f70521a58c3c92b877a3cc9bd97890dffa3e8ad1
@@ -0,0 +1,7 @@
1
+ .*.sw[pon]
2
+ .AppleDouble
3
+ .DS_Store
4
+ .rvmrc
5
+ Gemfile.lock
6
+ coverage
7
+ pkg
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1
4
+ - ruby-head
5
+ - jruby-head
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: ruby-head
9
+ - rvm: jruby-head
10
+ env:
11
+ - CODECLIMATE_REPO_TOKEN=9420ddf93d71e1d0e9c08789812e85aebad699d863b665f0cb5d507877ca5a0f
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # vim: set filetype=ruby et sw=2 ts=2:
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,43 @@
1
+ # WirecardCheckoutPage
2
+
3
+ ## Example usage
4
+
5
+ Gateway setup
6
+ ```ruby
7
+ gateway = WirecardCheckoutPage::Gateway.new(
8
+ secret: YOUR_SECRET,
9
+ customerId: YOUR_ID
10
+ )
11
+ ```
12
+
13
+ Init a new payment process
14
+ ```ruby
15
+ params = {
16
+ fingerprint_keys: ["secret", "customerId", "amount", ..], # Put in all your fingerprint keys
17
+ currency: 'EUR',
18
+ language: 'en',
19
+ amount: '100.00',
20
+ paymentType: 'SELECT',
21
+ orderDescription: 'Your order no 1',
22
+ successURL: 'http://example.com/success',
23
+ cancelURL: 'http://example.com/cancel',
24
+ failureURL: 'http://example.com/failure',
25
+ serviceURL: 'http://example.com/service',
26
+ confirmURL: 'http://example.com/confirm',
27
+ orderReference: YOUR_UNIQUE_ORDER_REFERENCE,
28
+ }
29
+
30
+ response = gateway.init(params)
31
+
32
+ puts response.success?
33
+ #=> true
34
+
35
+ puts response.params
36
+ #=> { payment_url: 'http://example.com/redirect_your_user_to_here' }
37
+ ```
38
+
39
+ ## Badges
40
+
41
+ [![Code Climate](https://codeclimate.com/github/flori/wirecard_checkout_page/badges/gpa.svg)](https://codeclimate.com/github/flori/wirecard_checkout_page)
42
+
43
+ [![Test Coverage](https://codeclimate.com/github/flori/wirecard_checkout_page/badges/coverage.svg)](https://codeclimate.com/github/flori/wirecard_checkout_page)
@@ -0,0 +1,25 @@
1
+ # vim: set filetype=ruby et sw=2 ts=2:
2
+
3
+ require 'gem_hadar'
4
+
5
+ GemHadar do
6
+ name 'wirecard_checkout_page'
7
+ author 'Florian Frank'
8
+ email 'flori@ping.de'
9
+ homepage "http://flori.github.com/#{name}"
10
+ summary 'Library for using Wirecard Checkout Page'
11
+ description 'This library allows you to use the Wirecard Checkout Page service.'
12
+ test_dir 'tests'
13
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc', '.AppleDouble', '.DS_Store'
14
+ readme 'README.md'
15
+ title "#{name.camelize} -- Wirecard Checkout Page implementation"
16
+ licenses << 'Apache-2.0'
17
+
18
+ dependency 'typhoeus'
19
+ development_dependency 'rake'
20
+ development_dependency 'simplecov'
21
+ development_dependency 'rspec'
22
+ development_dependency 'byebug'
23
+ end
24
+
25
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,12 @@
1
+ require 'digest/md5'
2
+ require 'uri'
3
+ require 'typhoeus'
4
+ require 'wirecard_checkout_page/errors'
5
+ require 'wirecard_checkout_page/gateway'
6
+ require 'wirecard_checkout_page/utils'
7
+ require 'wirecard_checkout_page/request_checksum'
8
+ require 'wirecard_checkout_page/response_checksum'
9
+ require 'wirecard_checkout_page/init_response'
10
+
11
+ module WirecardCheckoutPage
12
+ end
@@ -0,0 +1,5 @@
1
+ module WirecardCheckoutPage
2
+ class WirecardCheckoutPageError < StandardError; end
3
+
4
+ class ValueMissing < WirecardCheckoutPageError; end
5
+ end
@@ -0,0 +1,29 @@
1
+ module WirecardCheckoutPage
2
+ class Gateway
3
+ DEFAULT_INIT_URL = 'https://checkout.wirecard.com/page/init.php'
4
+
5
+ attr_accessor :customerId, :secret, :init_url
6
+
7
+ def initialize(customerId: nil, secret: nil, init_url: nil)
8
+ @customerId = customerId
9
+ @secret = secret
10
+ @init_url = init_url || DEFAULT_INIT_URL
11
+ end
12
+
13
+ def init(params = {})
14
+ checksum = WirecardCheckoutPage::RequestChecksum.new(params.merge(authentication_params))
15
+ InitResponse.new Typhoeus.post(init_url, body: checksum.request_parameters)
16
+ end
17
+
18
+ def response_valid?(params = {})
19
+ WirecardCheckoutPage::ResponseChecksum.new(params.merge(authentication_params)).valid?
20
+ end
21
+
22
+ private
23
+
24
+ def authentication_params
25
+ { secret: secret, customerId: customerId }
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ # works like ActiveMerchant::Billing::Response to maintain compatibility to
2
+ # active merchant gateways
3
+
4
+ module WirecardCheckoutPage
5
+ class InitResponse
6
+ def initialize(response)
7
+ @original_response = response
8
+ end
9
+
10
+ def params
11
+ {
12
+ payment_url: @original_response.headers['Location']
13
+ }
14
+ end
15
+
16
+ def success?
17
+ !!params[:payment_url]
18
+ end
19
+
20
+ def message
21
+ @original_response.body
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,88 @@
1
+ require 'wirecard_checkout_page/value_handling'
2
+
3
+ module WirecardCheckoutPage
4
+ class RequestChecksum
5
+ include WirecardCheckoutPage::Utils
6
+ include WirecardCheckoutPage::ValueHandling
7
+
8
+ FINGERPRINT_KEYS = %w[
9
+ secret
10
+ customerId
11
+ amount
12
+ paymentType
13
+ currency
14
+ language
15
+ orderDescription
16
+ serviceURL
17
+ successURL
18
+ cancelURL
19
+ failureURL
20
+ confirmURL
21
+ orderReference
22
+ requestFingerprintOrder
23
+ ].freeze
24
+
25
+ def initialize(values = {})
26
+ @values = stringify_keys(values)
27
+ @fingerprint_keys = @values.delete('fingerprint_keys') || FINGERPRINT_KEYS
28
+ @secret = @values.delete('secret') or
29
+ raise WirecardCheckoutPage::ValueMissing, 'value "secret" is missing'
30
+ @values = add_some_defaults @values
31
+ @values.freeze
32
+ @fingerprint_keys = fingerprint_keys
33
+ @secret = @secret
34
+ reset_missing_keys
35
+ end
36
+
37
+ attr_reader :fingerprint_keys
38
+
39
+ attr_reader :values
40
+
41
+ def request_parameters
42
+ reset_missing_keys
43
+ parameters = @values.dup
44
+ parameters['requestFingerprintOrder'] = requestFingerprintOrder
45
+ parameters['requestFingerprint'] = fingerprint
46
+ if missing_keys?
47
+ raise WirecardCheckoutPage::ValueMissing,
48
+ "values #{missing_keys * ', ' } are missing"
49
+ end
50
+ parameters
51
+ end
52
+
53
+ private
54
+
55
+ def fingerprint
56
+ values = @values.dup
57
+ values.update(
58
+ 'requestFingerprintOrder' => requestFingerprintOrder,
59
+ 'secret' => @secret,
60
+ )
61
+ Digest::MD5.hexdigest requestFingerprintSeed(values)
62
+ end
63
+
64
+ def requestFingerprintSeed(values)
65
+ seed = fingerprint_keys.map { |k|
66
+ values.fetch(k) do
67
+ add_missing_key k
68
+ next
69
+ end
70
+ } * ''
71
+ end
72
+
73
+ def requestFingerprintOrder
74
+ @requestFingerprintOrder ||= fingerprint_keys.join(',').freeze
75
+ end
76
+
77
+ def add_some_defaults(values)
78
+ default_values = {
79
+ 'paymentType' => 'SELECT',
80
+ 'currency' => 'EUR',
81
+ 'language' => 'de',
82
+ }
83
+ values.update(default_values) do |key,old,new|
84
+ old.nil? ? new : old
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'wirecard_checkout_page/value_handling'
4
+
5
+ module WirecardCheckoutPage
6
+ class ResponseChecksum
7
+ include WirecardCheckoutPage::Utils
8
+ include WirecardCheckoutPage::ValueHandling
9
+
10
+ def initialize(values = {})
11
+ @values = stringify_keys(values)
12
+ @secret = @values.delete('secret') or
13
+ raise WirecardCheckoutPage::ValueMissing, 'value "secret" is missing'
14
+ # This rails form value is escaped as an html entity by
15
+ # WirecardCheckoutPage, so set it back to the original UTF-8 here if it
16
+ # exists:
17
+ @values['utf8'] and @values['utf8'] = '✓'
18
+ @values.freeze
19
+ reset_missing_keys
20
+ end
21
+
22
+ attr_reader :values
23
+
24
+ attr_reader :expected_fingerprint
25
+
26
+ attr_reader :computed_fingerprint
27
+
28
+ def fingerprint
29
+ values = @values.dup
30
+ values['secret'] ||= @secret
31
+ if seed = responseFingerprintSeed(responseFingerprintOrder(values), values)
32
+ Digest::MD5.hexdigest seed
33
+ end
34
+ end
35
+
36
+ def valid?
37
+ reset_missing_keys
38
+ @expected_fingerprint = values.fetch('responseFingerprint') do |k|
39
+ add_missing_key k
40
+ end
41
+ @computed_fingerprint = fingerprint
42
+ !missing_keys? && computed_fingerprint == @expected_fingerprint
43
+ end
44
+
45
+ private
46
+
47
+ def responseFingerprintOrder(values)
48
+ order = values.fetch('responseFingerprintOrder') do |k|
49
+ add_missing_key k
50
+ return []
51
+ end
52
+ order.split(',')
53
+ end
54
+
55
+ def responseFingerprintSeed(keys, values)
56
+ fingerprint = keys.map do |k|
57
+ values.fetch(k) do
58
+ add_missing_key k
59
+ end
60
+ end * ''
61
+ fingerprint unless missing_keys?
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ module WirecardCheckoutPage::Utils
2
+ def stringify_keys(hash)
3
+ hash.each_with_object(hash.dup.clear) do |(k, v), new_hash|
4
+ new_hash[k.to_s] = v
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module WirecardCheckoutPage::ValueHandling
2
+ def missing_keys
3
+ @missing_keys ||= []
4
+ end
5
+
6
+ def missing_keys?
7
+ unless missing_keys.empty?
8
+ missing_keys
9
+ end
10
+ end
11
+
12
+ def add_missing_key(key)
13
+ missing_keys << key
14
+ end
15
+
16
+ def reset_missing_keys
17
+ missing_keys.clear
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require 'wirecard_checkout_page/errors'
@@ -0,0 +1,8 @@
1
+ module WirecardCheckoutPage
2
+ # WirecardCheckoutPage version
3
+ VERSION = '0.0.0'
4
+ VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
8
+ end
@@ -0,0 +1 @@
1
+ require 'wirecard_checkout_page/errors'
@@ -0,0 +1,27 @@
1
+ if ENV['START_SIMPLECOV'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "#{File.basename(File.dirname(__FILE__))}/"
5
+ end
6
+ end
7
+
8
+ if ENV.key?('CODECLIMATE_REPO_TOKEN')
9
+ begin
10
+ require "codeclimate-test-reporter"
11
+ rescue LoadError => e
12
+ warn "Caught #{e.class}: #{e.message} loading codeclimate-test-reporter"
13
+ else
14
+ CodeClimate::TestReporter.start
15
+ end
16
+ end
17
+
18
+ require 'rspec'
19
+ require 'byebug'
20
+ require 'wirecard_checkout_page'
21
+
22
+ 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
27
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe WirecardCheckoutPage::Gateway do
4
+ let(:gateway) { WirecardCheckoutPage::Gateway.new(customerId: 'foo', secret: 'bar') }
5
+
6
+ describe '#initialize' do
7
+ 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'
10
+ 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
18
+ end
19
+ end
20
+
21
+ describe '#init' do
22
+ let(:valid_params) do
23
+ {
24
+ amount: '100.00',
25
+ orderDescription: 'order',
26
+ serviceURL: 'service',
27
+ successURL: 'succes',
28
+ cancelURL: 'cancel',
29
+ failureURL: 'failure',
30
+ confirmURL: 'confirm',
31
+ orderReference: '123',
32
+ }
33
+ end
34
+
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
38
+ gateway.init(valid_params)
39
+ end
40
+
41
+ it 'returns a InitResponse with the correct payment url' do
42
+ response = gateway.init(valid_params)
43
+ expect(response).to be_a WirecardCheckoutPage::InitResponse
44
+ expect(response.params).to eq(payment_url: 'payment-url')
45
+ end
46
+ end
47
+
48
+ describe '#response_valid?' do
49
+ it 'builds a checksum with the authorization params' do
50
+ expect(WirecardCheckoutPage::ResponseChecksum).to receive(:new).
51
+ with(hash_including customerId: 'foo', secret: 'bar').and_call_original
52
+ gateway.response_valid?
53
+ end
54
+
55
+ it 'returns true if the response was valid' do
56
+ allow_any_instance_of(WirecardCheckoutPage::ResponseChecksum).to receive(:valid?).and_return(true)
57
+ expect(gateway.response_valid?).to be true
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe WirecardCheckoutPage::InitResponse do
4
+
5
+ let(:success_response) do
6
+ http_response = double(headers: { 'Location' => 'payment-url' }, body: '')
7
+ WirecardCheckoutPage::InitResponse.new(http_response)
8
+ end
9
+
10
+ let(:failure_response) do
11
+ http_response = double(headers: {}, body: 'Error message')
12
+ WirecardCheckoutPage::InitResponse.new(http_response)
13
+ end
14
+
15
+ describe '#params' do
16
+ it 'extracts the payment_url from the headers' do
17
+ expect(success_response.params).to eq({ payment_url: 'payment-url' })
18
+ end
19
+
20
+ it 'returns nil as payment_url on error' do
21
+ expect(failure_response.params).to eq({ payment_url: nil })
22
+ end
23
+ end
24
+
25
+ describe '#success?' do
26
+ it 'returns true if payment_url is present' do
27
+ expect(success_response).to be_success
28
+ end
29
+
30
+ it 'returns false if payment_url is blank' do
31
+ expect(failure_response).not_to be_success
32
+ end
33
+ end
34
+
35
+ describe '#message' do
36
+ it 'returns the response body' do
37
+ expect(success_response.message).to eq ''
38
+ expect(failure_response.message).to eq 'Error message'
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe WirecardCheckoutPage::RequestChecksum do
4
+ let :secret do
5
+ 'SOMESECRET'
6
+ end
7
+
8
+ let :customer_id do
9
+ 'SOMECUSTOMERID'
10
+ end
11
+
12
+ let :shop_id do
13
+ 'someshopid'
14
+ end
15
+
16
+ describe '.new' do
17
+ it "raises a WirecardCheckoutPage::ValueMissing if no values were passed" do
18
+ expect {
19
+ WirecardCheckoutPage::RequestChecksum.new
20
+ }.to raise_error WirecardCheckoutPage::ValueMissing
21
+ end
22
+ end
23
+
24
+ describe '#request_parameters' do
25
+ it "raises a WirecardCheckoutPage::ValueMissing if not all required values were passed" do
26
+ expect {
27
+ WirecardCheckoutPage::RequestChecksum.new(
28
+ secret: 'foo',
29
+ fingerprint_keys: %w[foo bar],
30
+ foo: 'foo'
31
+ ).request_parameters
32
+ }.to raise_error WirecardCheckoutPage::ValueMissing
33
+ end
34
+
35
+ it "doesn't an error if all required values were passed" do
36
+ expect {
37
+ WirecardCheckoutPage::RequestChecksum.new(
38
+ secret: 'foo',
39
+ fingerprint_keys: %w[foo bar],
40
+ foo: 'foo',
41
+ bar: 'bar',
42
+ ).request_parameters
43
+ }.not_to raise_error
44
+ end
45
+
46
+ it 'uses its default parameters and unless they were passed' do
47
+ parameters = WirecardCheckoutPage::RequestChecksum.new(
48
+ secret: 'foo',
49
+ fingerprint_keys: [],
50
+ currency: 'USD'
51
+ ).request_parameters
52
+ expect(parameters).to eq(
53
+ "currency" => "USD",
54
+ "language" => "de",
55
+ "paymentType" => "SELECT",
56
+ "requestFingerprint" => "d41d8cd98f00b204e9800998ecf8427e",
57
+ "requestFingerprintOrder" => "",
58
+ )
59
+ end
60
+
61
+ it "computes a checksum" do
62
+ checksum = WirecardCheckoutPage::RequestChecksum.new(
63
+ secret: secret,
64
+ fingerprint_keys: WirecardCheckoutPage::RequestChecksum::FINGERPRINT_KEYS + %w[shopId],
65
+ customerId: customer_id,
66
+ shopId: shop_id,
67
+ amount: '6.66',
68
+ orderDescription: 'Kauf einer Seele (billig)',
69
+ successURL: 'http://example.com/success',
70
+ cancelURL: 'http://example.com/cancel',
71
+ failureURL: 'http://example.com/failure',
72
+ serviceURL: 'http://example.com',
73
+ confirmURL: 'http://example.com/confirm',
74
+ orderReference: '475ae67f248578b92a701',
75
+ )
76
+ expect(checksum.__send__(:fingerprint)).to eq "10feda94a5db9f3e2fc7439d3c4c228b"
77
+ expect(checksum.request_parameters).to eq(
78
+ "customerId" => customer_id,
79
+ "shopId" => shop_id,
80
+ "paymentType" => "SELECT",
81
+ "currency" => "EUR",
82
+ "language" => "de",
83
+ "amount" => "6.66",
84
+ "orderDescription" => "Kauf einer Seele (billig)",
85
+ "successURL" => "http://example.com/success",
86
+ "cancelURL" => "http://example.com/cancel",
87
+ "failureURL" => "http://example.com/failure",
88
+ "serviceURL" => "http://example.com",
89
+ "confirmURL" => "http://example.com/confirm",
90
+ "orderReference" => "475ae67f248578b92a701",
91
+ "requestFingerprintOrder" => checksum.fingerprint_keys * ',',
92
+ "requestFingerprint" => "10feda94a5db9f3e2fc7439d3c4c228b"
93
+ )
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+ require 'wirecard_checkout_page'
3
+
4
+ describe WirecardCheckoutPage::ResponseChecksum do
5
+ let :secret do
6
+ 'SOMESECRET'
7
+ end
8
+
9
+ let :customer_id do
10
+ 'SOMECUSTOMERID'
11
+ end
12
+
13
+ let :shop_id do
14
+ 'someshopid'
15
+ end
16
+
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
53
+
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
87
+ end
88
+
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
124
+
125
+ it "fails check in an empty response" do
126
+ expect(WirecardCheckoutPage::ResponseChecksum.new(secret: secret)).to_not be_valid
127
+ end
128
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: wirecard_checkout_page 0.0.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "wirecard_checkout_page"
6
+ s.version = "0.0.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Florian Frank"]
11
+ s.date = "2014-10-24"
12
+ s.description = "This library allows you to use the Wirecard Checkout Page service."
13
+ s.email = "flori@ping.de"
14
+ s.extra_rdoc_files = ["README.md", "lib/wirecard_checkout_page.rb", "lib/wirecard_checkout_page/errors.rb", "lib/wirecard_checkout_page/gateway.rb", "lib/wirecard_checkout_page/init_response.rb", "lib/wirecard_checkout_page/request_checksum.rb", "lib/wirecard_checkout_page/response_checksum.rb", "lib/wirecard_checkout_page/utils.rb", "lib/wirecard_checkout_page/value_handling.rb", "lib/wirecard_checkout_page/value_missing.rb", "lib/wirecard_checkout_page/version.rb", "lib/wirecard_checkout_page/wirecard_checkout_page_error.rb"]
15
+ s.files = [".gitignore", ".rspec", ".travis.yml", "Gemfile", "README.md", "Rakefile", "VERSION", "lib/wirecard_checkout_page.rb", "lib/wirecard_checkout_page/errors.rb", "lib/wirecard_checkout_page/gateway.rb", "lib/wirecard_checkout_page/init_response.rb", "lib/wirecard_checkout_page/request_checksum.rb", "lib/wirecard_checkout_page/response_checksum.rb", "lib/wirecard_checkout_page/utils.rb", "lib/wirecard_checkout_page/value_handling.rb", "lib/wirecard_checkout_page/value_missing.rb", "lib/wirecard_checkout_page/version.rb", "lib/wirecard_checkout_page/wirecard_checkout_page_error.rb", "spec/spec_helper.rb", "spec/wirecard_checkout_page/gateway_spec.rb", "spec/wirecard_checkout_page/init_response_spec.rb", "spec/wirecard_checkout_page/request_checksum_spec.rb", "spec/wirecard_checkout_page/response_checksum_spec.rb", "wirecard_checkout_page.gemspec"]
16
+ s.homepage = "http://flori.github.com/wirecard_checkout_page"
17
+ s.licenses = ["Apache-2.0"]
18
+ s.rdoc_options = ["--title", "WirecardCheckoutPage -- Wirecard Checkout Page implementation", "--main", "README.md"]
19
+ s.rubygems_version = "2.2.2"
20
+ s.summary = "Library for using Wirecard Checkout Page"
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 4
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<gem_hadar>, ["~> 1.0.0"])
27
+ s.add_development_dependency(%q<rake>, [">= 0"])
28
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
29
+ s.add_development_dependency(%q<rspec>, [">= 0"])
30
+ s.add_development_dependency(%q<byebug>, [">= 0"])
31
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
32
+ else
33
+ s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
34
+ s.add_dependency(%q<rake>, [">= 0"])
35
+ s.add_dependency(%q<simplecov>, [">= 0"])
36
+ s.add_dependency(%q<rspec>, [">= 0"])
37
+ s.add_dependency(%q<byebug>, [">= 0"])
38
+ s.add_dependency(%q<typhoeus>, [">= 0"])
39
+ end
40
+ else
41
+ s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
42
+ s.add_dependency(%q<rake>, [">= 0"])
43
+ s.add_dependency(%q<simplecov>, [">= 0"])
44
+ s.add_dependency(%q<rspec>, [">= 0"])
45
+ s.add_dependency(%q<byebug>, [">= 0"])
46
+ s.add_dependency(%q<typhoeus>, [">= 0"])
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wirecard_checkout_page
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Frank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_hadar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: typhoeus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This library allows you to use the Wirecard Checkout Page service.
98
+ email: flori@ping.de
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.md
103
+ - lib/wirecard_checkout_page.rb
104
+ - lib/wirecard_checkout_page/errors.rb
105
+ - lib/wirecard_checkout_page/gateway.rb
106
+ - lib/wirecard_checkout_page/init_response.rb
107
+ - lib/wirecard_checkout_page/request_checksum.rb
108
+ - lib/wirecard_checkout_page/response_checksum.rb
109
+ - lib/wirecard_checkout_page/utils.rb
110
+ - lib/wirecard_checkout_page/value_handling.rb
111
+ - lib/wirecard_checkout_page/value_missing.rb
112
+ - lib/wirecard_checkout_page/version.rb
113
+ - lib/wirecard_checkout_page/wirecard_checkout_page_error.rb
114
+ files:
115
+ - .gitignore
116
+ - .rspec
117
+ - .travis.yml
118
+ - Gemfile
119
+ - README.md
120
+ - Rakefile
121
+ - VERSION
122
+ - lib/wirecard_checkout_page.rb
123
+ - lib/wirecard_checkout_page/errors.rb
124
+ - lib/wirecard_checkout_page/gateway.rb
125
+ - lib/wirecard_checkout_page/init_response.rb
126
+ - lib/wirecard_checkout_page/request_checksum.rb
127
+ - lib/wirecard_checkout_page/response_checksum.rb
128
+ - lib/wirecard_checkout_page/utils.rb
129
+ - lib/wirecard_checkout_page/value_handling.rb
130
+ - lib/wirecard_checkout_page/value_missing.rb
131
+ - lib/wirecard_checkout_page/version.rb
132
+ - lib/wirecard_checkout_page/wirecard_checkout_page_error.rb
133
+ - spec/spec_helper.rb
134
+ - spec/wirecard_checkout_page/gateway_spec.rb
135
+ - spec/wirecard_checkout_page/init_response_spec.rb
136
+ - spec/wirecard_checkout_page/request_checksum_spec.rb
137
+ - spec/wirecard_checkout_page/response_checksum_spec.rb
138
+ - wirecard_checkout_page.gemspec
139
+ homepage: http://flori.github.com/wirecard_checkout_page
140
+ licenses:
141
+ - Apache-2.0
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options:
145
+ - --title
146
+ - WirecardCheckoutPage -- Wirecard Checkout Page implementation
147
+ - --main
148
+ - README.md
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.2.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Library for using Wirecard Checkout Page
167
+ test_files: []