paid 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/README.md +5 -2
- data/VERSION +1 -1
- data/lib/paid.rb +5 -0
- data/lib/paid/api_resource.rb +6 -0
- data/lib/paid/order.rb +53 -0
- data/lib/paid/order_item.rb +54 -0
- data/lib/paid/plan.rb +3 -3
- data/lib/paid/plan_item.rb +46 -0
- data/lib/paid/product.rb +55 -0
- data/lib/paid/requester.rb +1 -1
- data/test/paid/order_item_test.rb +103 -0
- data/test/paid/order_test.rb +99 -0
- data/test/paid/plan_item_test.rb +87 -0
- data/test/paid/product_test.rb +105 -0
- data/test/test_data.rb +100 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39fa64093ad32cfdbb76949c4a9ee62efaab5c19
|
4
|
+
data.tar.gz: e9c939f3baf834a1ecf425cbe4aeb581702dc2fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99addad5ed759fa3a4577724d0d50605e2af910d54af3e8d4c86e2b9c56d78d97e92457da029d894d32726a7e5abb9072f6f06a3bc99b3b81fe37d0d2b7725af
|
7
|
+
data.tar.gz: 509f1b0d03ae37f78ea35f51a9f910fd5a83e82ec2f1f932f77398f203125e755ed4b38ae2e3c6c938896584a07f612e85c0938c04300003863f77fed5dfeecb
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -19,8 +19,9 @@ gem build paid.gemspec
|
|
19
19
|
|
20
20
|
## Requirements
|
21
21
|
|
22
|
-
* Ruby 1.
|
23
|
-
|
22
|
+
* Ruby 1.9.3 or above.
|
23
|
+
|
24
|
+
Ruby 1.8.6 may work if you load ActiveSupport. 1.8.7 may work if you add this to your Gemfile:
|
24
25
|
|
25
26
|
```ruby
|
26
27
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.2')
|
@@ -28,6 +29,8 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.2')
|
|
28
29
|
end
|
29
30
|
```
|
30
31
|
|
32
|
+
1.9.2 should work without any changes, but we don't currently test against it or any versions before 1.9.3.
|
33
|
+
|
31
34
|
* rest-client, json
|
32
35
|
|
33
36
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.3
|
data/lib/paid.rb
CHANGED
@@ -37,10 +37,15 @@ require 'paid/event'
|
|
37
37
|
require 'paid/event_data'
|
38
38
|
require 'paid/invoice'
|
39
39
|
require 'paid/plan'
|
40
|
+
require 'paid/plan_item'
|
41
|
+
require 'paid/order'
|
42
|
+
require 'paid/order_item'
|
43
|
+
require 'paid/product'
|
40
44
|
require 'paid/subscription'
|
41
45
|
require 'paid/transaction'
|
42
46
|
require 'paid/refund_list'
|
43
47
|
|
48
|
+
|
44
49
|
module Paid
|
45
50
|
@api_key = nil
|
46
51
|
|
data/lib/paid/api_resource.rb
CHANGED
@@ -60,6 +60,12 @@ module Paid
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.add_api_attribute(name)
|
63
|
+
if method_defined?(name)
|
64
|
+
remove_method(name)
|
65
|
+
end
|
66
|
+
if method_defined?("#{name}=")
|
67
|
+
remove_method("#{name}=")
|
68
|
+
end
|
63
69
|
attr_accessor name.to_sym
|
64
70
|
@api_attributes[name.to_sym] = {}
|
65
71
|
end
|
data/lib/paid/order.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Paid
|
2
|
+
class Order < APIResource
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :object
|
5
|
+
attr_reader :amount
|
6
|
+
attr_accessor :charge_now
|
7
|
+
attr_accessor :customer
|
8
|
+
attr_accessor :metadata
|
9
|
+
attr_accessor :subscription
|
10
|
+
|
11
|
+
|
12
|
+
def self.all(params={}, headers={})
|
13
|
+
method = APIMethod.new(:get, "/orders", params, headers, self)
|
14
|
+
APIList.new(self, method.execute, method)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.retrieve(id, params={}, headers={})
|
18
|
+
params = ParamsBuilder.merge(params, {
|
19
|
+
:id => id
|
20
|
+
})
|
21
|
+
method = APIMethod.new(:get, "/orders/:id", params, headers, self)
|
22
|
+
self.new(method.execute, method)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.create(params={}, headers={})
|
26
|
+
method = APIMethod.new(:post, "/orders", params, headers, self)
|
27
|
+
self.new(method.execute, method)
|
28
|
+
end
|
29
|
+
|
30
|
+
def refresh(params={}, headers={})
|
31
|
+
method = APIMethod.new(:get, "/orders/:id", params, headers, self)
|
32
|
+
self.refresh_from(method.execute, method)
|
33
|
+
end
|
34
|
+
|
35
|
+
def save(params={}, headers={})
|
36
|
+
params = ParamsBuilder.merge(params, changed_api_attributes)
|
37
|
+
method = APIMethod.new(:put, "/orders/:id", params, headers, self)
|
38
|
+
self.refresh_from(method.execute, method)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
APIResource.register_api_subclass(self, "order")
|
43
|
+
@api_attributes = {
|
44
|
+
:id => { :readonly => true },
|
45
|
+
:object => { :readonly => true },
|
46
|
+
:amount => { :readonly => true },
|
47
|
+
:charge_now => nil,
|
48
|
+
:customer => nil,
|
49
|
+
:metadata => nil,
|
50
|
+
:subscription => nil
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Paid
|
2
|
+
class OrderItem < APIResource
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :object
|
5
|
+
attr_accessor :order
|
6
|
+
attr_accessor :plan_item
|
7
|
+
attr_accessor :product
|
8
|
+
attr_accessor :service_ends_on
|
9
|
+
attr_accessor :service_starts_on
|
10
|
+
attr_accessor :transaction
|
11
|
+
|
12
|
+
def self.all(params={}, headers={})
|
13
|
+
method = APIMethod.new(:get, "/order_items", params, headers, self)
|
14
|
+
APIList.new(self, method.execute, method)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.retrieve(id, params={}, headers={})
|
18
|
+
params = ParamsBuilder.merge(params, {
|
19
|
+
:id => id
|
20
|
+
})
|
21
|
+
method = APIMethod.new(:get, "/order_items/:id", params, headers, self)
|
22
|
+
self.new(method.execute, method)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.create(params={}, headers={})
|
26
|
+
method = APIMethod.new(:post, "/order_items", params, headers, self)
|
27
|
+
self.new(method.execute, method)
|
28
|
+
end
|
29
|
+
|
30
|
+
def refresh(params={}, headers={})
|
31
|
+
method = APIMethod.new(:get, "/order_items/:id", params, headers, self)
|
32
|
+
self.refresh_from(method.execute, method)
|
33
|
+
end
|
34
|
+
|
35
|
+
def save(params={}, headers={})
|
36
|
+
params = ParamsBuilder.merge(params, changed_api_attributes)
|
37
|
+
method = APIMethod.new(:put, "/order_items/:id", params, headers, self)
|
38
|
+
self.refresh_from(method.execute, method)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
APIResource.register_api_subclass(self, "order_item")
|
43
|
+
@api_attributes = {
|
44
|
+
:id => { :readonly => true },
|
45
|
+
:object => { :readonly => true },
|
46
|
+
:order => nil,
|
47
|
+
:plan_item => nil,
|
48
|
+
:product => nil,
|
49
|
+
:service_ends_on => nil,
|
50
|
+
:service_starts_on => nil,
|
51
|
+
:transaction => nil
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
data/lib/paid/plan.rb
CHANGED
@@ -3,11 +3,11 @@ module Paid
|
|
3
3
|
attr_reader :id
|
4
4
|
attr_reader :object
|
5
5
|
attr_reader :created_at
|
6
|
+
attr_reader :amount
|
6
7
|
attr_accessor :name
|
7
8
|
attr_accessor :description
|
8
9
|
attr_accessor :interval
|
9
10
|
attr_accessor :interval_count
|
10
|
-
attr_accessor :amount
|
11
11
|
|
12
12
|
def self.all(params={}, headers={})
|
13
13
|
method = APIMethod.new(:get, "/plans", params, headers, self)
|
@@ -37,11 +37,11 @@ module Paid
|
|
37
37
|
:id => { :readonly => true },
|
38
38
|
:object => { :readonly => true },
|
39
39
|
:created_at => { :readonly => true },
|
40
|
+
:amount => { :readonly => true },
|
40
41
|
:name => nil,
|
41
42
|
:description => nil,
|
42
43
|
:interval => nil,
|
43
|
-
:interval_count => nil
|
44
|
-
:amount => nil,
|
44
|
+
:interval_count => nil
|
45
45
|
}
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Paid
|
2
|
+
class PlanItem < APIResource
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :object
|
5
|
+
attr_accessor :plan
|
6
|
+
attr_accessor :product
|
7
|
+
|
8
|
+
def self.all(params={}, headers={})
|
9
|
+
method = APIMethod.new(:get, "/plan_items", params, headers, self)
|
10
|
+
APIList.new(self, method.execute, method)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.retrieve(id, params={}, headers={})
|
14
|
+
params = ParamsBuilder.merge(params, {
|
15
|
+
:id => id
|
16
|
+
})
|
17
|
+
method = APIMethod.new(:get, "/plan_items/:id", params, headers, self)
|
18
|
+
self.new(method.execute, method)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.create(params={}, headers={})
|
22
|
+
method = APIMethod.new(:post, "/plan_items", params, headers, self)
|
23
|
+
self.new(method.execute, method)
|
24
|
+
end
|
25
|
+
|
26
|
+
def refresh(params={}, headers={})
|
27
|
+
method = APIMethod.new(:get, "/plan_items/:id", params, headers, self)
|
28
|
+
self.refresh_from(method.execute, method)
|
29
|
+
end
|
30
|
+
|
31
|
+
def save(params={}, headers={})
|
32
|
+
params = ParamsBuilder.merge(params, changed_api_attributes)
|
33
|
+
method = APIMethod.new(:put, "/plan_items/:id", params, headers, self)
|
34
|
+
self.refresh_from(method.execute, method)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
APIResource.register_api_subclass(self, "plan_item")
|
39
|
+
@api_attributes = {
|
40
|
+
:id => { :readonly => true },
|
41
|
+
:object => { :readonly => true },
|
42
|
+
:plan => nil,
|
43
|
+
:product => nil
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
data/lib/paid/product.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Paid
|
2
|
+
class Product < APIResource
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :object
|
5
|
+
attr_accessor :description
|
6
|
+
attr_accessor :external_id
|
7
|
+
attr_accessor :external_metric_id
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :transaction_description
|
10
|
+
attr_accessor :pricing_structure
|
11
|
+
|
12
|
+
|
13
|
+
def self.all(params={}, headers={})
|
14
|
+
method = APIMethod.new(:get, "/products", params, headers, self)
|
15
|
+
APIList.new(self, method.execute, method)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.retrieve(id, params={}, headers={})
|
19
|
+
params = ParamsBuilder.merge(params, {
|
20
|
+
:id => id
|
21
|
+
})
|
22
|
+
method = APIMethod.new(:get, "/products/:id", params, headers, self)
|
23
|
+
self.new(method.execute, method)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.create(params={}, headers={})
|
27
|
+
method = APIMethod.new(:post, "/products", params, headers, self)
|
28
|
+
self.new(method.execute, method)
|
29
|
+
end
|
30
|
+
|
31
|
+
def refresh(params={}, headers={})
|
32
|
+
method = APIMethod.new(:get, "/products/:id", params, headers, self)
|
33
|
+
self.refresh_from(method.execute, method)
|
34
|
+
end
|
35
|
+
|
36
|
+
def save(params={}, headers={})
|
37
|
+
params = ParamsBuilder.merge(params, changed_api_attributes)
|
38
|
+
method = APIMethod.new(:put, "/products/:id", params, headers, self)
|
39
|
+
self.refresh_from(method.execute, method)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
APIResource.register_api_subclass(self, "product")
|
44
|
+
@api_attributes = {
|
45
|
+
:id => { :readonly => true },
|
46
|
+
:object => { :readonly => true },
|
47
|
+
:description => nil,
|
48
|
+
:external_id => nil,
|
49
|
+
:external_metric_id => nil,
|
50
|
+
:name => nil,
|
51
|
+
:transaction_description => nil,
|
52
|
+
:pricing_structure => nil
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
data/lib/paid/requester.rb
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class OrderItemTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
@order_item_url = "#{Paid.api_base}/order_items"
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'OrderItem class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "order_item_id"
|
12
|
+
@mock.expects(:get).once.with("#{@order_item_url}/#{id}", anything, anything).returns(test_response(test_order_item))
|
13
|
+
order_item = Paid::OrderItem.retrieve(id)
|
14
|
+
assert(order_item.is_a?(Paid::OrderItem))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@order_item_url, anything, test_order_item).returns(test_response(test_order_item))
|
19
|
+
order_item = Paid::OrderItem.create(test_order_item)
|
20
|
+
assert(order_item.is_a?(Paid::OrderItem))
|
21
|
+
assert_equal(test_order_item[:id], order_item.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_order_item_list))
|
26
|
+
|
27
|
+
order_items = Paid::OrderItem.all
|
28
|
+
|
29
|
+
assert(order_items.is_a?(Paid::APIList))
|
30
|
+
order_items.each do |order_item|
|
31
|
+
assert(order_item.is_a?(Paid::OrderItem))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'OrderItem instance' do
|
37
|
+
should 'be refreshable' do
|
38
|
+
@mock.expects(:get).once.with("#{@order_item_url}/#{test_order_item[:id]}", anything, anything).returns(test_response(test_order_item))
|
39
|
+
order_item = Paid::OrderItem.new(test_order_item[:id])
|
40
|
+
order_item.refresh
|
41
|
+
assert_equal(test_order_item[:order], order_item.order)
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'be updateable' do
|
45
|
+
order_item = Paid::OrderItem.new(test_order_item)
|
46
|
+
order_item.product = "prod_123abc"
|
47
|
+
|
48
|
+
@mock.expects(:put).once.with do |url, headers, params|
|
49
|
+
!params.nil? && url == "#{@order_item_url}/#{order_item.id}"
|
50
|
+
end.returns(test_response(test_order_item))
|
51
|
+
|
52
|
+
# This should update this instance with test_order_item since it was returned
|
53
|
+
order_item.save
|
54
|
+
assert_equal(test_order_item[:product], order_item.product)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
context 'Retrieved Paid::OrderItem instance' do
|
60
|
+
setup do
|
61
|
+
@order_item = Paid::OrderItem.new(test_order_item)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'have the id attribute' do
|
65
|
+
assert_equal(test_order_item[:id], @order_item.id)
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'have the object attribute' do
|
69
|
+
assert_equal(test_order_item[:object], @order_item.object)
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'have the order attribute' do
|
73
|
+
assert_equal(test_order_item[:order], @order_item.order)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'have the plan_item attribute' do
|
77
|
+
assert_equal(test_order_item[:plan_item], @order_item.plan_item)
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'have the product attribute' do
|
81
|
+
assert_equal(test_order_item[:product], @order_item.product)
|
82
|
+
end
|
83
|
+
|
84
|
+
should 'have the service_ends_on attribute' do
|
85
|
+
assert_equal(test_order_item[:service_ends_on], @order_item.service_ends_on)
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'have the service_starts_on attribute' do
|
89
|
+
assert_equal(test_order_item[:service_starts_on], @order_item.service_starts_on)
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'have the transaction attribute' do
|
93
|
+
assert_equal(test_order_item[:transaction], @order_item.transaction)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'be registered' do
|
98
|
+
assert(APIResource.api_subclasses.include?(Paid::OrderItem))
|
99
|
+
assert_equal(Paid::OrderItem, APIResource.api_subclass_fetch("order_item"))
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class OrderTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
@order_url = "#{Paid.api_base}/orders"
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'Order class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "order_id"
|
12
|
+
@mock.expects(:get).once.with("#{@order_url}/#{id}", anything, anything).returns(test_response(test_order))
|
13
|
+
order = Paid::Order.retrieve(id)
|
14
|
+
assert(order.is_a?(Paid::Order))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@order_url, anything, test_order).returns(test_response(test_order))
|
19
|
+
order = Paid::Order.create(test_order)
|
20
|
+
assert(order.is_a?(Paid::Order))
|
21
|
+
assert_equal(test_order[:id], order.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_order_list))
|
26
|
+
|
27
|
+
orders = Paid::Order.all
|
28
|
+
|
29
|
+
assert(orders.is_a?(Paid::APIList))
|
30
|
+
orders.each do |order|
|
31
|
+
assert(order.is_a?(Paid::Order))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'Order instance' do
|
37
|
+
should 'be refreshable' do
|
38
|
+
@mock.expects(:get).once.with("#{@order_url}/#{test_order[:id]}", anything, anything).returns(test_response(test_order))
|
39
|
+
order = Paid::Order.new(test_order[:id])
|
40
|
+
order.refresh
|
41
|
+
assert_equal(test_order[:amount], order.amount)
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'be updateable' do
|
45
|
+
order = Paid::Order.new(test_order)
|
46
|
+
order.charge_now = true
|
47
|
+
|
48
|
+
@mock.expects(:put).once.with do |url, headers, params|
|
49
|
+
!params.nil? && url == "#{@order_url}/#{order.id}"
|
50
|
+
end.returns(test_response(test_order))
|
51
|
+
|
52
|
+
# This should update this instance with test_order since it was returned
|
53
|
+
order.save
|
54
|
+
assert_equal(test_order[:charge_now], order.charge_now)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
context 'Retrieved Paid::Order instance' do
|
60
|
+
setup do
|
61
|
+
@order = Paid::Order.new(test_order)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'have the id attribute' do
|
65
|
+
assert_equal(test_order[:id], @order.id)
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'have the object attribute' do
|
69
|
+
assert_equal(test_order[:object], @order.object)
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'have the amount attribute' do
|
73
|
+
assert_equal(test_order[:amount], @order.amount)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'have the charge_now attribute' do
|
77
|
+
assert_equal(test_order[:charge_now], @order.charge_now)
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'have the customer attribute' do
|
81
|
+
assert_equal(test_order[:customer], @order.customer)
|
82
|
+
end
|
83
|
+
|
84
|
+
should 'have the metadata attribute' do
|
85
|
+
assert_equal(test_order[:metadata], @order.metadata)
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'have the subscription attribute' do
|
89
|
+
assert_equal(test_order[:subscription], @order.subscription)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'be registered' do
|
94
|
+
assert(APIResource.api_subclasses.include?(Paid::Order))
|
95
|
+
assert_equal(Paid::Order, APIResource.api_subclass_fetch("order"))
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class PlanItemTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
@plan_item_url = "#{Paid.api_base}/plan_items"
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'PlanItem class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "plan_item_id"
|
12
|
+
@mock.expects(:get).once.with("#{@plan_item_url}/#{id}", anything, anything).returns(test_response(test_plan_item))
|
13
|
+
plan_item = Paid::PlanItem.retrieve(id)
|
14
|
+
assert(plan_item.is_a?(Paid::PlanItem))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@plan_item_url, anything, test_plan_item).returns(test_response(test_plan_item))
|
19
|
+
plan_item = Paid::PlanItem.create(test_plan_item)
|
20
|
+
assert(plan_item.is_a?(Paid::PlanItem))
|
21
|
+
assert_equal(test_plan_item[:id], plan_item.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_plan_item_list))
|
26
|
+
|
27
|
+
plan_items = Paid::PlanItem.all
|
28
|
+
|
29
|
+
assert(plan_items.is_a?(Paid::APIList))
|
30
|
+
plan_items.each do |plan_item|
|
31
|
+
assert(plan_item.is_a?(Paid::PlanItem))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'PlanItem instance' do
|
37
|
+
should 'be refreshable' do
|
38
|
+
@mock.expects(:get).once.with("#{@plan_item_url}/#{test_plan_item[:id]}", anything, anything).returns(test_response(test_plan_item))
|
39
|
+
plan_item = Paid::PlanItem.new(test_plan_item[:id])
|
40
|
+
plan_item.refresh
|
41
|
+
assert_equal(test_plan_item[:pricing][:quantity], plan_item.pricing[:quantity])
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'be updateable' do
|
45
|
+
plan_item = Paid::PlanItem.new(test_plan_item)
|
46
|
+
plan_item.pricing[:quantity] = 2.0
|
47
|
+
|
48
|
+
@mock.expects(:put).once.with do |url, headers, params|
|
49
|
+
!params.nil? && url == "#{@plan_item_url}/#{plan_item.id}"
|
50
|
+
end.returns(test_response(test_plan_item))
|
51
|
+
|
52
|
+
# This should update this instance with test_plan_item since it was returned
|
53
|
+
plan_item.save
|
54
|
+
assert_equal(test_plan_item[:pricing][:quantity], plan_item.pricing[:quantity])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
context 'Retrieved Paid::PlanItem instance' do
|
60
|
+
setup do
|
61
|
+
@plan_item = Paid::PlanItem.new(test_plan_item)
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'have the id attribute' do
|
65
|
+
assert_equal(test_plan_item[:id], @plan_item.id)
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'have the object attribute' do
|
69
|
+
assert_equal(test_plan_item[:object], @plan_item.object)
|
70
|
+
end
|
71
|
+
|
72
|
+
should 'have the plan attribute' do
|
73
|
+
assert_equal(test_plan_item[:plan], @plan_item.plan)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'have the product attribute' do
|
77
|
+
assert_equal(test_plan_item[:product], @plan_item.product)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'be registered' do
|
82
|
+
assert(APIResource.api_subclasses.include?(Paid::PlanItem))
|
83
|
+
assert_equal(Paid::PlanItem, APIResource.api_subclass_fetch("plan_item"))
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class ProductTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
@product_url = "#{Paid.api_base}/products"
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'Product class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "product_id"
|
12
|
+
@mock.expects(:get).once.with("#{@product_url}/#{id}", anything, anything).returns(test_response(test_product))
|
13
|
+
product = Paid::Product.retrieve(id)
|
14
|
+
assert(product.is_a?(Paid::Product))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@product_url, anything, anything).returns(test_response(test_product))
|
19
|
+
product = Paid::Product.create(test_product)
|
20
|
+
assert(product.is_a?(Paid::Product))
|
21
|
+
assert_equal(test_product[:id], product.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_product_list))
|
26
|
+
|
27
|
+
products = Paid::Product.all
|
28
|
+
|
29
|
+
assert(products.is_a?(Paid::APIList))
|
30
|
+
products.each do |product|
|
31
|
+
assert(product.is_a?(Paid::Product))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'Product instance' do
|
37
|
+
should 'be refreshable' do
|
38
|
+
@mock.expects(:get).once.with("#{@product_url}/#{test_product[:id]}", anything, anything).returns(test_response(test_product))
|
39
|
+
product = Paid::Product.new(test_product[:id])
|
40
|
+
product.refresh
|
41
|
+
assert_equal(test_product[:name], product.name)
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'be updateable' do
|
45
|
+
product = Paid::Product.new(test_product)
|
46
|
+
product.name = "new name"
|
47
|
+
product.description = "new description"
|
48
|
+
|
49
|
+
@mock.expects(:put).once.with do |url, headers, params|
|
50
|
+
!params.nil? && url == "#{@product_url}/#{product.id}"
|
51
|
+
end.returns(test_response(test_product))
|
52
|
+
|
53
|
+
# This should update this instance with test_product since it was returned
|
54
|
+
product.save
|
55
|
+
assert_equal(test_product[:name], product.name)
|
56
|
+
assert_equal(test_product[:description], product.description)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
context 'Retrieved Paid::Product instance' do
|
62
|
+
setup do
|
63
|
+
@product = Paid::Product.new(test_product)
|
64
|
+
end
|
65
|
+
|
66
|
+
should 'have the id attribute' do
|
67
|
+
assert_equal(test_product[:id], @product.id)
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'have the object attribute' do
|
71
|
+
assert_equal(test_product[:object], @product.object)
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'have the description attribute' do
|
75
|
+
assert_equal(test_product[:description], @product.description)
|
76
|
+
end
|
77
|
+
|
78
|
+
should 'have the external_id attribute' do
|
79
|
+
assert_equal(test_product[:external_id], @product.external_id)
|
80
|
+
end
|
81
|
+
|
82
|
+
should 'have the external_metric_id attribute' do
|
83
|
+
assert_equal(test_product[:external_metric_id], @product.external_metric_id)
|
84
|
+
end
|
85
|
+
|
86
|
+
should 'have the name attribute' do
|
87
|
+
assert_equal(test_product[:name], @product.name)
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'have the transaction_description attribute' do
|
91
|
+
assert_equal(test_product[:transaction_description], @product.transaction_description)
|
92
|
+
end
|
93
|
+
|
94
|
+
should 'have the pricing_structure attribute' do
|
95
|
+
assert_equal(test_product[:pricing_structure], @product.pricing_structure)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
should 'be registered' do
|
100
|
+
assert(APIResource.api_subclasses.include?(Paid::Product))
|
101
|
+
assert_equal(Paid::Product, APIResource.api_subclass_fetch("product"))
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
data/test/test_data.rb
CHANGED
@@ -146,6 +146,58 @@ module Paid
|
|
146
146
|
}
|
147
147
|
end
|
148
148
|
|
149
|
+
def test_plan_item
|
150
|
+
{
|
151
|
+
:created_at => 1463730588,
|
152
|
+
:object => "plan_item",
|
153
|
+
:id => "pl_itm_rvI2LsUFPAXLCIyYso0Q",
|
154
|
+
:updated_at => 1463730588,
|
155
|
+
:pricing => {
|
156
|
+
:currency => "usd",
|
157
|
+
:price => 1,
|
158
|
+
:quantity => 1.0,
|
159
|
+
:type => "quantity"
|
160
|
+
},
|
161
|
+
:plan => "pl_sXiYX4jmEE6VsTcRNkPg",
|
162
|
+
:product => "prod_sdhu3jttxzEfq7b9C1g"
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_plan_item_list
|
167
|
+
{
|
168
|
+
:data => [test_plan_item, test_plan_item, test_plan_item],
|
169
|
+
:object => 'list'
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_product
|
174
|
+
{
|
175
|
+
:created_at => 1463730588,
|
176
|
+
:object => "product",
|
177
|
+
:id => "prod_sdhu3jttxzEfq7b9C1g",
|
178
|
+
:updated_at => 1464733819,
|
179
|
+
:description => "This is money we want every day.",
|
180
|
+
:external_id => nil,
|
181
|
+
:metadata => {
|
182
|
+
"something" => "to something"
|
183
|
+
},
|
184
|
+
:name => "Test Daily Plan",
|
185
|
+
:pricing => {
|
186
|
+
:currency => "usd",
|
187
|
+
:price => 1,
|
188
|
+
:type => "quantity"
|
189
|
+
},
|
190
|
+
:transaction_description => "This is money we want every day."
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_product_list
|
195
|
+
{
|
196
|
+
:data => [test_product, test_product, test_product],
|
197
|
+
:object => 'list'
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
149
201
|
def test_event(data=test_invoice, type="invoice.generated")
|
150
202
|
{
|
151
203
|
:id => "evt_b8DZtUtZs8sxs0EsCcMg",
|
@@ -156,6 +208,54 @@ module Paid
|
|
156
208
|
}
|
157
209
|
end
|
158
210
|
|
211
|
+
def test_order
|
212
|
+
{
|
213
|
+
:created_at => 1463850015,
|
214
|
+
:object => "order",
|
215
|
+
:id => "ordr_qMjx3cpmJYabgz17LzXbQ",
|
216
|
+
:updated_at => 1464316156,
|
217
|
+
:amount => 15999,
|
218
|
+
:charge_now => false,
|
219
|
+
:service_ends_on => 1463875199,
|
220
|
+
:service_starts_on => 1463270400,
|
221
|
+
:customer => "cus_H17up4YDnwAPLE5Kpag"
|
222
|
+
}
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_order_list
|
226
|
+
{
|
227
|
+
:data => [test_order, test_order, test_order],
|
228
|
+
:object => 'list'
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_order_item
|
233
|
+
{
|
234
|
+
:created_at => 1463850015,
|
235
|
+
:object => "order_item",
|
236
|
+
:id => "ordr_itm_mxEZHQ1SDx4xYcaAP9WCQ",
|
237
|
+
:updated_at => 1463850015,
|
238
|
+
:pricing => {
|
239
|
+
:currency => "usd",
|
240
|
+
:price => 15999,
|
241
|
+
:quantity => 1.0,
|
242
|
+
:type => "quantity"
|
243
|
+
},
|
244
|
+
:order => "ordr_qMjx3cklJnabgz07XzXbQ",
|
245
|
+
:product => "prod_Q3UG2qooCHz1ywABkk93Lw",
|
246
|
+
:transaction => nil,
|
247
|
+
:service_ends_on => 1463803200,
|
248
|
+
:service_starts_on => 1463284800
|
249
|
+
}
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_order_item_list
|
253
|
+
{
|
254
|
+
:data => [test_order_item, test_order_item, test_order_item],
|
255
|
+
:object => 'list'
|
256
|
+
}
|
257
|
+
end
|
258
|
+
|
159
259
|
def test_event_list
|
160
260
|
{
|
161
261
|
:data => [test_event, test_event(test_customer, "customer.created"), test_event(test_plan, "plan.created")],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Calhoun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -151,9 +151,13 @@ files:
|
|
151
151
|
- lib/paid/event_data.rb
|
152
152
|
- lib/paid/headers_builder.rb
|
153
153
|
- lib/paid/invoice.rb
|
154
|
+
- lib/paid/order.rb
|
155
|
+
- lib/paid/order_item.rb
|
154
156
|
- lib/paid/params_builder.rb
|
155
157
|
- lib/paid/path_builder.rb
|
156
158
|
- lib/paid/plan.rb
|
159
|
+
- lib/paid/plan_item.rb
|
160
|
+
- lib/paid/product.rb
|
157
161
|
- lib/paid/refund_list.rb
|
158
162
|
- lib/paid/requester.rb
|
159
163
|
- lib/paid/subscription.rb
|
@@ -170,9 +174,13 @@ files:
|
|
170
174
|
- test/paid/event_test.rb
|
171
175
|
- test/paid/headers_builder_test.rb
|
172
176
|
- test/paid/invoice_test.rb
|
177
|
+
- test/paid/order_item_test.rb
|
178
|
+
- test/paid/order_test.rb
|
173
179
|
- test/paid/params_builder_test.rb
|
174
180
|
- test/paid/path_builder_test.rb
|
181
|
+
- test/paid/plan_item_test.rb
|
175
182
|
- test/paid/plan_test.rb
|
183
|
+
- test/paid/product_test.rb
|
176
184
|
- test/paid/requester_test.rb
|
177
185
|
- test/paid/subscription_test.rb
|
178
186
|
- test/paid/transaction_test.rb
|
@@ -212,9 +220,13 @@ test_files:
|
|
212
220
|
- test/paid/event_test.rb
|
213
221
|
- test/paid/headers_builder_test.rb
|
214
222
|
- test/paid/invoice_test.rb
|
223
|
+
- test/paid/order_item_test.rb
|
224
|
+
- test/paid/order_test.rb
|
215
225
|
- test/paid/params_builder_test.rb
|
216
226
|
- test/paid/path_builder_test.rb
|
227
|
+
- test/paid/plan_item_test.rb
|
217
228
|
- test/paid/plan_test.rb
|
229
|
+
- test/paid/product_test.rb
|
218
230
|
- test/paid/requester_test.rb
|
219
231
|
- test/paid/subscription_test.rb
|
220
232
|
- test/paid/transaction_test.rb
|