From 5a4d6fc7144937a6bb75422c2ff4aaa575d33b22 Mon Sep 17 00:00:00 2001 From: Kamil Pajdzik <99290280+kamil-stripe@users.noreply.github.com> Date: Wed, 27 Jul 2022 16:12:44 -0700 Subject: [PATCH] Generate stripe-ruby with breaking changes (#1102) * 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 --- lib/stripe/object_types.rb | 7 --- lib/stripe/resources.rb | 7 --- lib/stripe/resources/bitcoin_receiver.rb | 24 ------- lib/stripe/resources/bitcoin_transaction.rb | 16 ----- lib/stripe/resources/card.rb | 4 +- lib/stripe/resources/checkout/session.rb | 21 ++++++- lib/stripe/resources/customer.rb | 56 ++++++----------- lib/stripe/resources/issuing/card.rb | 18 ------ lib/stripe/resources/issuing/card_details.rb | 10 --- lib/stripe/resources/recipient.rb | 14 ----- lib/stripe/resources/reporting/report_type.rb | 1 - lib/stripe/resources/subscription.rb | 44 ++++++++++++- lib/stripe/resources/subscription_item.rb | 11 ---- lib/stripe/resources/three_d_secure.rb | 14 ----- lib/stripe/resources/transfer.rb | 18 ------ test/stripe/alipay_account_test.rb | 37 ----------- test/stripe/customer_test.rb | 26 ++------ test/stripe/generated_examples_test.rb | 26 +++++--- test/stripe/issuing/card_test.rb | 29 --------- test/stripe/recipient_test.rb | 62 ------------------- test/stripe/subscription_test.rb | 4 +- test/stripe/three_d_secure_test.rb | 23 ------- test/stripe/usage_record_summary_test.rb | 11 +--- 23 files changed, 110 insertions(+), 373 deletions(-) delete mode 100644 lib/stripe/resources/bitcoin_receiver.rb delete mode 100644 lib/stripe/resources/bitcoin_transaction.rb delete mode 100644 lib/stripe/resources/issuing/card_details.rb delete mode 100644 lib/stripe/resources/recipient.rb delete mode 100644 lib/stripe/resources/three_d_secure.rb delete mode 100644 test/stripe/alipay_account_test.rb delete mode 100644 test/stripe/recipient_test.rb delete mode 100644 test/stripe/three_d_secure_test.rb diff --git a/lib/stripe/object_types.rb b/lib/stripe/object_types.rb index 9e96b0d24..66b21a9ae 100644 --- a/lib/stripe/object_types.rb +++ b/lib/stripe/object_types.rb @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/lib/stripe/resources.rb b/lib/stripe/resources.rb index 83a3b0033..24c258a7c 100644 --- a/lib/stripe/resources.rb +++ b/lib/stripe/resources.rb @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/lib/stripe/resources/bitcoin_receiver.rb b/lib/stripe/resources/bitcoin_receiver.rb deleted file mode 100644 index ff0f2e9de..000000000 --- a/lib/stripe/resources/bitcoin_receiver.rb +++ /dev/null @@ -1,24 +0,0 @@ -# File generated from our OpenAPI spec -# frozen_string_literal: true - -module Stripe - # Directly creating or retrieving BitcoinReceivers is deprecated. Please use - # the Sources API instead: https://stripe.com/docs/sources/bitcoin - class BitcoinReceiver < APIResource - extend Stripe::APIOperations::List - - OBJECT_NAME = "bitcoin_receiver" - - def self.resource_url - "/v1/bitcoin/receivers" - end - - def resource_url - if respond_to?(:customer) && !customer.nil? && customer != "" - "#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}" - else - "#{self.class.resource_url}/#{CGI.escape(id)}" - end - end - end -end diff --git a/lib/stripe/resources/bitcoin_transaction.rb b/lib/stripe/resources/bitcoin_transaction.rb deleted file mode 100644 index d0cbe134d..000000000 --- a/lib/stripe/resources/bitcoin_transaction.rb +++ /dev/null @@ -1,16 +0,0 @@ -# File generated from our OpenAPI spec -# frozen_string_literal: true - -module Stripe - # Directly retrieving BitcoinTransactions is deprecated. Please use - # the Sources API instead: https://stripe.com/docs/sources/bitcoin - class BitcoinTransaction < APIResource - extend Stripe::APIOperations::List - - OBJECT_NAME = "bitcoin_transaction" - - def self.resource_url - "/v1/bitcoin/transactions" - end - end -end diff --git a/lib/stripe/resources/card.rb b/lib/stripe/resources/card.rb index 7a16abbbd..0e494d510 100644 --- a/lib/stripe/resources/card.rb +++ b/lib/stripe/resources/card.rb @@ -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)}" diff --git a/lib/stripe/resources/checkout/session.rb b/lib/stripe/resources/checkout/session.rb index c499c88b2..3eb083494 100644 --- a/lib/stripe/resources/checkout/session.rb +++ b/lib/stripe/resources/checkout/session.rb @@ -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, @@ -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/%s/line_items", { session: CGI.escape(self["id"]) }), + params: params, + opts: opts + ) + end + def self.expire(session, params = {}, opts = {}) request_stripe_object( method: :post, @@ -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/%s/line_items", { session: CGI.escape(session) }), + params: params, + opts: opts + ) + end end end end diff --git a/lib/stripe/resources/customer.rb b/lib/stripe/resources/customer.rb index 86cdad9f9..1f2c87cf3 100644 --- a/lib/stripe/resources/customer.rb +++ b/lib/stripe/resources/customer.rb @@ -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/%s/discount", { customer: CGI.escape(self["id"]) }), + params: params, + opts: opts + ) + end + def list_payment_methods(params = {}, opts = {}) request_stripe_object( method: :get, @@ -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/%s/discount", { customer: CGI.escape(customer) }), + params: params, + opts: opts + ) + end + def self.list_payment_methods(customer, params = {}, opts = {}) request_stripe_object( method: :get, @@ -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) @@ -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/%s/cash_balance", { customer: CGI.escape(customer) }), @@ -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/%s/cash_balance", { customer: CGI.escape(customer) }), diff --git a/lib/stripe/resources/issuing/card.rb b/lib/stripe/resources/issuing/card.rb index 23dfbc6a1..2e20bef01 100644 --- a/lib/stripe/resources/issuing/card.rb +++ b/lib/stripe/resources/issuing/card.rb @@ -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/%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/%s/details", { card: CGI.escape(card) }), - params: params, - opts: opts - ) - end - def test_helpers TestHelpers.new(self) end diff --git a/lib/stripe/resources/issuing/card_details.rb b/lib/stripe/resources/issuing/card_details.rb deleted file mode 100644 index 58d19cede..000000000 --- a/lib/stripe/resources/issuing/card_details.rb +++ /dev/null @@ -1,10 +0,0 @@ -# File generated from our OpenAPI spec -# frozen_string_literal: true - -module Stripe - module Issuing - class CardDetails < StripeObject - OBJECT_NAME = "issuing.card_details" - end - end -end diff --git a/lib/stripe/resources/recipient.rb b/lib/stripe/resources/recipient.rb deleted file mode 100644 index bd82f5da8..000000000 --- a/lib/stripe/resources/recipient.rb +++ /dev/null @@ -1,14 +0,0 @@ -# File generated from our OpenAPI spec -# frozen_string_literal: true - -module Stripe - # Recipients objects are deprecated. Please use Stripe Connect instead. - class Recipient < APIResource - extend Stripe::APIOperations::Create - include Stripe::APIOperations::Delete - extend Stripe::APIOperations::List - include Stripe::APIOperations::Save - - OBJECT_NAME = "recipient" - end -end diff --git a/lib/stripe/resources/reporting/report_type.rb b/lib/stripe/resources/reporting/report_type.rb index c08d7b689..97e821208 100644 --- a/lib/stripe/resources/reporting/report_type.rb +++ b/lib/stripe/resources/reporting/report_type.rb @@ -4,7 +4,6 @@ module Stripe module Reporting class ReportType < APIResource - extend Stripe::APIOperations::Create extend Stripe::APIOperations::List OBJECT_NAME = "reporting.report_type" diff --git a/lib/stripe/resources/subscription.rb b/lib/stripe/resources/subscription.rb index 986f5c8de..d2d41fed3 100644 --- a/lib/stripe/resources/subscription.rb +++ b/lib/stripe/resources/subscription.rb @@ -4,13 +4,21 @@ module Stripe class Subscription < APIResource extend Stripe::APIOperations::Create - include Stripe::APIOperations::Delete extend Stripe::APIOperations::List extend Stripe::APIOperations::Search include Stripe::APIOperations::Save OBJECT_NAME = "subscription" + def cancel(params = {}, opts = {}) + request_stripe_object( + method: :delete, + path: format("/v1/subscriptions/%s", { subscription_exposed_id: CGI.escape(self["id"]) }), + params: params, + opts: opts + ) + end + def delete_discount(params = {}, opts = {}) request_stripe_object( method: :delete, @@ -20,6 +28,15 @@ def delete_discount(params = {}, opts = {}) ) end + def self.cancel(subscription_exposed_id, params = {}, opts = {}) + request_stripe_object( + method: :delete, + path: format("/v1/subscriptions/%s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), + params: params, + opts: opts + ) + end + def self.delete_discount(subscription_exposed_id, params = {}, opts = {}) request_stripe_object( method: :delete, @@ -30,6 +47,31 @@ def self.delete_discount(subscription_exposed_id, params = {}, opts = {}) end save_nested_resource :source + def delete(params = {}, opts = {}) + request_stripe_object( + method: :delete, + path: format("/v1/subscriptions/%s", { subscription_exposed_id: CGI.escape(self["id"]) }), + params: params, + opts: opts + ) + end + + def self.delete(subscription_exposed_id, params = {}, opts = {}) + request_stripe_object( + method: :delete, + path: format("/v1/subscriptions/%s", { subscription_exposed_id: CGI.escape(subscription_exposed_id) }), + params: params, + opts: opts + ) + end + + extend Gem::Deprecate + deprecate :delete, "Stripe::Subscription.cancel", 2022, 7 + + class << self + extend Gem::Deprecate + deprecate :delete, "Stripe::Subscription#cancel", 2022, 7 + end def self.search(params = {}, opts = {}) _search("/v1/subscriptions/search", params, opts) diff --git a/lib/stripe/resources/subscription_item.rb b/lib/stripe/resources/subscription_item.rb index 16235e105..87d925a62 100644 --- a/lib/stripe/resources/subscription_item.rb +++ b/lib/stripe/resources/subscription_item.rb @@ -15,16 +15,5 @@ class SubscriptionItem < APIResource nested_resource_class_methods :usage_record_summary, operations: %i[list], resource_plural: "usage_record_summaries" - - def usage_record_summaries(params = {}, 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 end end diff --git a/lib/stripe/resources/three_d_secure.rb b/lib/stripe/resources/three_d_secure.rb deleted file mode 100644 index 9b6c28c59..000000000 --- a/lib/stripe/resources/three_d_secure.rb +++ /dev/null @@ -1,14 +0,0 @@ -# File generated from our OpenAPI spec -# frozen_string_literal: true - -module Stripe - class ThreeDSecure < APIResource - extend Stripe::APIOperations::Create - - OBJECT_NAME = "three_d_secure" - - def self.resource_url - "/v1/3d_secure" - end - end -end diff --git a/lib/stripe/resources/transfer.rb b/lib/stripe/resources/transfer.rb index df65a2672..7d8420dba 100644 --- a/lib/stripe/resources/transfer.rb +++ b/lib/stripe/resources/transfer.rb @@ -12,23 +12,5 @@ class Transfer < APIResource nested_resource_class_methods :reversal, operations: %i[create retrieve update list] - - def cancel(params = {}, opts = {}) - request_stripe_object( - method: :post, - path: format("/v1/transfers/%s/cancel", { id: CGI.escape(self["id"]) }), - params: params, - opts: opts - ) - end - - def self.cancel(id, params = {}, opts = {}) - request_stripe_object( - method: :post, - path: format("/v1/transfers/%s/cancel", { id: CGI.escape(id) }), - params: params, - opts: opts - ) - end end end diff --git a/test/stripe/alipay_account_test.rb b/test/stripe/alipay_account_test.rb deleted file mode 100644 index 627e39c89..000000000 --- a/test/stripe/alipay_account_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require ::File.expand_path("../test_helper", __dir__) - -module Stripe - class AlipayAccountTest < Test::Unit::TestCase - context "#resource_url" do - should "return a resource URL" do - alipay_account = Stripe::AlipayAccount.construct_from( - id: "aliacc_123", - customer: "cus_123" - ) - assert_equal "/v1/customers/cus_123/sources/aliacc_123", - alipay_account.resource_url - end - - should "raise without a customer" do - alipay_account = Stripe::AlipayAccount.construct_from(id: "aliacc_123") - assert_raises NotImplementedError do - alipay_account.resource_url - end - end - end - - should "raise on #retrieve" do - assert_raises NotImplementedError do - Stripe::AlipayAccount.retrieve("aliacc_123") - end - end - - should "raise on #update" do - assert_raises NotImplementedError do - Stripe::AlipayAccount.update("aliacc_123", {}) - end - end - end -end diff --git a/test/stripe/customer_test.rb b/test/stripe/customer_test.rb index 90487a7e5..326f54474 100644 --- a/test/stripe/customer_test.rb +++ b/test/stripe/customer_test.rb @@ -231,15 +231,15 @@ class CustomerTest < Test::Unit::TestCase context "#retrieve_cash_balance" do should "legacy call pattern - retrieve_cash_balance(customer_id, nil)" do - Stripe::Customer.retrieve_cash_balance("cus_123", nil) + Stripe::Customer.retrieve_cash_balance("cus_123") assert_requested :get, "#{Stripe.api_base}/v1/customers/cus_123/cash_balance" end - should "legacy call pattern - retrieve_cash_balance(customer_id, nil, opts)" do + should "legacy call pattern - retrieve_cash_balance(customer_id, opts)" do # Assert that we're actually making a change by swapping out the API base. assert Stripe.api_base != Stripe.connect_base - Stripe::Customer.retrieve_cash_balance("cus_123", nil, { api_base: Stripe.connect_base }) + Stripe::Customer.retrieve_cash_balance("cus_123", { api_base: Stripe.connect_base }) assert_requested :get, "#{Stripe.connect_base}/v1/customers/cus_123/cash_balance" end @@ -253,21 +253,20 @@ class CustomerTest < Test::Unit::TestCase end context "#update_cash_balance" do - should "legacy call pattern - update_cash_balance(customer, nil, params)" do - Stripe::Customer.update_cash_balance("cus_123", nil, { settings: { reconciliation_mode: "manual" } }) + should "legacy call pattern - update_cash_balance(customer, params)" do + Stripe::Customer.update_cash_balance("cus_123", { settings: { reconciliation_mode: "manual" } }) assert_requested :post, "#{Stripe.api_base}/v1/customers/cus_123/cash_balance" do |req| req.body == "settings[reconciliation_mode]=manual" end end - should "legacy call pattern - update_cash_balance(customer, nil, params, opts)" do + should "legacy call pattern - update_cash_balance(customer, params, opts)" do # Assert that we're actually making a change by swapping out the API base. assert Stripe.api_base != Stripe.connect_base Stripe::Customer.update_cash_balance( "cus_123", - nil, { settings: { reconciliation_mode: "manual" } }, { api_base: Stripe.connect_base } ) @@ -282,19 +281,6 @@ class CustomerTest < Test::Unit::TestCase assert_requested :post, "#{Stripe.api_base}/v1/customers/cus_123/cash_balance" end - - should "modern call pattern - fail if passing in hash to second argument" do - # We catch this on purpose to avoid mis-using the call as is. - # Unfortunately we can't automatically shift over arguments (eg. - # update_cash_balance(customer_id, params, opts) -> - # update_cash_balance(customer_id, nil, params, opts)) since we have - # the problematic case of update_cash_balance(customer_id, nil, hash) - # where we can't differentiate params and opts for the second hash. - e = assert_raises(ArgumentError) do - Stripe::Customer.update_cash_balance("cus_123", { settings: { reconciliation_mode: "manual" } }) - end - assert_match("update_cash_balance requires the second argument always be nil", e.message) - end end end end diff --git a/test/stripe/generated_examples_test.rb b/test/stripe/generated_examples_test.rb index c1934842c..1497a0bef 100644 --- a/test/stripe/generated_examples_test.rb +++ b/test/stripe/generated_examples_test.rb @@ -224,7 +224,6 @@ class CodegennedExampleTest < Test::Unit::TestCase should "support requests with args: customer, settings" do Stripe::Customer.update_cash_balance( "cus_123", - nil, { settings: { reconciliation_mode: "manual" } } ) assert_requested :post, "#{Stripe.api_base}/v1/customers/cus_123/cash_balance" @@ -329,6 +328,12 @@ class CodegennedExampleTest < Test::Unit::TestCase assert_requested :get, "#{Stripe.api_base}/v1/checkout/sessions?limit=3" end end + context "Checkout.Session.list_line_items" do + should "support requests with args: session" do + Stripe::Checkout::Session.list_line_items("sess_xyz") + assert_requested :get, "#{Stripe.api_base}/v1/checkout/sessions/sess_xyz/line_items?" + end + end context "Checkout.Session.retrieve" do should "support requests with args: id" do Stripe::Checkout::Session.retrieve("cs_test_xxxxxxxxxxxxx") @@ -1101,6 +1106,12 @@ class CodegennedExampleTest < Test::Unit::TestCase assert_requested :post, "#{Stripe.api_base}/v1/orders/order_xyz/reopen?" end end + context "Order.retrieve" do + should "support requests with args: order" do + Stripe::Order.retrieve("order_xyz") + assert_requested :get, "#{Stripe.api_base}/v1/orders/order_xyz?" + end + end context "Order.submit" do should "support requests with args: order, expected_total" do Stripe::Order.submit("order_xyz", { expected_total: 100 }) @@ -1108,13 +1119,12 @@ class CodegennedExampleTest < Test::Unit::TestCase end end context "Order.update" do - should "support requests with args: order" do - Stripe::Order.update("order_xyz") - assert_requested :post, "#{Stripe.api_base}/v1/orders/order_xyz?" - end - should "support requests with args: order2" do - Stripe::Order.update("order_xyz") - assert_requested :post, "#{Stripe.api_base}/v1/orders/order_xyz?" + should "support requests with args: order, metadata, ip_address" do + Stripe::Order.update( + "order_xyz", + { metadata: { reference_number: "123" }, ip_address: "0.0.0.0" } + ) + assert_requested :post, "#{Stripe.api_base}/v1/orders/order_xyz" end end context "PaymentIntent.apply_customer_balance" do diff --git a/test/stripe/issuing/card_test.rb b/test/stripe/issuing/card_test.rb index a493b141c..243ac047f 100644 --- a/test/stripe/issuing/card_test.rb +++ b/test/stripe/issuing/card_test.rb @@ -40,35 +40,6 @@ class CardTest < Test::Unit::TestCase assert_requested :post, "#{Stripe.api_base}/v1/issuing/cards/ic_123" assert card.is_a?(Stripe::Issuing::Card) end - - context "#details" do - should "retrieve a card's details" do - # The /details endpoint is deprecated and not in the spec so we mock - stub_request(:get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details") - .to_return(body: JSON.generate(object: "issuing.card_details")) - - card_details = Stripe::Issuing::Card.details("ic_123") - assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details" - assert card_details.is_a?(Stripe::Issuing::CardDetails) - end - end - - context ".details" do - should "retrieve a card's details" do - # The /details endpoint is deprecated and not in the spec so we mock - stub_request(:get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details") - .to_return(body: JSON.generate(object: "issuing.card_details")) - - card = Stripe::Issuing::Card.construct_from( - id: "ic_123", - object: "issuing.card_details" - ) - card_details = card.details - - assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details" - assert card_details.is_a?(Stripe::Issuing::CardDetails) - end - end end end end diff --git a/test/stripe/recipient_test.rb b/test/stripe/recipient_test.rb deleted file mode 100644 index 7a262d5a1..000000000 --- a/test/stripe/recipient_test.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -require ::File.expand_path("../test_helper", __dir__) - -module Stripe - class RecipientTest < Test::Unit::TestCase - should "be listable" do - recipients = Stripe::Recipient.list - assert_requested :get, "#{Stripe.api_base}/v1/recipients" - assert recipients.data.is_a?(Array) - assert recipients.data[0].is_a?(Stripe::Recipient) - end - - should "be retrievable" do - recipient = Stripe::Recipient.retrieve("rp_123") - assert_requested :get, "#{Stripe.api_base}/v1/recipients/rp_123" - assert recipient.is_a?(Stripe::Recipient) - end - - should "be creatable" do - recipient = Stripe::Recipient.create( - name: "Noah Jackson", - type: "individual" - ) - assert_requested :post, "#{Stripe.api_base}/v1/recipients" - assert recipient.is_a?(Stripe::Recipient) - end - - should "be saveable" do - recipient = Stripe::Recipient.retrieve("rp_123") - recipient.metadata["key"] = "value" - recipient.save - assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{recipient.id}" - end - - should "be updateable" do - recipient = Stripe::Recipient.update("rp_123", metadata: { foo: "bar" }) - assert_requested :post, "#{Stripe.api_base}/v1/recipients/rp_123" - assert recipient.is_a?(Stripe::Recipient) - end - - should "be deletable" do - end - - context "#delete" do - should "be deletable" do - recipient = Stripe::Recipient.retrieve("rp_123") - recipient = recipient.delete - assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{recipient.id}" - assert recipient.is_a?(Stripe::Recipient) - end - end - - context ".delete" do - should "be deletable" do - recipient = Stripe::Recipient.delete("rp_123") - assert_requested :delete, "#{Stripe.api_base}/v1/recipients/rp_123" - assert recipient.is_a?(Stripe::Recipient) - end - end - end -end diff --git a/test/stripe/subscription_test.rb b/test/stripe/subscription_test.rb index f5e20ec79..eaa8f62a1 100644 --- a/test/stripe/subscription_test.rb +++ b/test/stripe/subscription_test.rb @@ -44,7 +44,7 @@ class SubscriptionTest < Test::Unit::TestCase context "#delete" do should "be deletable" do subscription = Stripe::Subscription.retrieve("sub_123") - subscription = subscription.delete + subscription = subscription.cancel assert_requested :delete, "#{Stripe.api_base}/v1/subscriptions/#{subscription.id}" assert subscription.is_a?(Stripe::Subscription) @@ -53,7 +53,7 @@ class SubscriptionTest < Test::Unit::TestCase context ".delete" do should "be deletable" do - subscription = Stripe::Subscription.delete("sub_123") + subscription = Stripe::Subscription.cancel("sub_123") assert_requested :delete, "#{Stripe.api_base}/v1/subscriptions/sub_123" assert subscription.is_a?(Stripe::Subscription) diff --git a/test/stripe/three_d_secure_test.rb b/test/stripe/three_d_secure_test.rb deleted file mode 100644 index c318e2f38..000000000 --- a/test/stripe/three_d_secure_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require ::File.expand_path("../test_helper", __dir__) - -module Stripe - class ThreeDSecureTest < Test::Unit::TestCase - should "be retrievable" do - secure = Stripe::ThreeDSecure.retrieve("tdsrc_123") - assert_requested :get, "#{Stripe.api_base}/v1/3d_secure/tdsrc_123" - assert secure.is_a?(Stripe::ThreeDSecure) - end - - should "be creatable" do - _ = Stripe::ThreeDSecure.create( - card: "tok_123", - amount: 1500, - currency: "usd", - return_url: "https://example.org/3d-secure-result" - ) - assert_requested :post, "#{Stripe.api_base}/v1/3d_secure" - end - end -end diff --git a/test/stripe/usage_record_summary_test.rb b/test/stripe/usage_record_summary_test.rb index a040c68d3..8a307f7bb 100644 --- a/test/stripe/usage_record_summary_test.rb +++ b/test/stripe/usage_record_summary_test.rb @@ -4,23 +4,16 @@ module Stripe class UsageRecordSummaryTest < Test::Unit::TestCase - setup do - @sub_item = Stripe::SubscriptionItem.retrieve("si_123") - end - should "be listable" do old_stderr = $stderr $stderr = StringIO.new begin - transactions = @sub_item.usage_record_summaries + transactions = Stripe::SubscriptionItem.list_usage_record_summaries("si_123") - assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/#{@sub_item.id}/usage_record_summaries" + assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/si_123/usage_record_summaries" assert transactions.data.is_a?(Array) assert transactions.first.is_a?(Stripe::UsageRecordSummary) - - assert_include $stderr.string, - "use SubscriptionItem.list_usage_record_summaries instead" ensure $stderr = old_stderr end