paymentrails 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: c53c6a60f6f1f794c3e9b9c00622e3784775ec4f248a533da5fa1eed7a90d6eb
4
- data.tar.gz: 5c862b9b691ec0307978832b94b2be2d9b0ce404a1c1dc3955bacb7fc8b7c6fe
3
+ metadata.gz: 44ac83f800a214ab670b0f896817785b08c17a7991c1a9bd709eecefbea624f9
4
+ data.tar.gz: 8645750959fe8071d3d07e155473a4eb29ded347f44d25ea7bf12b92a71ec46b
5
5
  SHA512:
6
- metadata.gz: '098a1fdc46f93f41d788bd1f9786c104ad352c39d541bea990021462a888fb32eb24519dcdb5f6f5939a18ac285789c26412c47e3bdcbf66c187ed88970e3849'
7
- data.tar.gz: 7ea00ca85505bcfc89f6d75cc8408362a31ef845275c0b6231119bc10ccc2b4e302592e4399ffe5974ff84dcd240a6dc892f762e00f2e88f3e886458fd538555
6
+ metadata.gz: 17135435e18bda035813a88c3ad821add0a85cdf519e853e49c93ada53f24cd15a0432f5dbba439b7b25ae41bbcc621c7f032ae69ad7f9c4caaba63451d3086b
7
+ data.tar.gz: 86b59823d94e9d096d13580658b076d5548ac33ec4af4e8f6b6ca7de659c9038a5535f65b72ee0b20721a4e5ba17170af24c4dd21d7b2119a92952ceaf7e4943
@@ -18,8 +18,7 @@ require 'paymentrails/RecipientAccount'
18
18
  require 'paymentrails/OfflinePayment'
19
19
 
20
20
  module PaymentRails
21
- def self.client(key, secret, environment = 'production')
22
- client = Gateway.new(Configuration.new(key, secret, environment))
23
- return client
21
+ def self.client(key, secret, environment = 'production', **optionals)
22
+ Gateway.new(Configuration.new(key, secret, environment, optionals))
24
23
  end
25
24
  end
@@ -2,7 +2,6 @@
2
2
  require 'digest'
3
3
  require 'net/http'
4
4
  require 'openssl'
5
- require 'rest-client'
6
5
  require 'uri'
7
6
  require 'json'
8
7
 
@@ -34,7 +33,10 @@ module PaymentRails
34
33
 
35
34
  def send_request(endPoint, method, body = '')
36
35
  uri = URI.parse(@config.apiBase + endPoint)
37
- http = Net::HTTP.new(uri.host, uri.port)
36
+ http = Net::HTTP.new(
37
+ uri.host, uri.port,
38
+ @config.proxy&.host, @config.proxy&.port, @config.proxy&.user, @config.proxy&.password
39
+ )
38
40
  http.use_ssl = @config.useSsl?
39
41
 
40
42
  time = Time.now.to_i
@@ -1,12 +1,19 @@
1
1
  module PaymentRails
2
2
  class Configuration
3
+ class InvalidProxyAddress < StandardError; end
3
4
 
4
- def initialize(publicKey, privateKey, environment = 'production')
5
+ def initialize(publicKey, privateKey, environment = 'production', proxy_uri: nil)
5
6
  raise ArgumentError, 'Both key/secret must be a nonempty string' if publicKey.to_s&.empty? || privateKey.to_s&.empty?
6
7
 
7
8
  @publicKey = publicKey
8
9
  @privateKey = privateKey
9
10
  @environment = environment
11
+ # failfast on a bad proxy
12
+ begin
13
+ @proxy = proxy_uri.nil? ? nil : URI.parse(proxy_uri)
14
+ rescue URI::InvalidURIError
15
+ raise InvalidProxyAddress, "Invalid proxy provided to configuration: #{proxy_uri}"
16
+ end
10
17
  end
11
18
 
12
19
  def apiBase
@@ -26,6 +33,8 @@ module PaymentRails
26
33
  apiBase.start_with? 'https'
27
34
  end
28
35
 
36
+ attr_reader :proxy
37
+
29
38
  attr_reader :publicKey
30
39
 
31
40
  attr_writer :publicKey
@@ -21,6 +21,7 @@ module PaymentRails
21
21
  :merchantFees,
22
22
  :compliance,
23
23
  :payoutMethod,
24
+ :estimatedDeliveryAt,
24
25
  :recipient,
25
26
  :withholdingAmount,
26
27
  :withholdingCurrency,
@@ -4,14 +4,14 @@ Gem::Specification.new do |s|
4
4
  s.name = "paymentrails"
5
5
  s.summary = "PaymentRails Ruby SDK"
6
6
  s.description = "Ruby SDK for interacting with the PaymentRails API"
7
- s.version = '0.2.3'
7
+ s.version = '0.2.4'
8
8
  s.homepage = 'https://www.paymentrails.com/'
9
9
  s.email = ['joshua@paymentrails.com']
