paid 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/.travis.yml +16 -0
- data/History.txt +4 -0
- data/README.md +58 -0
- data/Rakefile +9 -29
- data/VERSION +1 -0
- data/bin/paid-console +7 -0
- data/gemfiles/default-with-activesupport.gemfile +10 -0
- data/gemfiles/json.gemfile +12 -0
- data/gemfiles/yajl.gemfile +12 -0
- data/lib/paid.rb +129 -177
- data/lib/paid/account.rb +14 -1
- data/lib/paid/api_class.rb +336 -0
- data/lib/paid/api_list.rb +47 -0
- data/lib/paid/api_resource.rb +8 -25
- data/lib/paid/api_singleton.rb +5 -0
- data/lib/paid/customer.rb +36 -21
- data/lib/paid/errors/api_error.rb +6 -0
- data/lib/paid/event.rb +22 -1
- data/lib/paid/invoice.rb +16 -21
- data/lib/paid/plan.rb +18 -2
- data/lib/paid/subscription.rb +17 -11
- data/lib/paid/transaction.rb +19 -12
- data/lib/paid/util.rb +53 -106
- data/lib/paid/version.rb +1 -1
- data/paid.gemspec +10 -11
- data/tasks/api_test.rb +187 -0
- data/test/mock_resource.rb +69 -0
- data/test/paid/account_test.rb +41 -4
- data/test/paid/api_class_test.rb +412 -0
- data/test/paid/api_list_test.rb +17 -0
- data/test/paid/api_resource_test.rb +13 -343
- data/test/paid/api_singleton_test.rb +12 -0
- data/test/paid/authentication_test.rb +50 -0
- data/test/paid/customer_test.rb +189 -29
- data/test/paid/event_test.rb +74 -0
- data/test/paid/invoice_test.rb +101 -20
- data/test/paid/plan_test.rb +84 -8
- data/test/paid/status_codes_test.rb +63 -0
- data/test/paid/subscription_test.rb +100 -20
- data/test/paid/transaction_test.rb +110 -37
- data/test/paid/util_test.rb +15 -24
- data/test/test_data.rb +144 -93
- data/test/test_helper.rb +6 -4
- metadata +32 -26
- data/Gemfile.lock +0 -54
- data/README.rdoc +0 -35
- data/lib/data/ca-certificates.crt +0 -0
- data/lib/paid/alias.rb +0 -16
- data/lib/paid/api_operations/create.rb +0 -17
- data/lib/paid/api_operations/delete.rb +0 -11
- data/lib/paid/api_operations/list.rb +0 -17
- data/lib/paid/api_operations/update.rb +0 -57
- data/lib/paid/certificate_blacklist.rb +0 -55
- data/lib/paid/list_object.rb +0 -37
- data/lib/paid/paid_object.rb +0 -187
- data/lib/paid/singleton_api_resource.rb +0 -20
- data/lib/tasks/paid_tasks.rake +0 -4
- data/test/paid/alias_test.rb +0 -22
- data/test/paid/certificate_blacklist_test.rb +0 -18
- data/test/paid/list_object_test.rb +0 -16
- data/test/paid/paid_object_test.rb +0 -27
- data/test/paid/properties_test.rb +0 -103
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path('../../test_helper', __FILE__)
|
3
|
+
|
4
|
+
module Paid
|
5
|
+
class StatusCodesTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
context 'InvalidRequestError' do
|
8
|
+
should 'be raised when HTTP status code is 400' do
|
9
|
+
response = test_response(test_missing_id_error, 400)
|
10
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
11
|
+
begin
|
12
|
+
MockResource.retrieve('bad_id')
|
13
|
+
rescue Paid::InvalidRequestError => e
|
14
|
+
assert_equal(400, e.http_status)
|
15
|
+
assert(!!e.http_body)
|
16
|
+
assert(e.json_body.is_a?(Hash))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'be raised when HTTP status code is 404' do
|
21
|
+
response = test_response(test_missing_id_error, 404)
|
22
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
23
|
+
assert_raises
|
24
|
+
begin
|
25
|
+
MockResource.retrieve('foo')
|
26
|
+
rescue Paid::InvalidRequestError => e
|
27
|
+
rescued = true
|
28
|
+
assert_equal(404, e.http_status)
|
29
|
+
assert_equal(true, !!e.http_body)
|
30
|
+
assert_equal(true, e.json_body.is_a?(Hash))
|
31
|
+
end
|
32
|
+
assert(rescued)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'APIError' do
|
37
|
+
should 'be raised when HTTP status code is 5XX' do
|
38
|
+
response = test_response(test_api_error, 500)
|
39
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
|
40
|
+
|
41
|
+
begin
|
42
|
+
MockResource.new('fake_id').refresh
|
43
|
+
rescue Paid::APIError => e
|
44
|
+
rescued = true
|
45
|
+
assert(e.is_a?(Paid::APIError))
|
46
|
+
end
|
47
|
+
assert(rescued)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'AuthenticationError' do
|
52
|
+
should 'be raised when HTTP status code is 401 (invalid credentials)' do
|
53
|
+
Paid.api_key = 'invalid'
|
54
|
+
response = test_response(test_invalid_api_key_error, 401)
|
55
|
+
assert_raises(Paid::AuthenticationError) do
|
56
|
+
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
57
|
+
MockResource.retrieve('failing')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -1,31 +1,111 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Paid
|
4
|
-
# SubscriptionTest
|
5
4
|
class SubscriptionTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
@
|
8
|
-
i = Paid::Subscription.retrieve('in_test_subscription')
|
9
|
-
assert_equal 'sub_test_subscription', i.id
|
5
|
+
setup do
|
6
|
+
@subscription_url = "#{Paid.api_base}/v0/subscriptions"
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
context 'Subscription class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "subscription_id"
|
12
|
+
@mock.expects(:get).once.with("#{@subscription_url}/#{id}", anything, anything).returns(test_response(test_subscription))
|
13
|
+
subscription = Paid::Subscription.retrieve(id)
|
14
|
+
assert(subscription.is_a?(Paid::Subscription))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@subscription_url, anything, test_subscription).returns(test_response(test_subscription))
|
19
|
+
subscription = Paid::Subscription.create(test_subscription)
|
20
|
+
assert(subscription.is_a?(Paid::Subscription))
|
21
|
+
assert_equal(test_subscription[:id], subscription.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_subscription_list))
|
26
|
+
|
27
|
+
subscriptions = Paid::Subscription.all
|
28
|
+
|
29
|
+
assert(subscriptions.is_a?(Paid::APIList))
|
30
|
+
subscriptions.each do |subscription|
|
31
|
+
assert(subscription.is_a?(Paid::Subscription))
|
32
|
+
end
|
33
|
+
end
|
16
34
|
end
|
17
35
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
36
|
+
context 'Subscription instance' do
|
37
|
+
setup do
|
38
|
+
@subscription = Paid::Subscription.new(test_subscription[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'be refreshable' do
|
42
|
+
@mock.expects(:get).once.with("#{@subscription_url}/#{@subscription.id}", anything, anything).returns(test_response(test_subscription))
|
43
|
+
@subscription.refresh
|
44
|
+
assert_equal(test_subscription[:customer], @subscription.customer)
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'be cancellable' do
|
48
|
+
response = test_response(test_subscription.merge(:cancelled_at => 1425494198))
|
49
|
+
@mock.expects(:post).once.with("#{@subscription_url}/#{@subscription.id}/cancel", anything, anything).returns(response)
|
50
|
+
|
51
|
+
@subscription.cancel
|
52
|
+
assert_equal(1425494198, @subscription.cancelled_at)
|
53
|
+
end
|
29
54
|
end
|
55
|
+
|
56
|
+
context 'Retrieved Paid::Subscription instance' do
|
57
|
+
setup do
|
58
|
+
@mock.expects(:get).once.returns(test_response(test_subscription))
|
59
|
+
@subscription = Paid::Subscription.retrieve('subscription_id')
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'have the id attribute' do
|
63
|
+
assert_equal(test_subscription[:id], @subscription.id)
|
64
|
+
end
|
65
|
+
|
66
|
+
should 'have the object attribute' do
|
67
|
+
assert_equal(test_subscription[:object], @subscription.object)
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'have the created_at attribute' do
|
71
|
+
assert_equal(test_subscription[:created_at], @subscription.created_at)
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'have the starts_on attribute' do
|
75
|
+
assert_equal(test_subscription[:starts_on], @subscription.starts_on)
|
76
|
+
end
|
77
|
+
|
78
|
+
should 'have the next_transaction_on attribute' do
|
79
|
+
assert_equal(test_subscription[:next_transaction_on], @subscription.next_transaction_on)
|
80
|
+
end
|
81
|
+
|
82
|
+
should 'have & convert the plan attribute' do
|
83
|
+
assert_equal(test_subscription[:plan][:id], @subscription.plan.id)
|
84
|
+
assert(@subscription.plan.is_a?(Paid::Plan))
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'have the customer attribute' do
|
88
|
+
assert_equal(test_subscription[:customer], @subscription.customer)
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'have the started_at attribute' do
|
92
|
+
assert_equal(test_subscription[:started_at], @subscription.started_at)
|
93
|
+
end
|
94
|
+
|
95
|
+
should 'have the ended_at attribute' do
|
96
|
+
assert_equal(test_subscription[:ended_at], @subscription.ended_at)
|
97
|
+
end
|
98
|
+
|
99
|
+
should 'have the cancelled_at attribute' do
|
100
|
+
assert_equal(test_subscription[:cancelled_at], @subscription.cancelled_at)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'be registered' do
|
106
|
+
assert(APIClass.subclasses.include?(Paid::Subscription))
|
107
|
+
assert_equal(Paid::Subscription, APIClass.subclass_fetch("subscription"))
|
108
|
+
end
|
109
|
+
|
30
110
|
end
|
31
111
|
end
|
@@ -2,54 +2,127 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Paid
|
4
4
|
class TransactionTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
@
|
7
|
-
c = Paid::Transaction.all
|
8
|
-
assert c.data.is_a? Array
|
9
|
-
c.each do |transaction|
|
10
|
-
assert transaction.is_a?(Paid::Transaction)
|
11
|
-
end
|
5
|
+
setup do
|
6
|
+
@transaction_url = "#{Paid.api_base}/v0/transactions"
|
12
7
|
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
context 'Transaction class' do
|
10
|
+
should 'be retrieveable' do
|
11
|
+
id = "transaction_id"
|
12
|
+
@mock.expects(:get).once.with("#{@transaction_url}/#{id}", anything, anything).returns(test_response(test_transaction))
|
13
|
+
transaction = Paid::Transaction.retrieve(id)
|
14
|
+
assert(transaction.is_a?(Paid::Transaction))
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'be createable' do
|
18
|
+
@mock.expects(:post).once.with(@transaction_url, anything, test_transaction).returns(test_response(test_transaction))
|
19
|
+
transaction = Paid::Transaction.create(test_transaction)
|
20
|
+
assert(transaction.is_a?(Paid::Transaction))
|
21
|
+
assert_equal(test_transaction[:id], transaction.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'be listable' do
|
25
|
+
@mock.expects(:get).once.returns(test_response(test_transaction_list))
|
26
|
+
|
27
|
+
transactions = Paid::Transaction.all
|
28
|
+
|
29
|
+
assert(transactions.is_a?(Paid::APIList))
|
30
|
+
transactions.each do |transaction|
|
31
|
+
assert(transaction.is_a?(Paid::Transaction))
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
36
|
+
context 'Transaction instance' do
|
37
|
+
setup do
|
38
|
+
@transaction = Paid::Transaction.new(test_transaction[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'be refreshable' do
|
42
|
+
@mock.expects(:get).once.with("#{@transaction_url}/#{@transaction.id}", anything, anything).returns(test_response(test_transaction))
|
43
|
+
@transaction.refresh
|
44
|
+
assert_equal(test_transaction[:description], @transaction.description)
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'be updateable' do
|
48
|
+
transaction = Paid::Transaction.new(test_transaction)
|
49
|
+
transaction.description = "new description"
|
50
|
+
|
51
|
+
@mock.expects(:put).once.with do |url, headers, params|
|
52
|
+
params == transaction.changed_attributes && url == "#{@transaction_url}/#{transaction.id}"
|
53
|
+
end.returns(test_response(test_transaction))
|
54
|
+
|
55
|
+
# This should update this instance with test_transaction since it was returned
|
56
|
+
transaction.save
|
57
|
+
assert_equal(test_transaction[:description], transaction.description)
|
58
|
+
end
|
59
|
+
|
60
|
+
should 'be able to mark as paid' do
|
61
|
+
paid_on = "2015-01-01"
|
62
|
+
response = test_response(test_invoice.merge(:paid => true, :paid_on => paid_on))
|
63
|
+
@mock.expects(:post).once.with("#{@transaction_url}/#{@transaction.id}/mark_as_paid", anything, { :paid_on => paid_on }).returns(response)
|
64
|
+
|
65
|
+
assert(!@transaction.paid)
|
66
|
+
@transaction.mark_as_paid(:paid_on => paid_on)
|
67
|
+
assert_equal(paid_on, @transaction.paid_on)
|
68
|
+
assert(@transaction.paid)
|
69
|
+
end
|
29
70
|
end
|
30
71
|
|
31
|
-
should 'execute should return a new, fully executed transaction when passed correct parameters' do
|
32
|
-
@mock.expects(:post).with do |url, api_key, params|
|
33
|
-
url == "#{Paid.api_base}/v0/transactions" && api_key.nil? && CGI.parse(params) == {
|
34
|
-
'amount' => ['100'],
|
35
|
-
'description' => ['a description'],
|
36
|
-
'customer' => ['cus_test_customer']
|
37
|
-
}
|
38
|
-
end.once.returns(test_response(test_transaction))
|
39
72
|
|
40
|
-
|
41
|
-
|
42
|
-
|
73
|
+
context 'Retrieved Paid::Transaction instance' do
|
74
|
+
setup do
|
75
|
+
@mock.expects(:get).once.returns(test_response(test_transaction))
|
76
|
+
@transaction = Paid::Transaction.retrieve('transaction_id')
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'have the id attribute' do
|
80
|
+
assert_equal(test_transaction[:id], @transaction.id)
|
81
|
+
end
|
82
|
+
|
83
|
+
should 'have the object attribute' do
|
84
|
+
assert_equal(test_transaction[:object], @transaction.object)
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'have the amount attribute' do
|
88
|
+
assert_equal(test_transaction[:amount], @transaction.amount)
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'have the description attribute' do
|
92
|
+
assert_equal(test_transaction[:description], @transaction.description)
|
93
|
+
end
|
94
|
+
|
95
|
+
should 'have the customer attribute' do
|
96
|
+
assert_equal(test_transaction[:customer], @transaction.customer)
|
97
|
+
end
|
98
|
+
|
99
|
+
should 'have the alias attribute' do
|
100
|
+
assert_equal(test_transaction[:alias], @transaction.alias)
|
101
|
+
end
|
102
|
+
|
103
|
+
should 'have the paid attribute' do
|
104
|
+
assert_equal(test_transaction[:paid], @transaction.paid)
|
105
|
+
end
|
106
|
+
|
107
|
+
should 'have the paid_on attribute' do
|
108
|
+
assert_equal(test_transaction[:paid_on], @transaction.paid_on)
|
109
|
+
end
|
110
|
+
|
111
|
+
should 'have the properties attribute' do
|
112
|
+
assert_equal(test_transaction[:properties], @transaction.properties)
|
113
|
+
end
|
114
|
+
|
115
|
+
should 'have the invoice attribute' do
|
116
|
+
assert_equal(test_transaction[:invoice], @transaction.invoice)
|
117
|
+
end
|
43
118
|
|
44
|
-
assert !c.paid
|
45
119
|
end
|
46
120
|
|
47
|
-
should '
|
48
|
-
|
49
|
-
|
50
|
-
t = Paid::Invoice.new('test_transaction')
|
51
|
-
t.mark_as_paid
|
52
|
-
assert t.paid
|
121
|
+
should 'be registered' do
|
122
|
+
assert(APIClass.subclasses.include?(Paid::Transaction))
|
123
|
+
assert_equal(Paid::Transaction, APIClass.subclass_fetch("transaction"))
|
53
124
|
end
|
125
|
+
|
126
|
+
|
54
127
|
end
|
55
128
|
end
|
data/test/paid/util_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Paid
|
4
4
|
class UtilTest < Test::Unit::TestCase
|
5
|
-
should "
|
5
|
+
should "symbolize_keys should convert keys to symbols" do
|
6
6
|
start = {
|
7
7
|
'foo' => 'bar',
|
8
8
|
'array' => [{ 'foo' => 'bar' }],
|
@@ -22,38 +22,29 @@ module Paid
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
-
symbolized = Paid::Util.
|
25
|
+
symbolized = Paid::Util.symbolize_keys(start)
|
26
26
|
assert_equal(finish, symbolized)
|
27
27
|
end
|
28
28
|
|
29
|
-
should
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal(nil, api_key)
|
33
|
-
end
|
29
|
+
should 'query_array should convert { :a => "value" } to []' do
|
30
|
+
start = { :a => "value" }
|
31
|
+
finish = ["a=value"]
|
34
32
|
|
35
|
-
|
36
|
-
api_key, headers = Paid::Util.parse_opts('foo')
|
37
|
-
assert_equal({}, headers)
|
38
|
-
assert_equal('foo', api_key)
|
33
|
+
assert_equal(finish, Paid::Util.query_array(start))
|
39
34
|
end
|
40
35
|
|
41
|
-
should
|
42
|
-
|
43
|
-
|
44
|
-
assert_equal('foo', api_key)
|
45
|
-
end
|
36
|
+
should 'query_array should convert { :a => { :b => { :c => "cvalue" } } } to ["a[b][c]=cvalue"]' do
|
37
|
+
start = { :a => { :b => { :c => "cvalue" } } }
|
38
|
+
finish = ["a[b][c]=cvalue"]
|
46
39
|
|
47
|
-
|
48
|
-
api_key, headers = Paid::Util.parse_opts({:idempotency_key => 'foo'})
|
49
|
-
assert_equal({:idempotency_key => 'foo'}, headers)
|
50
|
-
assert_equal(nil, api_key)
|
40
|
+
assert_equal(finish, Paid::Util.query_array(start))
|
51
41
|
end
|
52
42
|
|
53
|
-
should
|
54
|
-
|
55
|
-
|
56
|
-
|
43
|
+
should 'query_array should convert { :a => [1, 2] } to ["a[]=1", "a[]=2"]' do
|
44
|
+
start = { :a => [1, 2] }
|
45
|
+
finish = ["a[]=1", "a[]=2"]
|
46
|
+
|
47
|
+
assert_equal(finish, Paid::Util.query_array(start))
|
57
48
|
end
|
58
49
|
end
|
59
50
|
end
|
data/test/test_data.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Paid
|
2
2
|
module TestData
|
3
|
+
|
3
4
|
def test_response(body, code=200)
|
4
5
|
# When an exception is raised, restclient clobbers method_missing. Hence we
|
5
6
|
# can't just use the stubs interface.
|
@@ -11,155 +12,205 @@ module Paid
|
|
11
12
|
m
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
id = params[:id] || 'al_test_alias'
|
15
|
+
def test_mock_resource
|
16
16
|
{
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:name => 'test
|
20
|
-
:
|
21
|
-
|
17
|
+
:id => 'test_mock_resource_id',
|
18
|
+
:object => 'mock_resource',
|
19
|
+
:name => 'test mr name',
|
20
|
+
:nested => {
|
21
|
+
:id => 'test_nested_id',
|
22
|
+
:object => 'nested_resource',
|
23
|
+
:price => 500
|
24
|
+
},
|
25
|
+
:thash => { :some_key => "some value" },
|
26
|
+
:tarray => ["abc", "xyz"]
|
27
|
+
}
|
22
28
|
end
|
23
29
|
|
24
|
-
def
|
30
|
+
def test_mock_resource_list
|
25
31
|
{
|
26
|
-
:data => [test_alias, test_alias, test_alias],
|
27
32
|
:object => 'list',
|
28
|
-
:
|
33
|
+
:data => [test_mock_resource, test_mock_resource, test_mock_resource],
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_account
|
38
|
+
{
|
39
|
+
:id => 'account_id',
|
40
|
+
:object => 'account',
|
41
|
+
:business_name => 'some co inc',
|
42
|
+
:business_url => 'http://www.somecoinc.com/',
|
43
|
+
:business_logo => 'http://www.somecoinc.com/logo.png'
|
29
44
|
}
|
30
45
|
end
|
31
46
|
|
32
|
-
def test_customer
|
33
|
-
id = params[:id] || 'cus_test_customer'
|
47
|
+
def test_customer
|
34
48
|
{
|
35
|
-
:
|
49
|
+
:id => "cus_DLjf9aDKE9fkdncz",
|
36
50
|
:object => "customer",
|
37
|
-
:
|
38
|
-
:
|
39
|
-
|
51
|
+
:name => "Paid",
|
52
|
+
:email => "hello@paidapi.com",
|
53
|
+
:description => "Obviously this is just a description.",
|
54
|
+
:address_line1 => "2261 Market Street",
|
55
|
+
:address_line2 => "#567",
|
56
|
+
:address_city => "San Francisco",
|
57
|
+
:address_state => "CA",
|
58
|
+
:address_zip => "94114",
|
59
|
+
:phone => "4155069330",
|
60
|
+
:allow_ach => true,
|
61
|
+
:allow_check => true,
|
62
|
+
:allow_credit_card => true,
|
63
|
+
:allow_wire => true,
|
64
|
+
:terms => 30,
|
65
|
+
:billing_type => "invoice",
|
66
|
+
:billing_cycle => "manual",
|
67
|
+
:stripe_customer_id => nil,
|
68
|
+
:external_id => "customer_external_id",
|
69
|
+
:aliases => {
|
70
|
+
:object => "list",
|
71
|
+
:data => ["12345"]
|
72
|
+
}
|
73
|
+
}
|
40
74
|
end
|
41
75
|
|
42
|
-
def
|
76
|
+
def test_customer_list
|
43
77
|
{
|
44
78
|
:data => [test_customer, test_customer, test_customer],
|
45
|
-
:object => 'list'
|
46
|
-
:url => '/v0/customers'
|
79
|
+
:object => 'list'
|
47
80
|
}
|
48
81
|
end
|
49
82
|
|
50
|
-
def
|
51
|
-
id = params[:id] || 'tr_test_transaction'
|
83
|
+
def test_invoice
|
52
84
|
{
|
85
|
+
:object => "invoice",
|
86
|
+
:id => "inv_8KAu1BU4PiYnPE49XtN0A",
|
87
|
+
:summary => nil,
|
88
|
+
:chase_schedule => ["-7", "-1", "0", "1", "5", "10", "15", "20", "25", "30", "~1"],
|
89
|
+
:next_chase_on => nil,
|
90
|
+
:terms => 30,
|
91
|
+
:customer => "cus_XJuvZeQXQgKMrpUAzPbGA",
|
92
|
+
:issued_at => nil,
|
53
93
|
:paid => false,
|
54
|
-
:
|
55
|
-
|
94
|
+
:url => "https://payments.paid.com/invoices/inv_8KAu1BU4PiYnPE49XtN0A"
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_invoice_list
|
99
|
+
{
|
100
|
+
:data => [test_invoice, test_invoice, test_invoice],
|
101
|
+
:object => 'list'
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_transaction
|
106
|
+
{
|
107
|
+
:id => 'tr_a09sd8a8s9df7asdf98',
|
56
108
|
:object => "transaction",
|
109
|
+
:amount => 100,
|
57
110
|
:description => 'a description',
|
58
|
-
:
|
59
|
-
:
|
60
|
-
|
111
|
+
:customer => 'cus_test_customer',
|
112
|
+
:paid => false,
|
113
|
+
:paid_on => nil,
|
114
|
+
:properties => {},
|
115
|
+
:invoice => 'inv_8KAu1BU4PiYnPE49XtN0A'
|
116
|
+
}
|
61
117
|
end
|
62
118
|
|
63
|
-
def
|
119
|
+
def test_transaction_list
|
64
120
|
{
|
65
121
|
:data => [test_transaction, test_transaction, test_transaction],
|
66
|
-
:object => 'list'
|
67
|
-
:url => '/v0/transactions'
|
122
|
+
:object => 'list'
|
68
123
|
}
|
69
124
|
end
|
70
125
|
|
71
|
-
def
|
126
|
+
def test_plan
|
72
127
|
{
|
73
|
-
object
|
74
|
-
id
|
75
|
-
|
76
|
-
|
77
|
-
"
|
78
|
-
"
|
79
|
-
|
80
|
-
|
81
|
-
"5",
|
82
|
-
"10",
|
83
|
-
"15",
|
84
|
-
"20",
|
85
|
-
"25",
|
86
|
-
"30",
|
87
|
-
"~1"
|
88
|
-
],
|
89
|
-
next_chase_on: nil,
|
90
|
-
terms: 30,
|
91
|
-
due_date: nil,
|
92
|
-
customer: "cus_test_customer",
|
93
|
-
issued_at: nil
|
128
|
+
:object => "plan",
|
129
|
+
:id => "pl_F0h9MWFeZyXKVPHZ0bIcfQ",
|
130
|
+
:created_at => 1425494198,
|
131
|
+
:description => "Plan for testing stuff",
|
132
|
+
:name => "Test Plan",
|
133
|
+
:interval => "year",
|
134
|
+
:interval_count => 1,
|
135
|
+
:amount => 50000
|
94
136
|
}
|
95
137
|
end
|
96
138
|
|
97
|
-
def
|
139
|
+
def test_plan_list
|
98
140
|
{
|
99
|
-
:
|
100
|
-
|
101
|
-
:message => "Invalid API Key provided: invalid"
|
102
|
-
}
|
141
|
+
:data => [test_plan, test_plan, test_plan],
|
142
|
+
:object => 'list'
|
103
143
|
}
|
104
144
|
end
|
105
145
|
|
106
|
-
def
|
146
|
+
def test_event(data=test_invoice, type="invoice.generated")
|
107
147
|
{
|
108
|
-
:
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
148
|
+
:id => "evt_b8DZtUtZs8sxs0EsCcMg",
|
149
|
+
:object => "event",
|
150
|
+
:created_at => 1421719697,
|
151
|
+
:type => type,
|
152
|
+
:data => data
|
113
153
|
}
|
114
154
|
end
|
115
155
|
|
116
|
-
def
|
156
|
+
def test_event_list
|
117
157
|
{
|
118
|
-
:
|
119
|
-
|
120
|
-
}
|
158
|
+
:data => [test_event, test_event(test_customer, "customer.created"), test_event(test_plan, "plan.created")],
|
159
|
+
:object => 'list'
|
121
160
|
}
|
122
161
|
end
|
123
162
|
|
124
|
-
def
|
163
|
+
def test_subscription
|
125
164
|
{
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
|
165
|
+
:id => "sub_IQSGpEv9mKr6NBkKTr4qfA",
|
166
|
+
:object => "subscription",
|
167
|
+
:created_at => 1425494242,
|
168
|
+
:starts_on => "2015-03-04",
|
169
|
+
:next_transaction_on => "2016-03-04",
|
170
|
+
:plan => test_plan,
|
171
|
+
:customer => "cus_VygTkKwTBgfjV3xo60wRRA",
|
172
|
+
:started_at => 1425494242,
|
173
|
+
:ended_at => 0,
|
174
|
+
:cancelled_at => 0
|
175
|
+
}
|
134
176
|
end
|
135
177
|
|
136
|
-
def
|
178
|
+
def test_subscription_list
|
137
179
|
{
|
138
|
-
:data => [
|
139
|
-
:object => 'list'
|
140
|
-
:url => '/v0/plans'
|
180
|
+
:data => [test_subscription, test_subscription, test_subscription],
|
181
|
+
:object => 'list'
|
141
182
|
}
|
142
183
|
end
|
143
184
|
|
144
|
-
|
185
|
+
|
186
|
+
|
187
|
+
# Errors
|
188
|
+
def test_api_error
|
145
189
|
{
|
146
|
-
:
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
:ended_at => nil,
|
151
|
-
:started_at => 123_456_789,
|
152
|
-
:start_on => nil,
|
153
|
-
:plan => 'pl_test_plan'
|
154
|
-
}.merge(params)
|
190
|
+
:error => {
|
191
|
+
:type => "api_error"
|
192
|
+
}
|
193
|
+
}
|
155
194
|
end
|
156
195
|
|
157
|
-
def
|
196
|
+
def test_invalid_api_key_error
|
158
197
|
{
|
159
|
-
:
|
160
|
-
|
161
|
-
|
198
|
+
:error => {
|
199
|
+
:type => "invalid_request_error",
|
200
|
+
:message => "Invalid API Key provided: invalid"
|
201
|
+
}
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_missing_id_error
|
206
|
+
{
|
207
|
+
:error => {
|
208
|
+
:param => "id",
|
209
|
+
:type => "invalid_request_error",
|
210
|
+
:message => "Missing id"
|
211
|
+
}
|
162
212
|
}
|
163
213
|
end
|
214
|
+
|
164
215
|
end
|
165
216
|
end
|