invoiced 1.1.0 → 1.2.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
  SHA256:
3
- metadata.gz: bc29d5e9ff33831248d574c23a30169f149ba7b9ed11d2904de174cabba75163
4
- data.tar.gz: 4f2b87a74c4a58dffcadd4b46855089ac928a655f4b11e5e07598ea940d5e4b7
3
+ metadata.gz: 3c9a2f8ec999dc38fc2d99a9a6c70ed9f908453399e7a1391b139f08d0016c58
4
+ data.tar.gz: bded9ce98e08adf08061d9411958f358c2a53622f1c6df96ddbdee4ea34c02b8
5
5
  SHA512:
6
- metadata.gz: c3ba71d623fd4714ecd4975d29a7aa9730ceb8be5daaf8e7324eace2af003e6a986bab11bc83312cbb2316799ebdbfc922fa48b456ab6bb919c61608c33f04af
7
- data.tar.gz: eb098797e875032bd88e01452bdb2794cbdec350973ed46fb9ce06c3118b0355b2465643b8ec4aaae3212be46715e7f470826a27b0a2d0bf0c855412873afe8b
6
+ metadata.gz: cce64c5c13a67dcfb8d1b693fa915e3927b9785a4f27c9a19dd72c0c36e9b97ad17b1159a0023994d73562e90d8cd0384f51704c890e8f2e849d9e8b9f1a3800
7
+ data.tar.gz: 9763afc75104c54d36b1a31cf603d9fd13d8a777b17f3d871cb59eadc8b80fa1e0ebfd2bdfd68de52110e27fd6a35c73a29c4f34fafc0b647386a6073bb17b91
@@ -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
@@ -5,6 +5,7 @@ This repository contains the Ruby client library for the [Invoiced](https://invo
5
5
 
6
6
  [![Build Status](https://travis-ci.org/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.org/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
 
@@ -23,6 +23,7 @@ require 'invoiced/attachment'
23
23
  require 'invoiced/bank_account'
24
24
  require 'invoiced/card'
25
25
  require 'invoiced/catalog_item'
26
+ require 'invoiced/charge'
26
27
  require 'invoiced/contact'
27
28
  require 'invoiced/coupon'
28
29
  require 'invoiced/credit_note'
@@ -35,9 +36,11 @@ require 'invoiced/invoice'
35
36
  require 'invoiced/letter'
36
37
  require 'invoiced/line_item'
37
38
  require 'invoiced/note'
39
+ require 'invoiced/payment'
38
40
  require 'invoiced/payment_plan'
39
41
  require 'invoiced/payment_source'
40
42
  require 'invoiced/plan'
43
+ require 'invoiced/refund'
41
44
  require 'invoiced/subscription'
42
45
  require 'invoiced/task'
43
46
  require 'invoiced/tax_rate'
@@ -53,7 +56,7 @@ module Invoiced
53
56
  ReadTimeout = 80
54
57
 
55
58
  attr_reader :api_key, :api_url, :sandbox, :sso_key
56
- attr_reader :CatalogItem, :Coupon, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Plan, :Subscription, :Task, :TaxRate, :Transaction
59
+ attr_reader :CatalogItem, :Charge, :Coupon, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Payment, :Plan, :Refund, :Subscription, :Task, :TaxRate, :Transaction
57
60
 
58
61
  def initialize(api_key, sandbox=false, sso_key=false)
59
62
  @api_key = api_key
@@ -63,6 +66,7 @@ module Invoiced
63
66
 
64
67
  # Object endpoints
65
68
  @CatalogItem = Invoiced::CatalogItem.new(self)
69
+ @Charge = Invoiced::Charge.new(self)
66
70
  @Coupon = Invoiced::Coupon.new(self)
67
71
  @CreditNote = Invoiced::CreditNote.new(self)
68
72
  @Customer = Invoiced::Customer.new(self)
@@ -71,7 +75,9 @@ module Invoiced
71
75
  @File = Invoiced::File.new(self)
72
76
  @Invoice = Invoiced::Invoice.new(self)
73
77
  @Note = Invoiced::Note.new(self)
78
+ @Payment = Invoiced::Payment.new(self)
74
79
  @Plan = Invoiced::Plan.new(self)
80
+ @Refund = Invoiced::Refund.new(self)
75
81
  @Subscription = Invoiced::Subscription.new(self)
76
82
  @Task = Invoiced::Task.new(self)
77
83
  @TaxRate = Invoiced::TaxRate.new(self)
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class ChargeTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ charge = Charge.new(@client, 123)
7
+ assert_equal('/charges/123', charge.endpoint())
8
+ end
9
+
10
+ should "create a charge" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"a1b2c3","amount":100,"object":"charge"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ charge = Charge.new(@client, 1234)
19
+ charge = charge.create(:amount => 100, :payment_source_type => "card")
20
+
21
+ assert_instance_of(Invoiced::Payment, charge)
22
+ assert_equal(charge.id, "a1b2c3")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,107 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class PaymentTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ payment = Payment.new(@client, 123)
7
+ assert_equal('/payments/123', payment.endpoint())
8
+ end
9
+
10
+ should "create a payment" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":123,"amount":100}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ payment = @client.Payment.create({:amount => 800})
19
+
20
+ assert_instance_of(Invoiced::Payment, payment)
21
+ assert_equal(123, payment.id)
22
+ assert_equal(100, payment.amount)
23
+ end
24
+
25
+ should "retrieve a payment" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":123,"amount":100}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ payment = @client.Payment.retrieve(123)
34
+
35
+ assert_instance_of(Invoiced::Payment, payment)
36
+ assert_equal(123, payment.id)
37
+ assert_equal(100, payment.amount)
38
+ end
39
+
40
+ should "not update a payment when no params" do
41
+ payment = Payment.new(@client, 123)
42
+ assert_false(payment.save)
43
+ end
44
+
45
+ should "update a payment" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":123,"sent":true}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ payment = Payment.new(@client, 123)
54
+ payment.sent = true
55
+ assert_true(payment.save)
56
+
57
+ assert_true(payment.sent)
58
+ end
59
+
60
+ should "list all payments" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":123,"amount":100}]')
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
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ payments, metadata = @client.Payment.list
69
+
70
+ assert_instance_of(Array, payments)
71
+ assert_equal(1, payments.length)
72
+ assert_equal(123, payments[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a payment" 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
+ payment = Payment.new(@client, 123)
87
+ assert_true(payment.delete)
88
+ end
89
+
90
+ should "send a payment receipt" do
91
+ mockResponse = mock('RestClient::Response')
92
+ mockResponse.stubs(:code).returns(201)
93
+ mockResponse.stubs(:body).returns('[{"id":4567,"email":"test@example.com"}]')
94
+ mockResponse.stubs(:headers).returns({})
95
+
96
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
97
+
98
+ payment = Payment.new(@client, 1234)
99
+ emails = payment.send
100
+
101
+ assert_instance_of(Array, emails)
102
+ assert_equal(1, emails.length)
103
+ assert_instance_of(Invoiced::Email, emails[0])
104
+ assert_equal(4567, emails[0].id)
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class RefundTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ refund = Refund.new(@client, 123)
7
+ assert_equal('/refunds/123', refund.endpoint())
8
+ end
9
+
10
+ should "create a refund" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":456}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ refund = Refund.new(@client, 1234)
19
+ refund = refund.create(456, {:amount => 800})
20
+
21
+ assert_instance_of(Invoiced::Refund, refund)
22
+ assert_equal(456, refund.id)
23
+ end
24
+ end
25
+ 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: 1.1.0
4
+ version: 1.2.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-12-05 00:00:00.000000000 Z
11
+ date: 2020-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -56,6 +56,7 @@ files:
56
56
  - lib/invoiced/bank_account.rb
57
57
  - lib/invoiced/card.rb
58
58
  - lib/invoiced/catalog_item.rb
59
+ - lib/invoiced/charge.rb
59
60
  - lib/invoiced/contact.rb
60
61
  - lib/invoiced/coupon.rb
61
62
  - lib/invoiced/credit_note.rb
@@ -80,10 +81,12 @@ files:
80
81
  - lib/invoiced/operations/delete.rb
81
82
  - lib/invoiced/operations/list.rb
82
83
  - lib/invoiced/operations/update.rb
84
+ - lib/invoiced/payment.rb
83
85
  - lib/invoiced/payment_plan.rb
84
86
  - lib/invoiced/payment_source.rb
85
87
  - lib/invoiced/payment_source_object.rb
86
88
  - lib/invoiced/plan.rb
89
+ - lib/invoiced/refund.rb
87
90
  - lib/invoiced/subscription.rb
88
91
  - lib/invoiced/task.rb
89
92
  - lib/invoiced/tax_rate.rb
@@ -92,6 +95,7 @@ files:
92
95
  - lib/invoiced/util.rb
93
96
  - lib/invoiced/version.rb
94
97
  - test/invoiced/catalog_item_test.rb
98
+ - test/invoiced/charge_test.rb
95
99
  - test/invoiced/contact_test.rb
96
100
  - test/invoiced/coupon_test.rb
97
101
  - test/invoiced/credit_note_test.rb
@@ -107,7 +111,9 @@ files:
107
111
  - test/invoiced/object_test.rb
108
112
  - test/invoiced/payment_plan_test.rb
109
113
  - test/invoiced/payment_source_test.rb
114
+ - test/invoiced/payment_test.rb
110
115
  - test/invoiced/plan_test.rb
116
+ - test/invoiced/refund_test.rb
111
117
  - test/invoiced/subscription_test.rb
112
118
  - test/invoiced/task_test.rb
113
119
  - test/invoiced/tax_rate_test.rb
@@ -133,12 +139,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
139
  - !ruby/object:Gem::Version
134
140
  version: '0'
135
141
  requirements: []
136
- rubygems_version: 3.0.6
142
+ rubygems_version: 3.1.4
137
143
  signing_key:
138
144
  specification_version: 4
139
145
  summary: Ruby client library for the Invoiced API
140
146
  test_files:
141
147
  - test/invoiced/catalog_item_test.rb
148
+ - test/invoiced/charge_test.rb
142
149
  - test/invoiced/contact_test.rb
143
150
  - test/invoiced/coupon_test.rb
144
151
  - test/invoiced/credit_note_test.rb
@@ -154,7 +161,9 @@ test_files:
154
161
  - test/invoiced/object_test.rb
155
162
  - test/invoiced/payment_plan_test.rb
156
163
  - test/invoiced/payment_source_test.rb
164
+ - test/invoiced/payment_test.rb
157
165
  - test/invoiced/plan_test.rb
166
+ - test/invoiced/refund_test.rb
158
167
  - test/invoiced/subscription_test.rb
159
168
  - test/invoiced/task_test.rb
160
169
  - test/invoiced/tax_rate_test.rb