10
10
  s.license = "MIT"
11
11
  s.author = "PaymentRails"
12
12
  s.files = Dir.glob ["README.rdoc", "LICENSE", "lib/**/*.{rb,crt}", "spec/**/*", "*.gemspec"]
13
13
  s.required_ruby_version = '>= 2.4'
14
- s.add_dependency "rest-client", ">= 2.0.0"
14
+ s.add_development_dependency 'dotenv', '~> 2'
15
15
  s.add_development_dependency 'rake', '~> 12'
16
16
  s.add_development_dependency "rubocop", '~> 0.77'
17
17
  s.add_development_dependency 'test-unit', '~> 3'
@@ -1,10 +1,13 @@
1
- require_relative '../../lib/paymentrails'
2
- require 'test/unit'
3
- require 'securerandom'
1
+ require_relative 'helper'
4
2
 
5
3
  class BatchTest < Test::Unit::TestCase
6
4
  def setup
7
- @client = PaymentRails::Gateway.new(PaymentRails::Configuration.new('YOUR-API-KEY', 'YOUR-SECRET-KEY'))
5
+ @client = PaymentRails.client(
6
+ ENV.fetch('SANDBOX_API_KEY'),
7
+ ENV.fetch('SANDBOX_SECRET_KEY'),
8
+ 'production',
9
+ proxy_uri: ENV['PROXY_URI']
10
+ )
8
11
  end
9
12
 
10
13
  def create_recipient
@@ -1,10 +1,13 @@
1
- require_relative '../../lib/paymentrails'
2
- require 'test/unit'
3
- require 'securerandom'
1
+ require_relative 'helper'
4
2
 
5
3
  class RecipientTest < Test::Unit::TestCase
6
4
  def setup
7
- @client = PaymentRails::Gateway.new(PaymentRails::Configuration.new('YOUR-API-KEY', 'YOUR-SECRET-KEY'))
5
+ @client = PaymentRails.client(
6
+ ENV.fetch('SANDBOX_API_KEY'),
7
+ ENV.fetch('SANDBOX_SECRET_KEY'),
8
+ 'production',
9
+ proxy_uri: ENV['PROXY_URI']
10
+ )
8
11
  end
9
12
 
10
13
  def test_create
@@ -0,0 +1,4 @@
1
+ require 'dotenv/load'
2
+ require_relative '../../lib/paymentrails'
3
+ require 'test/unit'
4
+ require 'securerandom'
@@ -33,4 +33,19 @@ class ConfigurationTest < Test::Unit::TestCase
33
33
  assert_equal true, PaymentRails::Configuration.new('key', 'secret', 'development').useSsl?
34
34
  assert_equal true, PaymentRails::Configuration.new('key', 'secret', 'non_standard_environment').useSsl?
35
35
  end
36
+
37
+ def test_invalid_proxy_uri
38
+ proxy_uri = 'not_://*a_valid_proxy'
39
+ assert_raise PaymentRails::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
40
+ PaymentRails::Configuration.new('k', 's', 'production', proxy_uri: proxy_uri).proxy
41
+ end
42
+ end
43
+
44
+ def test_vaid_proxy_uri
45
+ config = PaymentRails::Configuration.new('k', 's', 'production', proxy_uri: 'http://user:pass@gimmeproxy.com:80')
46
+ assert_equal 'gimmeproxy.com', config.proxy.host
47
+ assert_equal 80, config.proxy.port
48
+ assert_equal 'user', config.proxy.user
49
+ assert_equal 'pass', config.proxy.password
50
+ end
36
51
  end
@@ -3,6 +3,13 @@ require 'test/unit'
3
3
 
4
4
  class PaymentRailsTest < Test::Unit::TestCase
5
5
  def test_client
6
- PaymentRails.client('key', 'secret', 'environment')
6
+ PaymentRails.client('key', 'secret', 'environment', proxy_uri: 'http://user:pass@gimmeproxy.com:80')
7
+ end
8
+
9
+ def test_client_invalid_proxy_uri
10
+ proxy_uri = 'not_://*a_valid_proxy'
11
+ assert_raise PaymentRails::Configuration::InvalidProxyAddress.new("Invalid proxy provided to configuration: #{proxy_uri}") do
12
+ PaymentRails.client('k', 's', 'production', proxy_uri: proxy_uri)
13
+ end
7
14
  end
8
15
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymentrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PaymentRails
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-18 00:00:00.000000000 Z
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: dotenv
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
20
- type: :runtime
19
+ version: '2'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +95,7 @@ files:
95
95
  - paymentrails.gemspec
96
96
  - spec/integration/BatchTest.rb
97
97
  - spec/integration/RecipientTest.rb
98
+ - spec/integration/helper.rb
98
99
  - spec/unit/ConfigurationTest.rb
99
100
  - spec/unit/PaymentRailsTest.rb
100
101
  homepage: https://www.paymentrails.com/