securetrading 0.3.2 → 0.4.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: b970bad76fbb9da1e4118576b2afac998b1842fa
4
- data.tar.gz: 5f49fa59a0f03981da3a95984b0dfaa300dbc590
3
+ metadata.gz: d65719b50f70a2f1733f1171d9904e83413a6b95
4
+ data.tar.gz: 22f0cf9463306e4d27962a7d3d4e17521e86ea2e
5
5
  SHA512:
6
- metadata.gz: 0d15ca99623960737276ae2858941a6fb80551509d4be53bf16c27a17a5275397fa198a4e3adb7e2209cef7250e2976351a894f60e2947a75cceec01d7d04b79
7
- data.tar.gz: afcef8ea5b271bc84e1ca724f1d41cb2d60f62d062824afe217dac632fb7dadf094feddc5703d65634843057501bb8226201f11a376966784f47e6930b315ccc
6
+ metadata.gz: 09e54f038bb0ac136d5b9c4fbabb9f63f40162415dfa0d5a4c7796c6967368d9181551d1018e1c5ab534bf64d5ea617457380227275c69cb3ee18bfedd333732
7
+ data.tar.gz: 4a459edcb584bee187125a3f329f9a0a2f8e3f9120686142cea3aaa411163f181027438f31c36250f63e542b3053e92f1501c42dc0cc7216627e1cd9f91074b3
@@ -1,6 +1,6 @@
1
1
  # Securetrading change log
2
2
 
3
- ## 0.4.0 / Unreleased
3
+ ## 0.4.1 / Unreleased
4
4
 
5
5
  * [Added]
6
6
 
@@ -10,6 +10,17 @@
10
10
 
11
11
  * [Fixed]
12
12
 
13
+ ## 0.4.0 / 2015-12-17
14
+
15
+ * [Added]
16
+ * Allow to pass configuration options directly to requests.
17
+
18
+ * [Deprecated]
19
+
20
+ * [Removed]
21
+
22
+ * [Fixed]
23
+
13
24
  ## 0.3.2 / 2015-09-07
14
25
 
15
26
  * [Fixed]
data/README.md CHANGED
@@ -36,6 +36,14 @@ Securetrading.configure do |c|
36
36
  end
