securetrading 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 267c87fa55b87574dfa58dea6a4da76083a27bd4
4
- data.tar.gz: bcbf98e2f5be0cd29a71bc99e8eb87d6ae0cb994
3
+ metadata.gz: 79415e27c8e12d4d5c2665453b2b297fb747eaf0
4
+ data.tar.gz: 7d83ddb86ca77c924e264c7a0ca0b7f65b319c44
5
5
  SHA512:
6
- metadata.gz: bbd79a4d7f3700ae3da76a66027ab92dbce3a90ecb00fe12e62262fb1024f4c4af4d5b09ceffeeea4051fc292a2bcb10e33bccd32d03bf9ef920dd296c346135
7
- data.tar.gz: eff794acdbf6cb1be1ec7545a97512fd73573e5863469bf40e27db9d395a59ff12caa264b580e4aa7030f6767b5bedbdf3958c7037ade6791baa5f02da85e7be
6
+ metadata.gz: 6ad10220ac03be131c8b22fc5378ffadaa1c320097a7d25b54dc1943935b428d77678eeef6756fe803382626902c9d2e109f9d26620017cfa4b5cabd2fd0333c
7
+ data.tar.gz: 1c817f6c672cfde5c01e7afe71c2409cb50751a2bc4d8decc25eecdb89e505064ddc85a770256fc0e28b5585df57c5e04ae337973d2bc378d994286ae6bc5923
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Securetrading change log
2
+
3
+ ## 0.2.0 / Unreleased
4
+
5
+ * [Added] Filter - query API for transactions details.
6
+
7
+ * [Deprecated]
8
+
9
+ * [Removed]
10
+
11
+ * [Fixed]
12
+
13
+ ## 0.1.0 / 2015-08-13
14
+
15
+ * [Added] Possibility to send REFUND request to API.
data/README.md CHANGED
@@ -75,6 +75,31 @@ Will send post request with xml:
75
75
  </requestblock>
76
76
  ```
77
77
 
78
+ #### FILTER
79
+
80
+ Parameters:
81
+ - filters - list of filter xml subtags. You may find full list of filters in this doc: [http://www.securetrading.com/support/document/xml-reference-transaction-query/](http://www.securetrading.com/support/document/xml-reference-transaction-query/)
82
+
83
+ Example:
84
+
85
+ ```ruby
86
+ > filter = Securetrading::Filter.new({ transactionreference: [ '5-9-1982481', '5-9-1980795'] })
87
+ > filter.perform
88
+ ```
89
+ It will send post request with xml:
90
+
91
+ ```XML
92
+ <requestblock version=\"3.67\">
93
+ <alias>user_site1234@securetrading.com</alias>
94
+ <request type=\"TRANSACTIONQUERY\">
95
+ <filter>
96
+ <transactionreference>5-9-1982481</transactionreference>
97
+ <transactionreference>5-9-1980795</transactionreference>
98
+ </filter>
99
+ </request>
100
+ </requestblock>
101
+ ```
102
+
78
103
  ## Development
79
104
 
80
105
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/securetrading.rb CHANGED
@@ -25,3 +25,4 @@ end
25
25
  require 'securetrading/connection'
26
26
  require 'securetrading/xml_doc'
27
27
  require 'securetrading/refund'
28
+ require 'securetrading/filter'
@@ -13,14 +13,44 @@ module Securetrading
13
13
  'Connection' => 'close'
14
14
  )
15
15
 
16
- def post_with(xml, options = {})
17
- self.class.post('/', options.merge(body: xml, headers: dynamic_headers))
16
+ def to_xml
17
+ Ox.dump(ox_xml)
18
18
  end
19
19
 
20
20
  private
21
21
 
22
+ def doc
23
+ @doc ||= XmlDoc.new(request_type, @account_type).doc
24
+ end
25
+
26
+ def request_type
27
+ fail NotImplementedError, 'Implement :request_type method in subclas!'
28
+ end
29
+
30
+ def ox_xml
31
+ fail NotImplementedError, 'Implement :ox_xml method in subclas!'
32
+ end
33
+
34
+ def perform_with(method, xml, options = {})
35
+ self.class.public_send(method,
36
+ '/',
37
+ options.merge(body: xml,
38
+ headers: dynamic_headers))
39
+ end
40
+
22
41
  def dynamic_headers
23
42
  { 'Authorization' => "Basic #{Securetrading.config.auth}" }
24
43
  end
44
+
45
+ def prepare_doc
46
+ return doc if xml_prepared?
47
+ yield
48
+ @xml_prepared = true
49
+ doc
50
+ end
51
+
52
+ def xml_prepared?
53
+ @xml_prepared
54
+ end
25
55
  end
26
56
  end
@@ -0,0 +1,23 @@
1
+ module Securetrading
2
+ class Filter < Connection
3
+ def initialize(filters)
4
+ @filters = filters
5
+ end
6
+
7
+ def perform(options = {})
8
+ perform_with(:post, to_xml, options)
9
+ end
10
+
11
+ private
12
+
13
+ def ox_xml
14
+ prepare_doc do
15
+ doc.requestblock.request << XmlDoc.elements(filter: @filters).first
16
+ end
17
+ end
18
+
19
+ def request_type
20
+ 'TRANSACTIONQUERY'.freeze
21
+ end
22
+ end
23
+ end
@@ -8,31 +8,30 @@ module Securetrading
8
8
  end
9
9
 
10
10
  def perform(options = {})
11
- post_with(to_xml, options)
12
- end
13
-
14
- def to_xml
15
- Ox.dump(ox_xml)
11
+ perform_with(:post, to_xml, options)
16
12
  end
17
13
 
18
14
  private
19
15
 
20
16
  def ox_xml
21
- return doc if xml_prepared?
22
- req = doc.requestblock.request
23
- req << merchant << billing
24
- req.operation << transaction_reference
25
- @xml_prepared = true
26
- doc
17
+ prepare_doc do
18
+ req = doc.requestblock.request
19
+ req << merchant << operation << billing
20
+ end
27
21
  end
28
22
 
29
- def doc
30
- @doc ||= XmlDoc.new('REFUND', @account_type).doc
23
+ def request_type
24
+ 'REFUND'.freeze
31
25
  end
32
26
 
33
- def transaction_reference
34
- return '' unless @parent_transaction.present?
35
- XmlDoc.elements(parenttransactionreference: @parent_transaction).first
27
+ def operation
28
+ XmlDoc.elements(
29
+ operation: {
30
+ sitereference: Securetrading.config.site_reference,
31
+ accounttypedescription: @account_type,
32
+ parenttransactionreference: @parent_transaction
33
+ }
34
+ ).first
36
35
  end
37
36
 
38
37
  def billing
@@ -43,9 +42,5 @@ module Securetrading
43
42
  return '' unless @options[:merchant].present?
44
43
  XmlDoc.elements(merchant: @options[:merchant]).first
45
44
  end
46
-
47
- def xml_prepared?
48
- @xml_prepared
49
- end
50
45
  end
51
46
  end
@@ -1,3 +1,3 @@
1
1
  module Securetrading
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -14,18 +14,21 @@ module Securetrading
14
14
  @doc << root
15
15
  end
16
16
 
17
+ # rubocop:disable Metrics/MethodLength
17
18
  def self.elements(hash)
18
- return unless hash.present?
19
- hash.map do |k, v|
19
+ return '' unless hash.present?
20
+ hash.flat_map do |k, v|
21
+ return v.flat_map { |e| elements(k => e) } if v.is_a?(Array)
20
22
  el = new_element(k.to_s)
21
- if v.is_a? Hash
23
+ if v.is_a?(Hash)
22
24
  elements(v).each { |e| el << e }
23
25
  else
24
26
  el << v.to_s
25
27
  end
26
- el
28
+ [el]
27
29
  end
28
30
  end
31
+ # rubocop:enable Metrics/MethodLength
29
32
 
30
33
  def self.new_element(name)
31
34
  Ox::Element.new(name)
@@ -37,15 +40,6 @@ module Securetrading
37
40
  self.class.new_element(name)
38
41
  end
39
42
 
40
- def operation
41
- self.class.elements(
42
- operation: {
43
- sitereference: Securetrading.config.site_reference,
44
- accounttypedescription: @account_type
45
- }
46
- ).first
47
- end
48
-
49
43
  def alias_el
50
44
  self.class.elements(alias: Securetrading.config.user).first
51
45
  end
@@ -53,7 +47,7 @@ module Securetrading
53
47
  def request_el
54
48
  el = new_element('request')
55
49
  el[:type] = @request_type
56
- el << operation
50
+ el
57
51
  end
58
52
  end
59
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securetrading
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitgamelabs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -162,6 +162,7 @@ files:
162
162
  - ".rspec"
163
163
  - ".rubocop.yml"
164
164
  - ".travis.yml"
165
+ - CHANGELOG.md
165
166
  - CODE_OF_CONDUCT.md
166
167
  - Gemfile
167
168
  - Guardfile
@@ -175,6 +176,7 @@ files:
175
176
  - lib/securetrading.rb
176
177
  - lib/securetrading/configuration.rb
177
178
  - lib/securetrading/connection.rb
179
+ - lib/securetrading/filter.rb
178
180
  - lib/securetrading/refund.rb
179
181
  - lib/securetrading/version.rb
180
182
  - lib/securetrading/xml_doc.rb