invoiced 0.13.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -1
- data/.travis.yml +3 -1
- data/Gemfile +1 -2
- data/README.md +14 -6
- data/invoiced.gemspec +2 -2
- data/lib/invoiced.rb +25 -4
- data/lib/invoiced/bank_account.rb +6 -0
- data/lib/invoiced/card.rb +6 -0
- data/lib/invoiced/charge.rb +12 -0
- data/lib/invoiced/{catalog_item.rb → coupon.rb} +2 -2
- data/lib/invoiced/credit_note.rb +8 -0
- data/lib/invoiced/customer.rb +34 -0
- data/lib/invoiced/estimate.rb +8 -0
- data/lib/invoiced/invoice.rb +31 -1
- data/lib/invoiced/item.rb +10 -0
- data/lib/invoiced/letter.rb +5 -0
- data/lib/invoiced/note.rb +10 -0
- data/lib/invoiced/object.rb +2 -2
- data/lib/invoiced/operations/create.rb +1 -1
- data/lib/invoiced/payment.rb +18 -0
- data/lib/invoiced/payment_source.rb +8 -0
- data/lib/invoiced/payment_source_object.rb +5 -0
- data/lib/invoiced/refund.rb +11 -0
- data/lib/invoiced/subscription.rb +6 -0
- data/lib/invoiced/task.rb +10 -0
- data/lib/invoiced/tax_rate.rb +10 -0
- data/lib/invoiced/text_message.rb +5 -0
- data/lib/invoiced/transaction.rb +6 -0
- data/lib/invoiced/util.rb +13 -1
- data/lib/invoiced/version.rb +1 -1
- data/test/invoiced/charge_test.rb +25 -0
- data/test/invoiced/{catalog_item_test.rb → coupon_test.rb} +33 -33
- data/test/invoiced/credit_note_test.rb +14 -0
- data/test/invoiced/customer_test.rb +101 -2
- data/test/invoiced/estimate_test.rb +14 -0
- data/test/invoiced/invoice_test.rb +69 -1
- data/test/invoiced/invoiced_test.rb +1 -2
- data/test/invoiced/item_test.rb +90 -0
- data/test/invoiced/note_test.rb +90 -0
- data/test/invoiced/payment_source_test.rb +57 -0
- data/test/invoiced/payment_test.rb +107 -0
- data/test/invoiced/refund_test.rb +25 -0
- data/test/invoiced/subscription_test.rb +13 -0
- data/test/invoiced/task_test.rb +90 -0
- data/test/invoiced/tax_rate_test.rb +90 -0
- data/test/invoiced/transaction_test.rb +15 -0
- metadata +38 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96fee7c8ec29ed8496d56e2ad01040962c4e793e03d8746cd1bb33dc9d455310
|
4
|
+
data.tar.gz: 24c4ac4cf3671312b13da58e7ffb0798041ff50572d06e49ccbab047f2fe7130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8a1fbde18532af461b0051de5a9a35beeefa4e6b9826cbbc65d8ce4ac73b91ce6d40d81c7b3d3fd6d68a989c74441cd0ee45d9cd1f8d9f1c7e50095a4666cd1
|
7
|
+
data.tar.gz: 79c75b2a9c9654ecf61a520aaa1e1bc3c2802d189b540238dd4556108c00255e0d88155f2d96200c11a8ddb870b4ee16be2e8fb0cd1b34e6e80597b7661b357d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,13 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
gem 'rest-client', '~> 2.0.0'
|
5
|
-
gem 'jwt', '~> 2.0
|
5
|
+
gem 'jwt', '~> 2.0'
|
6
6
|
|
7
7
|
gem 'mocha', '~> 0.13.2', :require => false, :group => :test
|
8
8
|
gem 'shoulda', '~> 3.4.0', :require => false, :group => :test
|
9
9
|
gem 'test-unit', :require => false, :group => :test
|
10
10
|
gem 'rake', :require => false, :group => :test
|
11
|
-
gem 'activesupport', '~> 4.2.9', :require => false, :group => :test
|
12
11
|
gem 'coveralls', :require => false, :group => :test
|
13
12
|
gem 'simplecov', '~> 0.10.0', :require => false, :group => :test
|
14
13
|
gem 'simplecov-console', '~> 0.3.1', :require => false, :group => :test
|
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.
|
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
|
|
@@ -24,8 +25,9 @@ gem 'invoiced'
|
|
24
25
|
|
25
26
|
## Requirements
|
26
27
|
|
27
|
-
- Ruby 2.
|
28
|
-
- rest_client gem
|
28
|
+
- Ruby 2.1+
|
29
|
+
- `rest_client` gem
|
30
|
+
- `jwt` gem
|
29
31
|
|
30
32
|
## Usage
|
31
33
|
|
@@ -43,10 +45,16 @@ Then, API calls can be made like this:
|
|
43
45
|
invoice = invoiced.Invoice.retrieve("{INVOICE_ID}")
|
44
46
|
|
45
47
|
# mark as paid
|
46
|
-
|
47
|
-
:invoice => invoice.id,
|
48
|
+
payment = invoiced.Payment.create(
|
48
49
|
:amount => invoice.balance,
|
49
|
-
:method => "check"
|
50
|
+
:method => "check",
|
51
|
+
:applied_to => [
|
52
|
+
{
|
53
|
+
:type => "invoice",
|
54
|
+
:invoice => invoice.id,
|
55
|
+
:amount => invoice.balance
|
56
|
+
}
|
57
|
+
])
|
50
58
|
```
|
51
59
|
|
52
60
|
If you want to use the sandbox API instead then you must set the second argument on the client to `true` like this:
|
data/invoiced.gemspec
CHANGED
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = 'support@invoiced.com'
|
13
13
|
s.files = ["lib/invoiced.rb"]
|
14
14
|
s.homepage = 'https://invoiced.com/docs/dev'
|
15
|
-
s.required_ruby_version = '>= 2.
|
15
|
+
s.required_ruby_version = '>= 2.1.0'
|
16
16
|
|
17
17
|
s.add_dependency('rest-client', '~> 2.0.0')
|
18
|
-
s.add_dependency('jwt', '~> 2.0
|
18
|
+
s.add_dependency('jwt', '~> 2.0')
|
19
19
|
|
20
20
|
s.files = `git ls-files`.split("\n")
|
21
21
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/lib/invoiced.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest-client'
|
2
|
+
require 'jwt'
|
2
3
|
require 'json'
|
3
4
|
require 'base64'
|
4
5
|
|
@@ -17,9 +18,14 @@ require 'invoiced/operations/delete'
|
|
17
18
|
require 'invoiced/operations/update'
|
18
19
|
|
19
20
|
require 'invoiced/object'
|
21
|
+
require 'invoiced/payment_source_object'
|
20
22
|
require 'invoiced/attachment'
|
21
|
-
require 'invoiced/
|
23
|
+
require 'invoiced/bank_account'
|
24
|
+
require 'invoiced/card'
|
25
|
+
require 'invoiced/item'
|
26
|
+
require 'invoiced/charge'
|
22
27
|
require 'invoiced/contact'
|
28
|
+
require 'invoiced/coupon'
|
23
29
|
require 'invoiced/credit_note'
|
24
30
|
require 'invoiced/customer'
|
25
31
|
require 'invoiced/email'
|
@@ -27,10 +33,18 @@ require 'invoiced/estimate'
|
|
27
33
|
require 'invoiced/event'
|
28
34
|
require 'invoiced/file'
|
29
35
|
require 'invoiced/invoice'
|
36
|
+
require 'invoiced/letter'
|
30
37
|
require 'invoiced/line_item'
|
38
|
+
require 'invoiced/note'
|
39
|
+
require 'invoiced/payment'
|
31
40
|
require 'invoiced/payment_plan'
|
41
|
+
require 'invoiced/payment_source'
|
32
42
|
require 'invoiced/plan'
|
43
|
+
require 'invoiced/refund'
|
33
44
|
require 'invoiced/subscription'
|
45
|
+
require 'invoiced/task'
|
46
|
+
require 'invoiced/tax_rate'
|
47
|
+
require 'invoiced/text_message'
|
34
48
|
require 'invoiced/transaction'
|
35
49
|
|
36
50
|
module Invoiced
|
@@ -42,7 +56,7 @@ module Invoiced
|
|
42
56
|
ReadTimeout = 80
|
43
57
|
|
44
58
|
attr_reader :api_key, :api_url, :sandbox, :sso_key
|
45
|
-
attr_reader :
|
59
|
+
attr_reader :Item, :Charge, :Coupon, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Payment, :Plan, :Refund, :Subscription, :Task, :TaxRate, :Transaction
|
46
60
|
|
47
61
|
def initialize(api_key, sandbox=false, sso_key=false)
|
48
62
|
@api_key = api_key
|
@@ -51,15 +65,22 @@ module Invoiced
|
|
51
65
|
@sso_key = sso_key
|
52
66
|
|
53
67
|
# Object endpoints
|
54
|
-
@
|
68
|
+
@Item = Invoiced::Item.new(self)
|
69
|
+
@Charge = Invoiced::Charge.new(self)
|
70
|
+
@Coupon = Invoiced::Coupon.new(self)
|
55
71
|
@CreditNote = Invoiced::CreditNote.new(self)
|
56
72
|
@Customer = Invoiced::Customer.new(self)
|
57
73
|
@Estimate = Invoiced::Estimate.new(self)
|
58
74
|
@Event = Invoiced::Event.new(self)
|
59
75
|
@File = Invoiced::File.new(self)
|
60
76
|
@Invoice = Invoiced::Invoice.new(self)
|
77
|
+
@Note = Invoiced::Note.new(self)
|
78
|
+
@Payment = Invoiced::Payment.new(self)
|
61
79
|
@Plan = Invoiced::Plan.new(self)
|
80
|
+
@Refund = Invoiced::Refund.new(self)
|
62
81
|
@Subscription = Invoiced::Subscription.new(self)
|
82
|
+
@Task = Invoiced::Task.new(self)
|
83
|
+
@TaxRate = Invoiced::TaxRate.new(self)
|
63
84
|
@Transaction = Invoiced::Transaction.new(self)
|
64
85
|
end
|
65
86
|
|
@@ -201,4 +222,4 @@ module Invoiced
|
|
201
222
|
ApiError.new("API Error #{code} - #{body}", code)
|
202
223
|
end
|
203
224
|
end
|
204
|
-
end
|
225
|
+
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
|
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 = '
|
8
|
+
OBJECT_NAME = 'coupon'
|
9
9
|
end
|
10
10
|
end
|
data/lib/invoiced/credit_note.rb
CHANGED
@@ -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
|
data/lib/invoiced/customer.rb
CHANGED
@@ -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
|
data/lib/invoiced/estimate.rb
CHANGED
@@ -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
|
data/lib/invoiced/invoice.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/invoiced/object.rb
CHANGED
@@ -46,7 +46,7 @@ module Invoiced
|
|
46
46
|
raise ArgumentError.new("Missing ID.")
|
47
47
|
end
|
48
48
|
|
49
|
-
response = @client.request(:get, "#{
|
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#{
|
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)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class Payment < 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 = 'payment'
|
9
|
+
|
10
|
+
def send(params={}, opts={})
|
11
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
12
|
+
|
13
|
+
# build email objects
|
14
|
+
email = Email.new(@client)
|
15
|
+
Util.build_objects(email, response[:body])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|