mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-11 00:01:02 -04:00
Use request_stripe_object for all requests (#1071)
This commit is contained in:
parent
001db8bd27
commit
b841931ffe
@ -4,8 +4,12 @@ module Stripe
|
||||
module APIOperations
|
||||
module Create
|
||||
def create(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(:post, resource_url, params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: resource_url,
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,17 +18,22 @@ module Stripe
|
||||
# api_key to be overwritten. See
|
||||
# {APIOperations::Request.execute_resource_request}.
|
||||
def delete(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(:delete,
|
||||
"#{resource_url}/#{id}",
|
||||
params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :delete,
|
||||
path: "#{resource_url}/#{id}",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(:delete, resource_url,
|
||||
params, opts)
|
||||
initialize_from(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :delete,
|
||||
path: resource_url,
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.included(base)
|
||||
|
@ -4,15 +4,12 @@ module Stripe
|
||||
module APIOperations
|
||||
module List
|
||||
def list(filters = {}, opts = {})
|
||||
opts = Util.normalize_opts(opts)
|
||||
|
||||
resp, opts = execute_resource_request(:get, resource_url, filters, opts)
|
||||
obj = ListObject.construct_from(resp.data, opts)
|
||||
|
||||
# set filters so that we can fetch the same limit, expansions, and
|
||||
# predicates when accessing the next and previous pages
|
||||
obj.filters = filters.dup
|
||||
obj
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url,
|
||||
params: filters,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -26,46 +26,74 @@ module Stripe
|
||||
end
|
||||
|
||||
operations.each do |operation|
|
||||
case operation
|
||||
when :create
|
||||
define_singleton_method(:"create_#{resource}") \
|
||||
define_operation(
|
||||
resource,
|
||||
operation,
|
||||
resource_url_method,
|
||||
resource_plural
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private def define_operation(
|
||||
resource,
|
||||
operation,
|
||||
resource_url_method,
|
||||
resource_plural
|
||||
)
|
||||
case operation
|
||||
when :create
|
||||
define_singleton_method(:"create_#{resource}") \
|
||||
do |id, params = {}, opts = {}|
|
||||
url = send(resource_url_method, id)
|
||||
resp, opts = execute_resource_request(:post, url, params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
when :retrieve
|
||||
define_singleton_method(:"retrieve_#{resource}") \
|
||||
do |id, nested_id, opts = {}|
|
||||
url = send(resource_url_method, id, nested_id)
|
||||
resp, opts = execute_resource_request(:get, url, {}, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
when :update
|
||||
define_singleton_method(:"update_#{resource}") \
|
||||
do |id, nested_id, params = {}, opts = {}|
|
||||
url = send(resource_url_method, id, nested_id)
|
||||
resp, opts = execute_resource_request(:post, url, params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
when :delete
|
||||
define_singleton_method(:"delete_#{resource}") \
|
||||
do |id, nested_id, params = {}, opts = {}|
|
||||
url = send(resource_url_method, id, nested_id)
|
||||
resp, opts = execute_resource_request(:delete, url, params,
|
||||
opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
when :list
|
||||
define_singleton_method(:"list_#{resource_plural}") \
|
||||
do |id, params = {}, opts = {}|
|
||||
url = send(resource_url_method, id)
|
||||
resp, opts = execute_resource_request(:get, url, params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Unknown operation: #{operation.inspect}"
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: send(resource_url_method, id),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
when :retrieve
|
||||
define_singleton_method(:"retrieve_#{resource}") \
|
||||
do |id, nested_id, opts = {}|
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: send(resource_url_method, id, nested_id),
|
||||
params: {},
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
when :update
|
||||
define_singleton_method(:"update_#{resource}") \
|
||||
do |id, nested_id, params = {}, opts = {}|
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: send(resource_url_method, id, nested_id),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
when :delete
|
||||
define_singleton_method(:"delete_#{resource}") \
|
||||
do |id, nested_id, params = {}, opts = {}|
|
||||
request_stripe_object(
|
||||
method: :delete,
|
||||
path: send(resource_url_method, id, nested_id),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
when :list
|
||||
define_singleton_method(:"list_#{resource_plural}") \
|
||||
do |id, params = {}, opts = {}|
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: send(resource_url_method, id),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Unknown operation: #{operation.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,6 +24,11 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
private def request_stripe_object(method:, path:, params:, opts: {})
|
||||
resp, opts = execute_resource_request(method, path, params, opts)
|
||||
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
|
||||
end
|
||||
|
||||
private def execute_resource_request_internal(client_request_method_sym,
|
||||
method, url,
|
||||
params, opts,
|
||||
@ -122,6 +127,11 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
private def request_stripe_object(method:, path:, params:, opts: {})
|
||||
resp, opts = execute_resource_request(method, path, params, opts)
|
||||
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
|
||||
end
|
||||
|
||||
# See notes on `alias` above.
|
||||
alias request execute_resource_request
|
||||
end
|
||||
|
@ -24,9 +24,12 @@ module Stripe
|
||||
end
|
||||
end
|
||||
|
||||
resp, opts = execute_resource_request(:post, "#{resource_url}/#{id}",
|
||||
params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: "#{resource_url}/#{id}",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,15 +4,12 @@ module Stripe
|
||||
module APIOperations
|
||||
module Search
|
||||
def _search(search_url, filters = {}, opts = {})
|
||||
opts = Util.normalize_opts(opts)
|
||||
|
||||
resp, opts = execute_resource_request(:get, search_url, filters, opts)
|
||||
obj = SearchResultObject.construct_from(resp.data, opts)
|
||||
|
||||
# set filters so that we can fetch the same limit and query
|
||||
# when accessing the next page
|
||||
obj.filters = filters.dup
|
||||
obj
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: search_url,
|
||||
params: filters,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -97,7 +97,7 @@ module Stripe
|
||||
if Util.object_name_matches_class?(resp.data[:object], self.class)
|
||||
initialize_from(resp.data, opts)
|
||||
else
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,23 +37,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.persons(account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/accounts/%<account>s/persons", { account: CGI.escape(account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/accounts/%<account>s/persons", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.reject(account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/accounts/%<account>s/reject", { account: CGI.escape(account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/accounts/%<account>s/reject", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
save_nested_resource :external_account
|
||||
|
@ -10,23 +10,21 @@ module Stripe
|
||||
OBJECT_NAME = "apps.secret"
|
||||
|
||||
def self.delete_where(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
"/v1/apps/secrets/delete",
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: "/v1/apps/secrets/delete",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.find(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
"/v1/apps/secrets/find",
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: "/v1/apps/secrets/find",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,13 +20,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.capture(charge, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/charges/%<charge>s/capture", { charge: CGI.escape(charge) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/charges/%<charge>s/capture", { charge: CGI.escape(charge) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.search(params = {}, opts = {})
|
||||
|
@ -22,13 +22,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.expire(session, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/checkout/sessions/%<session>s/expire", { session: CGI.escape(session) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/checkout/sessions/%<session>s/expire", { session: CGI.escape(session) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,23 +19,30 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.void_credit_note(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/credit_notes/%<id>s/void", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/credit_notes/%<id>s/void", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.preview(params, opts = {})
|
||||
resp, opts = execute_resource_request(:get, resource_url + "/preview", params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url + "/preview",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.list_preview_line_items(params, opts = {})
|
||||
resp, opts = execute_resource_request(:get, resource_url + "/preview/lines", params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url + "/preview/lines",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -45,23 +45,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.create_funding_instructions(customer, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/customers/%<customer>s/funding_instructions", { customer: CGI.escape(customer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/customers/%<customer>s/funding_instructions", { customer: CGI.escape(customer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.list_payment_methods(customer, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/customers/%<customer>s/payment_methods", { customer: CGI.escape(customer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/customers/%<customer>s/payment_methods", { customer: CGI.escape(customer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.retrieve_payment_method(
|
||||
@ -70,13 +68,12 @@ module Stripe
|
||||
params = {},
|
||||
opts = {}
|
||||
)
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/customers/%<customer>s/payment_methods/%<payment_method>s", { customer: CGI.escape(customer), payment_method: CGI.escape(payment_method) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/customers/%<customer>s/payment_methods/%<payment_method>s", { customer: CGI.escape(customer), payment_method: CGI.escape(payment_method) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
custom_method :delete_discount, http_verb: :delete, http_path: "discount"
|
||||
@ -97,8 +94,11 @@ module Stripe
|
||||
# so you must call `refresh` on it to get a new version with the
|
||||
# discount removed.
|
||||
def delete_discount
|
||||
resp, opts = execute_resource_request(:delete, resource_url + "/discount")
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :delete,
|
||||
path: resource_url + "/discount",
|
||||
params: {}
|
||||
)
|
||||
end
|
||||
|
||||
def self.search(params = {}, opts = {})
|
||||
@ -120,13 +120,12 @@ module Stripe
|
||||
if !opts_or_unused_nested_id.nil? && opts_or_unused_nested_id.class == Hash && opts.empty?
|
||||
opts = opts_or_unused_nested_id
|
||||
end
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
|
||||
{},
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
|
||||
params: {},
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.update_cash_balance(
|
||||
@ -140,13 +139,12 @@ module Stripe
|
||||
raise ArgumentError, "update_cash_balance requires the second argument always be nil for legacy reasons."
|
||||
end
|
||||
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,13 +18,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.close(dispute, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/disputes/%<dispute>s/close", { dispute: CGI.escape(dispute) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/disputes/%<dispute>s/close", { dispute: CGI.escape(dispute) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -36,33 +36,30 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.disconnect(account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/financial_connections/accounts/%<account>s/disconnect", { account: CGI.escape(account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/disconnect", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.list_owners(account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/financial_connections/accounts/%<account>s/owners", { account: CGI.escape(account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/owners", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.refresh_account(account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/financial_connections/accounts/%<account>s/refresh", { account: CGI.escape(account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/refresh", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -29,23 +29,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(session, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/identity/verification_sessions/%<session>s/cancel", { session: CGI.escape(session) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/identity/verification_sessions/%<session>s/cancel", { session: CGI.escape(session) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.redact(session, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/identity/verification_sessions/%<session>s/redact", { session: CGI.escape(session) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/identity/verification_sessions/%<session>s/redact", { session: CGI.escape(session) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -57,63 +57,66 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.finalize_invoice(invoice, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/invoices/%<invoice>s/finalize", { invoice: CGI.escape(invoice) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/invoices/%<invoice>s/finalize", { invoice: CGI.escape(invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.mark_uncollectible(invoice, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/invoices/%<invoice>s/mark_uncollectible", { invoice: CGI.escape(invoice) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/invoices/%<invoice>s/mark_uncollectible", { invoice: CGI.escape(invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.pay(invoice, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/invoices/%<invoice>s/pay", { invoice: CGI.escape(invoice) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/invoices/%<invoice>s/pay", { invoice: CGI.escape(invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.send_invoice(invoice, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/invoices/%<invoice>s/send", { invoice: CGI.escape(invoice) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/invoices/%<invoice>s/send", { invoice: CGI.escape(invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.void_invoice(invoice, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/invoices/%<invoice>s/void", { invoice: CGI.escape(invoice) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/invoices/%<invoice>s/void", { invoice: CGI.escape(invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.upcoming(params, opts = {})
|
||||
resp, opts = execute_resource_request(:get, resource_url + "/upcoming", params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url + "/upcoming",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.list_upcoming_line_items(params, opts = {})
|
||||
resp, opts = execute_resource_request(:get, resource_url + "/upcoming/lines", params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url + "/upcoming/lines",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.search(params = {}, opts = {})
|
||||
|
@ -28,23 +28,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.approve(authorization, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/issuing/authorizations/%<authorization>s/approve", { authorization: CGI.escape(authorization) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/issuing/authorizations/%<authorization>s/approve", { authorization: CGI.escape(authorization) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.decline(authorization, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/issuing/authorizations/%<authorization>s/decline", { authorization: CGI.escape(authorization) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/issuing/authorizations/%<authorization>s/decline", { authorization: CGI.escape(authorization) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,13 +20,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.details(card, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/issuing/cards/%<card>s/details", { card: CGI.escape(card) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/issuing/cards/%<card>s/details", { card: CGI.escape(card) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -20,13 +20,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.submit(dispute, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/issuing/disputes/%<dispute>s/submit", { dispute: CGI.escape(dispute) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/issuing/disputes/%<dispute>s/submit", { dispute: CGI.escape(dispute) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,43 +46,39 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/orders/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.list_line_items(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/orders/%<id>s/line_items", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/orders/%<id>s/line_items", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.reopen(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/orders/%<id>s/reopen", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/reopen", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.submit(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/orders/%<id>s/submit", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/submit", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -65,63 +65,57 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.apply_customer_balance(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_intents/%<intent>s/apply_customer_balance", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_intents/%<intent>s/apply_customer_balance", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.cancel(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_intents/%<intent>s/cancel", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_intents/%<intent>s/cancel", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.capture(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_intents/%<intent>s/capture", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_intents/%<intent>s/capture", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.confirm(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_intents/%<intent>s/confirm", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_intents/%<intent>s/confirm", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.increment_authorization(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_intents/%<intent>s/increment_authorization", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_intents/%<intent>s/increment_authorization", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.verify_microdeposits(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.search(params = {}, opts = {})
|
||||
|
@ -19,13 +19,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.list_line_items(payment_link, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/payment_links/%<payment_link>s/line_items", { payment_link: CGI.escape(payment_link) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/payment_links/%<payment_link>s/line_items", { payment_link: CGI.escape(payment_link) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -28,23 +28,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.attach(payment_method, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_methods/%<payment_method>s/attach", { payment_method: CGI.escape(payment_method) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_methods/%<payment_method>s/attach", { payment_method: CGI.escape(payment_method) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.detach(payment_method, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payment_methods/%<payment_method>s/detach", { payment_method: CGI.escape(payment_method) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payment_methods/%<payment_method>s/detach", { payment_method: CGI.escape(payment_method) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -28,23 +28,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(payout, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payouts/%<payout>s/cancel", { payout: CGI.escape(payout) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payouts/%<payout>s/cancel", { payout: CGI.escape(payout) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.reverse(payout, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/payouts/%<payout>s/reverse", { payout: CGI.escape(payout) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/payouts/%<payout>s/reverse", { payout: CGI.escape(payout) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -55,53 +55,48 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.accept(quote, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/quotes/%<quote>s/accept", { quote: CGI.escape(quote) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/accept", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.cancel(quote, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/quotes/%<quote>s/cancel", { quote: CGI.escape(quote) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/cancel", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.finalize_quote(quote, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/quotes/%<quote>s/finalize", { quote: CGI.escape(quote) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/finalize", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.list_computed_upfront_line_items(quote, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/quotes/%<quote>s/computed_upfront_line_items", { quote: CGI.escape(quote) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/computed_upfront_line_items", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.list_line_items(quote, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/quotes/%<quote>s/line_items", { quote: CGI.escape(quote) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/line_items", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def pdf(params = {}, opts = {}, &read_body_chunk_block)
|
||||
|
@ -19,13 +19,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(refund, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/refunds/%<refund>s/cancel", { refund: CGI.escape(refund) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/refunds/%<refund>s/cancel", { refund: CGI.escape(refund) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def test_helpers
|
||||
@ -36,13 +35,12 @@ module Stripe
|
||||
RESOURCE_CLASS = Refund
|
||||
|
||||
def self.expire(refund, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/refunds/%<refund>s/expire", { refund: CGI.escape(refund) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/refunds/%<refund>s/expire", { refund: CGI.escape(refund) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def expire(params = {}, opts = {})
|
||||
|
@ -17,13 +17,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.approve(review, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/reviews/%<review>s/approve", { review: CGI.escape(review) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/reviews/%<review>s/approve", { review: CGI.escape(review) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -37,33 +37,30 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/setup_intents/%<intent>s/cancel", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/setup_intents/%<intent>s/cancel", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.confirm(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/setup_intents/%<intent>s/confirm", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/setup_intents/%<intent>s/confirm", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.verify_microdeposits(intent, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/setup_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(intent) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/setup_intents/%<intent>s/verify_microdeposits", { intent: CGI.escape(intent) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -22,13 +22,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.verify(source, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/sources/%<source>s/verify", { source: CGI.escape(source) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/sources/%<source>s/verify", { source: CGI.escape(source) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def detach(params = {}, opts = {})
|
||||
@ -45,9 +44,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def source_transactions(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(:get, resource_url + "/source_transactions", params,
|
||||
opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url + "/source_transactions",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
extend Gem::Deprecate
|
||||
deprecate :source_transactions, :"Source.list_source_transactions", 2020, 1
|
||||
|
@ -21,13 +21,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.delete_discount(subscription_exposed_id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:delete,
|
||||
format("/v1/subscriptions/%<subscription_exposed_id>s/discount", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :delete,
|
||||
path: format("/v1/subscriptions/%<subscription_exposed_id>s/discount", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
save_nested_resource :source
|
||||
|
@ -17,8 +17,12 @@ module Stripe
|
||||
resource_plural: "usage_record_summaries"
|
||||
|
||||
def usage_record_summaries(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(:get, resource_url + "/usage_record_summaries", params, opts)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: resource_url + "/usage_record_summaries",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
extend Gem::Deprecate
|
||||
deprecate :usage_record_summaries, :"SubscriptionItem.list_usage_record_summaries", 2020, 1
|
||||
|
@ -28,23 +28,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(schedule, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/subscription_schedules/%<schedule>s/cancel", { schedule: CGI.escape(schedule) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/subscription_schedules/%<schedule>s/cancel", { schedule: CGI.escape(schedule) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.release(schedule, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/subscription_schedules/%<schedule>s/release", { schedule: CGI.escape(schedule) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/subscription_schedules/%<schedule>s/release", { schedule: CGI.escape(schedule) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -48,43 +48,39 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel_action(reader, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/terminal/readers/%<reader>s/cancel_action", { reader: CGI.escape(reader) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/cancel_action", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.process_payment_intent(reader, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/terminal/readers/%<reader>s/process_payment_intent", { reader: CGI.escape(reader) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/process_payment_intent", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.process_setup_intent(reader, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/terminal/readers/%<reader>s/process_setup_intent", { reader: CGI.escape(reader) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/process_setup_intent", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.set_reader_display(reader, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/terminal/readers/%<reader>s/set_reader_display", { reader: CGI.escape(reader) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/set_reader_display", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def test_helpers
|
||||
@ -95,13 +91,12 @@ module Stripe
|
||||
RESOURCE_CLASS = Reader
|
||||
|
||||
def self.present_payment_method(reader, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/terminal/readers/%<reader>s/present_payment_method", { reader: CGI.escape(reader) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/terminal/readers/%<reader>s/present_payment_method", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def present_payment_method(params = {}, opts = {})
|
||||
|
@ -20,13 +20,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.advance(test_clock, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/test_clocks/%<test_clock>s/advance", { test_clock: CGI.escape(test_clock) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/test_clocks/%<test_clock>s/advance", { test_clock: CGI.escape(test_clock) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,13 +19,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(topup, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/topups/%<topup>s/cancel", { topup: CGI.escape(topup) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/topups/%<topup>s/cancel", { topup: CGI.escape(topup) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -23,13 +23,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/transfers/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/transfers/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -29,23 +29,21 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.retrieve_features(financial_account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:get,
|
||||
format("/v1/treasury/financial_accounts/%<financial_account>s/features", { financial_account: CGI.escape(financial_account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/treasury/financial_accounts/%<financial_account>s/features", { financial_account: CGI.escape(financial_account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.update_features(financial_account, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/treasury/financial_accounts/%<financial_account>s/features", { financial_account: CGI.escape(financial_account) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/treasury/financial_accounts/%<financial_account>s/features", { financial_account: CGI.escape(financial_account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,13 +19,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(inbound_transfer, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/treasury/inbound_transfers/%<inbound_transfer>s/cancel", { inbound_transfer: CGI.escape(inbound_transfer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/treasury/inbound_transfers/%<inbound_transfer>s/cancel", { inbound_transfer: CGI.escape(inbound_transfer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def test_helpers
|
||||
@ -36,33 +35,30 @@ module Stripe
|
||||
RESOURCE_CLASS = InboundTransfer
|
||||
|
||||
def self.fail(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/fail", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/fail", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.return_inbound_transfer(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/return", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/return", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.succeed(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/succeed", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/inbound_transfers/%<id>s/succeed", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def fail(params = {}, opts = {})
|
||||
|
@ -19,13 +19,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/treasury/outbound_payments/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/treasury/outbound_payments/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def test_helpers
|
||||
@ -36,33 +35,30 @@ module Stripe
|
||||
RESOURCE_CLASS = OutboundPayment
|
||||
|
||||
def self.fail(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/outbound_payments/%<id>s/fail", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/fail", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.post(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/outbound_payments/%<id>s/post", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/post", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.return_outbound_payment(id, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/outbound_payments/%<id>s/return", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/outbound_payments/%<id>s/return", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def fail(params = {}, opts = {})
|
||||
|
@ -19,13 +19,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.cancel(outbound_transfer, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/treasury/outbound_transfers/%<outbound_transfer>s/cancel", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/treasury/outbound_transfers/%<outbound_transfer>s/cancel", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def test_helpers
|
||||
@ -36,23 +35,21 @@ module Stripe
|
||||
RESOURCE_CLASS = OutboundTransfer
|
||||
|
||||
def self.fail(outbound_transfer, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/outbound_transfers/%<outbound_transfer>s/fail", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/outbound_transfers/%<outbound_transfer>s/fail", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.post(outbound_transfer, params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/outbound_transfers/%<outbound_transfer>s/post", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/outbound_transfers/%<outbound_transfer>s/post", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def self.return_outbound_transfer(
|
||||
@ -60,13 +57,12 @@ module Stripe
|
||||
params = {},
|
||||
opts = {}
|
||||
)
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
format("/v1/test_helpers/treasury/outbound_transfers/%<outbound_transfer>s/return", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/treasury/outbound_transfers/%<outbound_transfer>s/return", { outbound_transfer: CGI.escape(outbound_transfer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def fail(params = {}, opts = {})
|
||||
|
@ -16,13 +16,12 @@ module Stripe
|
||||
RESOURCE_CLASS = ReceivedCredit
|
||||
|
||||
def self.create(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
"/v1/test_helpers/treasury/received_credits",
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: "/v1/test_helpers/treasury/received_credits",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,13 +16,12 @@ module Stripe
|
||||
RESOURCE_CLASS = ReceivedDebit
|
||||
|
||||
def self.create(params = {}, opts = {})
|
||||
resp, opts = execute_resource_request(
|
||||
:post,
|
||||
"/v1/test_helpers/treasury/received_debits",
|
||||
params,
|
||||
opts
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: "/v1/test_helpers/treasury/received_debits",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -90,10 +90,28 @@ module Stripe
|
||||
opts
|
||||
)
|
||||
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
Util.convert_to_stripe_object_with_params(resp.data, params, opts)
|
||||
end
|
||||
end
|
||||
|
||||
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
|
||||
# array of +StripeObject+s. These new objects will be created as a concrete
|
||||
# type as dictated by their `object` field (e.g. an `object` value of
|
||||
# `charge` would create an instance of +Charge+), but if `object` is not
|
||||
# present or of an unknown type, the newly created instance will fall back
|
||||
# to being a +StripeObject+.
|
||||
#
|
||||
# ==== Attributes
|
||||
#
|
||||
# * +data+ - Hash of fields and values to be converted into a StripeObject.
|
||||
# * +params+ - Params for +StripeObject+ like filters used in search that
|
||||
# will be reused on subsequent API calls.
|
||||
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
|
||||
# on subsequent API calls.
|
||||
def self.convert_to_stripe_object(data, opts = {})
|
||||
convert_to_stripe_object_with_params(data, {}, opts)
|
||||
end
|
||||
|
||||
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
|
||||
# array of +StripeObject+s. These new objects will be created as a concrete
|
||||
# type as dictated by their `object` field (e.g. an `object` value of
|
||||
@ -106,7 +124,7 @@ module Stripe
|
||||
# * +data+ - Hash of fields and values to be converted into a StripeObject.
|
||||
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
|
||||
# on subsequent API calls.
|
||||
def self.convert_to_stripe_object(data, opts = {})
|
||||
def self.convert_to_stripe_object_with_params(data, params, opts = {})
|
||||
opts = normalize_opts(opts)
|
||||
|
||||
case data
|
||||
@ -115,8 +133,16 @@ module Stripe
|
||||
when Hash
|
||||
# Try converting to a known object class. If none available, fall back
|
||||
# to generic StripeObject
|
||||
object_classes.fetch(data[:object], StripeObject)
|
||||
.construct_from(data, opts)
|
||||
obj = object_classes.fetch(data[:object], StripeObject)
|
||||
.construct_from(data, opts)
|
||||
|
||||
# set filters so that we can fetch the same limit, expansions, and
|
||||
# predicates when accessing the next and previous pages
|
||||
if obj && (obj.is_a?(SearchResultObject) || obj.is_a?(ListObject))
|
||||
obj.filters = params.dup
|
||||
end
|
||||
|
||||
obj
|
||||
else
|
||||
data
|
||||
end
|
||||
|
@ -187,13 +187,15 @@ module Stripe
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
||||
.with(query: { customer: "cus_123" })
|
||||
.to_return(body: JSON.generate(data: [charge_fixture],
|
||||
url: "/v1/charges"))
|
||||
url: "/v1/charges",
|
||||
object: "list"))
|
||||
charges = Stripe::Charge.list(customer: "cus_123")
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges")
|
||||
.with(query: { customer: "cus_123", created: "123" })
|
||||
.to_return(body: JSON.generate(data: [charge_fixture],
|
||||
url: "/v1/charges"))
|
||||
url: "/v1/charges",
|
||||
object: "list"))
|
||||
charges.list(created: 123)
|
||||
end
|
||||
|
||||
|
@ -51,7 +51,8 @@ module Stripe
|
||||
# used as a cursor to fetch the next page.
|
||||
list = TestListObject.construct_from(data: [{ id: 1 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
list.filters = { limit: 3 }
|
||||
|
||||
# The test will start with the synthetic list object above, and use it as
|
||||
@ -60,10 +61,12 @@ module Stripe
|
||||
# iteration stops.
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { starting_after: "1", limit: "3" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }, { id: 4 }], has_more: true, url: "/things"))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }, { id: 4 }], has_more: true, url: "/things",
|
||||
object: "list"))
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { starting_after: "4", limit: "3" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 5 }, { id: 6 }], has_more: false, url: "/things"))
|
||||
.to_return(body: JSON.generate(data: [{ id: 5 }, { id: 6 }], has_more: false, url: "/things",
|
||||
object: "list"))
|
||||
|
||||
assert_equal expected, list.auto_paging_each.to_a
|
||||
end
|
||||
@ -83,7 +86,8 @@ module Stripe
|
||||
# used as a cursor to fetch the next page.
|
||||
list = TestListObject.construct_from(data: [{ id: 6 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
|
||||
# We also add an `ending_before` filter on the list to simulate backwards
|
||||
# pagination.
|
||||
@ -95,10 +99,12 @@ module Stripe
|
||||
# iteration stops.
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { ending_before: "6", limit: "3" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 3 }, { id: 4 }, { id: 5 }], has_more: true, url: "/things"))
|
||||
.to_return(body: JSON.generate(data: [{ id: 3 }, { id: 4 }, { id: 5 }], has_more: true, url: "/things",
|
||||
object: "list"))
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { ending_before: "3", limit: "3" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 1 }, { id: 2 }], has_more: false, url: "/things"))
|
||||
.to_return(body: JSON.generate(data: [{ id: 1 }, { id: 2 }], has_more: false, url: "/things",
|
||||
object: "list"))
|
||||
|
||||
assert_equal expected, list.auto_paging_each.to_a
|
||||
end
|
||||
@ -113,10 +119,11 @@ module Stripe
|
||||
|
||||
list = TestListObject.construct_from(data: [{ id: 1 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { starting_after: "1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false, object: "list"))
|
||||
|
||||
actual = []
|
||||
list.auto_paging_each do |obj|
|
||||
@ -140,10 +147,11 @@ module Stripe
|
||||
should "fetch a next page through #next_page" do
|
||||
list = TestListObject.construct_from(data: [{ id: 1 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { starting_after: "1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false, object: "list"))
|
||||
next_list = list.next_page
|
||||
refute next_list.empty?
|
||||
end
|
||||
@ -151,11 +159,12 @@ module Stripe
|
||||
should "fetch a next page through #next_page and respect limit" do
|
||||
list = TestListObject.construct_from(data: [{ id: 1 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
list.filters = { expand: ["data.source"], limit: 3 }
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false, object: "list"))
|
||||
next_list = list.next_page
|
||||
assert_equal({ expand: ["data.source"], limit: 3, starting_after: 1 }, next_list.filters)
|
||||
end
|
||||
@ -163,7 +172,8 @@ module Stripe
|
||||
should "fetch an empty page through #next_page" do
|
||||
list = TestListObject.construct_from(data: [{ id: 1 }],
|
||||
has_more: false,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
next_list = list.next_page
|
||||
assert_equal Stripe::ListObject.empty_list, next_list
|
||||
end
|
||||
@ -175,10 +185,11 @@ module Stripe
|
||||
should "fetch a next page through #previous_page" do
|
||||
list = TestListObject.construct_from(data: [{ id: 2 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { ending_before: "2" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 1 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 1 }], has_more: false, object: "list"))
|
||||
next_list = list.previous_page
|
||||
refute next_list.empty?
|
||||
end
|
||||
@ -186,11 +197,12 @@ module Stripe
|
||||
should "fetch a next page through #previous_page and respect limit" do
|
||||
list = TestListObject.construct_from(data: [{ id: 2 }],
|
||||
has_more: true,
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "list")
|
||||
list.filters = { expand: ["data.source"], limit: 3 }
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 1 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 1 }], has_more: false, object: "list"))
|
||||
next_list = list.previous_page
|
||||
assert_equal({ ending_before: 2, expand: ["data.source"], limit: 3 }, next_list.filters)
|
||||
end
|
||||
|
@ -38,7 +38,8 @@ module Stripe
|
||||
list = TestSearchResultObject.construct_from({ data: [{ id: 1 }],
|
||||
has_more: true,
|
||||
next_page: "next_page_token_1",
|
||||
url: "/things", })
|
||||
url: "/things",
|
||||
object: "search_result", })
|
||||
list.filters = { limit: 3 }
|
||||
|
||||
# The test will start with the synthetic search result object above, and uses the
|
||||
@ -47,10 +48,10 @@ module Stripe
|
||||
# iteration stops.
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { limit: 3, page: "next_page_token_1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }, { id: 4 }], has_more: true, url: "/things", next_page: "next_page_token_2"))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }, { id: 4 }], has_more: true, url: "/things", next_page: "next_page_token_2", object: "search_result"))
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { limit: 3, page: "next_page_token_2" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 5 }, { id: 6 }], has_more: false, url: "/things", next_page: nil))
|
||||
.to_return(body: JSON.generate(data: [{ id: 5 }, { id: 6 }], has_more: false, url: "/things", next_page: nil, object: "search_result"))
|
||||
|
||||
assert_equal arr, list.auto_paging_each.to_a.map(&:to_hash)
|
||||
end
|
||||
@ -70,7 +71,7 @@ module Stripe
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { page: "next_page_token_1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }, { id: 3 }], has_more: false, object: "search_result"))
|
||||
|
||||
actual = []
|
||||
list.auto_paging_each do |obj|
|
||||
@ -98,7 +99,7 @@ module Stripe
|
||||
url: "/things")
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { page: "next_page_token_1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false, object: "search_result"))
|
||||
next_list = list.next_search_result_page
|
||||
refute next_list.empty?
|
||||
assert_equal [{ id: 2 }], next_list.auto_paging_each.to_a.map(&:to_hash)
|
||||
@ -108,11 +109,12 @@ module Stripe
|
||||
list = TestSearchResultObject.construct_from(data: [{ id: 1 }],
|
||||
has_more: true,
|
||||
next_page: "next_page_token_1",
|
||||
url: "/things")
|
||||
url: "/things",
|
||||
object: "search_result")
|
||||
list.filters = { limit: 3 }
|
||||
stub_request(:get, "#{Stripe.api_base}/things")
|
||||
.with(query: { "limit": 3, page: "next_page_token_1" })
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false))
|
||||
.to_return(body: JSON.generate(data: [{ id: 2 }], has_more: false, object: "search_result"))
|
||||
next_list = list.next_search_result_page
|
||||
assert_equal({ limit: 3, page: "next_page_token_1" }, next_list.filters)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user