Skip to content

Commit

Permalink
Generate stripe-ruby with breaking changes (#1102)
Browse files Browse the repository at this point in the history
* Generate stripe-ruby with breaking changes

* Remove RecipientTest

* Remove AlipayAccount tests

* Regenerate files

* Delete outdated tests

* Fix more tests

* Fix more tests

* Fix example test manually
  • Loading branch information
kamil-stripe authored Jul 27, 2022
1 parent c408baf commit 5a4d6fc
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 373 deletions.
7 changes: 0 additions & 7 deletions lib/stripe/object_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def self.object_names_to_classes
# business objects
Account::OBJECT_NAME => Account,
AccountLink::OBJECT_NAME => AccountLink,
AlipayAccount::OBJECT_NAME => AlipayAccount,
ApplePayDomain::OBJECT_NAME => ApplePayDomain,
ApplicationFee::OBJECT_NAME => ApplicationFee,
ApplicationFeeRefund::OBJECT_NAME => ApplicationFeeRefund,
Expand All @@ -24,8 +23,6 @@ def self.object_names_to_classes
BankAccount::OBJECT_NAME => BankAccount,
BillingPortal::Configuration::OBJECT_NAME => BillingPortal::Configuration,
BillingPortal::Session::OBJECT_NAME => BillingPortal::Session,
BitcoinReceiver::OBJECT_NAME => BitcoinReceiver,
BitcoinTransaction::OBJECT_NAME => BitcoinTransaction,
Capability::OBJECT_NAME => Capability,
Card::OBJECT_NAME => Card,
CashBalance::OBJECT_NAME => CashBalance,
Expand Down Expand Up @@ -58,7 +55,6 @@ def self.object_names_to_classes
InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
Issuing::Authorization::OBJECT_NAME => Issuing::Authorization,
Issuing::Card::OBJECT_NAME => Issuing::Card,
Issuing::CardDetails::OBJECT_NAME => Issuing::CardDetails,
Issuing::Cardholder::OBJECT_NAME => Issuing::Cardholder,
Issuing::Dispute::OBJECT_NAME => Issuing::Dispute,
Issuing::Transaction::OBJECT_NAME => Issuing::Transaction,
Expand All @@ -79,8 +75,6 @@ def self.object_names_to_classes
Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
Radar::ValueList::OBJECT_NAME => Radar::ValueList,
Radar::ValueListItem::OBJECT_NAME => Radar::ValueListItem,
Recipient::OBJECT_NAME => Recipient,
RecipientTransfer::OBJECT_NAME => RecipientTransfer,
Refund::OBJECT_NAME => Refund,
Reporting::ReportRun::OBJECT_NAME => Reporting::ReportRun,
Reporting::ReportType::OBJECT_NAME => Reporting::ReportType,
Expand All @@ -104,7 +98,6 @@ def self.object_names_to_classes
Terminal::Location::OBJECT_NAME => Terminal::Location,
Terminal::Reader::OBJECT_NAME => Terminal::Reader,
TestHelpers::TestClock::OBJECT_NAME => TestHelpers::TestClock,
ThreeDSecure::OBJECT_NAME => ThreeDSecure,
Token::OBJECT_NAME => Token,
Topup::OBJECT_NAME => Topup,
Transfer::OBJECT_NAME => Transfer,
Expand Down
7 changes: 0 additions & 7 deletions lib/stripe/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

require "stripe/resources/account"
require "stripe/resources/account_link"
require "stripe/resources/alipay_account"
require "stripe/resources/apple_pay_domain"
require "stripe/resources/application_fee"
require "stripe/resources/application_fee_refund"
Expand All @@ -13,8 +12,6 @@
require "stripe/resources/bank_account"
require "stripe/resources/billing_portal/configuration"
require "stripe/resources/billing_portal/session"
require "stripe/resources/bitcoin_receiver"
require "stripe/resources/bitcoin_transaction"
require "stripe/resources/capability"
require "stripe/resources/card"
require "stripe/resources/cash_balance"
Expand Down Expand Up @@ -45,7 +42,6 @@
require "stripe/resources/invoice_line_item"
require "stripe/resources/issuing/authorization"
require "stripe/resources/issuing/card"
require "stripe/resources/issuing/card_details"
require "stripe/resources/issuing/cardholder"
require "stripe/resources/issuing/dispute"
require "stripe/resources/issuing/transaction"
Expand All @@ -66,8 +62,6 @@
require "stripe/resources/radar/early_fraud_warning"
require "stripe/resources/radar/value_list"
require "stripe/resources/radar/value_list_item"
require "stripe/resources/recipient"
require "stripe/resources/recipient_transfer"
require "stripe/resources/refund"
require "stripe/resources/reporting/report_run"
require "stripe/resources/reporting/report_type"
Expand All @@ -91,7 +85,6 @@
require "stripe/resources/terminal/location"
require "stripe/resources/terminal/reader"
require "stripe/resources/test_helpers/test_clock"
require "stripe/resources/three_d_secure"
require "stripe/resources/token"
require "stripe/resources/topup"
require "stripe/resources/transfer"
Expand Down
24 changes: 0 additions & 24 deletions lib/stripe/resources/bitcoin_receiver.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/stripe/resources/bitcoin_transaction.rb

This file was deleted.

4 changes: 1 addition & 3 deletions lib/stripe/resources/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class Card < APIResource
OBJECT_NAME = "card"

def resource_url
if respond_to?(:recipient) && !recipient.nil? && !recipient.empty?
"#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
elsif respond_to?(:customer) && !customer.nil? && !customer.empty?
if respond_to?(:customer) && !customer.nil? && !customer.empty?
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
elsif respond_to?(:account) && !account.nil? && !account.empty?
"#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
Expand Down
21 changes: 18 additions & 3 deletions lib/stripe/resources/checkout/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ module Checkout
class Session < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
extend Stripe::APIOperations::NestedResource

OBJECT_NAME = "checkout.session"

nested_resource_class_methods :line_item, operations: %i[list]

def expire(params = {}, opts = {})
request_stripe_object(
method: :post,
Expand All @@ -21,6 +18,15 @@ def expire(params = {}, opts = {})
)
end

def list_line_items(params = {}, opts = {})
request_stripe_object(
method: :get,
path: format("/v1/checkout/sessions/%<session>s/line_items", { session: CGI.escape(self["id"]) }),
params: params,
opts: opts
)
end

def self.expire(session, params = {}, opts = {})
request_stripe_object(
method: :post,
Expand All @@ -29,6 +35,15 @@ def self.expire(session, params = {}, opts = {})
opts: opts
)
end

def self.list_line_items(session, params = {}, opts = {})
request_stripe_object(
method: :get,
path: format("/v1/checkout/sessions/%<session>s/line_items", { session: CGI.escape(session) }),
params: params,
opts: opts
)
end
end
end
end
56 changes: 20 additions & 36 deletions lib/stripe/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def create_funding_instructions(params = {}, opts = {})
)
end

