invoiced 0.14.0 → 2.0.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.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -1
  3. data/.travis.yml +3 -0
  4. data/README.md +11 -4
  5. data/lib/invoiced.rb +25 -5
  6. data/lib/invoiced/bank_account.rb +6 -0
  7. data/lib/invoiced/card.rb +6 -0
  8. data/lib/invoiced/charge.rb +12 -0
  9. data/lib/invoiced/{catalog_item.rb → coupon.rb} +2 -2
  10. data/lib/invoiced/credit_balance_adjustment.rb +10 -0
  11. data/lib/invoiced/credit_note.rb +8 -0
  12. data/lib/invoiced/customer.rb +34 -0
  13. data/lib/invoiced/estimate.rb +8 -0
  14. data/lib/invoiced/invoice.rb +31 -1
  15. data/lib/invoiced/item.rb +10 -0
  16. data/lib/invoiced/letter.rb +5 -0
  17. data/lib/invoiced/note.rb +10 -0
  18. data/lib/invoiced/object.rb +2 -2
  19. data/lib/invoiced/operations/create.rb +1 -1
  20. data/lib/invoiced/{transaction.rb → payment.rb} +2 -8
  21. data/lib/invoiced/payment_source.rb +8 -0
  22. data/lib/invoiced/payment_source_object.rb +5 -0
  23. data/lib/invoiced/refund.rb +11 -0
  24. data/lib/invoiced/subscription.rb +6 -0
  25. data/lib/invoiced/task.rb +10 -0
  26. data/lib/invoiced/tax_rate.rb +10 -0
  27. data/lib/invoiced/text_message.rb +5 -0
  28. data/lib/invoiced/util.rb +13 -1
  29. data/lib/invoiced/version.rb +1 -1
  30. data/test/invoiced/charge_test.rb +25 -0
  31. data/test/invoiced/{catalog_item_test.rb → coupon_test.rb} +33 -33
  32. data/test/invoiced/credit_balance_adjustment.rb +90 -0
  33. data/test/invoiced/credit_note_test.rb +14 -0
  34. data/test/invoiced/customer_test.rb +101 -2
  35. data/test/invoiced/estimate_test.rb +14 -0
  36. data/test/invoiced/invoice_test.rb +69 -1
  37. data/test/invoiced/item_test.rb +90 -0
  38. data/test/invoiced/note_test.rb +90 -0
  39. data/test/invoiced/payment_source_test.rb +57 -0
  40. data/test/invoiced/{transaction_test.rb → payment_test.rb} +32 -47
  41. data/test/invoiced/refund_test.rb +25 -0
  42. data/test/invoiced/subscription_test.rb +13 -0
  43. data/test/invoiced/task_test.rb +90 -0
  44. data/test/invoiced/tax_rate_test.rb +90 -0
  45. metadata +38 -10
@@ -87,7 +87,7 @@ module Invoiced
87
87
  assert_true(invoice.delete)
88
88
  end
89
89
 
90
- should "send an invoice" do
90
+ should "send an invoice by email" do
91
91
  mockResponse = mock('RestClient::Response')
92
92
  mockResponse.stubs(:code).returns(201)
93
93
  mockResponse.stubs(:body).returns('[{"id":4567,"email":"test@example.com"}]')
@@ -104,6 +104,40 @@ module Invoiced
104
104
  assert_equal(4567, emails[0].id)
105
105
  end
106
106
 
107
+ should "send an invoice by text message" do
108
+ mockResponse = mock('RestClient::Response')
109
+ mockResponse.stubs(:code).returns(201)
110
+ mockResponse.stubs(:body).returns('[{"id":5678,"state":"sent"}]')
111
+ mockResponse.stubs(:headers).returns({})
112
+
113
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
114
+
115
+ invoice = Invoice.new(@client, 1234)
116
+ text_messages = invoice.send_sms(:message => "example")
117
+
118
+ assert_instance_of(Array, text_messages)
119
+ assert_equal(1, text_messages.length)
120
+ assert_instance_of(Invoiced::TextMessage, text_messages[0])
121
+ assert_equal(5678, text_messages[0].id)
122
+ end
123
+
124
+ should "send an invoice by letter" do
125
+ mockResponse = mock('RestClient::Response')
126
+ mockResponse.stubs(:code).returns(201)
127
+ mockResponse.stubs(:body).returns('[{"id":6789,"state":"queued"}]')
128
+ mockResponse.stubs(:headers).returns({})
129
+
130
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
131
+
132
+ invoice = Invoice.new(@client, 1234)
133
+ letters = invoice.send_letter
134
+
135
+ assert_instance_of(Array, letters)
136
+ assert_equal(1, letters.length)
137
+ assert_instance_of(Invoiced::Letter, letters[0])
138
+ assert_equal(6789, letters[0].id)
139
+ end
140
+
107
141
  should "pay an invoice" do
108
142
  mockResponse = mock('RestClient::Response')
109
143
  mockResponse.stubs(:code).returns(200)
@@ -170,5 +204,39 @@ module Invoiced
170
204
  assert_equal("active", payment_plan.status)
171
205
  assert_equal('/invoices/456/payment_plan', payment_plan.endpoint())
172
206
  end
207
+
208
+ should "list all notes associated with invoice" do
209
+ mockResponse = mock('RestClient::Response')
210
+ mockResponse.stubs(:code).returns(200)
211
+ mockResponse.stubs(:body).returns('[{"id":1212,"notes":"example"}]')
212
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="last"')
213
+
214
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
215
+
216
+ invoice = Invoice.new(@client, 1234)
217
+ notes, metadata = invoice.notes.list
218
+
219
+ assert_instance_of(Array, notes)
220
+ assert_equal(1, notes.length)
221
+ assert_equal(1212, notes[0].id)
222
+ assert_equal('/invoices/1234/notes/1212', notes[0].endpoint())
223
+
224
+ assert_instance_of(Invoiced::List, metadata)
225
+ assert_equal(15, metadata.total_count)
226
+ end
227
+
228
+ should "void an invoice" do
229
+ mockResponse = mock('RestClient::Response')
230
+ mockResponse.stubs(:code).returns(200)
231
+ mockResponse.stubs(:body).returns('{"id":123,"status":"voided"}')
232
+ mockResponse.stubs(:headers).returns({})
233
+
234
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
235
+
236
+ invoice = Invoice.new(@client, 123)
237
+ assert_true(invoice.void)
238
+
239
+ assert_equal(invoice.status, 'voided')
240
+ end
173
241
  end
174
242
  end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class ItemTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ item = Item.new(@client, "test")