37
37
  ```
38
38
 
39
+ Alternatively you may pass configuration options directly to request.
40
+
41
+ ```
42
+ > config = { user: 'user', passowrd: 'password', site_reference: 'ref' }
43
+ > ref = Securetrading::Refund.new(11, '1-9-1912893', { merchant: { orderreference: 'order2'}, account_type: 'CFT' }, config)
44
+ > ref.perform
45
+ ```
46
+
39
47
  ### Supported Api requests
40
48
 
41
49
  Currently supported methods:
@@ -4,6 +4,13 @@ module Securetrading
4
4
  attr_accessor :user, :password
5
5
  attr_writer :site_reference, :auth_method, :site_security_password
6
6
 
7
+ def initialize(options = {})
8
+ %i(user password site_reference auth_method
9
+ site_security_password).each do |var|
10
+ instance_variable_set("@#{var}", options[var])
11
+ end
12
+ end
13
+
7
14
  def site_security_password
8
15
  return @site_security_password if @site_security_password.present?
9
16
  fail ConfigurationError, 'You are trying to use site security '\
@@ -19,8 +19,19 @@ module Securetrading
19
19
 
20
20
  private
21
21
 
22
+ attr_reader :config_options
23
+
24
+ def config
25
+ @config ||= configuration
26
+ end
27
+
28
+ def configuration
29
+ return Securetrading.config unless config_options.present?
30
+ Configuration.new(config_options)
31
+ end
32
+
22
33
  def doc
23
- @doc ||= XmlDoc.new(request_type, @account_type).doc
34
+ @doc ||= XmlDoc.new(request_type, @account_type, config.user).doc
24
35
  end
25
36
 
26
37
  def request_type
@@ -39,7 +50,7 @@ module Securetrading
39
50
  end
40
51
 
41
52
  def dynamic_headers
42
- { 'Authorization' => "Basic #{Securetrading.config.auth}" }
53
+ { 'Authorization' => "Basic #{config.auth}" }
43
54
  end
44
55
 
45
56
  def prepare_doc
@@ -1,10 +1,11 @@
1
1
  module Securetrading
2
2
  class Refund < Connection
3
- def initialize(amount, parent_transaction, options = {})
3
+ def initialize(amount, parent_transaction, opts = {}, config_opts = {})
4
4
  @amount = amount
5
5
  @parent_transaction = parent_transaction
6
- @account_type = options[:account_type].presence || 'ECOM'
7
- @options = options
6
+ @account_type = opts[:account_type].presence || 'ECOM'
7
+ @options = opts
8
+ @config_options = config_opts
8
9
  end
9
10
 
10
11
  def perform(options = {})
@@ -26,7 +27,7 @@ module Securetrading
26
27
 
27
28
  def operation
28
29
  Operation.new(
29
- sitereference: Securetrading.config.site_reference,
30
+ sitereference: config.site_reference,
30
31
  accounttypedescription: @account_type,
31
32
  parenttransactionreference: @parent_transaction
32
33
  ).ox_xml
@@ -1,20 +1,26 @@
1
1
  module Securetrading
2
2
  class SiteSecurity
3
- def self.hash(fields)
4
- Digest::SHA256.hexdigest(str_to_encode(fields))
3
+ def self.hash(fields, config_options = nil)
4
+ Digest::SHA256.hexdigest(str_to_encode(fields, config_options))
5
5
  end
6
6
 
7
- def self.str_to_encode(fields)
7
+ def self.str_to_encode(fields, config_options = nil)
8
+ config = configuration(config_options)
8
9
  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|
10
+ fields.reverse_merge!(authmethod: config.auth_method)
11
+ %i(currencyiso3a mainamount sitereference settlestatus authmethod
12
+ settleduedate paypaladdressoverride strequiredfields version
13
+ stprofile ruleidentifier successfulurlredirect
14
+ declinedurlredirect).each do |field|
14
15
  str << fields[field].to_s
15
16
  end
16
- str << Securetrading.config.site_security_password
17
+ str << config.site_security_password
17
18
  end
18
- private_class_method :str_to_encode
19
+
20
+ def self.configuration(config_options)
21
+ return Securetrading.config unless config_options.present?
22
+ Configuration.new(config_options)
23
+ end
24
+ private_class_method :str_to_encode, :configuration
19
25
  end
20
26
  end
@@ -1,7 +1,8 @@
1
1
  module Securetrading
2
2
  class TransactionQuery < Connection
3
- def initialize(filters)
3
+ def initialize(filters, config_options = {})
4
4
  @filters = filters
5
+ @config_options = config_options
5
6
  end
6
7
 
7
8
  def perform(options = {})
@@ -1,3 +1,3 @@
1
1
  module Securetrading
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -1,8 +1,9 @@
1
1
  module Securetrading
2
2
  class XmlDoc
3
- def initialize(request_type, account_type)
3
+ def initialize(request_type, account_type, user = nil)
4
4
  @account_type = account_type
5
5
  @request_type = request_type
6
+ @user = user
6
7
  end
7
8
 
8
9
  def doc
@@ -41,7 +42,7 @@ module Securetrading
41
42
  end
42
43
 
43
44
  def alias_el
44
- self.class.elements(alias: Securetrading.config.user).first
45
+ self.class.elements(alias: @user || Securetrading.config.user).first
45
46
  end
46
47
 
47
48
  def request_el
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.3.2
4
+ version: 0.4.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-09-07 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  version: '0'
209
209
  requirements: []
210
210
  rubyforge_project:
211
- rubygems_version: 2.4.6
211
+ rubygems_version: 2.5.0
212
212
  signing_key:
213
213
  specification_version: 4
214
214
  summary: Ruby library for securetrading.com API integration.