invoiced 0.8.1 → 0.9.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: 1b98433a3e628556bd4d294f5bae44d5b10f08fb
4
- data.tar.gz: 6bd2918198be5721927beed9fb274e3ca5bd9328
3
+ metadata.gz: 7d993a9653fa91682598ce436fd439aac622038b
4
+ data.tar.gz: 37fe418a43489d5455477001bd89d11a72a627fb
5
5
  SHA512:
6
- metadata.gz: b90dc335734439b91f07bb1bd5a22739959f49389f178d1e21dce3e77c5650fd0307dcf7223a9556bce8cbc0ec34581719b38775c637cc4f69bcc0d0df9099a5
7
- data.tar.gz: 42bad9d2f4113e27889dfff5334be4f5f947a31afe2514bb931a5ea6f5dac5bd80730ccf20d72e0bfb8582222fe8688149997f83539c484e38ad85e64558c51f
6
+ metadata.gz: d49663b88444545d104013081d64d7ef34b3a6e7ba631aa5ae33aa7562ebd545266af5d9fe46f0b56b98ddb1d8c8e89be048a80ae06bc0193d1bb89a5f26ac2a
7
+ data.tar.gz: a2b40dda8276ca3baeb4f2b0165249980d64fe92f0be2d9d8894738881409c22cae3f5e521b1be8e3ce079a9f7d40fa870e4c53075ad19303be856a92134b4c4
@@ -42,5 +42,10 @@ module Invoiced
42
42
 
43
43
  return attachments, metadata
44
44
  end
45
+
46
+ def payment_plan(opts={})
47
+ paymentPlan = PaymentPlan.new(@client)
48
+ paymentPlan.set_endpoint_base(self.endpoint())
49
+ end
45
50
  end
46
51
  end
@@ -0,0 +1,27 @@
1
+ module Invoiced
2
+ class PaymentPlan < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Delete
5
+
6
+ def initialize(client, id=nil, values={})
7
+ super
8
+ @endpoint = '/payment_plan'
9
+ end
10
+
11
+ def create(body={})
12
+ response = @client.request(:put, self.endpoint(), body)
13
+
14
+ Util.convert_to_object(self, response[:body])
15
+ end
16
+
17
+ def retrieve(opts={})
18
+ response = @client.request(:get, self.endpoint(), opts)
19
+
20
+ Util.convert_to_object(self, response[:body])
21
+ end
22
+
23
+ def cancel
24
+ delete
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '0.8.1'
2
+ VERSION = '0.9.0'
3
3
  end
data/lib/invoiced.rb CHANGED
@@ -27,6 +27,7 @@ require 'invoiced/event'
27
27
  require 'invoiced/file'
28
28
  require 'invoiced/invoice'
29
29
  require 'invoiced/line_item'
30
+ require 'invoiced/payment_plan'
30
31
  require 'invoiced/subscription'
31
32
  require 'invoiced/transaction'
32
33
 
@@ -136,5 +136,39 @@ module Invoiced
136
136
  assert_instance_of(Invoiced::List, metadata)
137
137
  assert_equal(10, metadata.total_count)
138
138
  end
