wirecard_sepa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +54 -0
  5. data/LICENSE +202 -0
  6. data/README.md +9 -0
  7. data/Rakefile +14 -0
  8. data/lib/templates/wirecard_sepa/direct_debit/request.xml +23 -0
  9. data/lib/templates/wirecard_sepa/recurring/first_request.xml +27 -0
  10. data/lib/templates/wirecard_sepa/recurring/recurring_request.xml +13 -0
  11. data/lib/wirecard_sepa/config.rb +61 -0
  12. data/lib/wirecard_sepa/direct_debit/request.rb +24 -0
  13. data/lib/wirecard_sepa/direct_debit/response.rb +58 -0
  14. data/lib/wirecard_sepa/errors.rb +5 -0
  15. data/lib/wirecard_sepa/gateway.rb +76 -0
  16. data/lib/wirecard_sepa/recurring/first_request.rb +24 -0
  17. data/lib/wirecard_sepa/recurring/first_response.rb +6 -0
  18. data/lib/wirecard_sepa/recurring/recurring_request.rb +22 -0
  19. data/lib/wirecard_sepa/recurring/recurring_response.rb +6 -0
  20. data/lib/wirecard_sepa/utils/params_validator.rb +18 -0
  21. data/lib/wirecard_sepa/utils/template.rb +35 -0
  22. data/lib/wirecard_sepa/version.rb +3 -0
  23. data/lib/wirecard_sepa.rb +30 -0
  24. data/spec/lib/wirecard_sepa/config_spec.rb +52 -0
  25. data/spec/lib/wirecard_sepa/direct_debit/request_spec.rb +34 -0
  26. data/spec/lib/wirecard_sepa/direct_debit/response_spec.rb +32 -0
  27. data/spec/lib/wirecard_sepa/gateway_spec.rb +65 -0
  28. data/spec/lib/wirecard_sepa/recurring/first_request_spec.rb +34 -0
  29. data/spec/lib/wirecard_sepa/recurring/first_response_spec.rb +25 -0
  30. data/spec/lib/wirecard_sepa/recurring/recurring_request_spec.rb +28 -0
  31. data/spec/lib/wirecard_sepa/recurring/recurring_response_spec.rb +25 -0
  32. data/spec/lib/wirecard_sepa_spec.rb +4 -0
  33. data/spec/spec_helper.rb +15 -0
  34. data/spec/support/direct_debit/failure/request.xml +19 -0
  35. data/spec/support/direct_debit/failure/response.xml +25 -0
  36. data/spec/support/direct_debit/success/request.xml +23 -0
  37. data/spec/support/direct_debit/success/response.xml +31 -0
  38. data/spec/support/recurring/failure/recurring_request.xml +27 -0
  39. data/spec/support/recurring/failure/recurring_response.xml +33 -0
  40. data/spec/support/recurring/success/first_request.xml +27 -0
  41. data/spec/support/recurring/success/first_response.xml +34 -0
  42. data/spec/support/recurring/success/recurring_request.xml +13 -0
  43. data/spec/support/recurring/success/recurring_response.xml +35 -0
  44. data/wirecard_sepa.gemspec +29 -0
  45. metadata +205 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6f8ab6d149ae746b1da4e8c9dee77c03bdb64ac
