From 0d465ce91c6fc292e5283133278b0d067c95cf1b Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 29 May 2019 18:16:29 -0400 Subject: [PATCH] More reordering and hopefully-safe formatting changes --- lib/stripe/account.rb | 25 +++++++++++++------------ lib/stripe/bank_account.rb | 6 ++---- lib/stripe/customer.rb | 10 +++++----- lib/stripe/file.rb | 5 ++++- lib/stripe/source.rb | 10 +++++----- lib/stripe/subscription.rb | 4 ++-- lib/stripe/subscription_schedule.rb | 3 +-- lib/stripe/transfer.rb | 6 +++--- 8 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/stripe/account.rb b/lib/stripe/account.rb index 12ea5c2bd..b28cb0a6f 100644 --- a/lib/stripe/account.rb +++ b/lib/stripe/account.rb @@ -4,8 +4,8 @@ module Stripe class Account < APIResource extend Gem::Deprecate extend Stripe::APIOperations::Create - extend Stripe::APIOperations::List include Stripe::APIOperations::Delete + extend Stripe::APIOperations::List include Stripe::APIOperations::Save extend Stripe::APIOperations::NestedResource @@ -13,17 +13,23 @@ class Account < APIResource custom_method :reject, http_verb: :post - save_nested_resource :external_account nested_resource_class_methods :capability, operations: %i[retrieve update list], resource_plural: "capabilities" + nested_resource_class_methods :person, + operations: %i[create retrieve update delete list] + + def reject(params = {}, opts = {}) + resp, opts = request(:post, resource_url + "/reject", params, opts) + initialize_from(resp.data, opts) + end + + save_nested_resource :external_account + nested_resource_class_methods :external_account, - operations: %i[create retrieve update delete - list] + operations: %i[create retrieve update delete list] + nested_resource_class_methods :login_link, operations: %i[create] - nested_resource_class_methods :person, - operations: %i[create retrieve update delete - list] # This method is deprecated. Please use `#external_account=` instead. save_nested_resource :bank_account @@ -66,11 +72,6 @@ def persons(params = {}, opts = {}) # already has a capabilities property which is a hash and not the sub-list # of capabilities. - def reject(params = {}, opts = {}) - resp, opts = request(:post, resource_url + "/reject", params, opts) - initialize_from(resp.data, opts) - end - # Somewhat unfortunately, we attempt to do a special encoding trick when # serializing `additional_owners` under an account: when updating a value, # we actually send the update parameters up as an integer-indexed hash diff --git a/lib/stripe/bank_account.rb b/lib/stripe/bank_account.rb index 666cf43be..833f13838 100644 --- a/lib/stripe/bank_account.rb +++ b/lib/stripe/bank_account.rb @@ -15,11 +15,9 @@ def verify(params = {}, opts = {}) def resource_url if respond_to?(:customer) - "#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \ - "/#{CGI.escape(id)}" + "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}" elsif respond_to?(:account) - "#{Account.resource_url}/#{CGI.escape(account)}/external_accounts" \ - "/#{CGI.escape(id)}" + "#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}" end end diff --git a/lib/stripe/customer.rb b/lib/stripe/customer.rb index d01150cd6..3b703829e 100644 --- a/lib/stripe/customer.rb +++ b/lib/stripe/customer.rb @@ -4,20 +4,20 @@ module Stripe class Customer < APIResource extend Stripe::APIOperations::Create include Stripe::APIOperations::Delete - include Stripe::APIOperations::Save extend Stripe::APIOperations::List + include Stripe::APIOperations::Save extend Stripe::APIOperations::NestedResource OBJECT_NAME = "customer".freeze + nested_resource_class_methods :tax_id, + operations: %i[create retrieve delete list] + custom_method :delete_discount, http_verb: :delete, http_path: "discount" save_nested_resource :source nested_resource_class_methods :source, - operations: %i[create retrieve update delete - list] - nested_resource_class_methods :tax_id, - operations: %i[create retrieve delete list] + operations: %i[create retrieve update delete list] # The API request for deleting a card or bank account and for detaching a # source object are the same. diff --git a/lib/stripe/file.rb b/lib/stripe/file.rb index c761f7d3a..5880da928 100644 --- a/lib/stripe/file.rb +++ b/lib/stripe/file.rb @@ -5,11 +5,12 @@ class File < APIResource extend Stripe::APIOperations::Create extend Stripe::APIOperations::List + OBJECT_NAME = "file".freeze + # This resource can have two different object names. In latter API # versions, only `file` is used, but since stripe-ruby may be used with # any API version, we need to support deserializing the older # `file_upload` object into the same class. - OBJECT_NAME = "file".freeze OBJECT_NAME_ALT = "file_upload".freeze def self.resource_url @@ -35,7 +36,9 @@ def self.create(params = {}, opts = {}) super end end +end +module Stripe # For backwards compatibility, the `File` class is aliased to `FileUpload`. FileUpload = File end diff --git a/lib/stripe/source.rb b/lib/stripe/source.rb index e5c9bd6a6..ec897b87e 100644 --- a/lib/stripe/source.rb +++ b/lib/stripe/source.rb @@ -9,6 +9,11 @@ class Source < APIResource custom_method :verify, http_verb: :post + def verify(params = {}, opts = {}) + resp, opts = request(:post, resource_url + "/verify", params, opts) + initialize_from(resp.data, opts) + end + def detach(params = {}, opts = {}) if !respond_to?(:customer) || customer.nil? || customer.empty? raise NotImplementedError, @@ -33,10 +38,5 @@ def source_transactions(params = {}, opts = {}) opts) Util.convert_to_stripe_object(resp.data, opts) end - - def verify(params = {}, opts = {}) - resp, opts = request(:post, resource_url + "/verify", params, opts) - initialize_from(resp.data, opts) - end end end diff --git a/lib/stripe/subscription.rb b/lib/stripe/subscription.rb index 0b64f80aa..0d077d44f 100644 --- a/lib/stripe/subscription.rb +++ b/lib/stripe/subscription.rb @@ -2,10 +2,10 @@ module Stripe class Subscription < APIResource - extend Stripe::APIOperations::List extend Stripe::APIOperations::Create - include Stripe::APIOperations::Save include Stripe::APIOperations::Delete + extend Stripe::APIOperations::List + include Stripe::APIOperations::Save OBJECT_NAME = "subscription".freeze diff --git a/lib/stripe/subscription_schedule.rb b/lib/stripe/subscription_schedule.rb index f5b13b474..2c24e784d 100644 --- a/lib/stripe/subscription_schedule.rb +++ b/lib/stripe/subscription_schedule.rb @@ -12,8 +12,7 @@ class SubscriptionSchedule < APIResource custom_method :cancel, http_verb: :post custom_method :release, http_verb: :post - nested_resource_class_methods :revision, - operations: %i[retrieve list] + nested_resource_class_methods :revision, operations: %i[retrieve list] def cancel(params = {}, opts = {}) resp, opts = request(:post, resource_url + "/cancel", params, opts) diff --git a/lib/stripe/transfer.rb b/lib/stripe/transfer.rb index c1aec264c..3918a5cd4 100644 --- a/lib/stripe/transfer.rb +++ b/lib/stripe/transfer.rb @@ -14,9 +14,9 @@ class Transfer < APIResource nested_resource_class_methods :reversal, operations: %i[create retrieve update list] - def cancel - resp, api_key = request(:post, cancel_url) - initialize_from(resp.data, api_key) + def cancel(params = {}, opts = {}) + resp, opts = request(:post, resource_url + "/cancel", params, opts) + initialize_from(resp.data, opts) end def cancel_url