stripe 1.30.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +4 -0
- data/.github/ISSUE_TEMPLATE.md +5 -0
- data/.travis.yml +3 -14
- data/Gemfile +28 -4
- data/History.txt +180 -0
- data/README.md +147 -0
- data/Rakefile +10 -0
- data/VERSION +1 -1
- data/bin/stripe-console +12 -5
- data/lib/data/ca-certificates.crt +3868 -5114
- data/lib/stripe/account.rb +43 -23
- data/lib/stripe/alipay_account.rb +20 -0
- data/lib/stripe/api_operations/create.rb +2 -2
- data/lib/stripe/api_operations/delete.rb +2 -2
- data/lib/stripe/api_operations/list.rb +2 -3
- data/lib/stripe/api_operations/request.rb +9 -3
- data/lib/stripe/api_operations/save.rb +85 -0
- data/lib/stripe/api_resource.rb +38 -5
- data/lib/stripe/apple_pay_domain.rb +12 -0
- data/lib/stripe/application_fee.rb +8 -8
- data/lib/stripe/application_fee_refund.rb +7 -3
- data/lib/stripe/balance_transaction.rb +1 -1
- data/lib/stripe/bank_account.rb +13 -4
- data/lib/stripe/bitcoin_receiver.rb +6 -6
- data/lib/stripe/bitcoin_transaction.rb +1 -1
- data/lib/stripe/card.rb +9 -5
- data/lib/stripe/charge.rb +38 -20
- data/lib/stripe/country_spec.rb +9 -0
- data/lib/stripe/coupon.rb +1 -1
- data/lib/stripe/customer.rb +12 -10
- data/lib/stripe/dispute.rb +4 -5
- data/lib/stripe/errors.rb +92 -0
- data/lib/stripe/file_upload.rb +1 -1
- data/lib/stripe/invoice.rb +7 -7
- data/lib/stripe/invoice_item.rb +1 -1
- data/lib/stripe/list_object.rb +8 -7
- data/lib/stripe/order.rb +12 -4
- data/lib/stripe/order_return.rb +9 -0
- data/lib/stripe/plan.rb +1 -1
- data/lib/stripe/product.rb +2 -10
- data/lib/stripe/recipient.rb +1 -1
- data/lib/stripe/refund.rb +1 -1
- data/lib/stripe/reversal.rb +7 -3
- data/lib/stripe/singleton_api_resource.rb +3 -3
- data/lib/stripe/sku.rb +2 -2
- data/lib/stripe/source.rb +11 -0
- data/lib/stripe/stripe_client.rb +396 -0
- data/lib/stripe/stripe_object.rb +167 -91
- data/lib/stripe/stripe_response.rb +48 -0
- data/lib/stripe/subscription.rb +15 -9
- data/lib/stripe/subscription_item.rb +12 -0
- data/lib/stripe/three_d_secure.rb +9 -0
- data/lib/stripe/transfer.rb +4 -5
- data/lib/stripe/util.rb +105 -33
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +69 -266
- data/spec/fixtures.json +1409 -0
- data/spec/fixtures.yaml +1153 -0
- data/spec/spec.json +19949 -0
- data/spec/spec.yaml +15504 -0
- data/stripe.gemspec +5 -18
- data/test/api_fixtures.rb +29 -0
- data/test/api_stub_helpers.rb +125 -0
- data/test/stripe/account_test.rb +163 -211
- data/test/stripe/alipay_account_test.rb +19 -0
- data/test/stripe/api_operations_test.rb +31 -0
- data/test/stripe/api_resource_test.rb +174 -340
- data/test/stripe/apple_pay_domain_test.rb +33 -0
- data/test/stripe/application_fee_refund_test.rb +22 -31
- data/test/stripe/application_fee_test.rb +6 -14
- data/test/stripe/balance_test.rb +3 -3
- data/test/stripe/bank_account_test.rb +41 -0
- data/test/stripe/bitcoin_receiver_test.rb +51 -42
- data/test/stripe/bitcoin_transaction_test.rb +11 -19
- data/test/stripe/charge_test.rb +39 -98
- data/test/stripe/country_spec_test.rb +20 -0
- data/test/stripe/coupon_test.rb +35 -11
- data/test/stripe/customer_card_test.rb +25 -46
- data/test/stripe/customer_test.rb +89 -61
- data/test/stripe/dispute_test.rb +28 -31
- data/test/stripe/errors_test.rb +18 -0
- data/test/stripe/file_upload_test.rb +32 -24
- data/test/stripe/invoice_item_test.rb +55 -0
- data/test/stripe/invoice_test.rb +50 -24
- data/test/stripe/list_object_test.rb +57 -45
- data/test/stripe/order_return_test.rb +21 -0
- data/test/stripe/order_test.rb +41 -34
- data/test/stripe/plan_test.rb +52 -0
- data/test/stripe/product_test.rb +31 -25
- data/test/stripe/recipient_card_test.rb +23 -40
- data/test/stripe/recipient_test.rb +50 -0
- data/test/stripe/refund_test.rb +20 -36
- data/test/stripe/reversal_test.rb +27 -31
- data/test/stripe/sku_test.rb +39 -13
- data/test/stripe/source_test.rb +43 -0
- data/test/stripe/stripe_client_test.rb +428 -0
- data/test/stripe/stripe_object_test.rb +186 -13
- data/test/stripe/stripe_response_test.rb +46 -0
- data/test/stripe/subscription_item_test.rb +54 -0
- data/test/stripe/subscription_test.rb +40 -52
- data/test/stripe/three_d_secure_test.rb +23 -0
- data/test/stripe/transfer_test.rb +38 -13
- data/test/stripe/util_test.rb +48 -16
- data/test/stripe_test.rb +25 -0
- data/test/test_data.rb +5 -621
- data/test/test_helper.rb +24 -24
- metadata +60 -139
- data/README.rdoc +0 -68
- data/gemfiles/default-with-activesupport.gemfile +0 -10
- data/gemfiles/json.gemfile +0 -12
- data/gemfiles/yajl.gemfile +0 -12
- data/lib/stripe/api_operations/update.rb +0 -58
- data/lib/stripe/errors/api_connection_error.rb +0 -4
- data/lib/stripe/errors/api_error.rb +0 -4
- data/lib/stripe/errors/authentication_error.rb +0 -4
- data/lib/stripe/errors/card_error.rb +0 -12
- data/lib/stripe/errors/invalid_request_error.rb +0 -11
- data/lib/stripe/errors/rate_limit_error.rb +0 -4
- data/lib/stripe/errors/stripe_error.rb +0 -26
- data/test/stripe/charge_refund_test.rb +0 -55
- data/test/stripe/metadata_test.rb +0 -129
@@ -2,62 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class CustomerCardTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:source)
|
6
6
|
|
7
|
-
|
8
|
-
@
|
9
|
-
|
7
|
+
setup do
|
8
|
+
@customer =
|
9
|
+
Stripe::Customer.retrieve(API_FIXTURES.fetch(:customer)[:id])
|
10
10
|
end
|
11
11
|
|
12
|
-
should "
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
assert
|
12
|
+
should "be listable" do
|
13
|
+
sources = @customer.sources.list
|
14
|
+
assert sources.data.kind_of?(Array)
|
15
|
+
# because of the terrible :wildcard nature of sources, the API stub
|
16
|
+
# cannot currently replace this response with anything meaningful so we
|
17
|
+
# don't assert on the type of individual items like we do in other tests
|
18
18
|
end
|
19
19
|
|
20
|
-
should "
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
)
|
26
|
-
card = c.sources.retrieve('card')
|
27
|
-
assert_equal CUSTOMER_CARD_URL, card.url
|
20
|
+
should "be creatable" do
|
21
|
+
card = @customer.sources.create(
|
22
|
+
source: API_FIXTURES.fetch(:token)[:id]
|
23
|
+
)
|
24
|
+
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
|
25
|
+
assert card.kind_of?(Stripe::BankAccount)
|
28
26
|
end
|
29
27
|
|
30
|
-
should "
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
card
|
35
|
-
card.delete
|
36
|
-
assert card.deleted
|
28
|
+
should "be deletable" do
|
29
|
+
card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
|
30
|
+
card = card.delete
|
31
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
|
32
|
+
assert card.kind_of?(Stripe::Card)
|
37
33
|
end
|
38
34
|
|
39
|
-
should "
|
40
|
-
|
41
|
-
|
42
|
-
@mock.expects(:post).once.returns(make_response(make_card(:exp_year => "2100")))
|
43
|
-
card = c.sources.retrieve('card')
|
44
|
-
assert_equal "2000", card.exp_year
|
45
|
-
card.exp_year = "2100"
|
35
|
+
should "be saveable" do
|
36
|
+
card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
|
37
|
+
card.metadata['key'] = 'value'
|
46
38
|
card.save
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
should "create should return a new customer card" do
|
51
|
-
c = customer
|
52
|
-
@mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
|
53
|
-
card = c.sources.create(:source => "tok_41YJ05ijAaWaFS")
|
54
|
-
assert_equal "test_card", card.id
|
55
|
-
end
|
56
|
-
|
57
|
-
should "raise if accessing Stripe::Card.retrieve directly" do
|
58
|
-
assert_raises NotImplementedError do
|
59
|
-
Stripe::Card.retrieve "card_12345"
|
60
|
-
end
|
39
|
+
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
|
61
40
|
end
|
62
41
|
end
|
63
42
|
end
|
@@ -2,87 +2,115 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class CustomerTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
@mock.expects(:get).once.returns(make_response(make_customer_array))
|
7
|
-
c = Stripe::Customer.list.data
|
8
|
-
assert c.kind_of? Array
|
9
|
-
assert c[0].kind_of? Stripe::Customer
|
10
|
-
end
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:customer)
|
11
6
|
|
12
|
-
should "
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
assert
|
7
|
+
should "be listable" do
|
8
|
+
customers = Stripe::Customer.list
|
9
|
+
assert_requested :get, "#{Stripe.api_base}/v1/customers"
|
10
|
+
assert customers.data.kind_of?(Array)
|
11
|
+
assert customers.first.kind_of?(Stripe::Customer)
|
17
12
|
end
|
18
13
|
|
19
|
-
should "
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal "foo", c.mnemonic
|
24
|
-
c.mnemonic = "bar"
|
25
|
-
c.save
|
26
|
-
assert_equal "bar", c.mnemonic
|
14
|
+
should "be retrievable" do
|
15
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
16
|
+
assert_requested :get, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
17
|
+
assert customer.kind_of?(Stripe::Customer)
|
27
18
|
end
|
28
19
|
|
29
|
-
should "
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
should "be creatable" do
|
21
|
+
customer = Stripe::Customer.create
|
22
|
+
assert_requested :post, "#{Stripe.api_base}/v1/customers"
|
23
|
+
assert customer.kind_of?(Stripe::Customer)
|
33
24
|
end
|
34
25
|
|
35
|
-
should "
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
should "be saveable" do
|
27
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
28
|
+
customer.metadata['key'] = 'value'
|
29
|
+
customer.save
|
30
|
+
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
39
31
|
end
|
40
32
|
|
41
|
-
should "be
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@mock.expects(:post).once.with do |url, api_key, params|
|
46
|
-
url == "#{Stripe.api_base}/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
|
47
|
-
end.returns(make_response(make_subscription(:plan => 'silver')))
|
48
|
-
s = c.update_subscription({:plan => 'silver'})
|
49
|
-
|
50
|
-
assert_equal 'subscription', s.object
|
51
|
-
assert_equal 'silver', s.plan.identifier
|
33
|
+
should "be updateable" do
|
34
|
+
customer = Stripe::Customer.update(FIXTURE[:id], metadata: { key: 'value' })
|
35
|
+
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
36
|
+
assert customer.kind_of?(Stripe::Customer)
|
52
37
|
end
|
53
38
|
|
54
|
-
should "be
|
55
|
-
|
56
|
-
|
39
|
+
should "be deletable" do
|
40
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
41
|
+
customer = customer.delete
|
42
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
43
|
+
assert customer.kind_of?(Stripe::Customer)
|
44
|
+
end
|
57
45
|
|
58
|
-
|
46
|
+
context "#create_subscription" do
|
47
|
+
should "create a new subscription" do
|
48
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
49
|
+
subscription = customer.create_subscription({:plan => 'silver'})
|
50
|
+
assert subscription.kind_of?(Stripe::Subscription)
|
51
|
+
end
|
52
|
+
end
|
59
53
|
|
60
|
-
|
61
|
-
|
54
|
+
context "#create_upcoming_invoice" do
|
55
|
+
should "create a new invoice" do
|
56
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
57
|
+
invoice = customer.create_upcoming_invoice
|
58
|
+
assert invoice.kind_of?(Stripe::Invoice)
|
59
|
+
end
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
62
|
+
context "#update_subscription" do
|
63
|
+
should "update a subscription" do
|
64
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
65
|
+
|
66
|
+
# deprecated API and not in schema
|
67
|
+
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
|
68
|
+
with(body: { plan: "silver" }).
|
69
|
+
to_return(body: JSON.generate(API_FIXTURES[:subscription]))
|
70
|
+
subscription = customer.update_subscription({:plan => 'silver'})
|
71
|
+
assert subscription.kind_of?(Stripe::Subscription)
|
72
|
+
end
|
65
73
|
end
|
66
74
|
|
67
|
-
|
68
|
-
|
75
|
+
context "#cancel_subscription" do
|
76
|
+
should "cancel a subscription" do
|
77
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
78
|
+
|
79
|
+
# deprecated API and not in schema
|
80
|
+
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
|
81
|
+
with(query: { at_period_end: "true" }).
|
82
|
+
to_return(body: JSON.generate(API_FIXTURES[:subscription]))
|
83
|
+
subscription = customer.cancel_subscription({:at_period_end => 'true'})
|
84
|
+
assert subscription.kind_of?(Stripe::Subscription)
|
85
|
+
end
|
86
|
+
end
|
69
87
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
s = c.create_subscription({:plan => 'silver'})
|
88
|
+
context "#delete_discount" do
|
89
|
+
should "delete a discount" do
|
90
|
+
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
74
91
|
|
75
|
-
|
76
|
-
|
92
|
+
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/discount").
|
93
|
+
to_return(body: JSON.generate(API_FIXTURES[:discount]))
|
94
|
+
discount = customer.delete_discount
|
95
|
+
assert discount.kind_of?(Stripe::Customer)
|
96
|
+
end
|
77
97
|
end
|
78
98
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
99
|
+
context "source field" do
|
100
|
+
should "allow setting source with token" do
|
101
|
+
c = Stripe::Customer.new("test_customer")
|
102
|
+
c.source = "tok_123"
|
103
|
+
assert_equal "tok_123", c.source
|
104
|
+
end
|
105
|
+
|
106
|
+
should "allow setting source with hash and set flag" do
|
107
|
+
c = Stripe::Customer.new("test_customer")
|
108
|
+
c.source = {
|
109
|
+
:object => 'card'
|
110
|
+
}
|
111
|
+
assert_equal true, c.source.save_with_parent
|
112
|
+
end
|
86
113
|
end
|
87
114
|
end
|
88
115
|
end
|
116
|
+
|
data/test/stripe/dispute_test.rb
CHANGED
@@ -2,44 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class DisputeTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:dispute)
|
6
|
+
|
7
|
+
should "be listable" do
|
8
|
+
disputes = Stripe::Dispute.list
|
9
|
+
assert_requested :get, "#{Stripe.api_base}/v1/disputes"
|
10
|
+
assert disputes.data.kind_of?(Array)
|
11
|
+
assert disputes.first.kind_of?(Stripe::Dispute)
|
9
12
|
end
|
10
13
|
|
11
|
-
should "
|
12
|
-
|
13
|
-
|
14
|
-
assert
|
15
|
-
d.each do |dispute|
|
16
|
-
assert dispute.kind_of?(Stripe::Dispute)
|
17
|
-
end
|
14
|
+
should "be retrievable" do
|
15
|
+
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
16
|
+
assert_requested :get, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
17
|
+
assert dispute.kind_of?(Stripe::Dispute)
|
18
18
|
end
|
19
19
|
|
20
|
-
should "
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
''
|
26
|
-
).once.returns(make_response({:id => 'dp_test_dispute', :status => 'lost'}))
|
27
|
-
d = Stripe::Dispute.new('test_dispute')
|
28
|
-
d.close
|
20
|
+
should "be saveable" do
|
21
|
+
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
22
|
+
dispute.metadata['key'] = 'value'
|
23
|
+
dispute.save
|
24
|
+
assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
29
25
|
end
|
30
26
|
|
31
|
-
should "
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
'evidence[customer_name]=customer'
|
37
|
-
).once.returns(make_response(make_dispute))
|
27
|
+
should "be updateable" do
|
28
|
+
dispute = Stripe::Dispute.update(FIXTURE[:id], metadata: { key: 'value' })
|
29
|
+
assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
30
|
+
assert dispute.kind_of?(Stripe::Dispute)
|
31
|
+
end
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
context "#close" do
|
34
|
+
should "be closeable" do
|
35
|
+
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
36
|
+
dispute.close
|
37
|
+
assert_requested :post,
|
38
|
+
"#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}/close"
|
39
|
+
end
|
43
40
|
end
|
44
41
|
end
|
45
42
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class StripeErrorTest < Test::Unit::TestCase
|
5
|
+
context "#to_s" do
|
6
|
+
should "convert to string" do
|
7
|
+
e = StripeError.new("message")
|
8
|
+
assert_equal "message", e.to_s
|
9
|
+
|
10
|
+
e = StripeError.new("message", http_status: 200)
|
11
|
+
assert_equal "(Status 200) message", e.to_s
|
12
|
+
|
13
|
+
e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { :request_id => "request-id" })
|
14
|
+
assert_equal "(Request request-id) message", e.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,38 +2,46 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class FileUploadTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# Note that these tests are written different from others because we
|
6
|
+
# don't have anything on the uploads service in our OpenAPI spec. This is
|
7
|
+
# something that should be looked into at some point. We may need to ship
|
8
|
+
# a separate spec for it though, so it's high effort with low reward for
|
9
|
+
# the time being.
|
10
|
+
FIXTURE = {
|
11
|
+
id: "fil_15ABpV2eZvKYlo2C7vu7XS5l",
|
12
|
+
object: "file_upload",
|
13
|
+
}.freeze
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
should "be listable" do
|
16
|
+
stub_request(:get, "#{Stripe.uploads_base}/v1/files").
|
17
|
+
to_return(body: JSON.generate({
|
18
|
+
data: [FIXTURE],
|
19
|
+
object: 'list',
|
20
|
+
resource_url: '/v1/files'
|
21
|
+
}))
|
14
22
|
|
15
|
-
|
16
|
-
|
23
|
+
files = Stripe::FileUpload.list
|
24
|
+
assert files.data.kind_of?(Array)
|
25
|
+
assert files.data[0].kind_of?(Stripe::FileUpload)
|
17
26
|
end
|
18
27
|
|
19
|
-
should "
|
20
|
-
|
21
|
-
|
22
|
-
returns(make_response(make_file))
|
28
|
+
should "be retrievable" do
|
29
|
+
stub_request(:get, "#{Stripe.uploads_base}/v1/files/#{FIXTURE[:id]}").
|
30
|
+
to_return(body: JSON.generate(FIXTURE))
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
assert_equal 1403047735, c.created
|
32
|
+
file = Stripe::FileUpload.retrieve(FIXTURE[:id])
|
33
|
+
assert file.kind_of?(Stripe::FileUpload)
|
27
34
|
end
|
28
35
|
|
29
|
-
should "
|
30
|
-
|
31
|
-
|
32
|
-
returns(make_response(make_file_array))
|
36
|
+
should "be creatable" do
|
37
|
+
stub_request(:post, "#{Stripe.uploads_base}/v1/files").
|
38
|
+
to_return(body: JSON.generate(FIXTURE))
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
file = Stripe::FileUpload.create(
|
41
|
+
purpose: "dispute_evidence",
|
42
|
+
file: File.new(__FILE__),
|
43
|
+
)
|
44
|
+
assert file.kind_of?(Stripe::FileUpload)
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class InvoiceItemTest < Test::Unit::TestCase
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:invoice_item)
|
6
|
+
|
7
|
+
should "be listable" do
|
8
|
+
invoiceitems = Stripe::InvoiceItem.list
|
9
|
+
assert_requested :get, "#{Stripe.api_base}/v1/invoiceitems"
|
10
|
+
assert invoiceitems.data.kind_of?(Array)
|
11
|
+
assert invoiceitems.first.kind_of?(Stripe::InvoiceItem)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be retrievable" do
|
15
|
+
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
16
|
+
assert_requested :get,
|
17
|
+
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
18
|
+
assert item.kind_of?(Stripe::InvoiceItem)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "be creatable" do
|
22
|
+
item = Stripe::InvoiceItem.create(
|
23
|
+
amount: 100,
|
24
|
+
currency: "USD",
|
25
|
+
customer: API_FIXTURES[:customer][:id]
|
26
|
+
)
|
27
|
+
assert_requested :post,
|
28
|
+
"#{Stripe.api_base}/v1/invoiceitems"
|
29
|
+
assert item.kind_of?(Stripe::InvoiceItem)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "be saveable" do
|
33
|
+
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
34
|
+
item.metadata['key'] = 'value'
|
35
|
+
item.save
|
36
|
+
assert_requested :post,
|
37
|
+
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
38
|
+
end
|
39
|
+
|
40
|
+
should "be updateable" do
|
41
|
+
item = Stripe::InvoiceItem.update(FIXTURE[:id], metadata: { key: 'value' })
|
42
|
+
assert_requested :post,
|
43
|
+
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
44
|
+
assert item.kind_of?(Stripe::InvoiceItem)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "be deletable" do
|
48
|
+
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
49
|
+
item = item.delete
|
50
|
+
assert_requested :delete,
|
51
|
+
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
52
|
+
assert item.kind_of?(Stripe::InvoiceItem)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/test/stripe/invoice_test.rb
CHANGED
@@ -2,39 +2,65 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class InvoiceTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:invoice)
|
6
|
+
|
7
|
+
should "be listable" do
|
8
|
+
invoices = Stripe::Invoice.list
|
9
|
+
assert_requested :get, "#{Stripe.api_base}/v1/invoices"
|
10
|
+
assert invoices.data.kind_of?(Array)
|
11
|
+
assert invoices.first.kind_of?(Stripe::Invoice)
|
9
12
|
end
|
10
13
|
|
11
|
-
should "
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
should "be retrievable" do
|
15
|
+
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
16
|
+
assert_requested :get, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
17
|
+
assert invoice.kind_of?(Stripe::Invoice)
|
15
18
|
end
|
16
19
|
|
17
|
-
should "
|
18
|
-
|
19
|
-
|
20
|
+
should "be creatable" do
|
21
|
+
invoice = Stripe::Invoice.create(
|
22
|
+
:customer => API_FIXTURES[:customer][:id]
|
23
|
+
)
|
24
|
+
assert_requested :post, "#{Stripe.api_base}/v1/invoices"
|
25
|
+
assert invoice.kind_of?(Stripe::Invoice)
|
26
|
+
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
should "be saveable" do
|
29
|
+
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
30
|
+
invoice.metadata['key'] = 'value'
|
31
|
+
invoice.save
|
32
|
+
assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
24
33
|
end
|
25
34
|
|
26
|
-
should "
|
27
|
-
|
28
|
-
|
35
|
+
should "be updateable" do
|
36
|
+
invoice = Stripe::Invoice.update(FIXTURE[:id], metadata: { key: 'value' })
|
37
|
+
assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
38
|
+
assert invoice.kind_of?(Stripe::Invoice)
|
39
|
+
end
|
29
40
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
context "#pay" do
|
42
|
+
should "pay invoice" do
|
43
|
+
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
44
|
+
invoice = invoice.pay
|
45
|
+
assert_requested :post,
|
46
|
+
"#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}/pay"
|
47
|
+
assert invoice.kind_of?(Stripe::Invoice)
|
48
|
+
end
|
49
|
+
end
|
35
50
|
|
36
|
-
|
37
|
-
|
51
|
+
context "#upcoming" do
|
52
|
+
should "retrieve upcoming invoices" do
|
53
|
+
invoice = Stripe::Invoice.upcoming(
|
54
|
+
customer: API_FIXTURES[:customer][:id],
|
55
|
+
subscription: API_FIXTURES[:subscription][:id]
|
56
|
+
)
|
57
|
+
assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
|
58
|
+
query: {
|
59
|
+
customer: API_FIXTURES[:customer][:id],
|
60
|
+
subscription: API_FIXTURES[:subscription][:id]
|
61
|
+
}
|
62
|
+
assert invoice.kind_of?(Stripe::Invoice)
|
63
|
+
end
|
38
64
|
end
|
39
65
|
end
|
40
66
|
end
|