stripe 4.22.0 → 4.22.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/VERSION +1 -1
- data/lib/stripe/api_resource.rb +11 -0
- data/lib/stripe/resources/account.rb +6 -2
- data/lib/stripe/resources/credit_note.rb +6 -2
- data/lib/stripe/resources/dispute.rb +6 -2
- data/lib/stripe/resources/invoice.rb +30 -10
- data/lib/stripe/resources/issuing/authorization.rb +12 -4
- data/lib/stripe/resources/issuing/card.rb +6 -2
- data/lib/stripe/resources/order.rb +12 -4
- data/lib/stripe/resources/payment_intent.rb +18 -6
- data/lib/stripe/resources/payment_method.rb +12 -4
- data/lib/stripe/resources/payout.rb +6 -2
- data/lib/stripe/resources/review.rb +6 -2
- data/lib/stripe/resources/setup_intent.rb +12 -4
- data/lib/stripe/resources/source.rb +6 -2
- data/lib/stripe/resources/subscription_schedule.rb +12 -4
- data/lib/stripe/resources/topup.rb +6 -2
- data/lib/stripe/resources/transfer.rb +6 -2
- data/lib/stripe/util.rb +4 -0
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/api_resource_test.rb +77 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 476e36b3d00026b4ecee9ec154dfaed3063cb9faab0ec44d7384e2670715a64c
|
4
|
+
data.tar.gz: 67483a0122ac08406cbd2c0b0ee33b332dafae86100ab5439f15f674662d071e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4632faee7ec59e8eb024bf27c08e98bd97c1b41b5872db0b1d13cb5611770e6ab16154e73ab1989d2a50e6ad7b4e94902395f5af5aa718f99122eef29ac83908
|
7
|
+
data.tar.gz: 0bd55c06591145a77defb666ff50ab292c75366d6cd46b315edbad7fd25a12931bce725c4d0d81c1faf67d3294594482e5c9b6f481ed344458d69cade3ec1697
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 4.22.1 - 2019-08-09
|
4
|
+
* [#808](https://github.com/stripe/stripe-ruby/pull/808) Unify request/response handling
|
5
|
+
|
3
6
|
## 4.22.0 - 2019-07-30
|
4
7
|
* [#821](https://github.com/stripe/stripe-ruby/pull/821) Listing `BalanceTransaction` objects now uses `/v1/balance_transactions` instead of `/v1/balance/history`
|
5
8
|
|
@@ -85,7 +88,7 @@
|
|
85
88
|
* [#718](https://github.com/stripe/stripe-ruby/pull/718) Fix an error message typo
|
86
89
|
|
87
90
|
## 4.4.0 - 2018-12-21
|
88
|
-
* [#716](https://github.com/stripe/stripe-ruby/pull/716) Add support for the `CheckoutSession` resource
|
91
|
+
* [#716](https://github.com/stripe/stripe-ruby/pull/716) Add support for the `CheckoutSession` resource
|
89
92
|
|
90
93
|
## 4.3.0 - 2018-12-10
|
91
94
|
* [#711](https://github.com/stripe/stripe-ruby/pull/711) Add support for account links
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.22.
|
1
|
+
4.22.1
|
data/lib/stripe/api_resource.rb
CHANGED
@@ -103,5 +103,16 @@ module Stripe
|
|
103
103
|
instance.refresh
|
104
104
|
instance
|
105
105
|
end
|
106
|
+
|
107
|
+
protected def request_stripe_object(method:, path:, params:, opts: {})
|
108
|
+
resp, opts = request(method, path, params, opts)
|
109
|
+
|
110
|
+
# If we're getting back this thing, update; otherwise, instantiate.
|
111
|
+
if Util.object_name_matches_class?(resp.data[:object], self.class)
|
112
|
+
initialize_from(resp.data, opts)
|
113
|
+
else
|
114
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
115
|
+
end
|
116
|
+
end
|
106
117
|
end
|
107
118
|
end
|
@@ -20,8 +20,12 @@ module Stripe
|
|
20
20
|
operations: %i[create retrieve update delete list]
|
21
21
|
|
22
22
|
def reject(params = {}, opts = {})
|
23
|
-
|
24
|
-
|
23
|
+
request_stripe_object(
|
24
|
+
method: :post,
|
25
|
+
path: resource_url + "/reject",
|
26
|
+
params: params,
|
27
|
+
opts: opts
|
28
|
+
)
|
25
29
|
end
|
26
30
|
|
27
31
|
save_nested_resource :external_account
|
@@ -11,8 +11,12 @@ module Stripe
|
|
11
11
|
custom_method :void_credit_note, http_verb: :post, http_path: "void"
|
12
12
|
|
13
13
|
def void_credit_note(params = {}, opts = {})
|
14
|
-
|
15
|
-
|
14
|
+
request_stripe_object(
|
15
|
+
method: :post,
|
16
|
+
path: resource_url + "/void",
|
17
|
+
params: params,
|
18
|
+
opts: opts
|
19
|
+
)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -10,8 +10,12 @@ module Stripe
|
|
10
10
|
custom_method :close, http_verb: :post
|
11
11
|
|
12
12
|
def close(params = {}, opts = {})
|
13
|
-
|
14
|
-
|
13
|
+
request_stripe_object(
|
14
|
+
method: :post,
|
15
|
+
path: resource_url + "/close",
|
16
|
+
params: params,
|
17
|
+
opts: opts
|
18
|
+
)
|
15
19
|
end
|
16
20
|
|
17
21
|
def close_url
|
@@ -16,28 +16,48 @@ module Stripe
|
|
16
16
|
custom_method :void_invoice, http_verb: :post, http_path: "void"
|
17
17
|
|
18
18
|
def finalize_invoice(params = {}, opts = {})
|
19
|
-
|
20
|
-
|
19
|
+
request_stripe_object(
|
20
|
+
method: :post,
|
21
|
+
path: resource_url + "/finalize",
|
22
|
+
params: params,
|
23
|
+
opts: opts
|
24
|
+
)
|
21
25
|
end
|
22
26
|
|
23
27
|
def mark_uncollectible(params = {}, opts = {})
|
24
|
-
|
25
|
-
|
28
|
+
request_stripe_object(
|
29
|
+
method: :post,
|
30
|
+
path: resource_url + "/mark_uncollectible",
|
31
|
+
params: params,
|
32
|
+
opts: opts
|
33
|
+
)
|
26
34
|
end
|
27
35
|
|
28
36
|
def pay(params = {}, opts = {})
|
29
|
-
|
30
|
-
|
37
|
+
request_stripe_object(
|
38
|
+
method: :post,
|
39
|
+
path: resource_url + "/pay",
|
40
|
+
params: params,
|
41
|
+
opts: opts
|
42
|
+
)
|
31
43
|
end
|
32
44
|
|
33
45
|
def send_invoice(params = {}, opts = {})
|
34
|
-
|
35
|
-
|
46
|
+
request_stripe_object(
|
47
|
+
method: :post,
|
48
|
+
path: resource_url + "/send",
|
49
|
+
params: params,
|
50
|
+
opts: opts
|
51
|
+
)
|
36
52
|
end
|
37
53
|
|
38
54
|
def void_invoice(params = {}, opts = {})
|
39
|
-
|
40
|
-
|
55
|
+
request_stripe_object(
|
56
|
+
method: :post,
|
57
|
+
path: resource_url + "/void",
|
58
|
+
params: params,
|
59
|
+
opts: opts
|
60
|
+
)
|
41
61
|
end
|
42
62
|
|
43
63
|
def self.upcoming(params, opts = {})
|
@@ -12,13 +12,21 @@ module Stripe
|
|
12
12
|
custom_method :decline, http_verb: :post
|
13
13
|
|
14
14
|
def approve(params = {}, opts = {})
|
15
|
-
|
16
|
-
|
15
|
+
request_stripe_object(
|
16
|
+
method: :post,
|
17
|
+
path: resource_url + "/approve",
|
18
|
+
params: params,
|
19
|
+
opts: opts
|
20
|
+
)
|
17
21
|
end
|
18
22
|
|
19
23
|
def decline(params = {}, opts = {})
|
20
|
-
|
21
|
-
|
24
|
+
request_stripe_object(
|
25
|
+
method: :post,
|
26
|
+
path: resource_url + "/decline",
|
27
|
+
params: params,
|
28
|
+
opts: opts
|
29
|
+
)
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -12,8 +12,12 @@ module Stripe
|
|
12
12
|
custom_method :details, http_verb: :get
|
13
13
|
|
14
14
|
def details(params = {}, opts = {})
|
15
|
-
|
16
|
-
|
15
|
+
request_stripe_object(
|
16
|
+
method: :get,
|
17
|
+
path: resource_url + "/details",
|
18
|
+
params: params,
|
19
|
+
opts: opts
|
20
|
+
)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -12,13 +12,21 @@ module Stripe
|
|
12
12
|
custom_method :return_order, http_verb: :post, http_path: "returns"
|
13
13
|
|
14
14
|
def pay(params = {}, opts = {})
|
15
|
-
|
16
|
-
|
15
|
+
request_stripe_object(
|
16
|
+
method: :post,
|
17
|
+
path: resource_url + "/pay",
|
18
|
+
params: params,
|
19
|
+
opts: opts
|
20
|
+
)
|
17
21
|
end
|
18
22
|
|
19
23
|
def return_order(params = {}, opts = {})
|
20
|
-
|
21
|
-
|
24
|
+
request_stripe_object(
|
25
|
+
method: :post,
|
26
|
+
path: resource_url + "/returns",
|
27
|
+
params: params,
|
28
|
+
opts: opts
|
29
|
+
)
|
22
30
|
end
|
23
31
|
|
24
32
|
private def pay_url
|
@@ -13,18 +13,30 @@ module Stripe
|
|
13
13
|
custom_method :confirm, http_verb: :post
|
14
14
|
|
15
15
|
def cancel(params = {}, opts = {})
|
16
|
-
|
17
|
-
|
16
|
+
request_stripe_object(
|
17
|
+
method: :post,
|
18
|
+
path: resource_url + "/cancel",
|
19
|
+
params: params,
|
20
|
+
opts: opts
|
21
|
+
)
|
18
22
|
end
|
19
23
|
|
20
24
|
def capture(params = {}, opts = {})
|
21
|
-
|
22
|
-
|
25
|
+
request_stripe_object(
|
26
|
+
method: :post,
|
27
|
+
path: resource_url + "/capture",
|
28
|
+
params: params,
|
29
|
+
opts: opts
|
30
|
+
)
|
23
31
|
end
|
24
32
|
|
25
33
|
def confirm(params = {}, opts = {})
|
26
|
-
|
27
|
-
|
34
|
+
request_stripe_object(
|
35
|
+
method: :post,
|
36
|
+
path: resource_url + "/confirm",
|
37
|
+
params: params,
|
38
|
+
opts: opts
|
39
|
+
)
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
@@ -12,13 +12,21 @@ module Stripe
|
|
12
12
|
custom_method :detach, http_verb: :post
|
13
13
|
|
14
14
|
def attach(params = {}, opts = {})
|
15
|
-
|
16
|
-
|
15
|
+
request_stripe_object(
|
16
|
+
method: :post,
|
17
|
+
path: resource_url + "/attach",
|
18
|
+
params: params,
|
19
|
+
opts: opts
|
20
|
+
)
|
17
21
|
end
|
18
22
|
|
19
23
|
def detach(params = {}, opts = {})
|
20
|
-
|
21
|
-
|
24
|
+
request_stripe_object(
|
25
|
+
method: :post,
|
26
|
+
path: resource_url + "/detach",
|
27
|
+
params: params,
|
28
|
+
opts: opts
|
29
|
+
)
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -11,8 +11,12 @@ module Stripe
|
|
11
11
|
custom_method :cancel, http_verb: :post
|
12
12
|
|
13
13
|
def cancel(params = {}, opts = {})
|
14
|
-
|
15
|
-
|
14
|
+
request_stripe_object(
|
15
|
+
method: :post,
|
16
|
+
path: resource_url + "/cancel",
|
17
|
+
params: params,
|
18
|
+
opts: opts
|
19
|
+
)
|
16
20
|
end
|
17
21
|
|
18
22
|
def cancel_url
|
@@ -9,8 +9,12 @@ module Stripe
|
|
9
9
|
custom_method :approve, http_verb: :post
|
10
10
|
|
11
11
|
def approve(params = {}, opts = {})
|
12
|
-
|
13
|
-
|
12
|
+
request_stripe_object(
|
13
|
+
method: :post,
|
14
|
+
path: resource_url + "/approve",
|
15
|
+
params: params,
|
16
|
+
opts: opts
|
17
|
+
)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -12,13 +12,21 @@ module Stripe
|
|
12
12
|
custom_method :confirm, http_verb: :post
|
13
13
|
|
14
14
|
def cancel(params = {}, opts = {})
|
15
|
-
|
16
|
-
|
15
|
+
request_stripe_object(
|
16
|
+
method: :post,
|
17
|
+
path: resource_url + "/cancel",
|
18
|
+
params: params,
|
19
|
+
opts: opts
|
20
|
+
)
|
17
21
|
end
|
18
22
|
|
19
23
|
def confirm(params = {}, opts = {})
|
20
|
-
|
21
|
-
|
24
|
+
request_stripe_object(
|
25
|
+
method: :post,
|
26
|
+
path: resource_url + "/confirm",
|
27
|
+
params: params,
|
28
|
+
opts: opts
|
29
|
+
)
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -10,8 +10,12 @@ module Stripe
|
|
10
10
|
custom_method :verify, http_verb: :post
|
11
11
|
|
12
12
|
def verify(params = {}, opts = {})
|
13
|
-
|
14
|
-
|
13
|
+
request_stripe_object(
|
14
|
+
method: :post,
|
15
|
+
path: resource_url + "/verify",
|
16
|
+
params: params,
|
17
|
+
opts: opts
|
18
|
+
)
|
15
19
|
end
|
16
20
|
|
17
21
|
def detach(params = {}, opts = {})
|
@@ -15,13 +15,21 @@ module Stripe
|
|
15
15
|
nested_resource_class_methods :revision, operations: %i[retrieve list]
|
16
16
|
|
17
17
|
def cancel(params = {}, opts = {})
|
18
|
-
|
19
|
-
|
18
|
+
request_stripe_object(
|
19
|
+
method: :post,
|
20
|
+
path: resource_url + "/cancel",
|
21
|
+
params: params,
|
22
|
+
opts: opts
|
23
|
+
)
|
20
24
|
end
|
21
25
|
|
22
26
|
def release(params = {}, opts = {})
|
23
|
-
|
24
|
-
|
27
|
+
request_stripe_object(
|
28
|
+
method: :post,
|
29
|
+
path: resource_url + "/release",
|
30
|
+
params: params,
|
31
|
+
opts: opts
|
32
|
+
)
|
25
33
|
end
|
26
34
|
|
27
35
|
def revisions(params = {}, opts = {})
|
@@ -11,8 +11,12 @@ module Stripe
|
|
11
11
|
custom_method :cancel, http_verb: :post
|
12
12
|
|
13
13
|
def cancel(params = {}, opts = {})
|
14
|
-
|
15
|
-
|
14
|
+
request_stripe_object(
|
15
|
+
method: :post,
|
16
|
+
path: resource_url + "/cancel",
|
17
|
+
params: params,
|
18
|
+
opts: opts
|
19
|
+
)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -15,8 +15,12 @@ module Stripe
|
|
15
15
|
operations: %i[create retrieve update list]
|
16
16
|
|
17
17
|
def cancel(params = {}, opts = {})
|
18
|
-
|
19
|
-
|
18
|
+
request_stripe_object(
|
19
|
+
method: :post,
|
20
|
+
path: resource_url + "/cancel",
|
21
|
+
params: params,
|
22
|
+
opts: opts
|
23
|
+
)
|
20
24
|
end
|
21
25
|
|
22
26
|
def cancel_url
|
data/lib/stripe/util.rb
CHANGED
@@ -43,6 +43,10 @@ module Stripe
|
|
43
43
|
@object_classes ||= Stripe::ObjectTypes.object_names_to_classes
|
44
44
|
end
|
45
45
|
|
46
|
+
def self.object_name_matches_class?(object_name, klass)
|
47
|
+
Util.object_classes[object_name] == klass
|
48
|
+
end
|
49
|
+
|
46
50
|
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
|
47
51
|
# array of +StripeObject+s. These new objects will be created as a concrete
|
48
52
|
# type as dictated by their `object` field (e.g. an `object` value of
|
data/lib/stripe/version.rb
CHANGED
@@ -511,6 +511,83 @@ module Stripe
|
|
511
511
|
end
|
512
512
|
end
|
513
513
|
|
514
|
+
context "#request_stripe_object" do
|
515
|
+
class HelloTestAPIResource < APIResource
|
516
|
+
OBJECT_NAME = "hello".freeze
|
517
|
+
def say_hello(params = {}, opts = {})
|
518
|
+
request_stripe_object(
|
519
|
+
method: :post,
|
520
|
+
path: resource_url + "/say",
|
521
|
+
params: params,
|
522
|
+
opts: opts
|
523
|
+
)
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
setup do
|
528
|
+
Util.instance_variable_set(
|
529
|
+
:@object_classes,
|
530
|
+
Stripe::ObjectTypes.object_names_to_classes.merge(
|
531
|
+
"hello" => HelloTestAPIResource
|
532
|
+
)
|
533
|
+
)
|
534
|
+
end
|
535
|
+
teardown do
|
536
|
+
Util.class.instance_variable_set(:@object_classes, Stripe::ObjectTypes.object_names_to_classes)
|
537
|
+
end
|
538
|
+
|
539
|
+
should "make requests appropriately" do
|
540
|
+
stub_request(:post, "#{Stripe.api_base}/v1/hellos/hi_123/say")
|
541
|
+
.with(body: { foo: "bar" }, headers: { "Stripe-Account" => "acct_hi" })
|
542
|
+
.to_return(body: JSON.generate("object" => "hello"))
|
543
|
+
|
544
|
+
hello = HelloTestAPIResource.new(id: "hi_123")
|
545
|
+
hello.say_hello({ foo: "bar" }, stripe_account: "acct_hi")
|
546
|
+
end
|
547
|
+
|
548
|
+
should "update attributes in-place when it returns the same thing" do
|
549
|
+
stub_request(:post, "#{Stripe.api_base}/v1/hellos/hi_123/say")
|
550
|
+
.to_return(body: JSON.generate("object" => "hello", "additional" => "attribute"))
|
551
|
+
|
552
|
+
hello = HelloTestAPIResource.new(id: "hi_123")
|
553
|
+
hello.unsaved = "a value"
|
554
|
+
new_hello = hello.say_hello
|
555
|
+
|
556
|
+
# Doesn't matter if you use the return variable or the instance.
|
557
|
+
assert_equal(hello, new_hello)
|
558
|
+
|
559
|
+
# It updates new attributes in-place.
|
560
|
+
assert_equal("attribute", hello.additional)
|
561
|
+
|
562
|
+
# It removes unsaved attributes, but at least lets you know about them.
|
563
|
+
e = assert_raises(NoMethodError) { hello.unsaved }
|
564
|
+
assert_match("The 'unsaved' attribute was set in the past", e.message)
|
565
|
+
end
|
566
|
+
|
567
|
+
should "instantiate a new object of the appropriate class when it is different than the host class" do
|
568
|
+
stub_request(:post, "#{Stripe.api_base}/v1/hellos/hi_123/say")
|
569
|
+
.to_return(body: JSON.generate("object" => "goodbye", "additional" => "attribute"))
|
570
|
+
|
571
|
+
hello = HelloTestAPIResource.new(id: "hi_123")
|
572
|
+
hello.unsaved = "a value"
|
573
|
+
new_goodbye = hello.say_hello
|
574
|
+
|
575
|
+
# The returned value and the instance are different objects.
|
576
|
+
refute_equal(new_goodbye, hello)
|
577
|
+
|
578
|
+
# The returned value has stuff from the server.
|
579
|
+
assert_equal("attribute", new_goodbye.additional)
|
580
|
+
assert_equal("goodbye", new_goodbye.object)
|
581
|
+
|
582
|
+
# You instance doesn't have stuff from the server.
|
583
|
+
e = assert_raises(NoMethodError) { hello.additional }
|
584
|
+
refute_match(/was set in the past/, e.message)
|
585
|
+
|
586
|
+
# The instance preserves unset attributes on the original instance (not sure this is good behavior?)
|
587
|
+
assert_equal("a value", hello.unsaved)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
514
591
|
@@fixtures = {} # rubocop:disable Style/ClassVars
|
515
592
|
setup do
|
516
593
|
if @@fixtures.empty?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.22.
|
4
|
+
version: 4.22.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|