wirecard_sepa 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6f8ab6d149ae746b1da4e8c9dee77c03bdb64ac
4
- data.tar.gz: bbddcf297b2f0c1c7417ff5658ae1203215f0df7
3
+ metadata.gz: 04e43db72ba035b59d9e26101b5c84664fdd745f
4
+ data.tar.gz: 2e174adf77802fce273870d8f72a57b7a1cf9cf7
5
5
  SHA512:
6
- metadata.gz: 36d6830f071919380ddd9719eb37a676526b1dd9b7b2eea500650297ee61eb564b3454ea3419c5f45c609ebd01f394bc3f1c96ddfbad5c977ccdce5dd8b772b4
7
- data.tar.gz: c9bf7b247c5b6c68c5ef0220c68056c7438faf5ab1052df93131875d93e4054648e6d62a48b6f26d677d045d1a91aa299126a6a3bb2350b0253ad4ba108c7763
6
+ metadata.gz: 449083675e209e5aa7956326e0a448a7fb41e444c9ce6b86f18ffaf6dd29cdc0e67862940e6f92e2ef00b7039270004f9a0e71db0d824a525146ade84d7cd8d9
7
+ data.tar.gz: 2edcc3b230df93a2cf7e740e70a72a17c180beab3897c7fdda76536d94e4cce13004e819968d1bc1b8ea7f7980a5b3c915d349587f537c080b22ba2492949bfc
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ /pkg/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.1
3
+ - 2.2
data/README.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Wirecard SEPA
2
+ [![Build Status](https://api.travis-ci.org/betterplace/wirecard_sepa.svg?branch=master)](http://travis-ci.org/betterplace/wirecard_sepa)
3
+ [![Code Climate](https://codeclimate.com/repos/55494936e30ba04e91005d6e/badges/cd0d22df220babab1b66/gpa.svg)](https://codeclimate.com/repos/55494936e30ba04e91005d6e/feed)
4
+
2
5
  A WORK IN PROGRESS PROJECT
3
6
 
7
+ ## TODOS
8
+ 1. Error Handling
9
+ 1. Maybe cache template files (are they loaded from disk each request?)
10
+ 1. Docs for usage in README.md
11
+ 1. Check Recurring Request/Response
12
+
4
13
  ## Contributing
5
14
  1. Fork it ( https://github.com/betterplace/wirecard_sepa/fork )
6
15
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -14,7 +14,7 @@
14
14
  <iban>{{BANK_ACCOUNT_IBAN}}</iban>
15
15
  <bic>{{BANK_ACCOUNT_BIC}}</bic>
16
16
  </bank-account>
17
- <mandate>
17
+ <mandate>
18
18
  <mandate-id>{{MANDATE_ID}}</mandate-id>
19
19
  <signed-date>{{MANDATE_SIGNED_DATE}}</signed-date>
20
20
  </mandate>
@@ -1,61 +1,22 @@
1
1
  module WirecardSepa
2
2
  # Usage:
3
3
  # WirecardSepa::Config.new({
4
+ # api_url: 'https://api-test.wirecard.com/engine/rest/paymentmethods',
4
5
  # http_auth_username: 'foo',
5
6
  # http_auth_password: 'bar',
6
- #
7
+ # merchant_account_id: '123',
8
+ # credit_id: '987',
7
9
  # })
8
10
  # => config
9
- #
10
- # For sandbox testing the config provides a hardcoded config object
11
- # WirecardSepa::Config.for_sandbox
12
- # => config # Object with all necessary infos for sandbox testing
13
11
  class Config
14
- AUTH_PARAMS = %i(http_auth_username http_auth_password)
15
- REQUEST_PARAMS = %i(merchant_account_id creditor_id)
16
- EXPECTED_PARAMS = AUTH_PARAMS + REQUEST_PARAMS
17
-
18
- attr_accessor *EXPECTED_PARAMS
19
- attr_reader :params
20
-
21
- def initialize(params = {})
22
- if params.keys.sort != EXPECTED_PARAMS.sort
23
- raise Errors::InvalidParamsError.new(
24
- "Please provide a hash exactly with the following keys: #{EXPECTED_PARAMS}\n" +
25
- "Missing params: #{EXPECTED_PARAMS - params.keys}\n" +
26
- "Unexpected params: #{params.keys - EXPECTED_PARAMS}"
27
- )
28
- end
29
- @params = params
30
- end
31
-
32
- def self.for_sandbox
33
- new(
34
- http_auth_username: '70000-APITEST-AP',
35
- http_auth_password: 'qD2wzQ_hrc!8',
36
- merchant_account_id: '4c901196-eff7-411e-82a3-5ef6b6860d64',
37
- creditor_id: 'abcdef'
38
- )
39
- end
40
-
41
- def http_auth_username
42
- params[:http_auth_username]
43
- end
44
-
45
- def http_auth_password
46
- params[:http_auth_password]
47
- end
48
-
49
- def [](key)
50
- params[key]
51
- end
52
-
53
- def request_params
54
- REQUEST_PARAMS.each_with_object({}) { |key, h| h[key] = params[key] }
55
- end
56
-
57
- def to_hash
58
- params
12
+ attr_reader :api_url, :http_auth_username, :http_auth_password, :merchant_account_id, :creditor_id
13
+
14
+ def initialize(api_url:, http_auth_username:, http_auth_password:, merchant_account_id:, creditor_id:)
15
+ @api_url = api_url
16
+ @http_auth_username = http_auth_username
17
+ @http_auth_password = http_auth_password
18
+ @merchant_account_id = merchant_account_id
19
+ @creditor_id = creditor_id
59
20
  end
60
21
  end
61
22
  end
@@ -1,21 +1,26 @@
1
1
  module WirecardSepa
2
2
  module DirectDebit
3
3
  class Response
4
- attr_reader :xml
4
+ attr_reader :xml, :request
5
5
 
6
- def initialize(xml)
6
+ def self.for_request(request)
7
+ new(request.body, request: request)
8
+ end
9
+
10
+ def initialize(xml, request: nil)
7
11
  @xml = xml
12
+ @request = request
8
13
  end
9
14
 
10
15
  def params
11
16
  {
12
- success: success?,
13
- transaction_id: transaction_id,
14
- transaction_state: transaction_state,
15
- status_code: status_code,
16
- status_description: status_description,
17
- due_date: due_date,
18
- reference_id: provider_transaction_reference_id,
17
+ success: success?,
18
+ transaction_id: transaction_id,
19
+ transaction_state: transaction_state,
20
+ status_code: status_code,
21
+ status_description: status_description,
22
+ due_date: due_date,
23
+ reference_id: provider_transaction_reference_id,
19
24
  original_response_xml: xml,
20
25
  }
21
26
  end
@@ -24,8 +29,6 @@ module WirecardSepa
24
29
  status_code == '201.0000'
25
30
  end
26
31
 
27
- private
28
-
29
32
  def transaction_id
30
33
  xml_doc.at_css('transaction-id').text
31
34
  end
@@ -50,6 +53,8 @@ module WirecardSepa
50
53
  xml_doc.at_css('provider-transaction-reference-id').text
51
54
  end
52
55
 
56
+ private
57
+
53
58
  def xml_doc
54
59
  @xml_doc ||= Nokogiri::XML xml
55
60
  end
@@ -1,6 +1,3 @@
1
- require 'securerandom'
2
- require 'typhoeus'
3
-
4
1
  module WirecardSepa
5
2
  # Usage:
6
3
  # config = WirecardSepa::Config.new(...)
@@ -20,43 +17,41 @@ module WirecardSepa
20
17
 
21
18
  def debit(params)
22
19
  request_params = params.merge({
23
- merchant_account_id: config[:merchant_account_id],
24
- creditor_id: config[:creditor_id],
20
+ merchant_account_id: config.merchant_account_id,
21
+ creditor_id: config.creditor_id,
25
22
  request_id: request_id,
26
23
  })
27
24
  request_xml = DirectDebit::Request.new(request_params).to_xml
28
- response_xml = post(request_xml).body
29
- DirectDebit::Response.new response_xml
25
+ DirectDebit::Response.for_request post(request_xml)
30
26
  end
31
27
 
32
28
  def recurring_init(params)
33
29
  request_params = params.merge({
34
- merchant_account_id: config[:merchant_account_id],
35
- creditor_id: config[:creditor_id],
30
+ merchant_account_id: config.merchant_account_id,
31
+ creditor_id: config.creditor_id,
36
32
  request_id: request_id,
37
33
  })
38
34
  request_xml = Recurring::FirstRequest.new(request_params).to_xml
39
- response_xml = post(request_xml).body
40
- Recurring::FirstResponse.new response_xml
35
+ Recurring::FirstResponse.for_request post(request_xml)
41
36
  end
42
37
 
43
38
  def recurring_process(params)
44
39
  request_params = params.merge({
45
- merchant_account_id: config[:merchant_account_id],
40
+ merchant_account_id: config.merchant_account_id,
46
41
  request_id: request_id,
47
42
  })
48
43
  request_xml = Recurring::RecurringRequest.new(request_params).to_xml
49
- response_xml = post(request_xml).body
50
- Recurring::RecurringResponse.new response_xml
44
+ Recurring::RecurringResponse.for_request post(request_xml)
51
45
  end
52
46
 
53
47
  private
54
48
 
55
49
  def post(request_xml)
56
50
  Typhoeus.post(
57
- WirecardSepa.gateway_url,
51
+ config.api_url,
58
52
  body: request_xml,
59
53
  userpwd: http_auth_credentials,
54
+ headers: { 'Content-Type' => 'application/xml' }
60
55
  )
61
56
  end
62
57
 
@@ -66,6 +61,8 @@ module WirecardSepa
66
61
  # This is the identification number of the request on the merchants side.
67
62
  # It must be unique for each request.
68
63
  # Sample Request-ID: 048b27e0-9c31-4cab-9eab-3b72b1b4d498
64
+ # SecureRandom.uuid
65
+ # SecureRandom.uuid
69
66
  SecureRandom.uuid
70
67
  end
71
68
 
@@ -5,7 +5,6 @@ module WirecardSepa
5
5
 
6
6
  def validate!(params, expected_params)
7
7
  if params.keys.sort != expected_params.sort
8
- # TODO: Provide link to official wirecard spec which explains the use of the keys
9
8
  raise Errors::InvalidParamsError.new(
10
9
  "Please provide a hash exactly with the following keys: #{expected_params}\n" +
11
10
  "Missing params: #{expected_params - params.keys}\n" +
@@ -8,8 +8,8 @@ module WirecardSepa
8
8
  end
9
9
 
10
10
  def to_xml
11
- xml_template = File.read template_path
12
- xml_template.gsub /{{\w+}}/, request_params
11
+ xml_template = File.open template_path, "r:UTF-8", &:read
12
+ xml_template.gsub(/{{\w+}}/, request_params)
13
13
  end
14
14
 
15
15
  private
@@ -1,3 +1,3 @@
1
1
  module WirecardSepa
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/wirecard_sepa.rb CHANGED
@@ -1,4 +1,7 @@
1
+ require 'securerandom'
2
+ require 'typhoeus'
1
3
  require 'nokogiri'
4
+
2
5
  require 'wirecard_sepa/version'
3
6
  require 'wirecard_sepa/errors'
4
7
  require 'wirecard_sepa/utils/template'
@@ -13,18 +16,4 @@ require 'wirecard_sepa/config'
13
16
  require 'wirecard_sepa/gateway'
14
17
 
15
18
  module WirecardSepa
16
- SANDBOX_URL = 'https://api-test.wirecard.com/engine/rest/paymentmethods/'
17
- LIVE_URL = ''
18
-
19
- def self.sandbox!
20
- @live = true
21
- end
22
-
23
- def self.sandboxed?
24
- !@live
25
- end
26
-
27
- def self.gateway_url
28
- sandboxed? ? SANDBOX_URL : LIVE_URL
29
- end
30
19
  end
@@ -4,6 +4,7 @@ describe WirecardSepa::Config do
4
4
  let(:config) { described_class.new(valid_params) }
5
5
  let(:valid_params) do
6
6
  {
7
+ api_url: 'http://example.com',
7
8
  http_auth_username: 'alice',
8
9
  http_auth_password: 'secret',
9
10
  merchant_account_id: '123',
@@ -11,23 +12,6 @@ describe WirecardSepa::Config do
11
12
  }
12
13
  end
13
14
 
14
- describe '#initialize' do
15
- it 'raises an Error when unexpected param keys are provided' do
16
- expect {
17
- described_class.new(valid_params.merge({ unexpected_key: 'foo' }))
18
- }.to raise_error WirecardSepa::Errors::InvalidParamsError
19
- end
20
- end
21
-
22
- describe '#request_params' do
23
- it 'returns the params for the request' do
24
- expect(config.request_params).to eq({
25
- merchant_account_id: '123',
26
- creditor_id: '31415',
27
- })
28
- end
29
- end
30
-
31
15
  describe '#http_auth_username' do
32
16
  it 'returns the http auth username' do
33
17
  expect(config.http_auth_username).to eq 'alice'
@@ -39,14 +23,4 @@ describe WirecardSepa::Config do
39
23
  expect(config.http_auth_password).to eq 'secret'
40
24
  end
41
25
  end
42
-
43
- describe '.for_sandbox' do
44
- it 'returns a config object with the correct sandbox settings' do
45
- config = described_class.for_sandbox
46
- expect(config[:http_auth_username]).to eq '70000-APITEST-AP'
47
- expect(config[:http_auth_password]).to eq 'qD2wzQ_hrc!8'
48
- expect(config[:merchant_account_id]).to eq '4c901196-eff7-411e-82a3-5ef6b6860d64'
49
- expect(config[:creditor_id]).to eq 'abcdef'
50
- end
51
- end
52
26
  end
@@ -30,5 +30,13 @@ describe WirecardSepa::DirectDebit::Request do
30
30
  expected_xml = read_support_file('direct_debit/success/request.xml')
31
31
  expect(subject.to_xml).to eq expected_xml
32
32
  end
33
+
34
+ it 'builds a valid request' do
35
+ xsd = Nokogiri::XML::Schema(read_support_file('payment.xsd'))
36
+ doc = Nokogiri::XML(subject.to_xml)
37
+
38
+ errors = xsd.validate(doc)
39
+ expect(errors).to be_empty
40
+ end
33
41
  end
34
42
  end
@@ -7,6 +7,19 @@ describe WirecardSepa::DirectDebit::Response do
7
7
  let(:success_response) { described_class.new success_xml }
8
8
  let(:failure_response) { described_class.new failure_xml }
9
9
 
10
+ describe '.for_request(request)' do
11
+ let(:request) { double('Fake Typhoeus request', body: '</xml>') }
12
+ let(:response) { described_class.for_request(request) }
13
+
14
+ it 'takes a uses the requests body to create a response' do
15
+ expect(response.xml).to eq '</xml>'
16
+ end
17
+
18
+ it 'stores the request object for debugging cases' do
19
+ expect(response.request).to eq request
20
+ end
21
+ end
22
+
10
23
  describe '#params' do
11
24
  context 'for a successful response' do
12
25
  let(:params) { success_response.params }
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe WirecardSepa::Gateway do
4
- let(:config) { WirecardSepa::Config.for_sandbox }
5
- let(:gateway) { described_class.new(config) }
4
+ let(:gateway) { described_class.new(sandbox_gateway_config) }
6
5
 
7
6
  describe '#debit(params)' do
8
7
  let(:params) do
@@ -24,6 +23,7 @@ describe WirecardSepa::Gateway do
24
23
  # "The Request Identifier has not been provided. Please check your input and try again."
25
24
  # Status-Code: 400.1010
26
25
  # expect(response).to be_success
26
+ expect(response.request.headers['Content-Type']).to eq 'application/xml;charset=UTF-8'
27
27
  end
28
28
  end
29
29
 
@@ -4,6 +4,19 @@ describe WirecardSepa::Recurring::FirstResponse do
4
4
  let(:success_xml) { read_support_file('recurring/success/first_response.xml') }
5
5
  let(:success_response) { described_class.new success_xml }
6
6
 
7
+ describe '.for_request(request)' do
8
+ let(:request) { double('Fake Typhoeus request', body: '</xml>') }
9
+ let(:response) { described_class.for_request(request) }
10
+
11
+ it 'takes a uses the requests body to create a response' do
12
+ expect(response.xml).to eq '</xml>'
13
+ end
14
+
15
+ it 'stores the request object for debugging cases' do
16
+ expect(response.request).to eq request
17
+ end
18
+ end
19
+
7
20
  describe '#params' do
8
21
  context 'for a successful response' do
9
22
  let(:params) { success_response.params }
@@ -4,6 +4,19 @@ describe WirecardSepa::Recurring::RecurringResponse do
4
4
  let(:success_xml) { read_support_file('recurring/success/recurring_response.xml') }
5
5
  let(:success_response) { described_class.new success_xml }
6
6
 
7
+ describe '.for_request(request)' do
8
+ let(:request) { double('Fake Typhoeus request', body: '</xml>') }
9
+ let(:response) { described_class.for_request(request) }
10
+
11
+ it 'takes a uses the requests body to create a response' do
12
+ expect(response.xml).to eq '</xml>'
13
+ end
14
+
15
+ it 'stores the request object for debugging cases' do
16
+ expect(response.request).to eq request
17
+ end
18
+ end
19
+
7
20
  describe '#params' do
8
21
  context 'for a successful response' do
9
22
  let(:params) { success_response.params }
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,17 @@ require 'byebug'
9
9
  # end
10
10
  # SimpleCov.start 'gem'
11
11
  def read_support_file(file_path)
12
- File.read File.expand_path("../support/#{file_path}", __FILE__)
12
+ File.open File.expand_path("../support/#{file_path}", __FILE__), "r:UTF-8", &:read
13
+ end
14
+
15
+ def sandbox_gateway_config
16
+ WirecardSepa::Config.new({
17
+ api_url: 'https://api-test.wirecard.com/engine/rest/paymentmethods/',
18
+ http_auth_username: '70000-APITEST-AP',
19
+ http_auth_password: 'qD2wzQ_hrc!8',
20
+ merchant_account_id: '4c901196-eff7-411e-82a3-5ef6b6860d64',
21
+ creditor_id: 'abcdef',
22
+ })
13
23
  end
14
24
 
15
25
  require 'wirecard_sepa'