docdata 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5271138fe601489cd244592780fc9f386673c7cc
4
- data.tar.gz: c60ccad98f4ae791df1e84608047a4e71e8ab7ab
3
+ metadata.gz: 583612f0f3405d88e304b04589e08faa14fc873c
4
+ data.tar.gz: e846c3af8a8be9caec3bddb1ca375565feb9e7e3
5
5
  SHA512:
6
- metadata.gz: eaa1d9dac46967a8e34d13e1a9435dcd72b6ec49134a83c49f7b5d10c6f7e01050af98a18d9a24824cb35f3881d766d6a4e997fe3232a83e8997c2e03988f34c
7
- data.tar.gz: b7f90e1cfe8c8284e8bec9fce47256c67e32c8f87ef0438e29d88b6ded7efa917e06d1267c56a20be4d351bb46325864b69682bf1f55f0eb22980b23603c89ae
6
+ metadata.gz: 4f78048e064e074ffc7e343267d94b45b54d9ef81bbab5a34fd535466557f89746d80d23e3c027d195fa19388588c22a7305d374dd14b8df6c812b137fafcb82
7
+ data.tar.gz: c039738e8915fa272fd01ea4c95e4e0df54f9823ba89febe6831f67a685f49018b68b8ee6594b930efc301188652b34701cda63a973039c4cf54a56e08e2fa97
@@ -1,3 +1,6 @@
1
+ ## v0.1.5
2
+ * Fixed a bug that occured when docdata reponded with multiple 'payment' nodes in the return object.
3
+
1
4
  ## v0.1.0
2
5
  * truncated description down to 50 characters in create xml
3
6
 
data/README.md CHANGED
@@ -126,6 +126,35 @@ end
126
126
 
