apruve 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24401a925e3305111fbbe854bba852da2abb854f
4
- data.tar.gz: bfed11774b2cec8edf220cc1cdb4f29eb8993a5e
3
+ metadata.gz: 98c782a3fb7299e0daf94737a4479ed7dbc96c34
4
+ data.tar.gz: 145cae5f4ef9e5513988bf0029677c2f1e3dc875
5
5
  SHA512:
6
- metadata.gz: c15cbe632feebad3ee53777e79e646b5c5b4bba422a0afbfa912b54fbd1e50e360261060200d33ea01a2593e30ad5f9a6d48da6a46c0deef5808ba2d3117cd09
7
- data.tar.gz: 4277d7145125765dfb4a9d5d4b02860bd65d1b51ac3ed3ea2210c951d29542bdc8d583a83a5f3a55b4fe0240f27a05c13336e39a1b4dc50e864836828c1a2915
6
+ metadata.gz: f0bed93d1aa94e6699f96177785c4f297a015e5fba18520690290aeba1f91ca500ec10d9a49fd7eb42f196064fe44cec03786d1164f00e4474f2fdfc79353c5d
7
+ data.tar.gz: ff7ff6ecc5bd7ad7c143cdbff25eb225da3929983226c996980e9a47e3af2b6059c00932c5ad9376d1f277bc2564fc77da1f1d384d3532521e41031e849db65e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apruve (1.1.3)
4
+ apruve (1.1.2)
5
5
  addressable (~> 2.3)
6
6
  faraday (>= 0.8.6, <= 0.9.0)
7
7
  faraday_middleware (~> 0.9)
@@ -123,4 +123,4 @@ DEPENDENCIES
123
123
  yard
124
124
 
125
125
  BUNDLED WITH
126
- 1.13.7
126
+ 1.12.5
@@ -1,11 +1,20 @@
1
1
  module Apruve
2
2
  class CorporateAccount < Apruve::ApruveObject
3
3
  attr_accessor :id, :merchant_uuid, :customer_uuid, :type, :created_at, :updated_at, :payment_term_strategy_name,
4
- :disabled_at, :name, :creditor_term_id, :payment_method_id, :status, :trusted_merchant
4
+ :disabled_at, :name, :creditor_term_id, :payment_method_id, :status, :trusted_merchant,
5
+ :authorized_buyers
5
6
 
6
- def self.find(merchant_id, email)
7
+ def self.find(merchant_id, email=nil)
8
+ if email.nil?
9
+ return find_all(merchant_id)
10
+ end
7
11
  response = Apruve.get("merchants/#{merchant_id}/corporate_accounts?email=#{email}")
8
- return CorporateAccount.new(response.body.empty? ? {} : response.body[0])
12
+ CorporateAccount.new(response.body.empty? ? {} : response.body[0])
13
+ end
14
+
15
+ def self.find_all(merchant_id)
16
+ response = Apruve.get("merchants/#{merchant_id}/corporate_accounts")
17
+ response.body.map { |ca| CorporateAccount.new(ca.empty? ? {} : ca) }
9
18
  end
10
19
  end
11
20
  end
@@ -10,6 +10,16 @@ module Apruve
10
10
  Order.new(response.body)
11
11
  end
12
12
 
13
+ def self.find_all(merchant_order_id = nil)
14
+ if merchant_order_id.nil?
15
+ response = Apruve.get('orders')
16
+ else
17
+ response = Apruve.get("orders?merchant_order_id=#{merchant_order_id}")
18
+ end
19
+ logger.debug response.body
20
+ response.body.map { |order| Order.new(order) }
21
+ end
22
+
13
23
  def self.finalize!(id)
14
24
  response = Apruve.post("orders/#{id}/finalize")
15
25
  logger.debug response.body
@@ -54,7 +64,6 @@ module Apruve
54
64
  def validate
55
65
  errors = []
56
66
  errors << 'merchant_id must be set' if merchant_id.nil?
57
- errors << 'payment_term must be supplied' if payment_term.nil?
58
67
  raise Apruve::ValidationError.new(errors) if errors.length > 0
59
68
  end
60
69
 
@@ -1,3 +1,3 @@
1
1
  module Apruve
2
- VERSION = '1.1.4'
2
+ VERSION = '1.1.5'
3
3
  end
@@ -38,31 +38,45 @@ describe Apruve::CorporateAccount do
38
38
  it { should respond_to(:payment_method_id) }
39
39
  it { should respond_to(:status) }
40
40
  it { should respond_to(:trusted_merchant) }
41
-
41
+ it { should respond_to(:authorized_buyers) }
42
42
 
43
43
  describe '#find' do
44
- describe 'success' do
44
+ context 'successful response' do
45
45
  let! (:stubs) do
46
46
  faraday_stubs do |stub|
47
47
  stub.get("/api/v4/merchants/#{merchant_uuid}/corporate_accounts?email=#{email}") { [200, {}, '{}'] }
48
48
  end
49
49
  end
50
- it 'should do a get' do
50
+ it 'should get a corporate account' do
51
51
  Apruve::CorporateAccount.find(merchant_uuid, email)
52
52
  stubs.verify_stubbed_calls
53
53
  end
54
54
  end
55
55
 
56
- describe 'not found' do
56
+ context 'when not found' do
57
57
  let! (:stubs) do
58
58
  faraday_stubs do |stub|
59
59
  stub.get("/api/v4/merchants/#{merchant_uuid}/corporate_accounts?email=#{email}") { [404, {}, 'Not Found'] }
60
60
  end
61
61
  end
62
- it 'should raise' do
62
+ it 'should raise not found' do
63
63
  expect { Apruve::CorporateAccount.find(merchant_uuid, email) }.to raise_error(Apruve::NotFound)
64
64
  stubs.verify_stubbed_calls
65
65
  end
66
66
  end
67
67
  end
68
- end
68
+
69
+ describe '#find_all' do
70
+ describe 'successful response' do
71
+ let! (:stubs) do
72
+ faraday_stubs do |stub|
73
+ stub.get("/api/v4/merchants/#{merchant_uuid}/corporate_accounts") { [200, {} , '{}'] }
74
+ end
75
+ end
76
+ it 'should get all corporate accounts for a merchant' do
77
+ Apruve::CorporateAccount.find_all(merchant_uuid)
78
+ stubs.verify_stubbed_calls
79
+ end
80
+ end
81
+ end
82
+ end
@@ -141,6 +141,33 @@ describe Apruve::Order do
141
141
  end
142
142
  end
143
143
 
144
+ describe '#find_all' do
145
+ context 'successful response' do
146
+ let! (:stubs) do
147
+ faraday_stubs do |stub|
148
+ stub.get('/api/v4/orders') { [200, {}, '[]'] }
149
+ end
150
+ end
151
+ it 'should get all orders' do
152
+ Apruve::Order.find_all
153
+ stubs.verify_stubbed_calls
154
+ end
155
+ end
156
+
157
+ context 'with invalid merchant_order_id query param' do
158
+ let (:invalid_id) { '123' }
159
+ let! (:stubs) do
160
+ faraday_stubs do |stub|
161
+ stub.get("api/v4/orders?merchant_order_id=#{invalid_id}") { [200, {}, '[]']}
162
+ end
163
+ end
164
+ it 'should return an empty array' do
165
+ Apruve::Order.find_all(invalid_id)
166
+ stubs.verify_stubbed_calls
167
+ end
168
+ end
169
+ end
170
+
144
171
  describe '#save' do
145
172
  let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
146
173
  let (:status) { 'pending' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apruve
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apruve, Inc.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-07 00:00:00.000000000 Z
12
+ date: 2017-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler