invoiced 0.14.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 30c5827c11d5486e3b59fe3443bb63d8674eca3c
4
- data.tar.gz: 7edd7c088f5df46d2159842c33620493ac1866b3
2
+ SHA256:
3
+ metadata.gz: ae182e66a354b88c600800a9f0ef40ff695c44671c8b3bf2bd24100c61be2cdf
4
+ data.tar.gz: 3e0897128ea15e9086098560b4beac41e61a97e44a8ec8db542be023e7486e75
5
5
  SHA512:
6
- metadata.gz: 507af5506883b32332cd60a0dc2fafecc084b57fd600e267f615690bc1ba8cfc9fd4b3969e6b2387582c211b1b648470625914bf8d0da9b9cb309f00d7a961ff
7
- data.tar.gz: 4cd5f77e2feeba132dee73ab7cb34b60d9e8d3eceeea5ae437cf7121c249967468cacd5982ed0497b032d6d08968a764d4fbc5c42b4764a65ca1d0fea5446896
6
+ metadata.gz: 4039ccc2d285ddfcdd0c0aa97aae3c02330fdfdbcfddd1e4c559d0f08b101ec698f396baba1f33a075ac11e805318bad24dac55cbabaafd675e7654e33549424
7
+ data.tar.gz: e2d7415d9b996f6ef9b1a63e80f4b14ebbdf411a1fccff21f07803a53048f4922d3eb015162b7f606b7d7a37e471ad8ef40943a4628e7d8c459b819d65c1ec07
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  Gemfile.lock
2
2
  example.rb
3
3
  /invoiced-*.gem
4
- /coverage
4
+ /coverage
5
+ .DS_Store
6
+ .idea/
@@ -5,6 +5,9 @@ rvm:
5
5
  - 2.2
6
6
  - 2.3
7
7
  - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ - 2.7
8
11
 
9
12
  sudo: false
10
13
 
data/README.md CHANGED
@@ -3,8 +3,9 @@ invoiced-ruby
3
3
 