def delete_discount(params = {}, opts = {})
request_stripe_object(
method: :delete,
path: format("/v1/customers/%<customer>s/discount", { customer: CGI.escape(self["id"]) }),
params: params,
opts: opts
)
end

def list_payment_methods(params = {}, opts = {})
request_stripe_object(
method: :get,
Expand Down Expand Up @@ -53,6 +62,15 @@ def self.create_funding_instructions(customer, params = {}, opts = {})
)
end

def self.delete_discount(customer, params = {}, opts = {})
request_stripe_object(
method: :delete,
path: format("/v1/customers/%<customer>s/discount", { customer: CGI.escape(customer) }),
params: params,
opts: opts
)
end

def self.list_payment_methods(customer, params = {}, opts = {})
request_stripe_object(
method: :get,
Expand Down Expand Up @@ -85,20 +103,6 @@ def self.retrieve_payment_method(
class << self
alias detach_source delete_source
end
custom_method :delete_discount, http_verb: :delete, http_path: "discount"

# Deletes a discount associated with the customer.
#
# Returns the deleted discount. The customer object is not updated,
# so you must call `refresh` on it to get a new version with the
# discount removed.
def delete_discount
request_stripe_object(
method: :delete,
path: resource_url + "/discount",
params: {}
)
end

def self.search(params = {}, opts = {})
_search("/v1/customers/search", params, opts)
Expand All @@ -108,17 +112,7 @@ def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end

def self.retrieve_cash_balance(
customer,
opts_or_unused_nested_id = nil,
opts = {}
)
# Support two call patterns for backwards compatibility.
# 1. Legacy: (nil unused nested_id, opts)
# 2. Fixed pattern: (opts)
if !opts_or_unused_nested_id.nil? && opts_or_unused_nested_id.class == Hash && opts.empty?
opts = opts_or_unused_nested_id
end
def self.retrieve_cash_balance(customer, opts = {})
request_stripe_object(
method: :get,
path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
Expand All @@ -127,17 +121,7 @@ def self.retrieve_cash_balance(
)
end

def self.update_cash_balance(
customer,
unused_nested_id = nil,
params = {},
opts = {}
)
# Do not allow passing in a hash as the second argument, as we require a nil for compatibility reasons. We cannot differentiate from a legacy pattern (nil, params) and a modern pattern (nil for params, opts).
if !unused_nested_id.nil? && unused_nested_id.class == Hash
raise ArgumentError, "update_cash_balance requires the second argument always be nil for legacy reasons."
end

def self.update_cash_balance(customer, params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/customers/%<customer>s/cash_balance", { customer: CGI.escape(customer) }),
Expand Down
18 changes: 0 additions & 18 deletions lib/stripe/resources/issuing/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ class Card < APIResource

OBJECT_NAME = "issuing.card"

def details(params = {}, opts = {})
request_stripe_object(
method: :get,
path: format("/v1/issuing/cards/%<card>s/details", { card: CGI.escape(self["id"]) }),
params: params,
opts: opts
)
end

def self.details(card, params = {}, opts = {})
request_stripe_object(
method: :get,
path: format("/v1/issuing/cards/%<card>s/details", { card: CGI.escape(card) }),
params: params,
opts: opts
)
end

def test_helpers
TestHelpers.new(self)
end
Expand Down
10 changes: 0 additions & 10 deletions lib/stripe/resources/issuing/card_details.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/stripe/resources/recipient.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/stripe/resources/reporting/report_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module Stripe
module Reporting
class ReportType < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List

OBJECT_NAME = "reporting.report_type"
Expand Down
Loading

0 comments on commit 5a4d6fc

Please sign in to comment.