7
+ assert_equal('/items/test', item.endpoint())
8
+ end
9
+
10
+ should "create an item" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Item"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ item = @client.Item.create({:name => "Test Item"})
19
+
20
+ assert_instance_of(Invoiced::Item, item)
21
+ assert_equal("test", item.id)
22
+ assert_equal('Test Item', item.name)
23
+ end
24
+
25
+ should "retrieve an item" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Item"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ item = @client.Item.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::Item, item)
36
+ assert_equal("test", item.id)
37
+ assert_equal('Test Item', item.name)
38
+ end
39
+
40
+ should "not update an item when no params" do
41
+ item = Item.new(@client, "test")
42
+ assert_false(item.save)
43
+ end
44
+
45
+ should "update an item" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","closed":true}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ item = Item.new(@client, "test")
54
+ item.closed = true
55
+ assert_true(item.save)
56
+
57
+ assert_true(item.closed)
58
+ end
59
+
60
+ should "list all items" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Item"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/items?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ items, metadata = @client.Item.list
69
+
70
+ assert_instance_of(Array, items)
71
+ assert_equal(1, items.length)
72
+ assert_equal("test", items[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete an item" do
79
+ mockResponse = mock('RestClient::Response')
80
+ mockResponse.stubs(:code).returns(204)
81
+ mockResponse.stubs(:body).returns('')
82
+ mockResponse.stubs(:headers).returns({})
83
+
84
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
+
86
+ item = Item.new(@client, "test")
87
+ assert_true(item.delete)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class NoteTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ note = Note.new(@client, "test")
7
+ assert_equal('/notes/test', note.endpoint())
8
+ end
9
+
10
+ should "create a note" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","notes":"Test Note"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ note = @client.Note.create({:notes => "Test Note"})
19
+
20
+ assert_instance_of(Invoiced::Note, note)
21
+ assert_equal("test", note.id)
22
+ assert_equal('Test Note', note.notes)
23
+ end
24
+
25
+ should "retrieve a note" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","notes":"Test Note"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ note = @client.Note.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::Note, note)
36
+ assert_equal("test", note.id)
37
+ assert_equal('Test Note', note.notes)
38
+ end
39
+
40
+ should "not update a note when no params" do
41
+ note = Note.new(@client, "test")
42
+ assert_false(note.save)
43
+ end
44
+
45
+ should "update a note" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","notes":"new contents"}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ note = Note.new(@client, "test")
54
+ note.notes = "new contents"
55
+ assert_true(note.save)
56
+
57
+ assert_equal(note.notes, 'new contents')
58
+ end
59
+
60
+ should "list all notes" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","notes":"Test Note"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/notes?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ notes, metadata = @client.Note.list
69
+
70
+ assert_instance_of(Array, notes)
71
+ assert_equal(1, notes.length)
72
+ assert_equal("test", notes[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a note" do
79
+ mockResponse = mock('RestClient::Response')
80
+ mockResponse.stubs(:code).returns(204)
81
+ mockResponse.stubs(:body).returns('')
82
+ mockResponse.stubs(:headers).returns({})
83
+
84
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
+
86
+ note = Note.new(@client, "test")
87
+ assert_true(note.delete)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class PaymentSourceTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ payment_source = Customer.new(@client, 1234).payment_sources()
7
+ assert_equal('/customers/1234/payment_sources', payment_source.endpoint())
8
+ end
9
+
10
+ should "list all payment sources" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(200)
13
+ mockResponse.stubs(:body).returns('[{"id":123,"object":"card"},{"id":234,"object":"bank_account"}]')
14
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/payment_sources?per_page=25&page=1>; rel="self", <https://api.invoiced.com/payment_sources?per_page=25&page=1>; rel="first", <https://api.invoiced.com/payment_sources?per_page=25&page=1>; rel="last"')
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ payment_source = PaymentSource.new(@client)
19
+ payment_sources, metadata = payment_source.list
20
+
21
+ assert_instance_of(Array, payment_sources)
22
+ assert_instance_of(Invoiced::Card, payment_sources[0])
23
+ assert_instance_of(Invoiced::BankAccount, payment_sources[1])
24
+ assert_equal(2, payment_sources.length)
25
+ assert_equal(123, payment_sources[0][:id])
26
+
27
+ assert_instance_of(Invoiced::List, metadata)
28
+ assert_equal(15, metadata.total_count)
29
+ end
30
+
31
+ should "delete a card payment source" do
32
+ mockResponse = mock('RestClient::Response')
33
+ mockResponse.stubs(:code).returns(204)
34
+ mockResponse.stubs(:body).returns('')
35
+ mockResponse.stubs(:headers).returns({})
36
+
37
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
38
+
39
+ card = Card.new(@client, 123)
40
+ card.object = 'card'
41
+ assert_true(card.delete)
42
+ end
43
+
44
+ should "delete a bank account payment source" do
45
+ mockResponse = mock('RestClient::Response')
46
+ mockResponse.stubs(:code).returns(204)
47
+ mockResponse.stubs(:body).returns('')
48
+ mockResponse.stubs(:headers).returns({})
49
+
50
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
51
+
52
+ bank_account = BankAccount.new(@client, 123)
53
+ bank_account.object = 'bank_account'
54
+ assert_true(bank_account.delete)
55
+ end
56
+ end
57
+ end
@@ -1,13 +1,13 @@
1
1
  require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
- class TransactionTest < Test::Unit::TestCase
4
+ class PaymentTest < Test::Unit::TestCase
5
5
  should "return the api endpoint" do
6
- transaction = Transaction.new(@client, 123)
7
- assert_equal('/transactions/123', transaction.endpoint())
6
+ payment = Payment.new(@client, 123)
7
+ assert_equal('/payments/123', payment.endpoint())
8
8
  end
9
9
 
10
- should "create a transaction" do
10
+ should "create a payment" do
11
11
  mockResponse = mock('RestClient::Response')
12
12
  mockResponse.stubs(:code).returns(201)
13
13
  mockResponse.stubs(:body).returns('{"id":123,"amount":100}')
@@ -15,14 +15,14 @@ module Invoiced
15
15
 
16
16
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
17
 
18
- transaction = @client.Transaction.create({:amount => 800})
18
+ payment = @client.Payment.create({:amount => 800})
19
19
 
20
- assert_instance_of(Invoiced::Transaction, transaction)
21
- assert_equal(123, transaction.id)
22
- assert_equal(100, transaction.amount)
20
+ assert_instance_of(Invoiced::Payment, payment)
21
+ assert_equal(123, payment.id)
22
+ assert_equal(100, payment.amount)
23
23
  end
24
24
 
25
- should "retrieve a transaction" do
25
+ should "retrieve a payment" do
26
26
  mockResponse = mock('RestClient::Response')
27
27
  mockResponse.stubs(:code).returns(200)
28
28
  mockResponse.stubs(:body).returns('{"id":123,"amount":100}')
@@ -30,19 +30,19 @@ module Invoiced
30
30
 
31
31
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
32
 
33
- transaction = @client.Transaction.retrieve(123)
33
+ payment = @client.Payment.retrieve(123)
34
34
 
35
- assert_instance_of(Invoiced::Transaction, transaction)
36
- assert_equal(123, transaction.id)
37
- assert_equal(100, transaction.amount)
35
+ assert_instance_of(Invoiced::Payment, payment)
36
+ assert_equal(123, payment.id)
37
+ assert_equal(100, payment.amount)
38
38
  end
39
39
 
40
- should "not update a transaction when no params" do
41
- transaction = Transaction.new(@client, 123)
42
- assert_false(transaction.save)
40
+ should "not update a payment when no params" do
41
+ payment = Payment.new(@client, 123)
42
+ assert_false(payment.save)
43
43
  end
44
44
 
45
- should "update a transaction" do
45
+ should "update a payment" do
46
46
  mockResponse = mock('RestClient::Response')
47
47
  mockResponse.stubs(:code).returns(200)
48
48
  mockResponse.stubs(:body).returns('{"id":123,"sent":true}')
@@ -50,32 +50,32 @@ module Invoiced
50
50
 
51
51
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
52
 
53
- transaction = Transaction.new(@client, 123)
54
- transaction.sent = true
55
- assert_true(transaction.save)
53
+ payment = Payment.new(@client, 123)
54
+ payment.sent = true
55
+ assert_true(payment.save)
56
56
 
57
- assert_true(transaction.sent)
57
+ assert_true(payment.sent)
58
58
  end
59
59
 
60
- should "list all transactions" do
60
+ should "list all payments" do
61
61
  mockResponse = mock('RestClient::Response')
62
62
  mockResponse.stubs(:code).returns(200)
63
63
  mockResponse.stubs(:body).returns('[{"id":123,"amount":100}]')
64
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/transactions?per_page=25&page=1>; rel="self", <https://api.invoiced.com/transactions?per_page=25&page=1>; rel="first", <https://api.invoiced.com/transactions?per_page=25&page=1>; rel="last"')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/payments?per_page=25&page=1>; rel="self", <https://api.invoiced.com/payments?per_page=25&page=1>; rel="first", <https://api.invoiced.com/payments?per_page=25&page=1>; rel="last"')
65
65
 
66
66
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
67
 
68
- transactions, metadata = @client.Transaction.list
68
+ payments, metadata = @client.Payment.list
69
69
 
70
- assert_instance_of(Array, transactions)
71
- assert_equal(1, transactions.length)
72
- assert_equal(123, transactions[0].id)
70
+ assert_instance_of(Array, payments)
71
+ assert_equal(1, payments.length)
72
+ assert_equal(123, payments[0].id)
73
73
 
74
74
  assert_instance_of(Invoiced::List, metadata)
75
75
  assert_equal(15, metadata.total_count)
76
76
  end
77
77
 
78
- should "delete a transaction" do
78
+ should "delete a payment" do
79
79
  mockResponse = mock('RestClient::Response')
80
80
  mockResponse.stubs(:code).returns(204)
81
81
  mockResponse.stubs(:body).returns('')
@@ -83,8 +83,8 @@ module Invoiced
83
83
 
84
84
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
85
 
86
- transaction = Transaction.new(@client, 123)
87
- assert_true(transaction.delete)
86
+ payment = Payment.new(@client, 123)
87
+ assert_true(payment.delete)
88
88
  end
89
89
 
90
90
  should "send a payment receipt" do
@@ -95,28 +95,13 @@ module Invoiced
95
95
 
96
96
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
97
97
 
98
- transaction = Transaction.new(@client, 1234)
99
- emails = transaction.send
98
+ payment = Payment.new(@client, 1234)
99
+ emails = payment.send
100
100
 
101
101
  assert_instance_of(Array, emails)
102
102
  assert_equal(1, emails.length)
103
103
  assert_instance_of(Invoiced::Email, emails[0])
104
104
  assert_equal(4567, emails[0].id)
105
105
  end
106
-
107
- should "refund a transaction" do
108
- mockResponse = mock('RestClient::Response')
109
- mockResponse.stubs(:code).returns(201)
110
- mockResponse.stubs(:body).returns('{"id":456}')
111
- mockResponse.stubs(:headers).returns({})
112
-
113
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
114
-
115
- transaction = Transaction.new(@client, 1234)
116
- refund = transaction.refund({:amount => 800})
117
-
118
- assert_instance_of(Invoiced::Transaction, refund)
119
- assert_equal(456, refund.id)
120
- end
121
106
  end
122
107
  end