127
127
  ```
128
128
 
129
+ After a payment is completed, Docdata Payments will do two things:
130
+
131
+ 1. Sends a GET request to your 'Update URL' (you can set this in the back office) with an 'id' parameter, containing your order_reference. This allows you to check the status of the transaction, before the user gets redirected back to your website.
132
+ 2. Redirects the consumer back to the `return_url`.
133
+
134
+ ```ruby
135
+ def check_transaction
136
+ # find the order from your database
137
+ # https://www.example.com/docdata/update?id=12345
138
+ @order = Order.find_by_order_reference(params[:id])
139
+
140
+ # Find this payment via the Docdata API,
141
+ # using the previously set 'docdata_key' attribute.
142
+ payment = Docdata::Payment.find(@order.docdata_key)
143
+ response = payment.status
144
+ if response.paid
145
+ # use your own methods to handle a paid order
146
+ # for example:
147
+ @order.mark_as_paid(response.payment_method)
148
+ else
149
+ # TODO: create logic to handle failed payments
150
+ end
151
+
152
+ # This action doesn't need a view template. It only needs to have a status 200 (OK)
153
+ render :nothing => true, :status => 200, :content_type => 'text/html'
154
+ end
155
+
156
+ ```
157
+
129
158
  ## Ideal
130
159
 
131
160
  For transactions in the Netherlands, iDeal is the most common option. To redirect a user directly to the bank page (skipping the Docdata web menu page), you can ask your user to choose a bank from any of the banks listed in the `Docdata::Ideal.banks` method.
@@ -222,7 +251,7 @@ To cancel an existing Payment, you can do one of the following:
222
251
 
223
252
 
224
253
  ## Contributing
225
- Want to contribute? Greate!
254
+ Want to contribute? Great!
226
255
 
227
256
 
228
257
  1. Fork it
@@ -61,7 +61,7 @@ module Docdata
61
61
  # Set the attributes based on the API response
62
62
  def set_attributes
63
63
  self.paid = is_paid?
64
- self.amount = report[:payment][:authorization][:amount].to_i if (report && report[:payment] && report[:payment][:authorization] && report[:payment][:authorization][:amount].present?)
64
+ self.amount = Response.payment_node(report)[:authorization][:amount].to_i if (report && Response.payment_node(report) && Response.payment_node(report)[:authorization] && Response.payment_node(report)[:authorization][:amount].present?)
65
65
  self.status = capture_status if capture_status
66
66
  self.currency = currency_to_set
67
67
  end
@@ -80,6 +80,7 @@ module Docdata
80
80
  m = body["#{method_name}_response".to_sym]["#{method_name}_success".to_sym]
81
81
  r = self.new(key: m[:key], message: m[:success], success: true)
82
82
  r.xml = xml #save the raw xml
83
+ # puts m[:report]
83
84
  if m[:report]
84
85
  r.report = m[:report]
85
86
  end
@@ -112,8 +113,8 @@ module Docdata
112
113
  # @return [String] the payment method of this transaction
113
114
  def payment_method
114
115
  begin
115
- if report && report[:payment].present? && report[:payment][:payment_method].present?
116
- report[:payment][:payment_method].to_s
116
+ if report && Response.payment_node(report).present? && Response.payment_node(report)[:payment_method].present?
117
+ Response.payment_node(report)[:payment_method].to_s
117
118
  else
118
119
  nil
119
120
  end
@@ -122,10 +123,11 @@ module Docdata
122
123
  end
123
124
  end
124
125
 
126
+
125
127
  # @return [String] the status string provided by the API. One of [AUTHORIZED, CANCELED]
126
128
  def payment_status
127
- if report && report[:payment] && report[:payment][:authorization]
128
- report[:payment][:authorization][:status]
129
+ if report && Response.payment_node(report) && Response.payment_node(report)[:authorization]
130
+ Response.payment_node(report)[:authorization][:status]
129
131
  else
130
132
  nil
131
133
  end
@@ -176,8 +178,8 @@ module Docdata
176
178
 
177
179
  # @return [String] the status of the capture, if exists
178
180
  def capture_status
179
- if report && report[:payment] && report[:payment][:authorization] && report[:payment][:authorization][:capture]
180
- report[:payment][:authorization][:capture][:status]
181
+ if report && Response.payment_node(report) && Response.payment_node(report)[:authorization] && Response.payment_node(report)[:authorization][:capture]
182
+ Response.payment_node(report)[:authorization][:capture][:status]
181
183
  else
182
184
  nil
183
185
  end
@@ -207,5 +209,19 @@ module Docdata
207
209
  @status_xml ||= Nokogiri.XML(doc.xpath("//S:Body").first.children.first.children.first.to_xml)
208
210
  end
209
211
 
212
+ private
213
+
214
+ # Sometimes a single response has multiple payment nodes. When a payment fails first and
215
+ # succeeds later, for example. In that case, always use the last (== newest) node.
216
+ def self.payment_node(hash)
217
+ if hash[:payment] && hash[:payment].is_a?(Hash)
218
+ hash[:payment]
219
+ elsif hash[:payment] && hash[:payment].is_a?(Array)
220
+ hash[:payment].last
221
+ else
222
+ false
223
+ end
224
+ end
225
+
210
226
  end
211
227
  end
@@ -1,3 +1,3 @@
1
1
  module Docdata
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -17,6 +17,22 @@ describe Docdata::Response do
17
17
  end
18
18
  end
19
19
 
20
+ describe "response with multiple payment nodes" do
21
+ before(:each) do
22
+ file = "#{File.dirname(__FILE__)}/xml/status-paid-ideal-multiple.xml"
23
+ @xml = open(file)
24
+ @response = Docdata::Response.parse(:status, @xml)
25
+ end
26
+
27
+ it "returs a response object" do
28
+ expect(@response).to be_kind_of(Docdata::Response)
29
+ end
30
+
31
+ it "is paid" do
32
+ expect(@response.paid).to eq(true)
33
+ end
34
+ end
35
+
20
36
  describe "different payment methods" do
21
37
  context ":status, paid iDeal" do
22
38
  before(:each) do
@@ -0,0 +1,42 @@
1
+ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
2
+ <S:Body>
3
+ <statusResponse xmlns="http://www.docdatapayments.com/services/paymentservice/1_1/">
4
+ <statusSuccess>
5
+ <success code="SUCCESS">Operation successful.</success>
6
+ <report>
7
+ <approximateTotals exchangedTo="EUR" exchangeRateDate="2014-08-22 09:57:18">
8
+ <totalRegistered>2200</totalRegistered>
9
+ <totalShopperPending>0</totalShopperPending>
10
+ <totalAcquirerPending>0</totalAcquirerPending>
11
+ <totalAcquirerApproved>2200</totalAcquirerApproved>
12
+ <totalCaptured>2200</totalCaptured>
13
+ <totalRefunded>0</totalRefunded>
14
+ <totalChargedback>0</totalChargedback>
15
+ </approximateTotals>
16
+ <payment>
17
+ <id>2492860866</id>
18
+ <paymentMethod>IDEAL</paymentMethod>
19
+ <authorization>
20
+ <status>CANCELED</status>
21
+ <amount currency="EUR">2200</amount>
22
+ <confidenceLevel/>
23
+ </authorization>
24
+ </payment>
25
+ <payment>
26
+ <id>2492861418</id>
27
+ <paymentMethod>IDEAL</paymentMethod>
28
+ <authorization>
29
+ <status>AUTHORIZED</status>
30
+ <amount currency="EUR">2200</amount>
31
+ <confidenceLevel>ACQUIRER_APPROVED</confidenceLevel>
32
+ <capture>
33
+ <status>CAPTURED</status>
34
+ <amount currency="EUR">2200</amount>
35
+ </capture>
36
+ </authorization>
37
+ </payment>
38
+ </report>
39
+ </statusSuccess>
40
+ </statusResponse>
41
+ </S:Body>
42
+ </S:Envelope>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henk Meijer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-18 00:00:00.000000000 Z
12
+ date: 2014-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -284,6 +284,7 @@ files:
284
284
  - spec/xml/status-canceled-ideal.xml
285
285
  - spec/xml/status-new.xml
286
286
  - spec/xml/status-paid-creditcard.xml
287
+ - spec/xml/status-paid-ideal-multiple.xml
287
288
  - spec/xml/status-paid-ideal.xml
288
289
  - spec/xml/status-paid-sofort.xml
289
290
  homepage: http://rdoc.info/github/henkm/docdata/
@@ -324,6 +325,7 @@ test_files:
324
325
  - spec/xml/status-canceled-ideal.xml
325
326
  - spec/xml/status-new.xml
326
327
  - spec/xml/status-paid-creditcard.xml
328
+ - spec/xml/status-paid-ideal-multiple.xml
327
329
  - spec/xml/status-paid-ideal.xml
328
330
  - spec/xml/status-paid-sofort.xml
329
331
  has_rdoc: