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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +25 -0
- data/lib/securetrading.rb +1 -0
- data/lib/securetrading/connection.rb +32 -2
- data/lib/securetrading/filter.rb +23 -0
- data/lib/securetrading/refund.rb +15 -20
- data/lib/securetrading/version.rb +1 -1
- data/lib/securetrading/xml_doc.rb +8 -14
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79415e27c8e12d4d5c2665453b2b297fb747eaf0
|
4
|
+
data.tar.gz: 7d83ddb86ca77c924e264c7a0ca0b7f65b319c44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ad10220ac03be131c8b22fc5378ffadaa1c320097a7d25b54dc1943935b428d77678eeef6756fe803382626902c9d2e109f9d26620017cfa4b5cabd2fd0333c
|
7
|
+
data.tar.gz: 1c817f6c672cfde5c01e7afe71c2409cb50751a2bc4d8decc25eecdb89e505064ddc85a770256fc0e28b5585df57c5e04ae337973d2bc378d994286ae6bc5923
|
data/CHANGELOG.md
ADDED
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
@@ -13,14 +13,44 @@ module Securetrading
|
|
13
13
|
'Connection' => 'close'
|
14
14
|
)
|
15
15
|
|
16
|
-
def
|
17
|
-
|
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
|
data/lib/securetrading/refund.rb
CHANGED
@@ -8,31 +8,30 @@ module Securetrading
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def perform(options = {})
|
11
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
30
|
-
|
23
|
+
def request_type
|
24
|
+
'REFUND'.freeze
|
31
25
|
end
|
32
26
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
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
|
@@ -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.
|
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?
|
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
|
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.
|
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-
|
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
|