bongloy 4.21.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +76 -0
  3. data/.editorconfig +10 -0
  4. data/.gitattributes +4 -0
  5. data/.github/ISSUE_TEMPLATE.md +5 -0
  6. data/.github/README.md +79 -0
  7. data/.github/pull.yml +5 -0
  8. data/.gitignore +8 -0
  9. data/.rubocop.yml +43 -0
  10. data/.rubocop_todo.yml +38 -0
  11. data/.travis.yml +43 -0
  12. data/.vscode/extensions.json +7 -0
  13. data/.vscode/settings.json +8 -0
  14. data/CHANGELOG.md +770 -0
  15. data/CONTRIBUTORS +3 -0
  16. data/Gemfile +39 -0
  17. data/History.txt +1 -0
  18. data/LICENSE +21 -0
  19. data/README.md +282 -0
  20. data/Rakefile +36 -0
  21. data/VERSION +1 -0
  22. data/bin/stripe-console +16 -0
  23. data/bongloy.gemspec +37 -0
  24. data/lib/bongloy.rb +7 -0
  25. data/lib/data/ca-certificates.crt +4043 -0
  26. data/lib/stripe.rb +208 -0
  27. data/lib/stripe/api_operations/create.rb +12 -0
  28. data/lib/stripe/api_operations/delete.rb +35 -0
  29. data/lib/stripe/api_operations/list.rb +30 -0
  30. data/lib/stripe/api_operations/nested_resource.rb +70 -0
  31. data/lib/stripe/api_operations/request.rb +53 -0
  32. data/lib/stripe/api_operations/save.rb +94 -0
  33. data/lib/stripe/api_resource.rb +107 -0
  34. data/lib/stripe/errors.rb +156 -0
  35. data/lib/stripe/list_object.rb +110 -0
  36. data/lib/stripe/oauth.rb +63 -0
  37. data/lib/stripe/object_types.rb +98 -0
  38. data/lib/stripe/resources.rb +79 -0
  39. data/lib/stripe/resources/account.rb +174 -0
  40. data/lib/stripe/resources/account_link.rb +9 -0
  41. data/lib/stripe/resources/alipay_account.rb +34 -0
  42. data/lib/stripe/resources/apple_pay_domain.rb +16 -0
  43. data/lib/stripe/resources/application_fee.rb +24 -0
  44. data/lib/stripe/resources/application_fee_refund.rb +30 -0
  45. data/lib/stripe/resources/balance.rb +7 -0
  46. data/lib/stripe/resources/balance_transaction.rb +13 -0
  47. data/lib/stripe/resources/bank_account.rb +42 -0
  48. data/lib/stripe/resources/bitcoin_receiver.rb +23 -0
  49. data/lib/stripe/resources/bitcoin_transaction.rb +15 -0
  50. data/lib/stripe/resources/capability.rb +33 -0
  51. data/lib/stripe/resources/card.rb +37 -0
  52. data/lib/stripe/resources/charge.rb +84 -0
  53. data/lib/stripe/resources/checkout/session.rb +11 -0
  54. data/lib/stripe/resources/country_spec.rb +9 -0
  55. data/lib/stripe/resources/coupon.rb +12 -0
  56. data/lib/stripe/resources/credit_note.rb +18 -0
  57. data/lib/stripe/resources/customer.rb +95 -0
  58. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  59. data/lib/stripe/resources/discount.rb +7 -0
  60. data/lib/stripe/resources/dispute.rb +23 -0
  61. data/lib/stripe/resources/ephemeral_key.rb +19 -0
  62. data/lib/stripe/resources/event.rb +9 -0
  63. data/lib/stripe/resources/exchange_rate.rb +9 -0
  64. data/lib/stripe/resources/file.rb +44 -0
  65. data/lib/stripe/resources/file_link.rb +11 -0
  66. data/lib/stripe/resources/invoice.rb +48 -0
  67. data/lib/stripe/resources/invoice_item.rb +12 -0
  68. data/lib/stripe/resources/invoice_line_item.rb +7 -0
  69. data/lib/stripe/resources/issuer_fraud_record.rb +9 -0
  70. data/lib/stripe/resources/issuing/authorization.rb +25 -0
  71. data/lib/stripe/resources/issuing/card.rb +20 -0
  72. data/lib/stripe/resources/issuing/card_details.rb +9 -0
  73. data/lib/stripe/resources/issuing/cardholder.rb +13 -0
  74. data/lib/stripe/resources/issuing/dispute.rb +13 -0
  75. data/lib/stripe/resources/issuing/transaction.rb +12 -0
  76. data/lib/stripe/resources/login_link.rb +14 -0
  77. data/lib/stripe/resources/order.rb +32 -0
  78. data/lib/stripe/resources/order_return.rb +9 -0
  79. data/lib/stripe/resources/payment_intent.rb +30 -0
  80. data/lib/stripe/resources/payment_method.rb +24 -0
  81. data/lib/stripe/resources/payout.rb +24 -0
  82. data/lib/stripe/resources/person.rb +31 -0
  83. data/lib/stripe/resources/plan.rb +12 -0
  84. data/lib/stripe/resources/product.rb +12 -0
  85. data/lib/stripe/resources/radar/early_fraud_warning.rb +11 -0
  86. data/lib/stripe/resources/radar/value_list.rb +14 -0
  87. data/lib/stripe/resources/radar/value_list_item.rb +13 -0
  88. data/lib/stripe/resources/recipient.rb +17 -0
  89. data/lib/stripe/resources/recipient_transfer.rb +7 -0
  90. data/lib/stripe/resources/refund.rb +11 -0
  91. data/lib/stripe/resources/reporting/report_run.rb +12 -0
  92. data/lib/stripe/resources/reporting/report_type.rb +12 -0
  93. data/lib/stripe/resources/reversal.rb +29 -0
  94. data/lib/stripe/resources/review.rb +16 -0
  95. data/lib/stripe/resources/setup_intent.rb +24 -0
  96. data/lib/stripe/resources/sigma/scheduled_query_run.rb +15 -0
  97. data/lib/stripe/resources/sku.rb +12 -0
  98. data/lib/stripe/resources/source.rb +42 -0
  99. data/lib/stripe/resources/source_transaction.rb +7 -0
  100. data/lib/stripe/resources/subscription.rb +25 -0
  101. data/lib/stripe/resources/subscription_item.rb +17 -0
  102. data/lib/stripe/resources/subscription_schedule.rb +32 -0
  103. data/lib/stripe/resources/subscription_schedule_revision.rb +34 -0
  104. data/lib/stripe/resources/tax_id.rb +26 -0
  105. data/lib/stripe/resources/tax_rate.rb +11 -0
  106. data/lib/stripe/resources/terminal/connection_token.rb +11 -0
  107. data/lib/stripe/resources/terminal/location.rb +14 -0
  108. data/lib/stripe/resources/terminal/reader.rb +14 -0
  109. data/lib/stripe/resources/three_d_secure.rb +13 -0
  110. data/lib/stripe/resources/token.rb +9 -0
  111. data/lib/stripe/resources/topup.rb +18 -0
  112. data/lib/stripe/resources/transfer.rb +27 -0
  113. data/lib/stripe/resources/usage_record.rb +23 -0
  114. data/lib/stripe/resources/usage_record_summary.rb +7 -0
  115. data/lib/stripe/resources/webhook_endpoint.rb +12 -0
  116. data/lib/stripe/singleton_api_resource.rb +26 -0
  117. data/lib/stripe/stripe_client.rb +686 -0
  118. data/lib/stripe/stripe_object.rb +583 -0
  119. data/lib/stripe/stripe_response.rb +50 -0
  120. data/lib/stripe/util.rb +336 -0
  121. data/lib/stripe/version.rb +5 -0
  122. data/lib/stripe/webhook.rb +90 -0
  123. data/stripe.gemspec +37 -0
  124. data/test/api_stub_helpers.rb +1 -0
  125. data/test/openapi/README.md +9 -0
  126. data/test/stripe/account_link_test.rb +18 -0
  127. data/test/stripe/account_test.rb +428 -0
  128. data/test/stripe/alipay_account_test.rb +37 -0
  129. data/test/stripe/api_operations_test.rb +80 -0
  130. data/test/stripe/api_resource_test.rb +544 -0
  131. data/test/stripe/apple_pay_domain_test.rb +46 -0
  132. data/test/stripe/application_fee_refund_test.rb +37 -0
  133. data/test/stripe/application_fee_test.rb +58 -0
  134. data/test/stripe/balance_test.rb +13 -0
  135. data/test/stripe/bank_account_test.rb +36 -0
  136. data/test/stripe/capability_test.rb +45 -0
  137. data/test/stripe/charge_test.rb +80 -0
  138. data/test/stripe/checkout/session_test.rb +41 -0
  139. data/test/stripe/country_spec_test.rb +20 -0
  140. data/test/stripe/coupon_test.rb +61 -0
  141. data/test/stripe/credit_note_test.rb +61 -0
  142. data/test/stripe/customer_balance_transaction_test.rb +37 -0
  143. data/test/stripe/customer_card_test.rb +42 -0
  144. data/test/stripe/customer_test.rb +269 -0
  145. data/test/stripe/dispute_test.rb +51 -0
  146. data/test/stripe/ephemeral_key_test.rb +93 -0
  147. data/test/stripe/errors_test.rb +20 -0
  148. data/test/stripe/exchange_rate_test.rb +20 -0
  149. data/test/stripe/file_link_test.rb +41 -0
  150. data/test/stripe/file_test.rb +97 -0
  151. data/test/stripe/file_upload_test.rb +79 -0
  152. data/test/stripe/invoice_item_test.rb +66 -0
  153. data/test/stripe/invoice_line_item_test.rb +8 -0
  154. data/test/stripe/invoice_test.rb +213 -0
  155. data/test/stripe/issuer_fraud_record_test.rb +20 -0
  156. data/test/stripe/issuing/authorization_test.rb +72 -0
  157. data/test/stripe/issuing/card_test.rb +62 -0
  158. data/test/stripe/issuing/cardholder_test.rb +53 -0
  159. data/test/stripe/issuing/dispute_test.rb +45 -0
  160. data/test/stripe/issuing/transaction_test.rb +48 -0
  161. data/test/stripe/list_object_test.rb +156 -0
  162. data/test/stripe/login_link_test.rb +37 -0
  163. data/test/stripe/oauth_test.rb +88 -0
  164. data/test/stripe/order_return_test.rb +21 -0
  165. data/test/stripe/order_test.rb +82 -0
  166. data/test/stripe/payment_intent_test.rb +107 -0
  167. data/test/stripe/payment_method_test.rb +84 -0
  168. data/test/stripe/payout_test.rb +57 -0
  169. data/test/stripe/person_test.rb +46 -0
  170. data/test/stripe/plan_test.rb +98 -0
  171. data/test/stripe/product_test.rb +59 -0
  172. data/test/stripe/radar/early_fraud_warning_test.rb +22 -0
  173. data/test/stripe/radar/value_list_item_test.rb +48 -0
  174. data/test/stripe/radar/value_list_test.rb +61 -0
  175. data/test/stripe/recipient_test.rb +62 -0
  176. data/test/stripe/refund_test.rb +39 -0
  177. data/test/stripe/reporting/report_run_test.rb +33 -0
  178. data/test/stripe/reporting/report_type_test.rb +22 -0
  179. data/test/stripe/reversal_test.rb +43 -0
  180. data/test/stripe/review_test.rb +27 -0
  181. data/test/stripe/setup_intent_test.rb +84 -0
  182. data/test/stripe/sigma/scheduled_query_run_test.rb +22 -0
  183. data/test/stripe/sku_test.rb +60 -0
  184. data/test/stripe/source_test.rb +99 -0
  185. data/test/stripe/source_transaction_test.rb +19 -0
  186. data/test/stripe/stripe_client_test.rb +842 -0
  187. data/test/stripe/stripe_object_test.rb +525 -0
  188. data/test/stripe/stripe_response_test.rb +49 -0
  189. data/test/stripe/subscription_item_test.rb +63 -0
  190. data/test/stripe/subscription_schedule_revision_test.rb +37 -0
  191. data/test/stripe/subscription_schedule_test.rb +116 -0
  192. data/test/stripe/subscription_test.rb +80 -0
  193. data/test/stripe/tax_id_test.rb +31 -0
  194. data/test/stripe/tax_rate_test.rb +43 -0
  195. data/test/stripe/terminal/connection_token_test.rb +16 -0
  196. data/test/stripe/terminal/location_test.rb +68 -0
  197. data/test/stripe/terminal/reader_test.rb +62 -0
  198. data/test/stripe/three_d_secure_test.rb +23 -0
  199. data/test/stripe/topup_test.rb +62 -0
  200. data/test/stripe/transfer_test.rb +88 -0
  201. data/test/stripe/usage_record_summary_test.rb +19 -0
  202. data/test/stripe/usage_record_test.rb +28 -0
  203. data/test/stripe/util_test.rb +402 -0
  204. data/test/stripe/webhook_endpoint_test.rb +59 -0
  205. data/test/stripe/webhook_test.rb +96 -0
  206. data/test/stripe_mock.rb +77 -0
  207. data/test/stripe_test.rb +63 -0
  208. data/test/test_data.rb +61 -0
  209. data/test/test_helper.rb +71 -0
  210. metadata +372 -0
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class APIResource < StripeObject
5
+ include Stripe::APIOperations::Request
6
+
7
+ # A flag that can be set a behavior that will cause this resource to be
8
+ # encoded and sent up along with an update of its parent resource. This is
9
+ # usually not desirable because resources are updated individually on their
10
+ # own endpoints, but there are certain cases, replacing a customer's source
11
+ # for example, where this is allowed.
12
+ attr_accessor :save_with_parent
13
+
14
+ def self.class_name
15
+ name.split("::")[-1]
16
+ end
17
+
18
+ def self.resource_url
19
+ if self == APIResource
20
+ raise NotImplementedError,
21
+ "APIResource is an abstract class. You should perform actions " \
22
+ "on its subclasses (Charge, Customer, etc.)"
23
+ end
24
+ # Namespaces are separated in object names with periods (.) and in URLs
25
+ # with forward slashes (/), so replace the former with the latter.
26
+ "/v1/#{self::OBJECT_NAME.downcase.tr('.', '/')}s"
27
+ end
28
+
29
+ # A metaprogramming call that specifies that a field of a resource can be
30
+ # its own type of API resource (say a nested card under an account for
31
+ # example), and if that resource is set, it should be transmitted to the
32
+ # API on a create or update. Doing so is not the default behavior because
33
+ # API resources should normally be persisted on their own RESTful
34
+ # endpoints.
35
+ def self.save_nested_resource(name)
36
+ define_method(:"#{name}=") do |value|
37
+ super(value)
38
+
39
+ # The parent setter will perform certain useful operations like
40
+ # converting to an APIResource if appropriate. Refresh our argument
41
+ # value to whatever it mutated to.
42
+ value = send(name)
43
+
44
+ # Note that the value may be subresource, but could also be a scalar
45
+ # (like a tokenized card's ID for example), so we check the type before
46
+ # setting #save_with_parent here.
47
+ value.save_with_parent = true if value.is_a?(APIResource)
48
+
49
+ value
50
+ end
51
+ end
52
+
53
+ # Adds a custom method to a resource class. This is used to add support for
54
+ # non-CRUDL API requests, e.g. capturing charges. custom_method takes the
55
+ # following parameters:
56
+ # - name: the name of the custom method to create (as a symbol)
57
+ # - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
58
+ # - http_path: the path to append to the resource's URL. If not provided,
59
+ # the name is used as the path
60
+ #
61
+ # For example, this call:
62
+ # custom_method :capture, http_verb: post
63
+ # adds a `capture` class method to the resource class that, when called,
64
+ # will send a POST request to `/v1/<object_name>/capture`.
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 = request(http_verb, url, params, opts)
80
+ Util.convert_to_stripe_object(resp.data, opts)
81
+ end
82
+ end
83
+
84
+ def resource_url
85
+ unless (id = self["id"])
86
+ raise InvalidRequestError.new(
87
+ "Could not determine which URL to request: #{self.class} instance " \
88
+ "has invalid ID: #{id.inspect}",
89
+ "id"
90
+ )
91
+ end
92
+ "#{self.class.resource_url}/#{CGI.escape(id)}"
93
+ end
94
+
95
+ def refresh
96
+ resp, opts = request(:get, resource_url, @retrieve_params)
97
+ initialize_from(resp.data, opts)
98
+ end
99
+
100
+ def self.retrieve(id, opts = {})
101
+ opts = Util.normalize_opts(opts)
102
+ instance = new(id, opts)
103
+ instance.refresh
104
+ instance
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ # StripeError is the base error from which all other more specific Stripe
5
+ # errors derive.
6
+ class StripeError < StandardError
7
+ attr_reader :message
8
+
9
+ # Response contains a StripeResponse object that has some basic information
10
+ # about the response that conveyed the error.
11
+ attr_accessor :response
12
+
13
+ attr_reader :code
14
+ attr_reader :http_body
15
+ attr_reader :http_headers
16
+ attr_reader :http_status
17
+ attr_reader :json_body # equivalent to #data
18
+ attr_reader :request_id
19
+
20
+ # Initializes a StripeError.
21
+ def initialize(message = nil, http_status: nil, http_body: nil,
22
+ json_body: nil, http_headers: nil, code: nil)
23
+ @message = message
24
+ @http_status = http_status
25
+ @http_body = http_body
26
+ @http_headers = http_headers || {}
27
+ @json_body = json_body
28
+ @code = code
29
+ @request_id = @http_headers[:request_id]
30
+ end
31
+
32
+ def to_s
33
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
34
+ id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
35
+ "#{status_string}#{id_string}#{@message}"
36
+ end
37
+ end
38
+
39
+ # AuthenticationError is raised when invalid credentials are used to connect
40
+ # to Stripe's servers.
41
+ class AuthenticationError < StripeError
42
+ end
43
+
44
+ # APIConnectionError is raised in the event that the SDK can't connect to
45
+ # Stripe's servers. That can be for a variety of different reasons from a
46
+ # downed network to a bad TLS certificate.
47
+ class APIConnectionError < StripeError
48
+ end
49
+
50
+ # APIError is a generic error that may be raised in cases where none of the
51
+ # other named errors cover the problem. It could also be raised in the case
52
+ # that a new error has been introduced in the API, but this version of the
53
+ # Ruby SDK doesn't know how to handle it.
54
+ class APIError < StripeError
55
+ end
56
+
57
+ # CardError is raised when a user enters a card that can't be charged for
58
+ # some reason.
59
+ class CardError < StripeError
60
+ attr_reader :param
61
+
62
+ # TODO: make code a keyword arg in next major release
63
+ def initialize(message, param, code, http_status: nil, http_body: nil,
64
+ json_body: nil, http_headers: nil)
65
+ super(message, http_status: http_status, http_body: http_body,
66
+ json_body: json_body, http_headers: http_headers,
67
+ code: code)
68
+ @param = param
69
+ end
70
+ end
71
+
72
+ # IdempotencyError is raised in cases where an idempotency key was used
73
+ # improperly.
74
+ class IdempotencyError < StripeError
75
+ end
76
+
77
+ # InvalidRequestError is raised when a request is initiated with invalid
78
+ # parameters.
79
+ class InvalidRequestError < StripeError
80
+ attr_accessor :param
81
+
82
+ def initialize(message, param, http_status: nil, http_body: nil,
83
+ json_body: nil, http_headers: nil, code: nil)
84
+ super(message, http_status: http_status, http_body: http_body,
85
+ json_body: json_body, http_headers: http_headers,
86
+ code: code)
87
+ @param = param
88
+ end
89
+ end
90
+
91
+ # PermissionError is raised in cases where access was attempted on a resource
92
+ # that wasn't allowed.
93
+ class PermissionError < StripeError
94
+ end
95
+
96
+ # RateLimitError is raised in cases where an account is putting too much load
97
+ # on Stripe's API servers (usually by performing too many requests). Please
98
+ # back off on request rate.
99
+ class RateLimitError < StripeError
100
+ end
101
+
102
+ # SignatureVerificationError is raised when the signature verification for a
103
+ # webhook fails
104
+ class SignatureVerificationError < StripeError
105
+ attr_accessor :sig_header
106
+
107
+ def initialize(message, sig_header, http_body: nil)
108
+ super(message, http_body: http_body)
109
+ @sig_header = sig_header
110
+ end
111
+ end
112
+
113
+ module OAuth
114
+ # OAuthError is raised when the OAuth API returns an error.
115
+ class OAuthError < StripeError
116
+ def initialize(code, description, http_status: nil, http_body: nil,
117
+ json_body: nil, http_headers: nil)
118
+ super(description, http_status: http_status, http_body: http_body,
119
+ json_body: json_body, http_headers: http_headers,
120
+ code: code)
121
+ end
122
+ end
123
+
124
+ # InvalidClientError is raised when the client doesn't belong to you, or
125
+ # the API key mode (live or test) doesn't match the client mode. Or the
126
+ # stripe_user_id doesn't exist or isn't connected to your application.
127
+ class InvalidClientError < OAuthError
128
+ end
129
+
130
+ # InvalidGrantError is raised when a specified code doesn't exist, is
131
+ # expired, has been used, or doesn't belong to you; a refresh token doesn't
132
+ # exist, or doesn't belong to you; or if an API key's mode (live or test)
133
+ # doesn't match the mode of a code or refresh token.
134
+ class InvalidGrantError < OAuthError
135
+ end
136
+
137
+ # InvalidRequestError is raised when a code, refresh token, or grant type
138
+ # parameter is not provided, but was required.
139
+ class InvalidRequestError < OAuthError
140
+ end
141
+
142
+ # InvalidScopeError is raised when an invalid scope parameter is provided.
143
+ class InvalidScopeError < OAuthError
144
+ end
145
+
146
+ # UnsupportedGrantTypeError is raised when an unuspported grant type
147
+ # parameter is specified.
148
+ class UnsupportedGrantTypeError < OAuthError
149
+ end
150
+
151
+ # UnsupportedResponseTypeError is raised when an unsupported response type
152
+ # parameter is specified.
153
+ class UnsupportedResponseTypeError < OAuthError
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class ListObject < StripeObject
5
+ include Enumerable
6
+ include Stripe::APIOperations::List
7
+ include Stripe::APIOperations::Request
8
+ include Stripe::APIOperations::Create
9
+
10
+ OBJECT_NAME = "list".freeze
11
+
12
+ # This accessor allows a `ListObject` to inherit various filters that were
13
+ # given to a predecessor. This allows for things like consistent limits,
14
+ # expansions, and predicates as a user pages through resources.
15
+ attr_accessor :filters
16
+
17
+ # An empty list object. This is returned from +next+ when we know that
18
+ # there isn't a next page in order to replicate the behavior of the API
19
+ # when it attempts to return a page beyond the last.
20
+ def self.empty_list(opts = {})
21
+ ListObject.construct_from({ data: [] }, opts)
22
+ end
23
+
24
+ def initialize(*args)
25
+ super
26
+ self.filters = {}
27
+ end
28
+
29
+ def [](key)
30
+ case key
31
+ when String, Symbol
32
+ super
33
+ else
34
+ raise ArgumentError,
35
+ "You tried to access the #{key.inspect} index, but ListObject " \
36
+ "types only support String keys. (HINT: List calls return an " \
37
+ "object with a 'data' (which is the data array). You likely " \
38
+ "want to call #data[#{key.inspect}])"
39
+ end
40
+ end
41
+
42
+ # Iterates through each resource in the page represented by the current
43
+ # `ListObject`.
44
+ #
45
+ # Note that this method makes no effort to fetch a new page when it gets to
46
+ # the end of the current page's resources. See also +auto_paging_each+.
47
+ def each(&blk)
48
+ data.each(&blk)
49
+ end
50
+
51
+ # Iterates through each resource in all pages, making additional fetches to
52
+ # the API as necessary.
53
+ #
54
+ # Note that this method will make as many API calls as necessary to fetch
55
+ # all resources. For more granular control, please see +each+ and
56
+ # +next_page+.
57
+ def auto_paging_each(&blk)
58
+ return enum_for(:auto_paging_each) unless block_given?
59
+
60
+ page = self
61
+ loop do
62
+ page.each(&blk)
63
+ page = page.next_page
64
+ break if page.empty?
65
+ end
66
+ end
67
+
68
+ # Returns true if the page object contains no elements.
69
+ def empty?
70
+ data.empty?
71
+ end
72
+
73
+ def retrieve(id, opts = {})
74
+ id, retrieve_params = Util.normalize_id(id)
75
+ resp, opts = request(:get, "#{resource_url}/#{CGI.escape(id)}",
76
+ retrieve_params, opts)
77
+ Util.convert_to_stripe_object(resp.data, opts)
78
+ end
79
+
80
+ # Fetches the next page in the resource list (if there is one).
81
+ #
82
+ # This method will try to respect the limit of the current page. If none
83
+ # was given, the default limit will be fetched again.
84
+ def next_page(params = {}, opts = {})
85
+ return self.class.empty_list(opts) unless has_more
86
+ last_id = data.last.id
87
+
88
+ params = filters.merge(starting_after: last_id).merge(params)
89
+
90
+ list(params, opts)
91
+ end
92
+
93
+ # Fetches the previous page in the resource list (if there is one).
94
+ #
95
+ # This method will try to respect the limit of the current page. If none
96
+ # was given, the default limit will be fetched again.
97
+ def previous_page(params = {}, opts = {})
98
+ first_id = data.first.id
99
+
100
+ params = filters.merge(ending_before: first_id).merge(params)
101
+
102
+ list(params, opts)
103
+ end
104
+
105
+ def resource_url
106
+ url ||
107
+ raise(ArgumentError, "List object does not contain a 'url' field.")
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ module OAuth
5
+ module OAuthOperations
6
+ extend APIOperations::Request::ClassMethods
7
+
8
+ def self.request(method, url, params, opts)
9
+ opts = Util.normalize_opts(opts)
10
+ opts[:client] ||= StripeClient.active_client
11
+ opts[:api_base] ||= Stripe.connect_base
12
+
13
+ super(method, url, params, opts)
14
+ end
15
+ end
16
+
17
+ def self.get_client_id(params = {})
18
+ client_id = params[:client_id] || Stripe.client_id
19
+ unless client_id
20
+ raise AuthenticationError, "No client_id provided. " \
21
+ 'Set your client_id using "Stripe.client_id = <CLIENT-ID>". ' \
22
+ "You can find your client_ids in your Stripe dashboard at " \
23
+ "https://dashboard.stripe.com/account/applications/settings, " \
24
+ "after registering your account as a platform. See " \
25
+ "https://stripe.com/docs/connect/standalone-accounts for details, " \
26
+ "or email support@stripe.com if you have any questions."
27
+ end
28
+ client_id
29
+ end
30
+
31
+ def self.authorize_url(params = {}, opts = {})
32
+ base = opts[:connect_base] || Stripe.connect_base
33
+
34
+ path = "/oauth/authorize"
35
+ path = "/express" + path if opts[:express]
36
+
37
+ params[:client_id] = get_client_id(params)
38
+ params[:response_type] ||= "code"
39
+ query = Util.encode_parameters(params)
40
+
41
+ "#{base}#{path}?#{query}"
42
+ end
43
+
44
+ def self.token(params = {}, opts = {})
45
+ opts = Util.normalize_opts(opts)
46
+ resp, opts = OAuthOperations.request(
47
+ :post, "/oauth/token", params, opts
48
+ )
49
+ # This is just going to return a generic StripeObject, but that's okay
50
+ Util.convert_to_stripe_object(resp.data, opts)
51
+ end
52
+
53
+ def self.deauthorize(params = {}, opts = {})
54
+ opts = Util.normalize_opts(opts)
55
+ params[:client_id] = get_client_id(params)
56
+ resp, opts = OAuthOperations.request(
57
+ :post, "/oauth/deauthorize", params, opts
58
+ )
59
+ # This is just going to return a generic StripeObject, but that's okay
60
+ Util.convert_to_stripe_object(resp.data, opts)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/LineLength
4
+ # rubocop:disable Metrics/MethodLength
5
+
6
+ module Stripe
7
+ module ObjectTypes
8
+ def self.object_names_to_classes
9
+ {
10
+ # data structures
11
+ ListObject::OBJECT_NAME => ListObject,
12
+
13
+ # business objects
14
+ Account::OBJECT_NAME => Account,
15
+ AccountLink::OBJECT_NAME => AccountLink,
16
+ AlipayAccount::OBJECT_NAME => AlipayAccount,
17
+ ApplePayDomain::OBJECT_NAME => ApplePayDomain,
18
+ ApplicationFee::OBJECT_NAME => ApplicationFee,
19
+ ApplicationFeeRefund::OBJECT_NAME => ApplicationFeeRefund,
20
+ Balance::OBJECT_NAME => Balance,
21
+ BalanceTransaction::OBJECT_NAME => BalanceTransaction,
22
+ BankAccount::OBJECT_NAME => BankAccount,
23
+ BitcoinReceiver::OBJECT_NAME => BitcoinReceiver,
24
+ BitcoinTransaction::OBJECT_NAME => BitcoinTransaction,
25
+ Capability::OBJECT_NAME => Capability,
26
+ Card::OBJECT_NAME => Card,
27
+ Charge::OBJECT_NAME => Charge,
28
+ Checkout::Session::OBJECT_NAME => Checkout::Session,
29
+ CountrySpec::OBJECT_NAME => CountrySpec,
30
+ Coupon::OBJECT_NAME => Coupon,
31
+ CreditNote::OBJECT_NAME => CreditNote,
32
+ Customer::OBJECT_NAME => Customer,
33
+ CustomerBalanceTransaction::OBJECT_NAME => CustomerBalanceTransaction,
34
+ Discount::OBJECT_NAME => Discount,
35
+ Dispute::OBJECT_NAME => Dispute,
36
+ EphemeralKey::OBJECT_NAME => EphemeralKey,
37
+ Event::OBJECT_NAME => Event,
38
+ ExchangeRate::OBJECT_NAME => ExchangeRate,
39
+ File::OBJECT_NAME => File,
40
+ File::OBJECT_NAME_ALT => File,
41
+ FileLink::OBJECT_NAME => FileLink,
42
+ Invoice::OBJECT_NAME => Invoice,
43
+ InvoiceItem::OBJECT_NAME => InvoiceItem,
44
+ InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
45
+ IssuerFraudRecord::OBJECT_NAME => IssuerFraudRecord,
46
+ Issuing::Authorization::OBJECT_NAME => Issuing::Authorization,
47
+ Issuing::Card::OBJECT_NAME => Issuing::Card,
48
+ Issuing::CardDetails::OBJECT_NAME => Issuing::CardDetails,
49
+ Issuing::Cardholder::OBJECT_NAME => Issuing::Cardholder,
50
+ Issuing::Dispute::OBJECT_NAME => Issuing::Dispute,
51
+ Issuing::Transaction::OBJECT_NAME => Issuing::Transaction,
52
+ LoginLink::OBJECT_NAME => LoginLink,
53
+ Order::OBJECT_NAME => Order,
54
+ OrderReturn::OBJECT_NAME => OrderReturn,
55
+ PaymentIntent::OBJECT_NAME => PaymentIntent,
56
+ PaymentMethod::OBJECT_NAME => PaymentMethod,
57
+ Payout::OBJECT_NAME => Payout,
58
+ Person::OBJECT_NAME => Person,
59
+ Plan::OBJECT_NAME => Plan,
60
+ Product::OBJECT_NAME => Product,
61
+ Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
62
+ Radar::ValueList::OBJECT_NAME => Radar::ValueList,
63
+ Radar::ValueListItem::OBJECT_NAME => Radar::ValueListItem,
64
+ Recipient::OBJECT_NAME => Recipient,
65
+ RecipientTransfer::OBJECT_NAME => RecipientTransfer,
66
+ Refund::OBJECT_NAME => Refund,
67
+ Reporting::ReportRun::OBJECT_NAME => Reporting::ReportRun,
68
+ Reporting::ReportType::OBJECT_NAME => Reporting::ReportType,
69
+ Reversal::OBJECT_NAME => Reversal,
70
+ Review::OBJECT_NAME => Review,
71
+ SKU::OBJECT_NAME => SKU,
72
+ SetupIntent::OBJECT_NAME => SetupIntent,
73
+ Sigma::ScheduledQueryRun::OBJECT_NAME => Sigma::ScheduledQueryRun,
74
+ Source::OBJECT_NAME => Source,
75
+ SourceTransaction::OBJECT_NAME => SourceTransaction,
76
+ Subscription::OBJECT_NAME => Subscription,
77
+ SubscriptionItem::OBJECT_NAME => SubscriptionItem,
78
+ SubscriptionSchedule::OBJECT_NAME => SubscriptionSchedule,
79
+ SubscriptionScheduleRevision::OBJECT_NAME => SubscriptionScheduleRevision,
80
+ TaxId::OBJECT_NAME => TaxId,
81
+ TaxRate::OBJECT_NAME => TaxRate,
82
+ Terminal::ConnectionToken::OBJECT_NAME => Terminal::ConnectionToken,
83
+ Terminal::Location::OBJECT_NAME => Terminal::Location,
84
+ Terminal::Reader::OBJECT_NAME => Terminal::Reader,
85
+ ThreeDSecure::OBJECT_NAME => ThreeDSecure,
86
+ Token::OBJECT_NAME => Token,
87
+ Topup::OBJECT_NAME => Topup,
88
+ Transfer::OBJECT_NAME => Transfer,
89
+ UsageRecord::OBJECT_NAME => UsageRecord,
90
+ UsageRecordSummary::OBJECT_NAME => UsageRecordSummary,
91
+ WebhookEndpoint::OBJECT_NAME => WebhookEndpoint,
92
+ }
93
+ end
94
+ end
95
+ end
96
+
97
+ # rubocop:enable Metrics/LineLength
98
+ # rubocop:enable Metrics/MethodLength