4
+ data.tar.gz: bbddcf297b2f0c1c7417ff5658ae1203215f0df7
5
+ SHA512:
6
+ metadata.gz: 36d6830f071919380ddd9719eb37a676526b1dd9b7b2eea500650297ee61eb564b3454ea3419c5f45c609ebd01f394bc3f1c96ddfbad5c977ccdce5dd8b772b4
7
+ data.tar.gz: c9bf7b247c5b6c68c5ef0220c68056c7438faf5ab1052df93131875d93e4054648e6d62a48b6f26d677d045d1a91aa299126a6a3bb2350b0253ad4ba108c7763
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wirecard_sepa (0.0.1)
5
+ nokogiri
6
+ typhoeus
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ byebug (4.0.5)
12
+ columnize (= 0.9.0)
13
+ columnize (0.9.0)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.5)
16
+ ethon (0.7.3)
17
+ ffi (>= 1.3.0)
18
+ ffi (1.9.8)
19
+ json (1.8.2)
20
+ mini_portile (0.6.2)
21
+ nokogiri (1.6.6.2)
22
+ mini_portile (~> 0.6.0)
23
+ rake (10.4.2)
24
+ rspec (3.2.0)
25
+ rspec-core (~> 3.2.0)
26
+ rspec-expectations (~> 3.2.0)
27
+ rspec-mocks (~> 3.2.0)
28
+ rspec-core (3.2.3)
29
+ rspec-support (~> 3.2.0)
30
+ rspec-expectations (3.2.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.2.0)
33
+ rspec-mocks (3.2.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.2.0)
36
+ rspec-support (3.2.2)
37
+ simplecov (0.10.0)
38
+ docile (~> 1.1.0)
39
+ json (~> 1.8)
40
+ simplecov-html (~> 0.10.0)
41
+ simplecov-html (0.10.0)
42
+ typhoeus (0.7.1)
43
+ ethon (>= 0.7.1)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (~> 1.9)
50
+ byebug
51
+ rake (~> 10.4)
52
+ rspec
53
+ simplecov
54
+ wirecard_sepa!
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Wirecard SEPA
2
+ A WORK IN PROGRESS PROJECT
3
+
4
+ ## Contributing
5
+ 1. Fork it ( https://github.com/betterplace/wirecard_sepa/fork )
6
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
7
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
8
+ 4. Push to the branch (`git push origin my-new-feature`)
9
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
6
+
7
+ desc 'Open an irb session preloaded with this library'
8
+ task :console do
9
+ require 'irb'
10
+ require 'irb/completion'
11
+ require 'wirecard_giropay'
12
+ ARGV.clear
13
+ IRB.start
14
+ end
@@ -0,0 +1,23 @@
1
+ <payment xmlns="http://www.elastic-payments.com/schema/payment">
2
+ <merchant-account-id>{{MERCHANT_ACCOUNT_ID}}</merchant-account-id>
3
+ <request-id>{{REQUEST_ID}}</request-id>
4
+ <transaction-type>pending-debit</transaction-type>
5
+ <requested-amount currency="EUR">{{REQUESTED_AMOUNT}}</requested-amount>
6
+ <account-holder>
7
+ <first-name>{{ACCOUNT_HOLDER_FIRST_NAME}}</first-name>
8
+ <last-name>{{ACCOUNT_HOLDER_LAST_NAME}}</last-name>
9
+ </account-holder>
10
+ <payment-methods>
11
+ <payment-method name="sepadirectdebit"/>
12
+ </payment-methods>
13
+ <bank-account>
14
+ <iban>{{BANK_ACCOUNT_IBAN}}</iban>
15
+ <bic>{{BANK_ACCOUNT_BIC}}</bic>
16
+ </bank-account>
17
+  <mandate>
18
+ <mandate-id>{{MANDATE_ID}}</mandate-id>
19
+ <signed-date>{{MANDATE_SIGNED_DATE}}</signed-date>
20
+ </mandate>
21
+ <creditor-id>{{CREDITOR_ID}}</creditor-id>
22
+ </payment>
23
+
@@ -0,0 +1,27 @@
1
+ <payment xmlns="http://www.elastic-payments.com/schema/payment">
2
+ <merchant-account-id>{{MERCHANT_ACCOUNT_ID}}</merchant-account-id>
3
+ <request-id>{{REQUEST_ID}}</request-id>
4
+ <transaction-type>debit</transaction-type>
5
+ <requested-amount currency="EUR">{{REQUESTED_AMOUNT}}</requested-amount>
6
+ <account-holder>
7
+ <first-name>{{ACCOUNT_HOLDER_FIRST_NAME}}</first-name>
8
+ <last-name>{{ACCOUNT_HOLDER_LAST_NAME}}</last-name>
9
+ </account-holder>
10
+ <payment-methods>
11
+ <payment-method name="sepadirectdebit" />
12
+ </payment-methods>
13
+ <bank-account>
14
+ <iban>{{BANK_ACCOUNT_IBAN}}</iban>
15
+ <bic>{{BANK_ACCOUNT_BIC}}</bic>
16
+ </bank-account>
17
+ <mandate>
18
+ <mandate-id>{{MANDATE_ID}}</mandate-id>
19
+ <signed-date>{{MANDATE_SIGNED_DATE}}</signed-date>
20
+ </mandate>
21
+ <creditor-id>{{CREDITOR_ID}}</creditor-id>
22
+ <periodic>
23
+ <periodic-type>recurring</periodic-type>
24
+ <sequence-type>first</sequence-type>
25
+ </periodic>
26
+ </payment>
27
+
@@ -0,0 +1,13 @@
1
+ <payment xmlns="http://www.elastic-payments.com/schema/payment">
2
+ <merchant-account-id>{{MERCHANT_ACCOUNT_ID}}</merchant-account-id>
3
+ <request-id>{{REQUEST_ID}}</request-id>
4
+ <transaction-type>debit</transaction-type>
5
+ <parent-transaction-id>{{PARENT_TRANSACTION_ID}}</parent-transaction-id>
6
+ <payment-methods>
7
+ <payment-method name="sepadirectdebit" />
8
+ </payment-methods>
9
+ <periodic>
10
+ <periodic-type>recurring</periodic-type>
11
+ <sequence-type>recurring</sequence-type>
12
+ </periodic>
13
+ </payment>
@@ -0,0 +1,61 @@
1
+ module WirecardSepa
2
+ # Usage:
3
+ # WirecardSepa::Config.new({
4
+ # http_auth_username: 'foo',
5
+ # http_auth_password: 'bar',
6
+ # …
7
+ # })
8
+ # => 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
+ 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
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ module WirecardSepa
2
+ module DirectDebit
3
+ class Request
4
+ attr_reader :params
5
+
6
+ def initialize(params = {})
7
+ Utils::ParamsValidator.validate!(params, expected_params)
8
+ @params = params
9
+ end
10
+
11
+ def to_xml
12
+ Utils::Template.new(self).to_xml
13
+ end
14
+
15
+ private
16
+
17
+ def expected_params
18
+ %i( merchant_account_id request_id requested_amount
19
+ account_holder_first_name account_holder_last_name bank_account_iban
20
+ bank_account_bic mandate_id mandate_signed_date creditor_id )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,58 @@
1
+ module WirecardSepa
2
+ module DirectDebit
3
+ class Response
4
+ attr_reader :xml
5
+
6
+ def initialize(xml)
7
+ @xml = xml
8
+ end
9
+
10
+ def params
11
+ {
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,
19
+ original_response_xml: xml,
20
+ }
21
+ end
22
+
23
+ def success?
24
+ status_code == '201.0000'
25
+ end
26
+
27
+ private
28
+
29
+ def transaction_id
30
+ xml_doc.at_css('transaction-id').text
31
+ end
32
+
33
+ def transaction_state
34
+ xml_doc.at_css('transaction-state').text
35
+ end
36
+
37
+ def status_code
38
+ xml_doc.at_css('status')[:code]
39
+ end
40
+
41
+ def status_description
42
+ xml_doc.at_css('status')[:description]
43
+ end
44
+
45
+ def due_date
46
+ xml_doc.at_css('due-date').text
47
+ end
48
+
49
+ def provider_transaction_reference_id
50
+ xml_doc.at_css('provider-transaction-reference-id').text
51
+ end
52
+
53
+ def xml_doc
54
+ @xml_doc ||= Nokogiri::XML xml
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module WirecardSepa
2
+ module Errors
3
+ InvalidParamsError = Class.new StandardError
4
+ end
5
+ end
@@ -0,0 +1,76 @@
1
+ require 'securerandom'
2
+ require 'typhoeus'
3
+
4
+ module WirecardSepa
5
+ # Usage:
6
+ # config = WirecardSepa::Config.new(...)
7
+ # gateway = WirecardSepa::Gateway.new(config)
8
+ #
9
+ # gateway.debit({ requested_amount: 12.12, .. })
10
+ # => response
11
+ #
12
+ # gateway.recurring_init
13
+ # => response
14
+ class Gateway
15
+ attr_accessor :config
16
+
17
+ def initialize(config)
18
+ @config = config
19
+ end
20
+
21
+ def debit(params)
22
+ request_params = params.merge({
23
+ merchant_account_id: config[:merchant_account_id],
24
+ creditor_id: config[:creditor_id],
25
+ request_id: request_id,
26
+ })
27
+ request_xml = DirectDebit::Request.new(request_params).to_xml
28
+ response_xml = post(request_xml).body
29
+ DirectDebit::Response.new response_xml
30
+ end
31
+
32
+ def recurring_init(params)
33
+ request_params = params.merge({
34
+ merchant_account_id: config[:merchant_account_id],
35
+ creditor_id: config[:creditor_id],
36
+ request_id: request_id,
37
+ })
38
+ request_xml = Recurring::FirstRequest.new(request_params).to_xml
39
+ response_xml = post(request_xml).body
40
+ Recurring::FirstResponse.new response_xml
41
+ end
42
+
43
+ def recurring_process(params)
44
+ request_params = params.merge({
45
+ merchant_account_id: config[:merchant_account_id],
46
+ request_id: request_id,
47
+ })
48
+ request_xml = Recurring::RecurringRequest.new(request_params).to_xml
49
+ response_xml = post(request_xml).body
50
+ Recurring::RecurringResponse.new response_xml
51
+ end
52
+
53
+ private
54
+
55
+ def post(request_xml)
56
+ Typhoeus.post(
57
+ WirecardSepa.gateway_url,
58
+ body: request_xml,
59
+ userpwd: http_auth_credentials,
60
+ )
61
+ end
62
+
63
+ def request_id
64
+ # From the Wirecard processing spec:
65
+ # Type: Alphanumeric, Length: 150
66
+ # This is the identification number of the request on the merchants side.
67
+ # It must be unique for each request.
68
+ # Sample Request-ID: 048b27e0-9c31-4cab-9eab-3b72b1b4d498
69
+ SecureRandom.uuid
70
+ end
71
+
72
+ def http_auth_credentials
73
+ [config.http_auth_username, config.http_auth_password].join(':')
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,24 @@
1
+ module WirecardSepa
2
+ module Recurring
3
+ class FirstRequest
4
+ attr_reader :params
5
+
6
+ def initialize(params = {})
7
+ Utils::ParamsValidator.validate!(params, expected_params)
8
+ @params = params
9
+ end
10
+
11
+ def to_xml
12
+ Utils::Template.new(self).to_xml
13
+ end
14
+
15
+ private
16
+
17
+ def expected_params
18
+ %i( merchant_account_id request_id requested_amount
19
+ account_holder_first_name account_holder_last_name bank_account_iban
20
+ bank_account_bic mandate_id mandate_signed_date creditor_id )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ module WirecardSepa
2
+ module Recurring
3
+ class FirstResponse < DirectDebit::Response
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ module WirecardSepa
2
+ module Recurring
3
+ class RecurringRequest
4
+ attr_reader :params
5
+
6
+ def initialize(params = {})
7
+ Utils::ParamsValidator.validate!(params, expected_params)
8
+ @params = params
9
+ end
10
+
11
+ def to_xml
12
+ Utils::Template.new(self).to_xml
13
+ end
14
+
15
+ private
16
+
17
+ def expected_params
18
+ %i( merchant_account_id request_id parent_transaction_id )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ module WirecardSepa
2
+ module Recurring
3
+ class RecurringResponse < DirectDebit::Response
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module WirecardSepa
2
+ module Utils
3
+ module ParamsValidator
4
+ module_function
5
+
6
+ def validate!(params, expected_params)
7
+ if params.keys.sort != expected_params.sort
8
+ # TODO: Provide link to official wirecard spec which explains the use of the keys
9
+ raise Errors::InvalidParamsError.new(
10
+ "Please provide a hash exactly with the following keys: #{expected_params}\n" +
11
+ "Missing params: #{expected_params - params.keys}\n" +
12
+ "Unexpected params: #{params.keys - expected_params}"
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end