invoiced 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/invoiced.rb +4 -0
- data/lib/invoiced/bank_account.rb +6 -0
- data/lib/invoiced/card.rb +6 -0
- data/lib/invoiced/customer.rb +5 -0
- data/lib/invoiced/object.rb +2 -2
- data/lib/invoiced/operations/create.rb +1 -1
- data/lib/invoiced/payment_source.rb +8 -0
- data/lib/invoiced/payment_source_object.rb +5 -0
- data/lib/invoiced/util.rb +13 -1
- data/lib/invoiced/version.rb +1 -1
- data/test/invoiced/customer_test.rb +30 -0
- data/test/invoiced/payment_source_test.rb +57 -0
- data/test/invoiced/transaction_test.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc29d5e9ff33831248d574c23a30169f149ba7b9ed11d2904de174cabba75163
|
4
|
+
data.tar.gz: 4f2b87a74c4a58dffcadd4b46855089ac928a655f4b11e5e07598ea940d5e4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3ba71d623fd4714ecd4975d29a7aa9730ceb8be5daaf8e7324eace2af003e6a986bab11bc83312cbb2316799ebdbfc922fa48b456ab6bb919c61608c33f04af
|
7
|
+
data.tar.gz: eb098797e875032bd88e01452bdb2794cbdec350973ed46fb9ce06c3118b0355b2465643b8ec4aaae3212be46715e7f470826a27b0a2d0bf0c855412873afe8b
|
data/.gitignore
CHANGED
data/lib/invoiced.rb
CHANGED
@@ -18,7 +18,10 @@ 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'
|
23
|
+
require 'invoiced/bank_account'
|
24
|
+
require 'invoiced/card'
|
22
25
|
require 'invoiced/catalog_item'
|
23
26
|
require 'invoiced/contact'
|
24
27
|
require 'invoiced/coupon'
|
@@ -33,6 +36,7 @@ require 'invoiced/letter'
|
|
33
36
|
require 'invoiced/line_item'
|
34
37
|
require 'invoiced/note'
|
35
38
|
require 'invoiced/payment_plan'
|
39
|
+
require 'invoiced/payment_source'
|
36
40
|
require 'invoiced/plan'
|
37
41
|
require 'invoiced/subscription'
|
38
42
|
require 'invoiced/task'
|
data/lib/invoiced/customer.rb
CHANGED
@@ -42,6 +42,11 @@ module Invoiced
|
|
42
42
|
contact.set_endpoint_base(self.endpoint())
|
43
43
|
end
|
44
44
|
|
45
|
+
def payment_sources()
|
46
|
+
source = PaymentSource.new(@client)
|
47
|
+
source.set_endpoint_base(self.endpoint())
|
48
|
+
end
|
49
|
+
|
45
50
|
def line_items()
|
46
51
|
line = LineItem.new(@client)
|
47
52
|
line.set_endpoint_base(self.endpoint())
|
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)
|
data/lib/invoiced/util.rb
CHANGED
@@ -17,7 +17,19 @@ module Invoiced
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def convert_to_object(_class, values)
|
20
|
-
|
20
|
+
object_class = _class.class
|
21
|
+
|
22
|
+
# check for PaymentSource special case where class must be forced to Card or BankAccount
|
23
|
+
unless values[:object].nil?
|
24
|
+
if values[:object] == 'card'
|
25
|
+
object_class = Invoiced::Card
|
26
|
+
elsif values[:object] == 'bank_account'
|
27
|
+
object_class = Invoiced::BankAccount
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
object = object_class.new(_class.client, values[:id], values)
|
32
|
+
|
21
33
|
object.set_endpoint_base(_class.endpoint_base())
|
22
34
|
end
|
23
35
|
|
data/lib/invoiced/version.rb
CHANGED
@@ -315,5 +315,35 @@ module Invoiced
|
|
315
315
|
assert_instance_of(Invoiced::Invoice, invoice)
|
316
316
|
assert_equal(invoice.id, 999)
|
317
317
|
end
|
318
|
+
|
319
|
+
should "create a bank account associated with customer" do
|
320
|
+
mockResponse = mock('RestClient::Response')
|
321
|
+
mockResponse.stubs(:code).returns(201)
|
322
|
+
mockResponse.stubs(:body).returns('{"id": 999,"object":"bank_account"}')
|
323
|
+
mockResponse.stubs(:headers).returns({})
|
324
|
+
|
325
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
326
|
+
|
327
|
+
customer = Customer.new(@client, 123)
|
328
|
+
account = customer.payment_sources.create
|
329
|
+
|
330
|
+
assert_instance_of(Invoiced::BankAccount, account)
|
331
|
+
assert_equal(account.endpoint, "/customers/123/bank_accounts/999")
|
332
|
+
end
|
333
|
+
|
334
|
+
should "create a card associated with customer" do
|
335
|
+
mockResponse = mock('RestClient::Response')
|
336
|
+
mockResponse.stubs(:code).returns(201)
|
337
|
+
mockResponse.stubs(:body).returns('{"id": 888,"object":"card"}')
|
338
|
+
mockResponse.stubs(:headers).returns({})
|
339
|
+
|
340
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
341
|
+
|
342
|
+
customer = Customer.new(@client, 123)
|
343
|
+
card = customer.payment_sources.create
|
344
|
+
|
345
|
+
assert_instance_of(Invoiced::Card, card)
|
346
|
+
assert_equal(card.endpoint, "/customers/123/cards/888")
|
347
|
+
end
|
318
348
|
end
|
319
349
|
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
|
@@ -122,7 +122,7 @@ module Invoiced
|
|
122
122
|
should "initiate a charge" do
|
123
123
|
mockResponse = mock('RestClient::Response')
|
124
124
|
mockResponse.stubs(:code).returns(201)
|
125
|
-
mockResponse.stubs(:body).returns('{"id":"a1b2c3","amount":100,"object":"
|
125
|
+
mockResponse.stubs(:body).returns('{"id":"a1b2c3","amount":100,"object":"charge"}')
|
126
126
|
mockResponse.stubs(:headers).returns({})
|
127
127
|
|
128
128
|
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
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: 1.
|
4
|
+
version: 1.1.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: 2019-
|
11
|
+
date: 2019-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -53,6 +53,8 @@ files:
|
|
53
53
|
- invoiced.gemspec
|
54
54
|
- lib/invoiced.rb
|
55
55
|
- lib/invoiced/attachment.rb
|
56
|
+
- lib/invoiced/bank_account.rb
|
57
|
+
- lib/invoiced/card.rb
|
56
58
|
- lib/invoiced/catalog_item.rb
|
57
59
|
- lib/invoiced/contact.rb
|
58
60
|
- lib/invoiced/coupon.rb
|
@@ -79,6 +81,8 @@ files:
|
|
79
81
|
- lib/invoiced/operations/list.rb
|
80
82
|
- lib/invoiced/operations/update.rb
|
81
83
|
- lib/invoiced/payment_plan.rb
|
84
|
+
- lib/invoiced/payment_source.rb
|
85
|
+
- lib/invoiced/payment_source_object.rb
|
82
86
|
- lib/invoiced/plan.rb
|
83
87
|
- lib/invoiced/subscription.rb
|
84
88
|
- lib/invoiced/task.rb
|
@@ -102,6 +106,7 @@ files:
|
|
102
106
|
- test/invoiced/note_test.rb
|
103
107
|
- test/invoiced/object_test.rb
|
104
108
|
- test/invoiced/payment_plan_test.rb
|
109
|
+
- test/invoiced/payment_source_test.rb
|
105
110
|
- test/invoiced/plan_test.rb
|
106
111
|
- test/invoiced/subscription_test.rb
|
107
112
|
- test/invoiced/task_test.rb
|
@@ -148,6 +153,7 @@ test_files:
|
|
148
153
|
- test/invoiced/note_test.rb
|
149
154
|
- test/invoiced/object_test.rb
|
150
155
|
- test/invoiced/payment_plan_test.rb
|
156
|
+
- test/invoiced/payment_source_test.rb
|
151
157
|
- test/invoiced/plan_test.rb
|
152
158
|
- test/invoiced/subscription_test.rb
|
153
159
|
- test/invoiced/task_test.rb
|