stripe 3.3.2 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +20 -0
- data/.rubocop_todo.yml +62 -0
- data/.travis.yml +1 -1
- data/Gemfile +19 -12
- data/History.txt +10 -0
- data/README.md +5 -1
- data/Rakefile +8 -5
- data/VERSION +1 -1
- data/bin/stripe-console +2 -2
- data/lib/stripe.rb +72 -74
- data/lib/stripe/account.rb +15 -17
- data/lib/stripe/alipay_account.rb +10 -7
- data/lib/stripe/api_operations/create.rb +1 -1
- data/lib/stripe/api_operations/delete.rb +1 -1
- data/lib/stripe/api_operations/list.rb +2 -2
- data/lib/stripe/api_operations/request.rb +5 -12
- data/lib/stripe/api_operations/save.rb +6 -6
- data/lib/stripe/api_resource.rb +7 -9
- data/lib/stripe/apple_pay_domain.rb +2 -2
- data/lib/stripe/application_fee.rb +5 -5
- data/lib/stripe/application_fee_refund.rb +5 -5
- data/lib/stripe/balance.rb +1 -1
- data/lib/stripe/balance_transaction.rb +2 -2
- data/lib/stripe/bank_account.rb +7 -7
- data/lib/stripe/bitcoin_receiver.rb +4 -2
- data/lib/stripe/bitcoin_transaction.rb +3 -1
- data/lib/stripe/card.rb +5 -5
- data/lib/stripe/charge.rb +18 -18
- data/lib/stripe/country_spec.rb +2 -2
- data/lib/stripe/coupon.rb +1 -1
- data/lib/stripe/customer.rb +23 -23
- data/lib/stripe/dispute.rb +3 -3
- data/lib/stripe/ephemeral_key.rb +4 -4
- data/lib/stripe/errors.rb +4 -4
- data/lib/stripe/event.rb +1 -1
- data/lib/stripe/file_upload.rb +5 -5
- data/lib/stripe/invoice.rb +7 -7
- data/lib/stripe/invoice_item.rb +1 -1
- data/lib/stripe/invoice_line_item.rb +1 -1
- data/lib/stripe/list_object.rb +14 -18
- data/lib/stripe/login_link.rb +3 -3
- data/lib/stripe/oauth.rb +15 -13
- data/lib/stripe/order.rb +5 -5
- data/lib/stripe/order_return.rb +1 -1
- data/lib/stripe/payout.rb +3 -3
- data/lib/stripe/plan.rb +1 -1
- data/lib/stripe/product.rb +1 -1
- data/lib/stripe/recipient.rb +3 -2
- data/lib/stripe/recipient_transfer.rb +1 -2
- data/lib/stripe/refund.rb +1 -1
- data/lib/stripe/reversal.rb +5 -5
- data/lib/stripe/singleton_api_resource.rb +3 -3
- data/lib/stripe/sku.rb +1 -1
- data/lib/stripe/source.rb +13 -10
- data/lib/stripe/stripe_client.rb +149 -169
- data/lib/stripe/stripe_object.rb +77 -76
- data/lib/stripe/subscription.rb +5 -5
- data/lib/stripe/subscription_item.rb +2 -2
- data/lib/stripe/three_d_secure.rb +1 -1
- data/lib/stripe/token.rb +1 -1
- data/lib/stripe/transfer.rb +3 -3
- data/lib/stripe/util.rb +77 -62
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe/webhook.rb +14 -10
- data/stripe.gemspec +14 -14
- data/test/stripe/account_test.rb +69 -81
- data/test/stripe/alipay_account_test.rb +19 -1
- data/test/stripe/api_operations_test.rb +7 -7
- data/test/stripe/api_resource_test.rb +224 -260
- data/test/stripe/apple_pay_domain_test.rb +8 -8
- data/test/stripe/application_fee_refund_test.rb +8 -8
- data/test/stripe/application_fee_test.rb +3 -3
- data/test/stripe/balance_test.rb +2 -2
- data/test/stripe/bank_account_test.rb +9 -11
- data/test/stripe/charge_test.rb +11 -11
- data/test/stripe/country_spec_test.rb +4 -4
- data/test/stripe/coupon_test.rb +10 -10
- data/test/stripe/customer_card_test.rb +11 -15
- data/test/stripe/customer_test.rb +26 -27
- data/test/stripe/dispute_test.rb +8 -8
- data/test/stripe/ephemeral_key_test.rb +14 -14
- data/test/stripe/errors_test.rb +2 -2
- data/test/stripe/file_upload_test.rb +26 -28
- data/test/stripe/invoice_item_test.rb +14 -14
- data/test/stripe/invoice_line_item_test.rb +1 -1
- data/test/stripe/invoice_test.rb +37 -37
- data/test/stripe/list_object_test.rb +60 -76
- data/test/stripe/login_link_test.rb +14 -14
- data/test/stripe/oauth_test.rb +42 -50
- data/test/stripe/order_return_test.rb +5 -5
- data/test/stripe/order_test.rb +12 -12
- data/test/stripe/payout_test.rb +9 -9
- data/test/stripe/plan_test.rb +9 -9
- data/test/stripe/product_test.rb +8 -8
- data/test/stripe/recipient_test.rb +9 -10
- data/test/stripe/refund_test.rb +9 -9
- data/test/stripe/reversal_test.rb +10 -10
- data/test/stripe/sku_test.rb +8 -8
- data/test/stripe/source_test.rb +14 -16
- data/test/stripe/stripe_client_test.rb +235 -266
- data/test/stripe/stripe_object_test.rb +163 -147
- data/test/stripe/stripe_response_test.rb +4 -3
- data/test/stripe/subscription_item_test.rb +11 -11
- data/test/stripe/subscription_test.rb +14 -14
- data/test/stripe/three_d_secure_test.rb +2 -2
- data/test/stripe/transfer_test.rb +8 -8
- data/test/stripe/util_test.rb +59 -57
- data/test/stripe/webhook_test.rb +18 -16
- data/test/stripe_test.rb +4 -4
- data/test/test_data.rb +26 -26
- data/test/test_helper.rb +29 -25
- metadata +6 -10
- data/test/stripe/bitcoin_receiver_test.rb +0 -67
- data/test/stripe/bitcoin_transaction_test.rb +0 -19
- data/test/stripe/recipient_card_test.rb +0 -44
data/test/stripe/dispute_test.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class DisputeTest < Test::Unit::TestCase
|
5
5
|
should "be listable" do
|
6
6
|
disputes = Stripe::Dispute.list
|
7
7
|
assert_requested :get, "#{Stripe.api_base}/v1/disputes"
|
8
|
-
assert disputes.data.
|
9
|
-
assert disputes.first.
|
8
|
+
assert disputes.data.is_a?(Array)
|
9
|
+
assert disputes.first.is_a?(Stripe::Dispute)
|
10
10
|
end
|
11
11
|
|
12
12
|
should "be retrievable" do
|
13
13
|
dispute = Stripe::Dispute.retrieve("dp_123")
|
14
14
|
assert_requested :get, "#{Stripe.api_base}/v1/disputes/dp_123"
|
15
|
-
assert dispute.
|
15
|
+
assert dispute.is_a?(Stripe::Dispute)
|
16
16
|
end
|
17
17
|
|
18
18
|
should "be saveable" do
|
19
19
|
dispute = Stripe::Dispute.retrieve("dp_123")
|
20
|
-
dispute.metadata[
|
20
|
+
dispute.metadata["key"] = "value"
|
21
21
|
dispute.save
|
22
22
|
assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{dispute.id}"
|
23
23
|
end
|
24
24
|
|
25
25
|
should "be updateable" do
|
26
|
-
dispute = Stripe::Dispute.update("dp_123", metadata: { key:
|
26
|
+
dispute = Stripe::Dispute.update("dp_123", metadata: { key: "value" })
|
27
27
|
assert_requested :post, "#{Stripe.api_base}/v1/disputes/dp_123"
|
28
|
-
assert dispute.
|
28
|
+
assert dispute.is_a?(Stripe::Dispute)
|
29
29
|
end
|
30
30
|
|
31
31
|
context "#close" do
|
@@ -33,7 +33,7 @@ module Stripe
|
|
33
33
|
dispute = Stripe::Dispute.retrieve("dp_123")
|
34
34
|
dispute.close
|
35
35
|
assert_requested :post,
|
36
|
-
|
36
|
+
"#{Stripe.api_base}/v1/disputes/#{dispute.id}/close"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class EphemeralKeyTest < Test::Unit::TestCase
|
5
5
|
context "#create" do
|
6
6
|
should "succeed" do
|
7
7
|
key = Stripe::EphemeralKey.create(
|
8
|
-
{customer:"cus_123"},
|
9
|
-
|
8
|
+
{ customer: "cus_123" },
|
9
|
+
stripe_version: "2017-05-25"
|
10
10
|
)
|
11
11
|
|
12
12
|
assert_requested(
|
13
13
|
:post,
|
14
14
|
"#{Stripe.api_base}/v1/ephemeral_keys",
|
15
|
-
headers: {
|
15
|
+
headers: { "Stripe-Version" => "2017-05-25" }
|
16
16
|
)
|
17
17
|
|
18
|
-
assert key.
|
18
|
+
assert key.is_a?(Stripe::EphemeralKey)
|
19
19
|
end
|
20
20
|
|
21
21
|
context "#no global version" do
|
22
22
|
should "use the correct api version" do
|
23
23
|
key = Stripe::EphemeralKey.create(
|
24
|
-
{customer: "cus_123"},
|
25
|
-
|
24
|
+
{ customer: "cus_123" },
|
25
|
+
stripe_version: "2017-06-05"
|
26
26
|
)
|
27
27
|
|
28
28
|
assert_requested(
|
29
29
|
:post,
|
30
30
|
"#{Stripe.api_base}/v1/ephemeral_keys",
|
31
|
-
headers: {
|
31
|
+
headers: { "Stripe-Version" => "2017-06-05" }
|
32
32
|
)
|
33
33
|
|
34
|
-
assert key.
|
34
|
+
assert key.is_a?(Stripe::EphemeralKey)
|
35
35
|
end
|
36
36
|
|
37
37
|
should "error without an explicit api version" do
|
@@ -53,11 +53,11 @@ module Stripe
|
|
53
53
|
|
54
54
|
should "use the correct api version" do
|
55
55
|
key = Stripe::EphemeralKey.create(
|
56
|
-
{customer: "cus_123"},
|
57
|
-
|
56
|
+
{ customer: "cus_123" },
|
57
|
+
stripe_version: "2017-05-25"
|
58
58
|
)
|
59
59
|
|
60
|
-
assert key.
|
60
|
+
assert key.is_a?(Stripe::EphemeralKey)
|
61
61
|
end
|
62
62
|
|
63
63
|
should "error without an explicit api version" do
|
@@ -72,8 +72,8 @@ module Stripe
|
|
72
72
|
context "#delete" do
|
73
73
|
should "succeed" do
|
74
74
|
key = Stripe::EphemeralKey.create(
|
75
|
-
{customer:
|
76
|
-
|
75
|
+
{ customer: "cus_123" },
|
76
|
+
stripe_version: "2017-05-25"
|
77
77
|
)
|
78
78
|
|
79
79
|
key.delete
|
data/test/stripe/errors_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class StripeErrorTest < Test::Unit::TestCase
|
@@ -10,7 +10,7 @@ module Stripe
|
|
10
10
|
e = StripeError.new("message", http_status: 200)
|
11
11
|
assert_equal "(Status 200) message", e.to_s
|
12
12
|
|
13
|
-
e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { :
|
13
|
+
e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { request_id: "request-id" })
|
14
14
|
assert_equal "(Request request-id) message", e.to_s
|
15
15
|
end
|
16
16
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class FileUploadTest < Test::Unit::TestCase
|
@@ -13,54 +13,52 @@ module Stripe
|
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
should "be listable" do
|
16
|
-
stub_request(:get, "#{Stripe.uploads_base}/v1/files")
|
17
|
-
to_return(body: JSON.generate(
|
18
|
-
|
19
|
-
|
20
|
-
resource_url: '/v1/files'
|
21
|
-
}))
|
16
|
+
stub_request(:get, "#{Stripe.uploads_base}/v1/files")
|
17
|
+
.to_return(body: JSON.generate(data: [FIXTURE],
|
18
|
+
object: "list",
|
19
|
+
resource_url: "/v1/files"))
|
22
20
|
|
23
21
|
files = Stripe::FileUpload.list
|
24
|
-
assert files.data.
|
25
|
-
assert files.data[0].
|
22
|
+
assert files.data.is_a?(Array)
|
23
|
+
assert files.data[0].is_a?(Stripe::FileUpload)
|
26
24
|
end
|
27
25
|
|
28
26
|
should "be retrievable" do
|
29
|
-
stub_request(:get, "#{Stripe.uploads_base}/v1/files/file_123")
|
30
|
-
to_return(body: JSON.generate(FIXTURE))
|
27
|
+
stub_request(:get, "#{Stripe.uploads_base}/v1/files/file_123")
|
28
|
+
.to_return(body: JSON.generate(FIXTURE))
|
31
29
|
|
32
30
|
file = Stripe::FileUpload.retrieve("file_123")
|
33
|
-
assert file.
|
31
|
+
assert file.is_a?(Stripe::FileUpload)
|
34
32
|
end
|
35
33
|
|
36
34
|
should "be creatable" do
|
37
|
-
stub_request(:post, "#{Stripe.uploads_base}/v1/files")
|
38
|
-
with(:
|
39
|
-
"Content-Type" =>
|
40
|
-
})
|
41
|
-
|
42
|
-
|
35
|
+
stub_request(:post, "#{Stripe.uploads_base}/v1/files")
|
36
|
+
.with(headers: {
|
37
|
+
"Content-Type" => /\A#{Faraday::Request::Multipart.mime_type}/,
|
38
|
+
}) do |request|
|
39
|
+
request.body =~ /FileUploadTest/
|
40
|
+
end.to_return(body: JSON.generate(FIXTURE))
|
43
41
|
|
44
42
|
file = Stripe::FileUpload.create(
|
45
43
|
purpose: "dispute_evidence",
|
46
|
-
file: File.new(__FILE__)
|
44
|
+
file: File.new(__FILE__)
|
47
45
|
)
|
48
|
-
assert file.
|
46
|
+
assert file.is_a?(Stripe::FileUpload)
|
49
47
|
end
|
50
48
|
|
51
49
|
should "be creatable with Faraday::UploadIO" do
|
52
|
-
stub_request(:post, "#{Stripe.uploads_base}/v1/files")
|
53
|
-
with(:
|
54
|
-
"Content-Type" =>
|
55
|
-
})
|
56
|
-
|
57
|
-
|
50
|
+
stub_request(:post, "#{Stripe.uploads_base}/v1/files")
|
51
|
+
.with(headers: {
|
52
|
+
"Content-Type" => /\A#{Faraday::Request::Multipart.mime_type}/,
|
53
|
+
}) do |request|
|
54
|
+
request.body =~ /FileUploadTest/
|
55
|
+
end.to_return(body: JSON.generate(FIXTURE))
|
58
56
|
|
59
57
|
file = Stripe::FileUpload.create(
|
60
58
|
purpose: "dispute_evidence",
|
61
|
-
file: Faraday::UploadIO.new(File.new(__FILE__), nil)
|
59
|
+
file: Faraday::UploadIO.new(File.new(__FILE__), nil)
|
62
60
|
)
|
63
|
-
assert file.
|
61
|
+
assert file.is_a?(Stripe::FileUpload)
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class InvoiceItemTest < Test::Unit::TestCase
|
5
5
|
should "be listable" do
|
6
6
|
invoiceitems = Stripe::InvoiceItem.list
|
7
7
|
assert_requested :get, "#{Stripe.api_base}/v1/invoiceitems"
|
8
|
-
assert invoiceitems.data.
|
9
|
-
assert invoiceitems.first.
|
8
|
+
assert invoiceitems.data.is_a?(Array)
|
9
|
+
assert invoiceitems.first.is_a?(Stripe::InvoiceItem)
|
10
10
|
end
|
11
11
|
|
12
12
|
should "be retrievable" do
|
13
13
|
item = Stripe::InvoiceItem.retrieve("ii_123")
|
14
14
|
assert_requested :get,
|
15
|
-
|
16
|
-
assert item.
|
15
|
+
"#{Stripe.api_base}/v1/invoiceitems/ii_123"
|
16
|
+
assert item.is_a?(Stripe::InvoiceItem)
|
17
17
|
end
|
18
18
|
|
19
19
|
should "be creatable" do
|
@@ -23,31 +23,31 @@ module Stripe
|
|
23
23
|
customer: "cus_123"
|
24
24
|
)
|
25
25
|
assert_requested :post,
|
26
|
-
|
27
|
-
assert item.
|
26
|
+
"#{Stripe.api_base}/v1/invoiceitems"
|
27
|
+
assert item.is_a?(Stripe::InvoiceItem)
|
28
28
|
end
|
29
29
|
|
30
30
|
should "be saveable" do
|
31
31
|
item = Stripe::InvoiceItem.retrieve("ii_123")
|
32
|
-
item.metadata[
|
32
|
+
item.metadata["key"] = "value"
|
33
33
|
item.save
|
34
34
|
assert_requested :post,
|
35
|
-
|
35
|
+
"#{Stripe.api_base}/v1/invoiceitems/#{item.id}"
|
36
36
|
end
|
37
37
|
|
38
38
|
should "be updateable" do
|
39
|
-
item = Stripe::InvoiceItem.update("ii_123", metadata: { key:
|
39
|
+
item = Stripe::InvoiceItem.update("ii_123", metadata: { key: "value" })
|
40
40
|
assert_requested :post,
|
41
|
-
|
42
|
-
assert item.
|
41
|
+
"#{Stripe.api_base}/v1/invoiceitems/ii_123"
|
42
|
+
assert item.is_a?(Stripe::InvoiceItem)
|
43
43
|
end
|
44
44
|
|
45
45
|
should "be deletable" do
|
46
46
|
item = Stripe::InvoiceItem.retrieve("ii_123")
|
47
47
|
item = item.delete
|
48
48
|
assert_requested :delete,
|
49
|
-
|
50
|
-
assert item.
|
49
|
+
"#{Stripe.api_base}/v1/invoiceitems/#{item.id}"
|
50
|
+
assert item.is_a?(Stripe::InvoiceItem)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/test/stripe/invoice_test.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class InvoiceTest < Test::Unit::TestCase
|
5
5
|
should "be listable" do
|
6
6
|
invoices = Stripe::Invoice.list
|
7
7
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices"
|
8
|
-
assert invoices.data.
|
9
|
-
assert invoices.first.
|
8
|
+
assert invoices.data.is_a?(Array)
|
9
|
+
assert invoices.first.is_a?(Stripe::Invoice)
|
10
10
|
end
|
11
11
|
|
12
12
|
should "be retrievable" do
|
13
13
|
invoice = Stripe::Invoice.retrieve("in_123")
|
14
14
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices/in_123"
|
15
|
-
assert invoice.
|
15
|
+
assert invoice.is_a?(Stripe::Invoice)
|
16
16
|
end
|
17
17
|
|
18
18
|
should "be creatable" do
|
19
19
|
invoice = Stripe::Invoice.create(
|
20
|
-
:
|
20
|
+
customer: "cus_123"
|
21
21
|
)
|
22
22
|
assert_requested :post, "#{Stripe.api_base}/v1/invoices"
|
23
|
-
assert invoice.
|
23
|
+
assert invoice.is_a?(Stripe::Invoice)
|
24
24
|
end
|
25
25
|
|
26
26
|
should "be saveable" do
|
27
27
|
invoice = Stripe::Invoice.retrieve("in_123")
|
28
|
-
invoice.metadata[
|
28
|
+
invoice.metadata["key"] = "value"
|
29
29
|
invoice.save
|
30
30
|
assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{invoice.id}"
|
31
31
|
end
|
32
32
|
|
33
33
|
should "be updateable" do
|
34
|
-
invoice = Stripe::Invoice.update("in_123", metadata: { key:
|
34
|
+
invoice = Stripe::Invoice.update("in_123", metadata: { key: "value" })
|
35
35
|
assert_requested :post, "#{Stripe.api_base}/v1/invoices/in_123"
|
36
|
-
assert invoice.
|
36
|
+
assert invoice.is_a?(Stripe::Invoice)
|
37
37
|
end
|
38
38
|
|
39
39
|
context "#pay" do
|
@@ -41,21 +41,21 @@ module Stripe
|
|
41
41
|
invoice = Stripe::Invoice.retrieve("in_123")
|
42
42
|
invoice = invoice.pay
|
43
43
|
assert_requested :post,
|
44
|
-
|
45
|
-
assert invoice.
|
44
|
+
"#{Stripe.api_base}/v1/invoices/#{invoice.id}/pay"
|
45
|
+
assert invoice.is_a?(Stripe::Invoice)
|
46
46
|
end
|
47
47
|
|
48
48
|
should "pay invoice with a specific source" do
|
49
49
|
invoice = Stripe::Invoice.retrieve("in_123")
|
50
50
|
invoice = invoice.pay(
|
51
|
-
source:
|
51
|
+
source: "src_123"
|
52
52
|
)
|
53
53
|
assert_requested :post,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
assert invoice.
|
54
|
+
"#{Stripe.api_base}/v1/invoices/#{invoice.id}/pay",
|
55
|
+
body: {
|
56
|
+
source: "src_123",
|
57
|
+
}
|
58
|
+
assert invoice.is_a?(Stripe::Invoice)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -66,18 +66,18 @@ module Stripe
|
|
66
66
|
subscription: "sub_123"
|
67
67
|
)
|
68
68
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
assert invoice.
|
69
|
+
query: {
|
70
|
+
customer: "cus_123",
|
71
|
+
subscription: "sub_123",
|
72
|
+
}
|
73
|
+
assert invoice.is_a?(Stripe::Invoice)
|
74
74
|
end
|
75
75
|
|
76
76
|
should "retrieve upcoming invoices with items" do
|
77
77
|
items = [{
|
78
|
-
plan:
|
79
|
-
quantity: 2
|
80
|
-
}]
|
78
|
+
plan: "gold",
|
79
|
+
quantity: 2,
|
80
|
+
},]
|
81
81
|
|
82
82
|
invoice = Stripe::Invoice.upcoming(
|
83
83
|
customer: "cus_123",
|
@@ -85,25 +85,25 @@ module Stripe
|
|
85
85
|
)
|
86
86
|
|
87
87
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
assert invoice.
|
88
|
+
query: {
|
89
|
+
customer: "cus_123",
|
90
|
+
:'subscription_items[][plan]' => "gold",
|
91
|
+
:'subscription_items[][quantity]' => 2,
|
92
|
+
}
|
93
|
+
assert invoice.is_a?(Stripe::Invoice)
|
94
94
|
end
|
95
95
|
|
96
96
|
should "be callable with an empty string" do
|
97
97
|
invoice = Stripe::Invoice.upcoming(
|
98
|
-
coupon:
|
98
|
+
coupon: "",
|
99
99
|
customer: "cus_123"
|
100
100
|
)
|
101
101
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
assert invoice.
|
102
|
+
query: {
|
103
|
+
coupon: "",
|
104
|
+
customer: "cus_123",
|
105
|
+
}
|
106
|
+
assert invoice.is_a?(Stripe::Invoice)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class ListObjectTest < Test::Unit::TestCase
|
@@ -8,59 +8,53 @@ module Stripe
|
|
8
8
|
end
|
9
9
|
|
10
10
|
should "provide #count via enumerable" do
|
11
|
-
list = Stripe::ListObject.construct_from({
|
12
|
-
data: [{ object: "charge" }]
|
13
|
-
})
|
11
|
+
list = Stripe::ListObject.construct_from(data: [{ object: "charge" }])
|
14
12
|
assert_equal 1, list.count
|
15
13
|
end
|
16
14
|
|
17
15
|
should "provide #each" do
|
18
16
|
arr = [
|
19
|
-
{ :
|
20
|
-
{ :
|
21
|
-
{ :
|
17
|
+
{ id: 1 },
|
18
|
+
{ id: 2 },
|
19
|
+
{ id: 3 },
|
22
20
|
]
|
23
21
|
expected = Util.convert_to_stripe_object(arr, {})
|
24
|
-
list = Stripe::ListObject.construct_from(
|
22
|
+
list = Stripe::ListObject.construct_from(data: arr)
|
25
23
|
assert_equal expected, list.each.to_a
|
26
24
|
end
|
27
25
|
|
28
26
|
should "provide #auto_paging_each" do
|
29
27
|
arr = [
|
30
|
-
{ :
|
31
|
-
{ :
|
32
|
-
{ :
|
28
|
+
{ id: 1 },
|
29
|
+
{ id: 2 },
|
30
|
+
{ id: 3 },
|
33
31
|
]
|
34
32
|
expected = Util.convert_to_stripe_object(arr, {})
|
35
33
|
|
36
|
-
list = TestListObject.construct_from({
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
with(query: { starting_after: "1" }).
|
43
|
-
to_return(body: JSON.generate({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
34
|
+
list = TestListObject.construct_from(data: [{ id: 1 }],
|
35
|
+
has_more: true,
|
36
|
+
url: "/things")
|
37
|
+
stub_request(:get, "#{Stripe.api_base}/things")
|
38
|
+
.with(query: { starting_after: "1" })
|
39
|
+
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
|
44
40
|
|
45
41
|
assert_equal expected, list.auto_paging_each.to_a
|
46
42
|
end
|
47
43
|
|
48
44
|
should "provide #auto_paging_each that responds to a block" do
|
49
45
|
arr = [
|
50
|
-
{ :
|
51
|
-
{ :
|
52
|
-
{ :
|
46
|
+
{ id: 1 },
|
47
|
+
{ id: 2 },
|
48
|
+
{ id: 3 },
|
53
49
|
]
|
54
50
|
expected = Util.convert_to_stripe_object(arr, {})
|
55
51
|
|
56
|
-
list = TestListObject.construct_from({
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
with(query: { starting_after: "1" }).
|
63
|
-
to_return(body: JSON.generate({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
52
|
+
list = TestListObject.construct_from(data: [{ id: 1 }],
|
53
|
+
has_more: true,
|
54
|
+
url: "/things")
|
55
|
+
stub_request(:get, "#{Stripe.api_base}/things")
|
56
|
+
.with(query: { starting_after: "1" })
|
57
|
+
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
|
64
58
|
|
65
59
|
actual = []
|
66
60
|
list.auto_paging_each do |obj|
|
@@ -71,9 +65,9 @@ module Stripe
|
|
71
65
|
end
|
72
66
|
|
73
67
|
should "provide #empty?" do
|
74
|
-
list = Stripe::ListObject.construct_from(
|
68
|
+
list = Stripe::ListObject.construct_from(data: [])
|
75
69
|
assert list.empty?
|
76
|
-
list = Stripe::ListObject.construct_from(
|
70
|
+
list = Stripe::ListObject.construct_from(data: [{}])
|
77
71
|
refute list.empty?
|
78
72
|
end
|
79
73
|
|
@@ -82,38 +76,32 @@ module Stripe
|
|
82
76
|
#
|
83
77
|
|
84
78
|
should "fetch a next page through #next_page" do
|
85
|
-
list = TestListObject.construct_from({
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
with(query: { starting_after: "1" }).
|
92
|
-
to_return(body: JSON.generate({ :data => [{ :id => 2 }], :has_more => false }))
|
79
|
+
list = TestListObject.construct_from(data: [{ id: 1 }],
|
80
|
+
has_more: true,
|
81
|
+
url: "/things")
|
82
|
+
stub_request(:get, "#{Stripe.api_base}/things")
|
83
|
+
.with(query: { starting_after: "1" })
|
84
|
+
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
|
93
85
|
next_list = list.next_page
|
94
86
|
refute next_list.empty?
|
95
87
|
end
|
96
88
|
|
97
89
|
should "fetch a next page through #next_page and respect limit" do
|
98
|
-
list = TestListObject.construct_from({
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
})
|
103
|
-
|
104
|
-
|
105
|
-
with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" }).
|
106
|
-
to_return(body: JSON.generate({ :data => [{ :id => 2 }], :has_more => false }))
|
90
|
+
list = TestListObject.construct_from(data: [{ id: 1 }],
|
91
|
+
has_more: true,
|
92
|
+
url: "/things")
|
93
|
+
list.filters = { expand: ["data.source"], limit: 3 }
|
94
|
+
stub_request(:get, "#{Stripe.api_base}/things")
|
95
|
+
.with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" })
|
96
|
+
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
|
107
97
|
next_list = list.next_page
|
108
|
-
assert_equal({ :
|
98
|
+
assert_equal({ expand: ["data.source"], limit: 3 }, next_list.filters)
|
109
99
|
end
|
110
100
|
|
111
101
|
should "fetch an empty page through #next_page" do
|
112
|
-
list = TestListObject.construct_from({
|
113
|
-
|
114
|
-
|
115
|
-
:url => "/things",
|
116
|
-
})
|
102
|
+
list = TestListObject.construct_from(data: [{ id: 1 }],
|
103
|
+
has_more: false,
|
104
|
+
url: "/things")
|
117
105
|
next_list = list.next_page
|
118
106
|
assert_equal Stripe::ListObject.empty_list, next_list
|
119
107
|
end
|
@@ -123,28 +111,24 @@ module Stripe
|
|
123
111
|
#
|
124
112
|
|
125
113
|
should "fetch a next page through #previous_page" do
|
126
|
-
list = TestListObject.construct_from({
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
with(query: { ending_before: "2" }).
|
132
|
-
to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
|
114
|
+
list = TestListObject.construct_from(data: [{ id: 2 }],
|
115
|
+
url: "/things")
|
116
|
+
stub_request(:get, "#{Stripe.api_base}/things")
|
117
|
+
.with(query: { ending_before: "2" })
|
118
|
+
.to_return(body: JSON.generate(data: [{ id: 1 }]))
|
133
119
|
next_list = list.previous_page
|
134
120
|
refute next_list.empty?
|
135
121
|
end
|
136
122
|
|
137
123
|
should "fetch a next page through #previous_page and respect limit" do
|
138
|
-
list = TestListObject.construct_from({
|
139
|
-
|
140
|
-
|
141
|
-
})
|
142
|
-
|
143
|
-
|
144
|
-
with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" }).
|
145
|
-
to_return(body: JSON.generate({ :data => [{ :id => 1 }] }))
|
124
|
+
list = TestListObject.construct_from(data: [{ id: 2 }],
|
125
|
+
url: "/things")
|
126
|
+
list.filters = { expand: ["data.source"], limit: 3 }
|
127
|
+
stub_request(:get, "#{Stripe.api_base}/things")
|
128
|
+
.with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" })
|
129
|
+
.to_return(body: JSON.generate(data: [{ id: 1 }]))
|
146
130
|
next_list = list.previous_page
|
147
|
-
assert_equal({ :
|
131
|
+
assert_equal({ expand: ["data.source"], limit: 3 }, next_list.filters)
|
148
132
|
end
|
149
133
|
|
150
134
|
#
|
@@ -155,12 +139,12 @@ module Stripe
|
|
155
139
|
# in a list
|
156
140
|
should "be able to retrieve full lists given a listobject" do
|
157
141
|
c = Stripe::Charge.all
|
158
|
-
assert c.
|
159
|
-
assert_equal(
|
142
|
+
assert c.is_a?(Stripe::ListObject)
|
143
|
+
assert_equal("/v1/charges", c.resource_url)
|
160
144
|
all = c.all
|
161
|
-
assert all.
|
162
|
-
assert_equal(
|
163
|
-
assert all.data.
|
145
|
+
assert all.is_a?(Stripe::ListObject)
|
146
|
+
assert_equal("/v1/charges", all.resource_url)
|
147
|
+
assert all.data.is_a?(Array)
|
164
148
|
end
|
165
149
|
end
|
166
150
|
end
|