stripe 5.45.0 → 5.48.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2971f0ad2ef29349e932246a9bc9065d5d1ce53f21c14f7bcdb205b443779a42
4
- data.tar.gz: a9a980c5cbdc14d79d60f5873f267db10153bd556c81378ec3c3ca270d87252d
3
+ metadata.gz: 9a6917084338966ae208572554d5520cda85b854b6a6d73aac0b37fe6aff6271
4
+ data.tar.gz: 9ce0d94220e31287bcd84da00199d1d3cb3a6be125cf2548ddcac87c64bbc2fb
5
5
  SHA512:
6
- metadata.gz: 47c89bc9c732bafeae007d6663ca82cbf5e32938d392bb130209d389f7fa59fa54ecb26b0f7b93658b8cd18eab82127c2bfedd6b8c6e3887bb92c99bcc41f11b
7
- data.tar.gz: a73469bc20fbf0fae44c6409efbe53ce8d90c54dca56fe2f99dfc8a8fd045e9ac295b9df86f13be555648ead094746cb385cb2731cdbb40edbae858f2083f292
6
+ metadata.gz: 4f0925e465d0e32fc68e167cfa61959d307e3a9f12f245620c55ca3c59c8851a2a057b1b0845cd39b27d496391f44b9592cd7548494716e4420badfa6a3b351f
7
+ data.tar.gz: 52512c8409a883c68ef90a7d92732424487d3b2be029cc3bafa043911fa887b25a79d3b2fb243dbe7fe191beec95974696ffcb528eb0c6104d93019a0ceb92c2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.48.0 - 2022-03-30
4
+ * [#1041](https://github.com/stripe/stripe-ruby/pull/1041) API Updates
5
+ * Add support for `cancel_action`, `process_payment_intent`, `process_setup_intent`, and `set_reader_display` methods on resource `Terminal.Reader`
6
+
7
+ ## 5.47.0 - 2022-03-29
8
+ * [#1040](https://github.com/stripe/stripe-ruby/pull/1040) API Updates
9
+ * Add support for Search API
10
+ * Add support for `search` method on resources `Charge`, `Customer`, `Invoice`, `PaymentIntent`, `Price`, `Product`, and `Subscription`
11
+
12
+ * [#1034](https://github.com/stripe/stripe-ruby/pull/1034) Add supporting classes for test helper generation
13
+
14
+ ## 5.46.0 - 2022-03-23
15
+ * [#1039](https://github.com/stripe/stripe-ruby/pull/1039) API Updates
16
+ * Add support for `cancel` method on resource `Refund`
17
+ * [#992](https://github.com/stripe/stripe-ruby/pull/992) Add support for Search API
18
+
3
19
  ## 5.45.0 - 2022-03-01
4
20
  * [#1035](https://github.com/stripe/stripe-ruby/pull/1035) API Updates
5
21
  * Add support for new resource `TestHelpers.TestClock`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.45.0
1
+ 5.48.0
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ module APIOperations
5
+ module Search
6
+ def _search(search_url, filters = {}, opts = {})
7
+ opts = Util.normalize_opts(opts)
8
+
9
+ resp, opts = execute_resource_request(:get, search_url, filters, opts)
10
+ obj = SearchResultObject.construct_from(resp.data, opts)
11
+
12
+ # set filters so that we can fetch the same limit and query
13
+ # when accessing the next page
14
+ obj.filters = filters.dup
15
+ obj
16
+ end
17
+ end
18
+ end
19
+ end
@@ -63,22 +63,7 @@ module Stripe
63
63
  # adds a `capture` class method to the resource class that, when called,
64
64
  # will send a POST request to `/v1/<object_name>/capture`.
65
65
  def self.custom_method(name, http_verb:, http_path: nil)
66
- unless %i[get post delete].include?(http_verb)
67
- raise ArgumentError,
68
- "Invalid http_verb value: #{http_verb.inspect}. Should be one " \
69
- "of :get, :post or :delete."
70
- end
71
- http_path ||= name.to_s
72
- define_singleton_method(name) do |id, params = {}, opts = {}|
73
- unless id.is_a?(String)
74
- raise ArgumentError,
75
- "id should be a string representing the ID of an API resource"
76
- end
77
-
78
- url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(http_path)}"
79
- resp, opts = execute_resource_request(http_verb, url, params, opts)
80
- Util.convert_to_stripe_object(resp.data, opts)
81
- end
66
+ Util.custom_method self, self, name, http_verb, http_path
82
67
  end
83
68
 
84
69
  def resource_url
@@ -105,7 +90,7 @@ module Stripe
105
90
  instance
106
91
  end
107
92
 
108
- protected def request_stripe_object(method:, path:, params:, opts: {})
93
+ def request_stripe_object(method:, path:, params:, opts: {})
109
94
  resp, opts = execute_resource_request(method, path, params, opts)
110
95
 
111
96
  # If we're getting back this thing, update; otherwise, instantiate.
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ # The base class for nested TestHelpers classes in resource objects.
5
+ # The APIResourceTestHelpers handles URL generation and custom method
6
+ # support for test-helper methods.
7
+ #
8
+ # class MyAPIResource < APIResource
9
+ # class TestHelpers < APIResourceTestHelpers
10
+ class APIResourceTestHelpers
11
+ def initialize(resource)
12
+ @resource = resource
13
+ end
14
+
15
+ # Adds a custom method to a test helper. This is used to add support for
16
+ # non-CRUDL API requests, e.g. capturing charges. custom_method takes the
17
+ # following parameters:
18
+ # - name: the name of the custom method to create (as a symbol)
19
+ # - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
20
+ # - http_path: the path to append to the resource's URL. If not provided,
21
+ # the name is used as the path
22
+ #
23
+ # For example, this call:
24
+ # custom_method :capture, http_verb: post
25
+ # adds a `capture` class method to the resource class that, when called,
26
+ # will send a POST request to `/v1/<object_name>/capture`.
27
+ def self.custom_method(name, http_verb:, http_path: nil)
28
+ Util.custom_method self::RESOURCE_CLASS, self, name, http_verb, http_path
29
+ end
30
+
31
+ def self.resource_url
32
+ "/v1/test_helpers/"\
33
+ "#{self::RESOURCE_CLASS::OBJECT_NAME.downcase.tr('.', '/')}s"
34
+ end
35
+
36
+ def resource_url
37
+ unless (id = @resource["id"])
38
+ raise InvalidRequestError.new(
39
+ "Could not determine which URL to request: #{self.class} instance " \
40
+ "has invalid ID: #{id.inspect}",
41
+ "id"
42
+ )
43
+ end
44
+ "#{self.class.resource_url}/#{CGI.escape(id)}"
45
+ end
46
+ end
47
+ end
@@ -9,6 +9,7 @@ module Stripe
9
9
  {
10
10
  # data structures
11
11
  ListObject::OBJECT_NAME => ListObject,
12
+ SearchResultObject::OBJECT_NAME => SearchResultObject,
12
13
 
13
14
  # business objects
14
15
  Account::OBJECT_NAME => Account,
@@ -5,6 +5,7 @@ module Stripe
5
5
  class Charge < APIResource
6
6
  extend Stripe::APIOperations::Create
7
7
  extend Stripe::APIOperations::List
8
+ extend Stripe::APIOperations::Search
8
9
  include Stripe::APIOperations::Save
9
10
 
10
11
  OBJECT_NAME = "charge"
@@ -19,5 +20,13 @@ module Stripe
19
20
  opts: opts
20
21
  )
21
22
  end
23
+
24
+ def self.search(params = {}, opts = {})
25
+ _search("/v1/charges/search", params, opts)
26
+ end
27
+
28
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
29
+ search(params, opts).auto_paging_each(&blk)
30
+ end
22
31
  end
23
32
  end
@@ -6,6 +6,7 @@ module Stripe
6
6
  extend Stripe::APIOperations::Create
7
7
  include Stripe::APIOperations::Delete
8
8
  extend Stripe::APIOperations::List
9
+ extend Stripe::APIOperations::Search
9
10
  include Stripe::APIOperations::Save
10
11
  extend Stripe::APIOperations::NestedResource
11
12
 
@@ -48,5 +49,13 @@ module Stripe
48
49
  resp, opts = execute_resource_request(:delete, resource_url + "/discount")
49
50
  Util.convert_to_stripe_object(resp.data, opts)
50
51
  end
52
+
53
+ def self.search(params = {}, opts = {})
54
+ _search("/v1/customers/search", params, opts)
55
+ end
56
+
57
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
58
+ search(params, opts).auto_paging_each(&blk)
59
+ end
51
60
  end
52
61
  end
@@ -6,6 +6,7 @@ module Stripe
6
6
  extend Stripe::APIOperations::Create
7
7
  include Stripe::APIOperations::Delete
8
8
  extend Stripe::APIOperations::List
9
+ extend Stripe::APIOperations::Search
9
10
  include Stripe::APIOperations::Save
10
11
 
11
12
  OBJECT_NAME = "invoice"
@@ -70,5 +71,13 @@ module Stripe
70
71
  resp, opts = execute_resource_request(:get, resource_url + "/upcoming/lines", params, opts)
71
72
  Util.convert_to_stripe_object(resp.data, opts)
72
73
  end
74
+
75
+ def self.search(params = {}, opts = {})
76
+ _search("/v1/invoices/search", params, opts)
77
+ end
78
+
79
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
80
+ search(params, opts).auto_paging_each(&blk)
81
+ end
73
82
  end
74
83
  end
@@ -5,6 +5,7 @@ module Stripe
5
5
  class PaymentIntent < APIResource
6
6
  extend Stripe::APIOperations::Create
7
7
  extend Stripe::APIOperations::List
8
+ extend Stripe::APIOperations::Search
8
9
  include Stripe::APIOperations::Save
9
10
 
10
11
  OBJECT_NAME = "payment_intent"
@@ -49,5 +50,13 @@ module Stripe
49
50
  opts: opts
50
51
  )
51
52
  end
53
+
54
+ def self.search(params = {}, opts = {})
55
+ _search("/v1/payment_intents/search", params, opts)
56
+ end
57
+
58
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
59
+ search(params, opts).auto_paging_each(&blk)
60
+ end
52
61
  end
53
62
  end
@@ -5,8 +5,17 @@ module Stripe
5
5
  class Price < APIResource
6
6
  extend Stripe::APIOperations::Create
7
7
  extend Stripe::APIOperations::List
8
+ extend Stripe::APIOperations::Search
8
9
  include Stripe::APIOperations::Save
9
10
 
10
11
  OBJECT_NAME = "price"
12
+
13
+ def self.search(params = {}, opts = {})
14
+ _search("/v1/prices/search", params, opts)
15
+ end
16
+
17
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
18
+ search(params, opts).auto_paging_each(&blk)
19
+ end
11
20
  end
12
21
  end
@@ -6,8 +6,17 @@ module Stripe
6
6
  extend Stripe::APIOperations::Create
7
7
  include Stripe::APIOperations::Delete
8
8
  extend Stripe::APIOperations::List
9
+ extend Stripe::APIOperations::Search
9
10
  include Stripe::APIOperations::Save
10
11
 
11
12
  OBJECT_NAME = "product"
13
+
14
+ def self.search(params = {}, opts = {})
15
+ _search("/v1/products/search", params, opts)
16
+ end
17
+
18
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
19
+ search(params, opts).auto_paging_each(&blk)
20
+ end
12
21
  end
13
22
  end
@@ -8,5 +8,16 @@ module Stripe
8
8
  include Stripe::APIOperations::Save
9
9
 
10
10
  OBJECT_NAME = "refund"
11
+
12
+ custom_method :cancel, http_verb: :post
13
+
14
+ def cancel(params = {}, opts = {})
15
+ request_stripe_object(
16
+ method: :post,
17
+ path: resource_url + "/cancel",
18
+ params: params,
19
+ opts: opts
20
+ )
21
+ end
11
22
  end
12
23
  end
@@ -6,6 +6,7 @@ module Stripe
6
6
  extend Stripe::APIOperations::Create
7
7
  include Stripe::APIOperations::Delete
8
8
  extend Stripe::APIOperations::List
9
+ extend Stripe::APIOperations::Search
9
10
  include Stripe::APIOperations::Save
10
11
 
11
12
  OBJECT_NAME = "subscription"
@@ -22,5 +23,13 @@ module Stripe
22
23
  end
23
24
 
24
25
  save_nested_resource :source
26
+
27
+ def self.search(params = {}, opts = {})
28
+ _search("/v1/subscriptions/search", params, opts)
29
+ end
30
+
31
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
32
+ search(params, opts).auto_paging_each(&blk)
33
+ end
25
34
  end
26
35
  end
@@ -10,6 +10,66 @@ module Stripe
10
10
  include Stripe::APIOperations::Save
11
11
 
12
12
  OBJECT_NAME = "terminal.reader"
13
+
14
+ custom_method :cancel_action, http_verb: :post
15
+ custom_method :process_payment_intent, http_verb: :post
16
+ custom_method :process_setup_intent, http_verb: :post
17
+ custom_method :set_reader_display, http_verb: :post
18
+
19
+ def cancel_action(params = {}, opts = {})
20
+ request_stripe_object(
21
+ method: :post,
22
+ path: resource_url + "/cancel_action",
23
+ params: params,
24
+ opts: opts
25
+ )
26
+ end
27
+
28
+ def process_payment_intent(params = {}, opts = {})
29
+ request_stripe_object(
30
+ method: :post,
31
+ path: resource_url + "/process_payment_intent",
32
+ params: params,
33
+ opts: opts
34
+ )
35
+ end
36
+
37
+ def process_setup_intent(params = {}, opts = {})
38
+ request_stripe_object(
39
+ method: :post,
40
+ path: resource_url + "/process_setup_intent",
41
+ params: params,
42
+ opts: opts
43
+ )
44
+ end
45
+
46
+ def set_reader_display(params = {}, opts = {})
47
+ request_stripe_object(
48
+ method: :post,
49
+ path: resource_url + "/set_reader_display",
50
+ params: params,
51
+ opts: opts
52
+ )
53
+ end
54
+
55
+ def test_helpers
56
+ TestHelpers.new(self)
57
+ end
58
+
59
+ class TestHelpers < APIResourceTestHelpers
60
+ RESOURCE_CLASS = Reader
61
+
62
+ custom_method :present_payment_method, http_verb: :post
63
+
64
+ def present_payment_method(params = {}, opts = {})
65
+ @resource.request_stripe_object(
66
+ method: :post,
67
+ path: resource_url + "/present_payment_method",
68
+ params: params,
69
+ opts: opts
70
+ )
71
+ end
72
+ end
13
73
  end
14
74
  end
15
75
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class SearchResultObject < StripeObject
5
+ include Enumerable
6
+ include Stripe::APIOperations::Search
7
+ include Stripe::APIOperations::Request
8
+
9
+ OBJECT_NAME = "search_result"
10
+
11
+ # This accessor allows a `SearchResultObject` to inherit various filters
12
+ # that were given to a predecessor. This allows for things like consistent
13
+ # limits, expansions, and predicates as a user pages through resources.
14
+ attr_accessor :filters
15
+
16
+ # An empty search result object. This is returned from +next+ when we know
17
+ # that there isn't a next page in order to replicate the behavior of the API
18
+ # when it attempts to return a page beyond the last.
19
+ def self.empty_search_result(opts = {})
20
+ SearchResultObject.construct_from({ data: [] }, opts)
21
+ end
22
+
23
+ def initialize(*args)
24
+ super
25
+ self.filters = {}
26
+ end
27
+
28
+ def [](key)
29
+ case key
30
+ when String, Symbol
31
+ super
32
+ else
33
+ raise ArgumentError,
34
+ "You tried to access the #{key.inspect} index, but " \
35
+ "SearchResultObject types only support String keys. " \
36
+ "(HINT: Search calls return an object with a 'data' (which is " \
37
+ "the data array). You likely want to call #data[#{key.inspect}])"
38
+ end
39
+ end
40
+
41
+ # Iterates through each resource in the page represented by the current
42
+ # `SearchListObject`.
43
+ #
44
+ # Note that this method makes no effort to fetch a new page when it gets to
45
+ # the end of the current page's resources. See also +auto_paging_each+.
46
+ def each(&blk)
47
+ data.each(&blk)
48
+ end
49
+
50
+ # Returns true if the page object contains no elements.
51
+ def empty?
52
+ data.empty?
53
+ end
54
+
55
+ # Iterates through each resource in all pages, making additional fetches to
56
+ # the API as necessary.
57
+ #
58
+ # Note that this method will make as many API calls as necessary to fetch
59
+ # all resources. For more granular control, please see +each+ and
60
+ # +next_search_result_page+.
61
+ def auto_paging_each(&blk)
62
+ return enum_for(:auto_paging_each) unless block_given?
63
+
64
+ page = self
65
+
66
+ loop do
67
+ page.each(&blk)
68
+ page = page.next_search_result_page
69
+
70
+ break if page.empty?
71
+ end
72
+ end
73
+
74
+ # Fetches the next page in the resource list (if there is one).
75
+ #
76
+ # This method will try to respect the limit of the current page. If none
77
+ # was given, the default limit will be fetched again.
78
+ def next_search_result_page(params = {}, opts = {})
79
+ return self.class.empty_search_result(opts) unless has_more
80
+
81
+ params = filters.merge(page: next_page).merge(params)
82
+
83
+ _search(url, params, opts)
84
+ end
85
+ end
86
+ end
data/lib/stripe/util.rb CHANGED
@@ -47,6 +47,53 @@ module Stripe
47
47
  Util.object_classes[object_name] == klass
48
48
  end
49
49
 
50
+ # Adds a custom method to a resource class. This is used to add support for
51
+ # non-CRUDL API requests, e.g. capturing charges. custom_method takes the
52
+ # following parameters:
53
+ # - name: the name of the custom method to create (as a symbol)
54
+ # - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
55
+ # - http_path: the path to append to the resource's URL. If not provided,
56
+ # the name is used as the path
57
+ # - resource: the resource implementation class
58
+ # - target: the class that custom static method will be added to
59
+ #
60
+ # For example, this call:
61
+ # custom_method :capture, http_verb: post
62
+ # adds a `capture` class method to the resource class that, when called,
63
+ # will send a POST request to `/v1/<object_name>/capture`.
64
+ def self.custom_method(resource, target, name, http_verb, http_path)
65
+ unless %i[get post delete].include?(http_verb)
66
+ raise ArgumentError,
67
+ "Invalid http_verb value: #{http_verb.inspect}. Should be one " \
68
+ "of :get, :post or :delete."
69
+ end
70
+ unless target.respond_to?(:resource_url)
71
+ raise ArgumentError,
72
+ "Invalid target value: #{target}. Target class should have a " \
73
+ "`resource_url` method."
74
+ end
75
+ http_path ||= name.to_s
76
+ target.define_singleton_method(name) do |id, params = {}, opts = {}|
77
+ unless id.is_a?(String)
78
+ raise ArgumentError,
79
+ "id should be a string representing the ID of an API resource"
80
+ end
81
+
82
+ url = "#{target.resource_url}/"\
83
+ "#{CGI.escape(id)}/"\
84
+ "#{CGI.escape(http_path)}"
85
+
86
+ resp, opts = resource.execute_resource_request(
87
+ http_verb,
88
+ url,
89
+ params,
90
+ opts
91
+ )
92
+
93
+ Util.convert_to_stripe_object(resp.data, opts)
94
+ end
95
+ end
96
+
50
97
  # Converts a hash of fields or an array of hashes into a +StripeObject+ or
51
98
  # array of +StripeObject+s. These new objects will be created as a concrete
52
99
  # type as dictated by their `object` field (e.g. an `object` value of
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "5.45.0"
4
+ VERSION = "5.48.0"
5
5
  end
data/lib/stripe.rb CHANGED
@@ -24,6 +24,7 @@ require "stripe/api_operations/list"
24
24
  require "stripe/api_operations/nested_resource"
25
25
  require "stripe/api_operations/request"
26
26
  require "stripe/api_operations/save"
27
+ require "stripe/api_operations/search"
27
28
 
28
29
  # API resource support classes
29
30
  require "stripe/errors"
@@ -35,8 +36,10 @@ require "stripe/stripe_client"
35
36
  require "stripe/stripe_object"
36
37
  require "stripe/stripe_response"
37
38
  require "stripe/list_object"
39
+ require "stripe/search_result_object"
38
40
  require "stripe/error_object"
39
41
  require "stripe/api_resource"
42
+ require "stripe/api_resource_test_helpers"
40
43
  require "stripe/singleton_api_resource"
41
44
  require "stripe/webhook"
42
45
  require "stripe/stripe_configuration"
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: 5.45.0
4
+ version: 5.48.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-01 00:00:00.000000000 Z
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Stripe is the easiest way to accept payments online. See https://stripe.com
14
14
  for details.
@@ -36,7 +36,9 @@ files:
36
36
  - lib/stripe/api_operations/nested_resource.rb
37
37
  - lib/stripe/api_operations/request.rb
38
38
  - lib/stripe/api_operations/save.rb
39
+ - lib/stripe/api_operations/search.rb
39
40
  - lib/stripe/api_resource.rb
41
+ - lib/stripe/api_resource_test_helpers.rb
40
42
  - lib/stripe/connection_manager.rb
41
43
  - lib/stripe/error_object.rb
42
44
  - lib/stripe/errors.rb
@@ -136,6 +138,7 @@ files:
136
138
  - lib/stripe/resources/usage_record.rb
137
139
  - lib/stripe/resources/usage_record_summary.rb
138
140
  - lib/stripe/resources/webhook_endpoint.rb
141
+ - lib/stripe/search_result_object.rb
139
142
  - lib/stripe/singleton_api_resource.rb
140
143
  - lib/stripe/stripe_client.rb
141
144
  - lib/stripe/stripe_configuration.rb