4
4
  This repository contains the Ruby client library for the [Invoiced](https://invoiced.com) API.
5
5
 
6
- [![Build Status](https://travis-ci.org/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.org/Invoiced/invoiced-ruby)
6
+ [![Build Status](https://travis-ci.com/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.com/Invoiced/invoiced-ruby)
7
7
  [![Coverage Status](https://coveralls.io/repos/Invoiced/invoiced-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/Invoiced/invoiced-ruby?branch=master)
8
+ [![Gem Version](https://badge.fury.io/rb/invoiced.svg)](https://badge.fury.io/rb/invoiced)
8
9
 
9
10
  ## Installing
10
11
 
@@ -44,10 +45,16 @@ Then, API calls can be made like this:
44
45
  invoice = invoiced.Invoice.retrieve("{INVOICE_ID}")
45
46
 
46
47
  # mark as paid
47
- transaction = invoiced.Transaction.create(
48
- :invoice => invoice.id,
48
+ payment = invoiced.Payment.create(
49
49
  :amount => invoice.balance,
50
- :method => "check")
50
+ :method => "check",
51
+ :applied_to => [
52
+ {
53
+ :type => "invoice",
54
+ :invoice => invoice.id,
55
+ :amount => invoice.balance
56
+ }
57
+ ])
51
58
  ```
52
59
 
53
60
  If you want to use the sandbox API instead then you must set the second argument on the client to `true` like this:
@@ -18,9 +18,14 @@ require 'invoiced/operations/delete'
18
18
  require 'invoiced/operations/update'
19
19
 
20
20
  require 'invoiced/object'
21
+ require 'invoiced/payment_source_object'
21
22
  require 'invoiced/attachment'
22
- require 'invoiced/catalog_item'
23
+ require 'invoiced/bank_account'
24
+ require 'invoiced/card'
25
+ require 'invoiced/charge'
23
26
  require 'invoiced/contact'
27
+ require 'invoiced/coupon'
28
+ require 'invoiced/credit_balance_adjustment'
24
29
  require 'invoiced/credit_note'
25
30
  require 'invoiced/customer'
26
31
  require 'invoiced/email'
@@ -28,11 +33,19 @@ require 'invoiced/estimate'
28
33
  require 'invoiced/event'
29
34
  require 'invoiced/file'
30
35
  require 'invoiced/invoice'
36
+ require 'invoiced/item'
37
+ require 'invoiced/letter'
31
38
  require 'invoiced/line_item'
39
+ require 'invoiced/note'
40
+ require 'invoiced/payment'
32
41
  require 'invoiced/payment_plan'
42
+ require 'invoiced/payment_source'
33
43
  require 'invoiced/plan'
44
+ require 'invoiced/refund'
34
45
  require 'invoiced/subscription'
35
- require 'invoiced/transaction'
46
+ require 'invoiced/task'
47
+ require 'invoiced/tax_rate'
48
+ require 'invoiced/text_message'
36
49
 
37
50
  module Invoiced
38
51
  class Client
@@ -43,7 +56,7 @@ module Invoiced
43
56
  ReadTimeout = 80
44
57
 
45
58
  attr_reader :api_key, :api_url, :sandbox, :sso_key
46
- attr_reader :CatalogItem, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Plan, :Subscription, :Transaction
59
+ attr_reader :Item, :Charge, :Coupon, :CreditBalanceAdjustment, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Payment, :Plan, :Refund, :Subscription, :Task, :TaxRate
47
60
 
48
61
  def initialize(api_key, sandbox=false, sso_key=false)
49
62
  @api_key = api_key
@@ -52,16 +65,23 @@ module Invoiced
52
65
  @sso_key = sso_key
53
66
 
54
67
  # Object endpoints
55
- @CatalogItem = Invoiced::CatalogItem.new(self)
68
+ @Item = Invoiced::Item.new(self)
69
+ @Charge = Invoiced::Charge.new(self)
70
+ @Coupon = Invoiced::Coupon.new(self)
71
+ @CreditBalanceAdjustment = Invoiced::CreditBalanceAdjustment.new(self)
56
72
  @CreditNote = Invoiced::CreditNote.new(self)
57
73
  @Customer = Invoiced::Customer.new(self)
58
74
  @Estimate = Invoiced::Estimate.new(self)
59
75
  @Event = Invoiced::Event.new(self)
60
76
  @File = Invoiced::File.new(self)
61
77
  @Invoice = Invoiced::Invoice.new(self)
78
+ @Note = Invoiced::Note.new(self)
79
+ @Payment = Invoiced::Payment.new(self)
62
80
  @Plan = Invoiced::Plan.new(self)
81
+ @Refund = Invoiced::Refund.new(self)
63
82
  @Subscription = Invoiced::Subscription.new(self)
64
- @Transaction = Invoiced::Transaction.new(self)
83
+ @Task = Invoiced::Task.new(self)
84
+ @TaxRate = Invoiced::TaxRate.new(self)
65
85
  end
66
86
 
67
87
  def request(method, endpoint, params={}, opts={})
@@ -0,0 +1,6 @@
1
+ module Invoiced
2
+ class BankAccount < PaymentSourceObject
3
+
4
+ OBJECT_NAME = 'bank_account'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Invoiced
2
+ class Card < PaymentSourceObject
3
+
4
+ OBJECT_NAME = 'card'
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ module Invoiced
2
+ class Charge < Object
3
+ OBJECT_NAME = 'charge'
4
+
5
+ def create(body={}, opts={})
6
+ response = @client.request(:post, endpoint(), body, opts)
7
+
8
+ payment = Payment.new(@client)
9
+ Util.convert_to_object(payment, response[:body])
10
+ end
11
+ end
12
+ end
@@ -1,10 +1,10 @@
1
1
  module Invoiced
2
- class CatalogItem < Object
2
+ class Coupon < Object
3
3
  include Invoiced::Operations::List
4
4
  include Invoiced::Operations::Create
5
5
  include Invoiced::Operations::Update
6
6
  include Invoiced::Operations::Delete
7
7
 
8
- OBJECT_NAME = 'catalog_item'
8
+ OBJECT_NAME = 'coupon'
9
9
  end
10
10
  end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class CreditBalanceAdjustment < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'credit_balance_adjustment'
9
+ end
10
+ end
@@ -35,5 +35,13 @@ module Invoiced
35
35
 
36
36
  return attachments, metadata
37
37
  end
38
+
39
+ def void()
40
+ response = @client.request(:post, "#{self.endpoint()}/void", {})
41
+
42
+ refresh_from(response[:body].dup.merge({:id => self.id}))
43
+
44
+ return response[:code] == 200
45
+ end
38
46
  end
39
47
  end
@@ -15,6 +15,22 @@ module Invoiced
15
15
  Util.build_objects(email, response[:body])
16
16
  end
17
17
 
18
+ def send_statement_sms(params={}, opts={})
19
+ response = @client.request(:post, "#{self.endpoint()}/text_messages", params, opts)
20
+
21
+ # build text message objects
22
+ text_message = TextMessage.new(@client)
23
+ Util.build_objects(text_message, response[:body])
24
+ end
25
+
26
+ def send_statement_letter(params={}, opts={})
27
+ response = @client.request(:post, "#{self.endpoint()}/letters", params, opts)
28
+
29
+ # build letter objects
30
+ letter = Letter.new(@client)
31
+ Util.build_objects(letter, response[:body])
32
+ end
33
+
18
34
  def balance
19
35
  response = @client.request(:get, "#{self.endpoint()}/balance")
20
36
 
@@ -26,11 +42,21 @@ module Invoiced
26
42
  contact.set_endpoint_base(self.endpoint())
27
43
  end
28
44
 
45
+ def payment_sources()
46
+ source = PaymentSource.new(@client)
47
+ source.set_endpoint_base(self.endpoint())
48
+ end
49
+
29
50
  def line_items()
30
51
  line = LineItem.new(@client)
31
52
  line.set_endpoint_base(self.endpoint())
32
53
  end
33
54
 
55
+ def list_notes()
56
+ note = Note.new(@client)
57
+ note.set_endpoint_base(self.endpoint())
58
+ end
59
+
34
60
  def invoice(params={}, opts={})
35
61
  response = @client.request(:post, "#{self.endpoint()}/invoices", params, opts)
36
62
 
@@ -38,5 +64,13 @@ module Invoiced
38
64
  invoice = Invoice.new(@client)
39
65
  Util.convert_to_object(invoice, response[:body])
40
66
  end
67
+
68
+ def consolidate_invoices(params={})
69
+ response = @client.request(:post, "#{self.endpoint()}/consolidate_invoices", params)
70
+
71
+ # build invoice object
72
+ invoice = Invoice.new(@client)
73
+ Util.convert_to_object(invoice, response[:body])
74
+ end
41
75
  end
42
76
  end
@@ -43,5 +43,13 @@ module Invoiced
43
43
 
44
44
  return attachments, metadata
45
45
  end
46
+
47
+ def void()
48
+ response = @client.request(:post, "#{self.endpoint()}/void", {})
49
+
50
+ refresh_from(response[:body].dup.merge({:id => self.id}))
51
+
52
+ return response[:code] == 200
53
+ end
46
54
  end
47
55
  end
@@ -15,6 +15,23 @@ module Invoiced
15
15
  Util.build_objects(email, response[:body])
16
16
  end
17
17
 
18
+ def send_sms(params={}, opts={})
19
+ response = @client.request(:post, "#{self.endpoint()}/text_messages", params, opts)
20
+
21
+ # build text message objects
22
+ text_message = TextMessage.new(@client)
23
+ Util.build_objects(text_message, response[:body])
24
+ end
25
+
26
+ def send_letter(params={}, opts={})
27
+ response = @client.request(:post, "#{self.endpoint()}/letters", params, opts)
28
+
29
+ # build letter objects
30
+
31
+ letter = Letter.new(@client)
32
+ Util.build_objects(letter, response[:body])
33
+ end
34
+
18
35
  def pay(opts={})
19
36
  response = @client.request(:post, "#{self.endpoint()}/pay", {}, opts)
20
37
 
@@ -33,7 +50,7 @@ module Invoiced
33
50
  if !attachment.has_key?(:id)
34
51
  attachment[:id] = attachment[:file][:id]
35
52
  end
36
- end
53
+ end
37
54
 
38
55
  # build objects
39
56
  attachment = Attachment.new(@client)
@@ -49,5 +66,18 @@ module Invoiced
49
66
  paymentPlan = PaymentPlan.new(@client)
50
67
  paymentPlan.set_endpoint_base(self.endpoint())
51
68
  end
69
+
70
+ def notes()
71
+ note = Note.new(@client)
72
+ note.set_endpoint_base(self.endpoint())
73
+ end
74
+
75
+ def void()
76
+ response = @client.request(:post, "#{self.endpoint()}/void", {})
77
+
78
+ refresh_from(response[:body].dup.merge({:id => self.id}))
79
+
80
+ return response[:code] == 200
81
+ end
52
82
  end
53
83
  end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Item < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'item'
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Invoiced
2
+ class Letter < Object
3
+ OBJECT_NAME = 'letter'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Note < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'note'
9
+ end
10
+ end
@@ -46,7 +46,7 @@ module Invoiced
46
46
  raise ArgumentError.new("Missing ID.")
47
47
  end
48
48
 
49
- response = @client.request(:get, "#{self.endpoint()}/#{id}", params)
49
+ response = @client.request(:get, "#{endpoint()}/#{id}", params)
50
50
 
51
51
  Util.convert_to_object(self, response[:body])
52
52
  end
@@ -57,7 +57,7 @@ module Invoiced
57
57
 
58
58
  def inspect
59
59
  id_string = (!@id.nil?) ? " id=#{@id}" : ""
60
- "#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values)
60
+ "#<#{self.class}:0x#{object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values)
61
61
  end
62
62
 
63
63
  def refresh_from(values)
@@ -2,7 +2,7 @@ module Invoiced
2
2
  module Operations
3
3
  module Create
4
4
  def create(body={}, opts={})
5
- response = @client.request(:post, self.endpoint(), body, opts)
5
+ response = @client.request(:post, endpoint(), body, opts)
6
6
 
7
7
  Util.convert_to_object(self, response[:body])
8
8
  end
@@ -1,11 +1,11 @@
1
1
  module Invoiced
2
- class Transaction < Object
2
+ class Payment < Object
3
3
  include Invoiced::Operations::List
4
4
  include Invoiced::Operations::Create
5
5
  include Invoiced::Operations::Update
6
6
  include Invoiced::Operations::Delete
7
7
 
8
- OBJECT_NAME = 'transaction'
8
+ OBJECT_NAME = 'payment'
9
9
 
10
10
  def send(params={}, opts={})
11
11
  response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
@@ -14,11 +14,5 @@ module Invoiced
14
14
  email = Email.new(@client)
15
15
  Util.build_objects(email, response[:body])
16
16
  end
17
-
18
- def refund(params={}, opts={})
19
- response = @client.request(:post, "#{self.endpoint()}/refunds", params, opts)
20
-
21
- Util.convert_to_object(self, response[:body])
22
- end
23
17
  end
24
18
  end
@@ -0,0 +1,8 @@
1
+ module Invoiced
2
+ class PaymentSource < Object
3
+ include Invoiced::Operations::Create
4
+ include Invoiced::Operations::List
5
+
6
+ OBJECT_NAME = 'payment_source'
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Invoiced
2
+ class PaymentSourceObject < Object
3
+ include Invoiced::Operations::Delete
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Invoiced
2
+ class Refund < Object
3
+ OBJECT_NAME = 'refund'
4
+
5
+ def create(chargeId, body={}, opts={})
6
+ response = @client.request(:post, @endpoint_base + "/charges/#{chargeId}/refunds", body, opts)
7
+
8
+ Util.convert_to_object(self, response[:body])
9
+ end
10
+ end
11
+ end
@@ -10,5 +10,11 @@ module Invoiced
10
10
  def cancel
11
11
  delete
12
12
  end
13
+
14
+ def preview(params={}, opts={})
15
+ response = @client.request(:post, "/subscriptions/preview", params, opts)
16
+
17
+ response[:body]
18
+ end
13
19
  end
14
20
  end