stripe 3.0.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +23 -0
- data/Gemfile +1 -2
- data/History.txt +4 -0
- data/README.md +28 -3
- data/Rakefile +0 -12
- data/VERSION +1 -1
- data/lib/stripe.rb +24 -0
- data/lib/stripe/stripe_client.rb +166 -19
- data/lib/stripe/util.rb +127 -8
- data/lib/stripe/version.rb +1 -1
- data/test/api_stub_helpers.rb +0 -125
- data/test/stripe/account_test.rb +11 -13
- data/test/stripe/alipay_account_test.rb +2 -4
- data/test/stripe/api_resource_test.rb +112 -76
- data/test/stripe/apple_pay_domain_test.rb +4 -6
- data/test/stripe/application_fee_refund_test.rb +2 -5
- data/test/stripe/application_fee_test.rb +0 -2
- data/test/stripe/bank_account_test.rb +8 -13
- data/test/stripe/bitcoin_receiver_test.rb +13 -16
- data/test/stripe/bitcoin_transaction_test.rb +2 -4
- data/test/stripe/charge_test.rb +9 -11
- data/test/stripe/country_spec_test.rb +2 -4
- data/test/stripe/coupon_test.rb +6 -8
- data/test/stripe/customer_card_test.rb +13 -9
- data/test/stripe/customer_test.rb +16 -18
- data/test/stripe/dispute_test.rb +8 -10
- data/test/stripe/file_upload_test.rb +3 -3
- data/test/stripe/invoice_item_test.rb +9 -11
- data/test/stripe/invoice_line_item_test.rb +0 -1
- data/test/stripe/invoice_test.rb +39 -21
- data/test/stripe/list_object_test.rb +1 -1
- data/test/stripe/login_link_test.rb +6 -7
- data/test/stripe/order_return_test.rb +2 -4
- data/test/stripe/order_test.rb +10 -12
- data/test/stripe/payout_test.rb +7 -9
- data/test/stripe/plan_test.rb +8 -10
- data/test/stripe/product_test.rb +8 -10
- data/test/stripe/recipient_card_test.rb +13 -9
- data/test/stripe/recipient_test.rb +8 -10
- data/test/stripe/refund_test.rb +7 -9
- data/test/stripe/reversal_test.rb +5 -7
- data/test/stripe/sku_test.rb +9 -11
- data/test/stripe/source_test.rb +16 -15
- data/test/stripe/stripe_client_test.rb +190 -26
- data/test/stripe/subscription_item_test.rb +12 -14
- data/test/stripe/subscription_test.rb +10 -12
- data/test/stripe/three_d_secure_test.rb +3 -5
- data/test/stripe/transfer_test.rb +7 -9
- data/test/stripe/util_test.rb +164 -0
- data/test/test_helper.rb +33 -18
- metadata +2 -8
- data/openapi/fixtures.json +0 -1896
- data/openapi/fixtures.yaml +0 -1505
- data/openapi/spec2.json +0 -24601
- data/openapi/spec2.yaml +0 -18801
- data/test/api_fixtures.rb +0 -29
data/test/stripe/product_test.rb
CHANGED
@@ -2,8 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class ProductTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:product)
|
6
|
-
|
7
5
|
should "be listable" do
|
8
6
|
products = Stripe::Product.list
|
9
7
|
assert_requested :get, "#{Stripe.api_base}/v1/products"
|
@@ -12,8 +10,8 @@ module Stripe
|
|
12
10
|
end
|
13
11
|
|
14
12
|
should "be retrievable" do
|
15
|
-
product = Stripe::Product.retrieve(
|
16
|
-
assert_requested :get, "#{Stripe.api_base}/v1/products
|
13
|
+
product = Stripe::Product.retrieve("prod_123")
|
14
|
+
assert_requested :get, "#{Stripe.api_base}/v1/products/prod_123"
|
17
15
|
assert product.kind_of?(Stripe::Product)
|
18
16
|
end
|
19
17
|
|
@@ -25,22 +23,22 @@ module Stripe
|
|
25
23
|
end
|
26
24
|
|
27
25
|
should "be saveable" do
|
28
|
-
product = Stripe::Product.retrieve(
|
26
|
+
product = Stripe::Product.retrieve("prod_123")
|
29
27
|
product.metadata['key'] = 'value'
|
30
28
|
product.save
|
31
|
-
assert_requested :post, "#{Stripe.api_base}/v1/products/#{
|
29
|
+
assert_requested :post, "#{Stripe.api_base}/v1/products/#{product.id}"
|
32
30
|
end
|
33
31
|
|
34
32
|
should "be updateable" do
|
35
|
-
product = Stripe::Product.update(
|
36
|
-
assert_requested :post, "#{Stripe.api_base}/v1/products
|
33
|
+
product = Stripe::Product.update("prod_123", metadata: {foo: 'bar'})
|
34
|
+
assert_requested :post, "#{Stripe.api_base}/v1/products/prod_123"
|
37
35
|
assert product.kind_of?(Stripe::Product)
|
38
36
|
end
|
39
37
|
|
40
38
|
should "be deletable" do
|
41
|
-
product = Stripe::Product.retrieve(
|
39
|
+
product = Stripe::Product.retrieve("prod_123")
|
42
40
|
product = product.delete
|
43
|
-
assert_requested :delete, "#{Stripe.api_base}/v1/products/#{
|
41
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/products/#{product.id}"
|
44
42
|
assert product.kind_of?(Stripe::Product)
|
45
43
|
end
|
46
44
|
end
|
@@ -2,11 +2,8 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class RecipientCardTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:source)
|
6
|
-
|
7
5
|
setup do
|
8
|
-
@recipient =
|
9
|
-
Stripe::Recipient.retrieve(API_FIXTURES.fetch(:transfer_recipient)[:id])
|
6
|
+
@recipient = Stripe::Recipient.retrieve("rp_123")
|
10
7
|
end
|
11
8
|
|
12
9
|
should "be listable" do
|
@@ -17,24 +14,31 @@ module Stripe
|
|
17
14
|
|
18
15
|
should "be creatable" do
|
19
16
|
card = @recipient.cards.create(
|
20
|
-
card:
|
17
|
+
card: "tok_123"
|
21
18
|
)
|
22
19
|
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards"
|
23
20
|
assert card.kind_of?(Stripe::Card)
|
24
21
|
end
|
25
22
|
|
26
23
|
should "be deletable" do
|
27
|
-
card = Stripe::Card.construct_from(
|
24
|
+
card = Stripe::Card.construct_from({
|
25
|
+
id: "card_123",
|
26
|
+
recipient: @recipient.id
|
27
|
+
})
|
28
28
|
card = card.delete
|
29
|
-
assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards
|
29
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/card_123"
|
30
30
|
assert card.kind_of?(Stripe::Card)
|
31
31
|
end
|
32
32
|
|
33
33
|
should "be saveable" do
|
34
|
-
card = Stripe::Card.construct_from(
|
34
|
+
card = Stripe::Card.construct_from({
|
35
|
+
id: "card_123",
|
36
|
+
metadata: {},
|
37
|
+
recipient: @recipient.id
|
38
|
+
})
|
35
39
|
card.metadata['key'] = 'value'
|
36
40
|
card.save
|
37
|
-
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards
|
41
|
+
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/card_123"
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -2,8 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class RecipientTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:transfer_recipient)
|
6
|
-
|
7
5
|
should "be listable" do
|
8
6
|
recipients = Stripe::Recipient.list
|
9
7
|
assert_requested :get, "#{Stripe.api_base}/v1/recipients"
|
@@ -12,8 +10,8 @@ module Stripe
|
|
12
10
|
end
|
13
11
|
|
14
12
|
should "be retrievable" do
|
15
|
-
recipient = Stripe::Recipient.retrieve(
|
16
|
-
assert_requested :get, "#{Stripe.api_base}/v1/recipients
|
13
|
+
recipient = Stripe::Recipient.retrieve("rp_123")
|
14
|
+
assert_requested :get, "#{Stripe.api_base}/v1/recipients/rp_123"
|
17
15
|
assert recipient.kind_of?(Stripe::Recipient)
|
18
16
|
end
|
19
17
|
|
@@ -27,22 +25,22 @@ module Stripe
|
|
27
25
|
end
|
28
26
|
|
29
27
|
should "be saveable" do
|
30
|
-
recipient = Stripe::Recipient.retrieve(
|
28
|
+
recipient = Stripe::Recipient.retrieve("rp_123")
|
31
29
|
recipient.metadata['key'] = 'value'
|
32
30
|
recipient.save
|
33
|
-
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{
|
31
|
+
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{recipient.id}"
|
34
32
|
end
|
35
33
|
|
36
34
|
should "be updateable" do
|
37
|
-
recipient = Stripe::Recipient.update(
|
38
|
-
assert_requested :post, "#{Stripe.api_base}/v1/recipients
|
35
|
+
recipient = Stripe::Recipient.update("rp_123", metadata: {foo: 'bar'})
|
36
|
+
assert_requested :post, "#{Stripe.api_base}/v1/recipients/rp_123"
|
39
37
|
assert recipient.kind_of?(Stripe::Recipient)
|
40
38
|
end
|
41
39
|
|
42
40
|
should "be deletable" do
|
43
|
-
recipient = Stripe::Recipient.retrieve(
|
41
|
+
recipient = Stripe::Recipient.retrieve("rp_123")
|
44
42
|
recipient = recipient.delete
|
45
|
-
assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{
|
43
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{recipient.id}"
|
46
44
|
assert recipient.kind_of?(Stripe::Recipient)
|
47
45
|
end
|
48
46
|
end
|
data/test/stripe/refund_test.rb
CHANGED
@@ -2,8 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class RefundTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:refund)
|
6
|
-
|
7
5
|
should "be listable" do
|
8
6
|
refunds = Stripe::Refund.list
|
9
7
|
assert_requested :get, "#{Stripe.api_base}/v1/refunds"
|
@@ -12,27 +10,27 @@ module Stripe
|
|
12
10
|
end
|
13
11
|
|
14
12
|
should "be retrievable" do
|
15
|
-
refund = Stripe::Refund.retrieve(
|
16
|
-
assert_requested :get, "#{Stripe.api_base}/v1/refunds
|
13
|
+
refund = Stripe::Refund.retrieve("re_123")
|
14
|
+
assert_requested :get, "#{Stripe.api_base}/v1/refunds/re_123"
|
17
15
|
assert refund.kind_of?(Stripe::Refund)
|
18
16
|
end
|
19
17
|
|
20
18
|
should "be creatable" do
|
21
|
-
refund = Stripe::Refund.create(:charge =>
|
19
|
+
refund = Stripe::Refund.create(:charge => "ch_123")
|
22
20
|
assert_requested :post, "#{Stripe.api_base}/v1/refunds"
|
23
21
|
assert refund.kind_of?(Stripe::Refund)
|
24
22
|
end
|
25
23
|
|
26
24
|
should "be saveable" do
|
27
|
-
refund = Stripe::Refund.retrieve(
|
25
|
+
refund = Stripe::Refund.retrieve("re_123")
|
28
26
|
refund.metadata['key'] = 'value'
|
29
27
|
refund.save
|
30
|
-
assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{
|
28
|
+
assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{refund.id}"
|
31
29
|
end
|
32
30
|
|
33
31
|
should "be updateable" do
|
34
|
-
refund = Stripe::Refund.update(
|
35
|
-
assert_requested :post, "#{Stripe.api_base}/v1/refunds
|
32
|
+
refund = Stripe::Refund.update("re_123", metadata: { key: 'value' })
|
33
|
+
assert_requested :post, "#{Stripe.api_base}/v1/refunds/re_123"
|
36
34
|
assert refund.kind_of?(Stripe::Refund)
|
37
35
|
end
|
38
36
|
end
|
@@ -2,10 +2,8 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class ReversalTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:transfer_reversal)
|
6
|
-
|
7
5
|
setup do
|
8
|
-
@transfer = Stripe::Transfer.retrieve(
|
6
|
+
@transfer = Stripe::Transfer.retrieve("tr_123")
|
9
7
|
end
|
10
8
|
|
11
9
|
should "be listable" do
|
@@ -17,9 +15,9 @@ module Stripe
|
|
17
15
|
end
|
18
16
|
|
19
17
|
should "be retrievable" do
|
20
|
-
reversal = @transfer.reversals.retrieve(
|
18
|
+
reversal = @transfer.reversals.retrieve("trr_123")
|
21
19
|
assert_requested :get,
|
22
|
-
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals
|
20
|
+
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/trr_123"
|
23
21
|
assert reversal.kind_of?(Stripe::Reversal)
|
24
22
|
end
|
25
23
|
|
@@ -33,11 +31,11 @@ module Stripe
|
|
33
31
|
end
|
34
32
|
|
35
33
|
should "be saveable" do
|
36
|
-
reversal = @transfer.reversals.retrieve(
|
34
|
+
reversal = @transfer.reversals.retrieve("trr_123")
|
37
35
|
reversal.metadata['key'] = 'value'
|
38
36
|
reversal.save
|
39
37
|
assert_requested :post,
|
40
|
-
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{
|
38
|
+
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{reversal.id}"
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
data/test/stripe/sku_test.rb
CHANGED
@@ -2,8 +2,6 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class SKUTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:sku)
|
6
|
-
|
7
5
|
should "be listable" do
|
8
6
|
skus = Stripe::SKU.list
|
9
7
|
assert_requested :get, "#{Stripe.api_base}/v1/skus"
|
@@ -12,8 +10,8 @@ module Stripe
|
|
12
10
|
end
|
13
11
|
|
14
12
|
should "be retrievable" do
|
15
|
-
sku = Stripe::SKU.retrieve(
|
16
|
-
assert_requested :get, "#{Stripe.api_base}/v1/skus
|
13
|
+
sku = Stripe::SKU.retrieve("sku_123")
|
14
|
+
assert_requested :get, "#{Stripe.api_base}/v1/skus/sku_123"
|
17
15
|
assert sku.kind_of?(Stripe::SKU)
|
18
16
|
end
|
19
17
|
|
@@ -22,28 +20,28 @@ module Stripe
|
|
22
20
|
currency: "USD",
|
23
21
|
inventory: { type: "finite", quantity: 500 },
|
24
22
|
price: 100,
|
25
|
-
product:
|
23
|
+
product: "prod_123"
|
26
24
|
)
|
27
25
|
assert_requested :post, "#{Stripe.api_base}/v1/skus"
|
28
26
|
end
|
29
27
|
|
30
28
|
should "be saveable" do
|
31
|
-
sku = Stripe::SKU.retrieve(
|
29
|
+
sku = Stripe::SKU.retrieve("sku_123")
|
32
30
|
sku.metadata['key'] = 'value'
|
33
31
|
sku.save
|
34
|
-
assert_requested :post, "#{Stripe.api_base}/v1/skus/#{
|
32
|
+
assert_requested :post, "#{Stripe.api_base}/v1/skus/#{sku.id}"
|
35
33
|
end
|
36
34
|
|
37
35
|
should "be updateable" do
|
38
|
-
sku = Stripe::SKU.update(
|
39
|
-
assert_requested :post, "#{Stripe.api_base}/v1/skus
|
36
|
+
sku = Stripe::SKU.update("sku_123", metadata: {foo: 'bar'})
|
37
|
+
assert_requested :post, "#{Stripe.api_base}/v1/skus/sku_123"
|
40
38
|
assert sku.kind_of?(Stripe::SKU)
|
41
39
|
end
|
42
40
|
|
43
41
|
should "be deletable" do
|
44
|
-
sku = Stripe::SKU.retrieve(
|
42
|
+
sku = Stripe::SKU.retrieve("sku_123")
|
45
43
|
sku = sku.delete
|
46
|
-
assert_requested :delete, "#{Stripe.api_base}/v1/skus/#{
|
44
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/skus/#{sku.id}"
|
47
45
|
assert sku.kind_of?(Stripe::SKU)
|
48
46
|
end
|
49
47
|
end
|
data/test/stripe/source_test.rb
CHANGED
@@ -2,39 +2,37 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class SourceTest < Test::Unit::TestCase
|
5
|
-
FIXTURE = API_FIXTURES.fetch(:source)
|
6
|
-
|
7
5
|
should "be retrievable" do
|
8
|
-
source = Stripe::Source.retrieve(
|
9
|
-
assert_requested :get, "#{Stripe.api_base}/v1/sources
|
6
|
+
source = Stripe::Source.retrieve("src_123")
|
7
|
+
assert_requested :get, "#{Stripe.api_base}/v1/sources/src_123"
|
10
8
|
assert source.kind_of?(Stripe::Source)
|
11
9
|
end
|
12
10
|
|
13
11
|
should "be creatable" do
|
14
12
|
source = Stripe::Source.create(
|
15
13
|
type: 'card',
|
16
|
-
token:
|
14
|
+
token: "tok_123"
|
17
15
|
)
|
18
16
|
assert_requested :post, "#{Stripe.api_base}/v1/sources"
|
19
17
|
assert source.kind_of?(Stripe::Source)
|
20
18
|
end
|
21
19
|
|
22
20
|
should "be saveable" do
|
23
|
-
source = Stripe::Source.retrieve(
|
21
|
+
source = Stripe::Source.retrieve("src_123")
|
24
22
|
source.metadata['key'] = 'value'
|
25
23
|
source.save
|
26
|
-
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{
|
24
|
+
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{source.id}"
|
27
25
|
end
|
28
26
|
|
29
27
|
should "be updateable" do
|
30
|
-
source = Stripe::Source.update(
|
31
|
-
assert_requested :post, "#{Stripe.api_base}/v1/sources
|
28
|
+
source = Stripe::Source.update("src_123", metadata: {foo: 'bar'})
|
29
|
+
assert_requested :post, "#{Stripe.api_base}/v1/sources/src_123"
|
32
30
|
assert source.kind_of?(Stripe::Source)
|
33
31
|
end
|
34
32
|
|
35
33
|
context "#delete" do
|
36
34
|
should "not be deletable when unattached" do
|
37
|
-
source = Stripe::Source.retrieve(
|
35
|
+
source = Stripe::Source.retrieve("src_123")
|
38
36
|
|
39
37
|
assert_raises NotImplementedError do
|
40
38
|
source.delete
|
@@ -42,10 +40,13 @@ module Stripe
|
|
42
40
|
end
|
43
41
|
|
44
42
|
should "be deletable when attached to a customer" do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
source = Stripe::Source.construct_from({
|
44
|
+
customer: "cus_123",
|
45
|
+
id: "src_123",
|
46
|
+
object: "source"
|
47
|
+
})
|
48
|
+
source = source.delete
|
49
|
+
assert_requested :delete, "#{Stripe.api_base}/v1/customers/cus_123/sources/src_123"
|
49
50
|
assert source.kind_of?(Stripe::Source)
|
50
51
|
end
|
51
52
|
end
|
@@ -58,7 +59,7 @@ module Stripe
|
|
58
59
|
|
59
60
|
context "#verify" do
|
60
61
|
should "verify the source" do
|
61
|
-
source = Stripe::Source.retrieve(
|
62
|
+
source = Stripe::Source.retrieve("src_123")
|
62
63
|
source = source.verify(:values => [1,2])
|
63
64
|
assert source.kind_of?(Stripe::Source)
|
64
65
|
end
|
@@ -121,7 +121,7 @@ module Stripe
|
|
121
121
|
should "support literal headers" do
|
122
122
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
123
123
|
with(headers: { "Stripe-Account" => "bar" }).
|
124
|
-
to_return(body: JSON.generate(
|
124
|
+
to_return(body: JSON.generate({ object: "account" }))
|
125
125
|
|
126
126
|
client = StripeClient.new
|
127
127
|
client.execute_request(:post, '/v1/account',
|
@@ -132,7 +132,7 @@ module Stripe
|
|
132
132
|
should "support RestClient-style header keys" do
|
133
133
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
134
134
|
with(headers: { "Stripe-Account" => "bar" }).
|
135
|
-
to_return(body: JSON.generate(
|
135
|
+
to_return(body: JSON.generate({ object: "account" }))
|
136
136
|
|
137
137
|
client = StripeClient.new
|
138
138
|
client.execute_request(:post, '/v1/account',
|
@@ -141,6 +141,158 @@ module Stripe
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
+
context "logging" do
|
145
|
+
setup do
|
146
|
+
# Freeze time for the purposes of the `elapsed` parameter that we
|
147
|
+
# emit for responses. I didn't want to bring in a new dependency for
|
148
|
+
# this, but Mocha's `anything` parameter can't match inside of a hash
|
149
|
+
# and is therefore not useful for this purpose. If we switch over to
|
150
|
+
# rspec-mocks at some point, we can probably remove Timecop from the
|
151
|
+
# project.
|
152
|
+
Timecop.freeze(Time.local(1990))
|
153
|
+
end
|
154
|
+
|
155
|
+
teardown do
|
156
|
+
Timecop.return
|
157
|
+
end
|
158
|
+
|
159
|
+
should "produce appropriate logging" do
|
160
|
+
body = JSON.generate({ object: "account" })
|
161
|
+
|
162
|
+
Util.expects(:log_info).with("Request to Stripe API",
|
163
|
+
api_version: '2010-11-12',
|
164
|
+
idempotency_key: "abc",
|
165
|
+
method: :post,
|
166
|
+
path: "/v1/account"
|
167
|
+
)
|
168
|
+
Util.expects(:log_debug).with("Request details",
|
169
|
+
body: '',
|
170
|
+
idempotency_key: "abc"
|
171
|
+
)
|
172
|
+
|
173
|
+
Util.expects(:log_info).with("Response from Stripe API",
|
174
|
+
api_version: '2010-11-12',
|
175
|
+
elapsed: 0.0,
|
176
|
+
idempotency_key: "abc",
|
177
|
+
method: :post,
|
178
|
+
path: "/v1/account",
|
179
|
+
request_id: "req_123",
|
180
|
+
status: 200
|
181
|
+
)
|
182
|
+
Util.expects(:log_debug).with("Response details",
|
183
|
+
body: body,
|
184
|
+
idempotency_key: "abc",
|
185
|
+
request_id: "req_123"
|
186
|
+
)
|
187
|
+
Util.expects(:log_debug).with("Dashboard link for request",
|
188
|
+
idempotency_key: "abc",
|
189
|
+
request_id: "req_123",
|
190
|
+
url: Util.request_id_dashboard_url("req_123", Stripe.api_key)
|
191
|
+
)
|
192
|
+
|
193
|
+
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
194
|
+
to_return(
|
195
|
+
body: body,
|
196
|
+
headers: {
|
197
|
+
"Idempotency-Key" => "abc",
|
198
|
+
"Request-Id" => "req_123",
|
199
|
+
"Stripe-Version" => "2010-11-12"
|
200
|
+
}
|
201
|
+
)
|
202
|
+
|
203
|
+
client = StripeClient.new
|
204
|
+
client.execute_request(:post, '/v1/account',
|
205
|
+
headers: {
|
206
|
+
"Idempotency-Key" => "abc",
|
207
|
+
"Stripe-Version" => "2010-11-12"
|
208
|
+
}
|
209
|
+
)
|
210
|
+
end
|
211
|
+
|
212
|
+
should "produce logging on API error" do
|
213
|
+
Util.expects(:log_info).with("Request to Stripe API",
|
214
|
+
api_version: nil,
|
215
|
+
idempotency_key: nil,
|
216
|
+
method: :post,
|
217
|
+
path: "/v1/account"
|
218
|
+
)
|
219
|
+
Util.expects(:log_info).with("Response from Stripe API",
|
220
|
+
api_version: nil,
|
221
|
+
elapsed: 0.0,
|
222
|
+
idempotency_key: nil,
|
223
|
+
method: :post,
|
224
|
+
path: "/v1/account",
|
225
|
+
request_id: nil,
|
226
|
+
status: 500
|
227
|
+
)
|
228
|
+
|
229
|
+
error = {
|
230
|
+
code: 'code',
|
231
|
+
message: 'message',
|
232
|
+
param: 'param',
|
233
|
+
type: 'type',
|
234
|
+
}
|
235
|
+
Util.expects(:log_info).with('Stripe API error',
|
236
|
+
status: 500,
|
237
|
+
error_code: error['code'],
|
238
|
+
error_message: error['message'],
|
239
|
+
error_param: error['param'],
|
240
|
+
error_type: error['type'],
|
241
|
+
idempotency_key: nil,
|
242
|
+
request_id: nil
|
243
|
+
)
|
244
|
+
|
245
|
+
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
246
|
+
to_return(
|
247
|
+
body: JSON.generate({ :error => error }),
|
248
|
+
status: 500
|
249
|
+
)
|
250
|
+
|
251
|
+
client = StripeClient.new
|
252
|
+
assert_raises Stripe::APIError do
|
253
|
+
client.execute_request(:post, '/v1/account')
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
should "produce logging on OAuth error" do
|
258
|
+
Util.expects(:log_info).with("Request to Stripe API",
|
259
|
+
api_version: nil,
|
260
|
+
idempotency_key: nil,
|
261
|
+
method: :post,
|
262
|
+
path: "/oauth/token"
|
263
|
+
)
|
264
|
+
Util.expects(:log_info).with("Response from Stripe API",
|
265
|
+
api_version: nil,
|
266
|
+
elapsed: 0.0,
|
267
|
+
idempotency_key: nil,
|
268
|
+
method: :post,
|
269
|
+
path: "/oauth/token",
|
270
|
+
request_id: nil,
|
271
|
+
status: 400
|
272
|
+
)
|
273
|
+
|
274
|
+
Util.expects(:log_info).with('Stripe OAuth error',
|
275
|
+
status: 400,
|
276
|
+
error_code: "invalid_request",
|
277
|
+
error_description: "No grant type specified",
|
278
|
+
idempotency_key: nil,
|
279
|
+
request_id: nil
|
280
|
+
)
|
281
|
+
|
282
|
+
stub_request(:post, "#{Stripe.connect_base}/oauth/token").
|
283
|
+
to_return(body: JSON.generate({
|
284
|
+
error: "invalid_request",
|
285
|
+
error_description: "No grant type specified",
|
286
|
+
}), status: 400)
|
287
|
+
|
288
|
+
client = StripeClient.new
|
289
|
+
opts = {api_base: Stripe.connect_base}
|
290
|
+
assert_raises Stripe::OAuth::InvalidRequestError do
|
291
|
+
client.execute_request(:post, '/oauth/token', opts)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
144
296
|
context "Stripe-Account header" do
|
145
297
|
should "use a globally set header" do
|
146
298
|
begin
|
@@ -149,7 +301,7 @@ module Stripe
|
|
149
301
|
|
150
302
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
151
303
|
with(headers: {"Stripe-Account" => Stripe.stripe_account}).
|
152
|
-
to_return(body: JSON.generate(
|
304
|
+
to_return(body: JSON.generate({ object: "account" }))
|
153
305
|
|
154
306
|
client = StripeClient.new
|
155
307
|
client.execute_request(:post, '/v1/account')
|
@@ -162,7 +314,7 @@ module Stripe
|
|
162
314
|
stripe_account = "acct_0000"
|
163
315
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
164
316
|
with(headers: {"Stripe-Account" => stripe_account}).
|
165
|
-
to_return(body: JSON.generate(
|
317
|
+
to_return(body: JSON.generate({ object: "account" }))
|
166
318
|
|
167
319
|
client = StripeClient.new
|
168
320
|
client.execute_request(:post, '/v1/account',
|
@@ -174,7 +326,7 @@ module Stripe
|
|
174
326
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
175
327
|
with { |req|
|
176
328
|
req.headers["Stripe-Account"].nil?
|
177
|
-
}.to_return(body: JSON.generate(
|
329
|
+
}.to_return(body: JSON.generate({ object: "account" }))
|
178
330
|
|
179
331
|
client = StripeClient.new
|
180
332
|
client.execute_request(:post, '/v1/account')
|
@@ -208,7 +360,7 @@ module Stripe
|
|
208
360
|
}, data[:application])
|
209
361
|
|
210
362
|
true
|
211
|
-
}.to_return(body: JSON.generate(
|
363
|
+
}.to_return(body: JSON.generate({ object: "account" }))
|
212
364
|
|
213
365
|
client = StripeClient.new
|
214
366
|
client.execute_request(:post, '/v1/account')
|
@@ -413,30 +565,30 @@ module Stripe
|
|
413
565
|
|
414
566
|
should 'not add an idempotency key to GET requests' do
|
415
567
|
SecureRandom.expects(:uuid).times(0)
|
416
|
-
stub_request(:get, "#{Stripe.api_base}/v1/charges
|
568
|
+
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123").
|
417
569
|
with { |req|
|
418
570
|
req.headers['Idempotency-Key'].nil?
|
419
|
-
}.to_return(body: JSON.generate(
|
571
|
+
}.to_return(body: JSON.generate({ object: "charge" }))
|
420
572
|
client = StripeClient.new
|
421
|
-
client.execute_request(:get, "/v1/charges
|
573
|
+
client.execute_request(:get, "/v1/charges/ch_123")
|
422
574
|
end
|
423
575
|
|
424
576
|
should 'ensure there is always an idempotency_key on POST requests' do
|
425
577
|
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
426
578
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
427
579
|
with(headers: {"Idempotency-Key" => "random_key"}).
|
428
|
-
to_return(body: JSON.generate(
|
580
|
+
to_return(body: JSON.generate({ object: "charge" }))
|
429
581
|
client = StripeClient.new
|
430
582
|
client.execute_request(:post, "/v1/charges")
|
431
583
|
end
|
432
584
|
|
433
585
|
should 'ensure there is always an idempotency_key on DELETE requests' do
|
434
586
|
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
435
|
-
stub_request(:delete, "#{Stripe.api_base}/v1/charges
|
587
|
+
stub_request(:delete, "#{Stripe.api_base}/v1/charges/ch_123").
|
436
588
|
with(headers: {"Idempotency-Key" => "random_key"}).
|
437
|
-
to_return(body: JSON.generate(
|
589
|
+
to_return(body: JSON.generate({ object: "charge" }))
|
438
590
|
client = StripeClient.new
|
439
|
-
client.execute_request(:delete, "/v1/charges
|
591
|
+
client.execute_request(:delete, "/v1/charges/ch_123")
|
440
592
|
end
|
441
593
|
|
442
594
|
should 'not override a provided idempotency_key' do
|
@@ -448,7 +600,7 @@ module Stripe
|
|
448
600
|
# expected.
|
449
601
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
450
602
|
with(headers: {"Idempotency-Key" => "provided_key"}).
|
451
|
-
to_return(body: JSON.generate(
|
603
|
+
to_return(body: JSON.generate({ object: "charge" }))
|
452
604
|
|
453
605
|
client = StripeClient.new
|
454
606
|
client.execute_request(:post, "/v1/charges",
|
@@ -495,21 +647,33 @@ module Stripe
|
|
495
647
|
context "params serialization" do
|
496
648
|
should 'allows empty strings in params' do
|
497
649
|
client = StripeClient.new
|
498
|
-
client.execute_request(:get, '/v1/invoices/upcoming',
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
650
|
+
client.execute_request(:get, '/v1/invoices/upcoming', params: {
|
651
|
+
customer: 'cus_123',
|
652
|
+
coupon: ''
|
653
|
+
})
|
654
|
+
assert_requested(
|
655
|
+
:get,
|
656
|
+
"#{Stripe.api_base}/v1/invoices/upcoming?",
|
657
|
+
query: {
|
658
|
+
customer: 'cus_123',
|
659
|
+
coupon: ''
|
660
|
+
}
|
661
|
+
)
|
504
662
|
end
|
505
663
|
|
506
664
|
should 'filter nils in params' do
|
507
665
|
client = StripeClient.new
|
508
|
-
client.execute_request(:get, '/v1/invoices/upcoming',
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
666
|
+
client.execute_request(:get, '/v1/invoices/upcoming', params: {
|
667
|
+
customer: 'cus_123',
|
668
|
+
coupon: nil
|
669
|
+
})
|
670
|
+
assert_requested(
|
671
|
+
:get,
|
672
|
+
"#{Stripe.api_base}/v1/invoices/upcoming?",
|
673
|
+
query: {
|
674
|
+
customer: 'cus_123'
|
675
|
+
}
|
676
|
+
)
|
513
677
|
end
|
514
678
|
end
|
515
679
|
end
|
@@ -517,7 +681,7 @@ module Stripe
|
|
517
681
|
context "#request" do
|
518
682
|
should "return a result and response object" do
|
519
683
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
520
|
-
to_return(body: JSON.generate(
|
684
|
+
to_return(body: JSON.generate({ object: "charge" }))
|
521
685
|
|
522
686
|
client = StripeClient.new
|
523
687
|
charge, resp = client.request { Charge.create }
|