139
+
140
+ should "create a payment plan" do
141
+ mockResponse = mock('RestClient::Response')
142
+ mockResponse.stubs(:code).returns(201)
143
+ mockResponse.stubs(:body).returns('{"id":123,"status":"active"}')
144
+ mockResponse.stubs(:headers).returns({})
145
+
146
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
147
+
148
+ invoice = Invoice.new(@client, 456)
149
+ payment_plan = invoice.payment_plan.create({:installments => [{"date"=>1234,"amount" => 100}]})
150
+
151
+ assert_instance_of(Invoiced::PaymentPlan, payment_plan)
152
+ assert_equal(123, payment_plan.id)
153
+ assert_equal("active", payment_plan.status)
154
+ assert_equal('/invoices/456/payment_plan', payment_plan.endpoint())
155
+ end
156
+
157
+ should "retrieve a payment plan" do
158
+ mockResponse = mock('RestClient::Response')
159
+ mockResponse.stubs(:code).returns(200)
160
+ mockResponse.stubs(:body).returns('{"id":123,"status":"active"}')
161
+ mockResponse.stubs(:headers).returns({})
162
+
163
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
164
+
165
+ invoice = Invoice.new(@client, 456)
166
+ payment_plan = invoice.payment_plan.retrieve()
167
+
168
+ assert_instance_of(Invoiced::PaymentPlan, payment_plan)
169
+ assert_equal(123, payment_plan.id)
170
+ assert_equal("active", payment_plan.status)
171
+ assert_equal('/invoices/456/payment_plan', payment_plan.endpoint())
172
+ end
139
173
  end
140
174
  end
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class PaymentPlanTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ paymentPlan = PaymentPlan.new(@client, 123)
7
+ assert_equal('/payment_plan', paymentPlan.endpoint())
8
+ end
9
+
10
+ should "create a payment plan" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":123,"status":"active"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ paymentPlan = PaymentPlan.new(@client)
19
+ payment_plan = paymentPlan.create({:installments => [{"date"=>1234,"amount" => 100}]})
20
+
21
+ assert_instance_of(Invoiced::PaymentPlan, payment_plan)
22
+ assert_equal(123, payment_plan.id)
23
+ assert_equal("active", payment_plan.status)
24
+ end
25
+
26
+ should "retrieve a payment plan" do
27
+ mockResponse = mock('RestClient::Response')
28
+ mockResponse.stubs(:code).returns(200)
29
+ mockResponse.stubs(:body).returns('{"id":123,"status":"active"}')
30
+ mockResponse.stubs(:headers).returns({})
31
+
32
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
33
+
34
+ paymentPlan = PaymentPlan.new(@client)
35
+ payment_plan = paymentPlan.retrieve()
36
+
37
+ assert_instance_of(Invoiced::PaymentPlan, payment_plan)
38
+ assert_equal(123, payment_plan.id)
39
+ assert_equal("active", payment_plan.status)
40
+ end
41
+
42
+ should "cancel a payment plan" do
43
+ mockResponse = mock('RestClient::Response')
44
+ mockResponse.stubs(:code).returns(204)
45
+ mockResponse.stubs(:body).returns('')
46
+ mockResponse.stubs(:headers).returns({})
47
+
48
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
49
+
50
+ payment_plan = PaymentPlan.new(@client, 123)
51
+ assert_true(payment_plan.cancel)
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoiced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared King
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -143,6 +143,7 @@ files:
143
143
  - lib/invoiced/operations/delete.rb
144
144
  - lib/invoiced/operations/list.rb
145
145
  - lib/invoiced/operations/update.rb
146
+ - lib/invoiced/payment_plan.rb
146
147
  - lib/invoiced/subscription.rb
147
148
  - lib/invoiced/transaction.rb
148
149
  - lib/invoiced/util.rb
@@ -158,6 +159,7 @@ files:
158
159
  - test/invoiced/invoiced_test.rb
159
160
  - test/invoiced/line_item_test.rb
160
161
  - test/invoiced/object_test.rb
162
+ - test/invoiced/payment_plan_test.rb
161
163
  - test/invoiced/subscription_test.rb
162
164
  - test/invoiced/transaction_test.rb
163
165
  - test/invoiced/util_test.rb
@@ -198,6 +200,7 @@ test_files:
198
200
  - test/invoiced/invoiced_test.rb
199
201
  - test/invoiced/line_item_test.rb
200
202
  - test/invoiced/object_test.rb
203
+ - test/invoiced/payment_plan_test.rb
201
204
  - test/invoiced/subscription_test.rb
202
205
  - test/invoiced/transaction_test.rb
203
206
  - test/invoiced/util_test.rb