stripe 5.46.0 → 5.49.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: dc0fdc03553a1cb2d1d67ebe31538b25abd248d7f48ba0c6377bb8a9ff097a89
4
- data.tar.gz: 31e2871a1f52b97e1994c3a4a4eb62068361167cb8c1d5a731244380247d2905
3
+ metadata.gz: 86b2523f0ba5dc9577ec83de2608e76e77d5d08cd7611c92f41a957a90a019e6
4
+ data.tar.gz: 849e0b6f2adcc0db8b496da23873d250be962ae9f4e5c3e47fc161d44e1602fd
5
5
  SHA512:
6
- metadata.gz: 568b6acfdd6d7824cba36b8cf7c5ca6c85a11f2c0f9081df12175045e917a321b937c81ce98ebe43f455fc49e3d95d315c8da77ff6f7427d87197c4fbf08d80e
7
- data.tar.gz: af1ed8b0d8d5f0782a7e953a6f56834f1fe7fb91eef2eeb82178e3dff784d5781cbee9fa53ac0c6ba0301124a7672cee39659716ac5c4a881e4a51a45cfec754
6
+ metadata.gz: c75a5b1d4229f4489e5198dce6ab38f444106891e3ff42d74b68138b4a1d4258c7a1c3f827007bf74d1d525b7f9b741ba34144b85cf6366b170bf45c0255e90d
7
+ data.tar.gz: '0835cbdf3d368a81801e3171d3affb69eb94dee7ca91bc46a402506b7525f0887f1f8b1b27c97abb9db3bc14cf4bac92d9eccdb76474f9fc842a72ce4df3bea0'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.49.0 - 2022-04-08
4
+ * [#1043](https://github.com/stripe/stripe-ruby/pull/1043) API Updates
5
+ * Add support for `apply_customer_balance` method on resource `PaymentIntent`
6
+
7
+ ## 5.48.0 - 2022-03-30
8
+ * [#1041](https://github.com/stripe/stripe-ruby/pull/1041) API Updates
9
+ * Add support for `cancel_action`, `process_payment_intent`, `process_setup_intent`, and `set_reader_display` methods on resource `Terminal.Reader`
10
+
11
+ ## 5.47.0 - 2022-03-29
12
+ * [#1040](https://github.com/stripe/stripe-ruby/pull/1040) API Updates
13
+ * Add support for Search API
14
+ * Add support for `search` method on resources `Charge`, `Customer`, `Invoice`, `PaymentIntent`, `Price`, `Product`, and `Subscription`
15
+
16
+ * [#1034](https://github.com/stripe/stripe-ruby/pull/1034) Add supporting classes for test helper generation
17
+
3
18
  ## 5.46.0 - 2022-03-23
4
19
  * [#1039](https://github.com/stripe/stripe-ruby/pull/1039) API Updates
5
20
  * Add support for `cancel` method on resource `Refund`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.46.0
1
+ 5.49.0
@@ -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
@@ -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,15 +5,26 @@ 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"
11
12
 
13
+ custom_method :apply_customer_balance, http_verb: :post
12
14
  custom_method :cancel, http_verb: :post
13
15
  custom_method :capture, http_verb: :post
14
16
  custom_method :confirm, http_verb: :post
15
17
  custom_method :verify_microdeposits, http_verb: :post
16
18
 
19
+ def apply_customer_balance(params = {}, opts = {})
20
+ request_stripe_object(
21
+ method: :post,
22
+ path: resource_url + "/apply_customer_balance",
23
+ params: params,
24
+ opts: opts
25
+ )
26
+ end
27
+
17
28
  def cancel(params = {}, opts = {})
18
29
  request_stripe_object(
19
30
  method: :post,
@@ -49,5 +60,13 @@ module Stripe
49
60
  opts: opts
50
61
  )
51
62
  end
63
+
64
+ def self.search(params = {}, opts = {})
65
+ _search("/v1/payment_intents/search", params, opts)
66
+ end
67
+
68
+ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
69
+ search(params, opts).auto_paging_each(&blk)
70
+ end
52
71
  end
53
72
  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
@@ -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
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.46.0"
4
+ VERSION = "5.49.0"
5
5
  end
data/lib/stripe.rb CHANGED
@@ -39,6 +39,7 @@ require "stripe/list_object"
39
39
  require "stripe/search_result_object"
40
40
  require "stripe/error_object"
41
41
  require "stripe/api_resource"
42
+ require "stripe/api_resource_test_helpers"
42
43
  require "stripe/singleton_api_resource"
43
44
  require "stripe/webhook"
44
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.46.0
4
+ version: 5.49.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-23 00:00:00.000000000 Z
11
+ date: 2022-04-08 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.
@@ -38,6 +38,7 @@ files:
38
38
  - lib/stripe/api_operations/save.rb
39
39
  - lib/stripe/api_operations/search.rb
40
40
  - lib/stripe/api_resource.rb
41
+ - lib/stripe/api_resource_test_helpers.rb
41
42
  - lib/stripe/connection_manager.rb
42
43
  - lib/stripe/error_object.rb
43
44
  - lib/stripe/errors.rb