securetrading 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -2
- data/README.md +11 -3
- data/lib/securetrading.rb +3 -1
- data/lib/securetrading/amount.rb +13 -0
- data/lib/securetrading/base_model.rb +39 -0
- data/lib/securetrading/billing.rb +9 -0
- data/lib/securetrading/configuration.rb +11 -1
- data/lib/securetrading/connection.rb +6 -6
- data/lib/securetrading/models.rb +18 -0
- data/lib/securetrading/record.rb +9 -0
- data/lib/securetrading/refund.rb +7 -9
- data/lib/securetrading/response.rb +47 -0
- data/lib/securetrading/site_security.rb +20 -0
- data/lib/securetrading/{filter.rb → transaction_query.rb} +1 -1
- data/lib/securetrading/version.rb +1 -1
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa0b858de02b3d93f7394e6b2b2b86de5bd544c7
|
4
|
+
data.tar.gz: de7c1bc1b95797567c9789ee960af85b7b498cc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b8441e9c2d9edfef640a416d84dfa10a52fba29417361652e53376f275fad4a121cc54ac3347bd769b1707a8cd263dcaf9d3c2bb683dd9a52fa7de28c0f962b
|
7
|
+
data.tar.gz: 9fb7c71a6538567f39e6f9a5acc986c535b481e82920a994fb1c460a7164968b426b661e865528918049d75baedc12a383a87455b68bf5f5414d0a1aa01d2a43
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Securetrading change log
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.4.0 / Unreleased
|
4
4
|
|
5
|
-
* [Added]
|
5
|
+
* [Added]
|
6
6
|
|
7
7
|
* [Deprecated]
|
8
8
|
|
@@ -10,6 +10,21 @@
|
|
10
10
|
|
11
11
|
* [Fixed]
|
12
12
|
|
13
|
+
## 0.3.0 / 2015-08-25
|
14
|
+
|
15
|
+
* [Added]
|
16
|
+
* Securetrading::SiteSecurity.hash(fields) to return SHA256 encoded sitesecurity value from hash of fields to encode.
|
17
|
+
* auth_method configuration value
|
18
|
+
* site_security_password configuration value
|
19
|
+
* Securetrading::Response to objectify response from httparty
|
20
|
+
|
21
|
+
* [Deprecated]
|
22
|
+
* Renamed Filter class to TransactionQuery class as much more relevant.
|
23
|
+
|
24
|
+
## 0.2.0 / 2015-08-14
|
25
|
+
|
26
|
+
* [Added] Filter - query API for transactions details.
|
27
|
+
|
13
28
|
## 0.1.0 / 2015-08-13
|
14
29
|
|
15
30
|
* [Added] Possibility to send REFUND request to API.
|
data/README.md
CHANGED
@@ -75,7 +75,7 @@ Will send post request with xml:
|
|
75
75
|
</requestblock>
|
76
76
|
```
|
77
77
|
|
78
|
-
####
|
78
|
+
#### TRANSACTIONQUERY
|
79
79
|
|
80
80
|
Parameters:
|
81
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/)
|
@@ -83,8 +83,8 @@ Parameters:
|
|
83
83
|
Example:
|
84
84
|
|
85
85
|
```ruby
|
86
|
-
>
|
87
|
-
>
|
86
|
+
> query = Securetrading::TransactionQuery.new(transactionreference: [ '5-9-1982481', '5-9-1980795'])
|
87
|
+
> query.perform
|
88
88
|
```
|
89
89
|
It will send post request with xml:
|
90
90
|
|
@@ -100,6 +100,14 @@ It will send post request with xml:
|
|
100
100
|
</requestblock>
|
101
101
|
```
|
102
102
|
|
103
|
+
#### SiteSecurity
|
104
|
+
|
105
|
+
Helper class for sitesecurity value calculation.
|
106
|
+
More details in [STPP-Payment-Pages-Setup-Guide-V2](http://www.securetrading.com/files/documentation/STPP-Payment-Pages-Setup-Guide-V2.pdf) chapter 6.
|
107
|
+
|
108
|
+
Methods:
|
109
|
+
* hash(fields) - calculates SHA256 hash from fields. List of fields you can check in doc above.
|
110
|
+
|
103
111
|
## Development
|
104
112
|
|
105
113
|
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
@@ -0,0 +1,39 @@
|
|
1
|
+
module Securetrading
|
2
|
+
class BaseModel
|
3
|
+
def initialize(attrs_hash = {})
|
4
|
+
@attributes_hash = attrs_hash.presence && attrs_hash.stringify_keys
|
5
|
+
end
|
6
|
+
|
7
|
+
def ox_xml
|
8
|
+
XmlDoc.elements(xml_tag_name => @attributes_hash).first
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def xml_tag_name
|
14
|
+
self.class.name.demodulize.downcase
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(m, *args, &block)
|
18
|
+
return super unless attributes_hash.key?(m.to_s)
|
19
|
+
determine_value(m.to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def determine_value(name)
|
23
|
+
if name == 'error'
|
24
|
+
Securetrading::ResponseError.new(attributes_hash[name])
|
25
|
+
elsif name.in?(sub_classes)
|
26
|
+
"Securetrading::#{name.capitalize}".constantize
|
27
|
+
.public_send(:new, attributes_hash[name])
|
28
|
+
else
|
29
|
+
attributes_hash[name]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def sub_classes
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :attributes_hash
|
38
|
+
end
|
39
|
+
end
|
@@ -2,7 +2,17 @@ module Securetrading
|
|
2
2
|
class ConfigurationError < StandardError; end
|
3
3
|
class Configuration
|
4
4
|
attr_accessor :user, :password
|
5
|
-
attr_writer :site_reference
|
5
|
+
attr_writer :site_reference, :auth_method, :site_security_password
|
6
|
+
|
7
|
+
def site_security_password
|
8
|
+
return @site_security_password if @site_security_password.present?
|
9
|
+
fail ConfigurationError, 'You are trying to use site security '\
|
10
|
+
'but your password is empty. Please check gem configuration.'
|
11
|
+
end
|
12
|
+
|
13
|
+
def auth_method
|
14
|
+
@auth_method ||= 'FINAL'.freeze
|
15
|
+
end
|
6
16
|
|
7
17
|
def site_reference
|
8
18
|
return @site_reference if @site_reference.present?
|
@@ -24,18 +24,18 @@ module Securetrading
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def request_type
|
27
|
-
fail NotImplementedError, 'Implement :request_type method in
|
27
|
+
fail NotImplementedError, 'Implement :request_type method in sub-class!'
|
28
28
|
end
|
29
29
|
|
30
30
|
def ox_xml
|
31
|
-
fail NotImplementedError, 'Implement :ox_xml method in
|
31
|
+
fail NotImplementedError, 'Implement :ox_xml method in sub-class!'
|
32
32
|
end
|
33
33
|
|
34
34
|
def perform_with(method, xml, options = {})
|
35
|
-
self.class.public_send(
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
party = self.class.public_send(
|
36
|
+
method, '/', options.merge(body: xml, headers: dynamic_headers)
|
37
|
+
)
|
38
|
+
Securetrading::Response.new(party)
|
39
39
|
end
|
40
40
|
|
41
41
|
def dynamic_headers
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'securetrading/base_model'
|
2
|
+
|
3
|
+
module Securetrading
|
4
|
+
class Customer < BaseModel; end
|
5
|
+
class Dcc < BaseModel; end
|
6
|
+
class Merchant < BaseModel; end
|
7
|
+
class Name < BaseModel; end
|
8
|
+
class Operation < BaseModel; end
|
9
|
+
class Payment < BaseModel; end
|
10
|
+
class ResponseError < BaseModel; end
|
11
|
+
class Settlement < BaseModel; end
|
12
|
+
class Security < BaseModel; end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'securetrading/amount'
|
16
|
+
require 'securetrading/billing'
|
17
|
+
require 'securetrading/record'
|
18
|
+
require 'securetrading/response'
|
data/lib/securetrading/refund.rb
CHANGED
@@ -25,22 +25,20 @@ module Securetrading
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def operation
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
).first
|
28
|
+
Operation.new(
|
29
|
+
sitereference: Securetrading.config.site_reference,
|
30
|
+
accounttypedescription: @account_type,
|
31
|
+
parenttransactionreference: @parent_transaction
|
32
|
+
).ox_xml
|
35
33
|
end
|
36
34
|
|
37
35
|
def billing
|
38
|
-
|
36
|
+
Billing.new(amount: @amount).ox_xml
|
39
37
|
end
|
40
38
|
|
41
39
|
def merchant
|
42
40
|
return '' unless @options[:merchant].present?
|
43
|
-
|
41
|
+
Merchant.new(@options[:merchant]).ox_xml
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Securetrading
|
2
|
+
class Response < BaseModel
|
3
|
+
attr_reader :httparty
|
4
|
+
|
5
|
+
def initialize(httparty)
|
6
|
+
@httparty = httparty
|
7
|
+
end
|
8
|
+
|
9
|
+
def data
|
10
|
+
rows.map { |row| Record.new(row) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def found
|
14
|
+
attributes_hash['found'].to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def rows
|
20
|
+
case found
|
21
|
+
when 0 then []
|
22
|
+
when 1 then [record]
|
23
|
+
else record
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes_hash
|
28
|
+
return @attributes_hash if @attributes_hash.present?
|
29
|
+
@attributes_hash = responseblock
|
30
|
+
@attributes_hash.merge!(additional_attributes)
|
31
|
+
end
|
32
|
+
|
33
|
+
def additional_attributes
|
34
|
+
if responseblock['type'] == 'ERROR'
|
35
|
+
{}
|
36
|
+
elsif responseblock['response']['type'] == 'TRANSACTIONQUERY'
|
37
|
+
@attributes_hash.delete('response')
|
38
|
+
else
|
39
|
+
{ 'record' => @attributes_hash.delete('response'), 'found' => '1' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def responseblock
|
44
|
+
@responseblock ||= @httparty.parsed_response['responseblock']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Securetrading
|
2
|
+
class SiteSecurity
|
3
|
+
def self.hash(fields)
|
4
|
+
Digest::SHA256.hexdigest(str_to_encode(fields))
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.str_to_encode(fields)
|
8
|
+
str = ''
|
9
|
+
fields.reverse_merge!(authmethod: Securetrading.config.auth_method)
|
10
|
+
[:currencyiso3a, :mainamount, :sitereference, :settlestatus,
|
11
|
+
:settleduedate, :authmethod, :paypaladdressoverride,
|
12
|
+
:strequiredfields, :version, :stprofile, :ruleidentifier,
|
13
|
+
:successfulurlredirect, :declinedurlredirect].each do |field|
|
14
|
+
str << fields[field].to_s
|
15
|
+
end
|
16
|
+
str << Securetrading.config.site_security_password
|
17
|
+
end
|
18
|
+
private_class_method :str_to_encode
|
19
|
+
end
|
20
|
+
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.3.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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -174,10 +174,17 @@ files:
|
|
174
174
|
- bin/guard
|
175
175
|
- bin/setup
|
176
176
|
- lib/securetrading.rb
|
177
|
+
- lib/securetrading/amount.rb
|
178
|
+
- lib/securetrading/base_model.rb
|
179
|
+
- lib/securetrading/billing.rb
|
177
180
|
- lib/securetrading/configuration.rb
|
178
181
|
- lib/securetrading/connection.rb
|
179
|
-
- lib/securetrading/
|
182
|
+
- lib/securetrading/models.rb
|
183
|
+
- lib/securetrading/record.rb
|
180
184
|
- lib/securetrading/refund.rb
|
185
|
+
- lib/securetrading/response.rb
|
186
|
+
- lib/securetrading/site_security.rb
|
187
|
+
- lib/securetrading/transaction_query.rb
|
181
188
|
- lib/securetrading/version.rb
|
182
189
|
- lib/securetrading/xml_doc.rb
|
183
190
|
- securetrading.gemspec
|