From 4705a5f5f9aa2140bbb0286a716fb0a0aa6e95de Mon Sep 17 00:00:00 2001 From: helenye-stripe <111009531+helenye-stripe@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:10:30 -0700 Subject: [PATCH] Refactor after SDK based generation pattern (#1354) * Refactor after SDK based generation pattern * update for object types & reorder --- lib/stripe/object_types.rb | 9 ++-- lib/stripe/resources/account.rb | 2 +- lib/stripe/resources/charge.rb | 2 +- lib/stripe/resources/customer.rb | 2 +- lib/stripe/resources/issuing/authorization.rb | 48 +++++++++---------- lib/stripe/resources/issuing/card.rb | 44 ++++++++--------- lib/stripe/resources/source.rb | 2 +- lib/stripe/resources/subscription_item.rb | 2 +- lib/stripe/resources/tax/settings.rb | 1 - lib/stripe/resources/transfer.rb | 2 +- .../resources/treasury/inbound_transfer.rb | 28 +++++------ .../resources/treasury/outbound_payment.rb | 28 +++++------ .../resources/treasury/outbound_transfer.rb | 28 +++++------ test/stripe/generated_examples_test.rb | 19 ++++++++ 14 files changed, 117 insertions(+), 100 deletions(-) diff --git a/lib/stripe/object_types.rb b/lib/stripe/object_types.rb index c871f811d..86b36e8f7 100644 --- a/lib/stripe/object_types.rb +++ b/lib/stripe/object_types.rb @@ -1,4 +1,3 @@ -# File generated from our OpenAPI spec # frozen_string_literal: true # rubocop:disable Metrics/MethodLength @@ -11,9 +10,9 @@ def self.object_names_to_classes # data structures ListObject.object_name => ListObject, SearchResultObject.object_name => SearchResultObject, - - # business objects File.object_name_alt => File, + + # The beginning of the section generated from our OpenAPI spec Account.object_name => Account, AccountLink.object_name => AccountLink, AccountSession.object_name => AccountSession, @@ -51,8 +50,7 @@ def self.object_names_to_classes FileLink.object_name => FileLink, FinancialConnections::Account.object_name => FinancialConnections::Account, FinancialConnections::AccountOwner.object_name => FinancialConnections::AccountOwner, - FinancialConnections::AccountOwnership.object_name => - FinancialConnections::AccountOwnership, + FinancialConnections::AccountOwnership.object_name => FinancialConnections::AccountOwnership, FinancialConnections::Session.object_name => FinancialConnections::Session, FinancialConnections::Transaction.object_name => FinancialConnections::Transaction, FundingInstructions.object_name => FundingInstructions, @@ -130,6 +128,7 @@ def self.object_names_to_classes UsageRecord.object_name => UsageRecord, UsageRecordSummary.object_name => UsageRecordSummary, WebhookEndpoint.object_name => WebhookEndpoint, + # The end of the section generated from our OpenAPI spec } end end diff --git a/lib/stripe/resources/account.rb b/lib/stripe/resources/account.rb index e22188ca7..5968b8e3e 100644 --- a/lib/stripe/resources/account.rb +++ b/lib/stripe/resources/account.rb @@ -13,8 +13,8 @@ class Account < APIResource extend Stripe::APIOperations::Create include Stripe::APIOperations::Delete extend Stripe::APIOperations::List - include Stripe::APIOperations::Save extend Stripe::APIOperations::NestedResource + include Stripe::APIOperations::Save OBJECT_NAME = "account" def self.object_name diff --git a/lib/stripe/resources/charge.rb b/lib/stripe/resources/charge.rb index 48d0f3505..8177b75f6 100644 --- a/lib/stripe/resources/charge.rb +++ b/lib/stripe/resources/charge.rb @@ -9,9 +9,9 @@ module Stripe class Charge < APIResource extend Stripe::APIOperations::Create extend Stripe::APIOperations::List + extend Stripe::APIOperations::NestedResource extend Stripe::APIOperations::Search include Stripe::APIOperations::Save - extend Stripe::APIOperations::NestedResource OBJECT_NAME = "charge" def self.object_name diff --git a/lib/stripe/resources/customer.rb b/lib/stripe/resources/customer.rb index 4755faf00..4587b20ce 100644 --- a/lib/stripe/resources/customer.rb +++ b/lib/stripe/resources/customer.rb @@ -9,9 +9,9 @@ class Customer < APIResource extend Stripe::APIOperations::Create include Stripe::APIOperations::Delete extend Stripe::APIOperations::List + extend Stripe::APIOperations::NestedResource extend Stripe::APIOperations::Search include Stripe::APIOperations::Save - extend Stripe::APIOperations::NestedResource OBJECT_NAME = "customer" def self.object_name diff --git a/lib/stripe/resources/issuing/authorization.rb b/lib/stripe/resources/issuing/authorization.rb index 8d4ebfd7e..decc5e3b7 100644 --- a/lib/stripe/resources/issuing/authorization.rb +++ b/lib/stripe/resources/issuing/authorization.rb @@ -101,6 +101,16 @@ def self.capture(authorization, params = {}, opts = {}) ) end + # Capture a test-mode authorization. + def capture(params = {}, opts = {}) + @resource.request_stripe_object( + method: :post, + path: format("/v1/test_helpers/issuing/authorizations/%s/capture", { authorization: CGI.escape(@resource["id"]) }), + params: params, + opts: opts + ) + end + # Create a test-mode authorization. def self.create(params = {}, opts = {}) request_stripe_object( @@ -121,51 +131,41 @@ def self.expire(authorization, params = {}, opts = {}) ) end - # Increment a test-mode Authorization. - def self.increment(authorization, params = {}, opts = {}) - request_stripe_object( + # Expire a test-mode Authorization. + def expire(params = {}, opts = {}) + @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/authorizations/%s/increment", { authorization: CGI.escape(authorization) }), + path: format("/v1/test_helpers/issuing/authorizations/%s/expire", { authorization: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Reverse a test-mode Authorization. - def self.reverse(authorization, params = {}, opts = {}) + # Increment a test-mode Authorization. + def self.increment(authorization, params = {}, opts = {}) request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/authorizations/%s/reverse", { authorization: CGI.escape(authorization) }), - params: params, - opts: opts - ) - end - - # Capture a test-mode authorization. - def capture(params = {}, opts = {}) - @resource.request_stripe_object( - method: :post, - path: format("/v1/test_helpers/issuing/authorizations/%s/capture", { authorization: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/issuing/authorizations/%s/increment", { authorization: CGI.escape(authorization) }), params: params, opts: opts ) end - # Expire a test-mode Authorization. - def expire(params = {}, opts = {}) + # Increment a test-mode Authorization. + def increment(params = {}, opts = {}) @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/authorizations/%s/expire", { authorization: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/issuing/authorizations/%s/increment", { authorization: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Increment a test-mode Authorization. - def increment(params = {}, opts = {}) - @resource.request_stripe_object( + # Reverse a test-mode Authorization. + def self.reverse(authorization, params = {}, opts = {}) + request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/authorizations/%s/increment", { authorization: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/issuing/authorizations/%s/reverse", { authorization: CGI.escape(authorization) }), params: params, opts: opts ) diff --git a/lib/stripe/resources/issuing/card.rb b/lib/stripe/resources/issuing/card.rb index 28f3247b7..36cdf0ecc 100644 --- a/lib/stripe/resources/issuing/card.rb +++ b/lib/stripe/resources/issuing/card.rb @@ -54,61 +54,61 @@ def self.deliver_card(card, params = {}, opts = {}) ) end - # Updates the shipping status of the specified Issuing Card object to failure. - def self.fail_card(card, params = {}, opts = {}) - request_stripe_object( + # Updates the shipping status of the specified Issuing Card object to delivered. + def deliver_card(params = {}, opts = {}) + @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/cards/%s/shipping/fail", { card: CGI.escape(card) }), + path: format("/v1/test_helpers/issuing/cards/%s/shipping/deliver", { card: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Updates the shipping status of the specified Issuing Card object to returned. - def self.return_card(card, params = {}, opts = {}) + # Updates the shipping status of the specified Issuing Card object to failure. + def self.fail_card(card, params = {}, opts = {}) request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/cards/%s/shipping/return", { card: CGI.escape(card) }), + path: format("/v1/test_helpers/issuing/cards/%s/shipping/fail", { card: CGI.escape(card) }), params: params, opts: opts ) end - # Updates the shipping status of the specified Issuing Card object to shipped. - def self.ship_card(card, params = {}, opts = {}) - request_stripe_object( + # Updates the shipping status of the specified Issuing Card object to failure. + def fail_card(params = {}, opts = {}) + @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/cards/%s/shipping/ship", { card: CGI.escape(card) }), + path: format("/v1/test_helpers/issuing/cards/%s/shipping/fail", { card: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Updates the shipping status of the specified Issuing Card object to delivered. - def deliver_card(params = {}, opts = {}) - @resource.request_stripe_object( + # Updates the shipping status of the specified Issuing Card object to returned. + def self.return_card(card, params = {}, opts = {}) + request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/cards/%s/shipping/deliver", { card: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/issuing/cards/%s/shipping/return", { card: CGI.escape(card) }), params: params, opts: opts ) end - # Updates the shipping status of the specified Issuing Card object to failure. - def fail_card(params = {}, opts = {}) + # Updates the shipping status of the specified Issuing Card object to returned. + def return_card(params = {}, opts = {}) @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/cards/%s/shipping/fail", { card: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/issuing/cards/%s/shipping/return", { card: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Updates the shipping status of the specified Issuing Card object to returned. - def return_card(params = {}, opts = {}) - @resource.request_stripe_object( + # Updates the shipping status of the specified Issuing Card object to shipped. + def self.ship_card(card, params = {}, opts = {}) + request_stripe_object( method: :post, - path: format("/v1/test_helpers/issuing/cards/%s/shipping/return", { card: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/issuing/cards/%s/shipping/ship", { card: CGI.escape(card) }), params: params, opts: opts ) diff --git a/lib/stripe/resources/source.rb b/lib/stripe/resources/source.rb index aff52e27e..ba5e442ba 100644 --- a/lib/stripe/resources/source.rb +++ b/lib/stripe/resources/source.rb @@ -14,8 +14,8 @@ module Stripe # Related guides: [Sources API](https://stripe.com/docs/sources) and [Sources & Customers](https://stripe.com/docs/sources/customers). class Source < APIResource extend Stripe::APIOperations::Create - include Stripe::APIOperations::Save extend Stripe::APIOperations::NestedResource + include Stripe::APIOperations::Save OBJECT_NAME = "source" def self.object_name diff --git a/lib/stripe/resources/subscription_item.rb b/lib/stripe/resources/subscription_item.rb index 61948da98..d37a70b2a 100644 --- a/lib/stripe/resources/subscription_item.rb +++ b/lib/stripe/resources/subscription_item.rb @@ -8,8 +8,8 @@ class SubscriptionItem < APIResource extend Stripe::APIOperations::Create include Stripe::APIOperations::Delete extend Stripe::APIOperations::List - include Stripe::APIOperations::Save extend Stripe::APIOperations::NestedResource + include Stripe::APIOperations::Save OBJECT_NAME = "subscription_item" def self.object_name diff --git a/lib/stripe/resources/tax/settings.rb b/lib/stripe/resources/tax/settings.rb index 66eab9e80..1250ea35f 100644 --- a/lib/stripe/resources/tax/settings.rb +++ b/lib/stripe/resources/tax/settings.rb @@ -8,7 +8,6 @@ module Tax # Related guide: [Using the Settings API](https://stripe.com/docs/tax/settings-api) class Settings < SingletonAPIResource include Stripe::APIOperations::SingletonSave - OBJECT_NAME = "tax.settings" def self.object_name "tax.settings" diff --git a/lib/stripe/resources/transfer.rb b/lib/stripe/resources/transfer.rb index 4543fad3a..476be51fd 100644 --- a/lib/stripe/resources/transfer.rb +++ b/lib/stripe/resources/transfer.rb @@ -15,8 +15,8 @@ module Stripe class Transfer < APIResource extend Stripe::APIOperations::Create extend Stripe::APIOperations::List - include Stripe::APIOperations::Save extend Stripe::APIOperations::NestedResource + include Stripe::APIOperations::Save OBJECT_NAME = "transfer" def self.object_name diff --git a/lib/stripe/resources/treasury/inbound_transfer.rb b/lib/stripe/resources/treasury/inbound_transfer.rb index c48b0da14..ec55fdc11 100644 --- a/lib/stripe/resources/treasury/inbound_transfer.rb +++ b/lib/stripe/resources/treasury/inbound_transfer.rb @@ -73,41 +73,41 @@ def self.fail(id, params = {}, opts = {}) ) end - # Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state. - def self.return_inbound_transfer(id, params = {}, opts = {}) - request_stripe_object( + # Transitions a test mode created InboundTransfer to the failed status. The InboundTransfer must already be in the processing state. + def fail(params = {}, opts = {}) + @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/inbound_transfers/%s/return", { id: CGI.escape(id) }), + path: format("/v1/test_helpers/treasury/inbound_transfers/%s/fail", { id: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Transitions a test mode created InboundTransfer to the succeeded status. The InboundTransfer must already be in the processing state. - def self.succeed(id, params = {}, opts = {}) + # Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state. + def self.return_inbound_transfer(id, params = {}, opts = {}) request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/inbound_transfers/%s/succeed", { id: CGI.escape(id) }), + path: format("/v1/test_helpers/treasury/inbound_transfers/%s/return", { id: CGI.escape(id) }), params: params, opts: opts ) end - # Transitions a test mode created InboundTransfer to the failed status. The InboundTransfer must already be in the processing state. - def fail(params = {}, opts = {}) + # Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state. + def return_inbound_transfer(params = {}, opts = {}) @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/inbound_transfers/%s/fail", { id: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/treasury/inbound_transfers/%s/return", { id: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Marks the test mode InboundTransfer object as returned and links the InboundTransfer to a ReceivedDebit. The InboundTransfer must already be in the succeeded state. - def return_inbound_transfer(params = {}, opts = {}) - @resource.request_stripe_object( + # Transitions a test mode created InboundTransfer to the succeeded status. The InboundTransfer must already be in the processing state. + def self.succeed(id, params = {}, opts = {}) + request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/inbound_transfers/%s/return", { id: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/treasury/inbound_transfers/%s/succeed", { id: CGI.escape(id) }), params: params, opts: opts ) diff --git a/lib/stripe/resources/treasury/outbound_payment.rb b/lib/stripe/resources/treasury/outbound_payment.rb index a376de29b..232db3b6b 100644 --- a/lib/stripe/resources/treasury/outbound_payment.rb +++ b/lib/stripe/resources/treasury/outbound_payment.rb @@ -75,41 +75,41 @@ def self.fail(id, params = {}, opts = {}) ) end - # Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state. - def self.post(id, params = {}, opts = {}) - request_stripe_object( + # Transitions a test mode created OutboundPayment to the failed status. The OutboundPayment must already be in the processing state. + def fail(params = {}, opts = {}) + @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_payments/%s/post", { id: CGI.escape(id) }), + path: format("/v1/test_helpers/treasury/outbound_payments/%s/fail", { id: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Transitions a test mode created OutboundPayment to the returned status. The OutboundPayment must already be in the processing state. - def self.return_outbound_payment(id, params = {}, opts = {}) + # Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state. + def self.post(id, params = {}, opts = {}) request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_payments/%s/return", { id: CGI.escape(id) }), + path: format("/v1/test_helpers/treasury/outbound_payments/%s/post", { id: CGI.escape(id) }), params: params, opts: opts ) end - # Transitions a test mode created OutboundPayment to the failed status. The OutboundPayment must already be in the processing state. - def fail(params = {}, opts = {}) + # Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state. + def post(params = {}, opts = {}) @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_payments/%s/fail", { id: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/treasury/outbound_payments/%s/post", { id: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Transitions a test mode created OutboundPayment to the posted status. The OutboundPayment must already be in the processing state. - def post(params = {}, opts = {}) - @resource.request_stripe_object( + # Transitions a test mode created OutboundPayment to the returned status. The OutboundPayment must already be in the processing state. + def self.return_outbound_payment(id, params = {}, opts = {}) + request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_payments/%s/post", { id: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/treasury/outbound_payments/%s/return", { id: CGI.escape(id) }), params: params, opts: opts ) diff --git a/lib/stripe/resources/treasury/outbound_transfer.rb b/lib/stripe/resources/treasury/outbound_transfer.rb index 261cdbea6..59451cb6c 100644 --- a/lib/stripe/resources/treasury/outbound_transfer.rb +++ b/lib/stripe/resources/treasury/outbound_transfer.rb @@ -75,41 +75,41 @@ def self.fail(outbound_transfer, params = {}, opts = {}) ) end - # Transitions a test mode created OutboundTransfer to the posted status. The OutboundTransfer must already be in the processing state. - def self.post(outbound_transfer, params = {}, opts = {}) - request_stripe_object( + # Transitions a test mode created OutboundTransfer to the failed status. The OutboundTransfer must already be in the processing state. + def fail(params = {}, opts = {}) + @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_transfers/%s/post", { outbound_transfer: CGI.escape(outbound_transfer) }), + path: format("/v1/test_helpers/treasury/outbound_transfers/%s/fail", { outbound_transfer: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Transitions a test mode created OutboundTransfer to the returned status. The OutboundTransfer must already be in the processing state. - def self.return_outbound_transfer(outbound_transfer, params = {}, opts = {}) + # Transitions a test mode created OutboundTransfer to the posted status. The OutboundTransfer must already be in the processing state. + def self.post(outbound_transfer, params = {}, opts = {}) request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_transfers/%s/return", { outbound_transfer: CGI.escape(outbound_transfer) }), + path: format("/v1/test_helpers/treasury/outbound_transfers/%s/post", { outbound_transfer: CGI.escape(outbound_transfer) }), params: params, opts: opts ) end - # Transitions a test mode created OutboundTransfer to the failed status. The OutboundTransfer must already be in the processing state. - def fail(params = {}, opts = {}) + # Transitions a test mode created OutboundTransfer to the posted status. The OutboundTransfer must already be in the processing state. + def post(params = {}, opts = {}) @resource.request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_transfers/%s/fail", { outbound_transfer: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/treasury/outbound_transfers/%s/post", { outbound_transfer: CGI.escape(@resource["id"]) }), params: params, opts: opts ) end - # Transitions a test mode created OutboundTransfer to the posted status. The OutboundTransfer must already be in the processing state. - def post(params = {}, opts = {}) - @resource.request_stripe_object( + # Transitions a test mode created OutboundTransfer to the returned status. The OutboundTransfer must already be in the processing state. + def self.return_outbound_transfer(outbound_transfer, params = {}, opts = {}) + request_stripe_object( method: :post, - path: format("/v1/test_helpers/treasury/outbound_transfers/%s/post", { outbound_transfer: CGI.escape(@resource["id"]) }), + path: format("/v1/test_helpers/treasury/outbound_transfers/%s/return", { outbound_transfer: CGI.escape(outbound_transfer) }), params: params, opts: opts ) diff --git a/test/stripe/generated_examples_test.rb b/test/stripe/generated_examples_test.rb index 1533be1f4..10de5d909 100644 --- a/test/stripe/generated_examples_test.rb +++ b/test/stripe/generated_examples_test.rb @@ -1600,6 +1600,25 @@ class CodegennedExampleTest < Test::Unit::TestCase Stripe::TaxCode.retrieve("txcd_xxxxxxxxxxxxx") assert_requested :get, "#{Stripe.api_base}/v1/tax_codes/txcd_xxxxxxxxxxxxx?" end + should "Test tax ids delete" do + Stripe::TaxId.delete("taxid_123") + assert_requested :delete, "#{Stripe.api_base}/v1/tax_ids/taxid_123?" + end + should "Test tax ids get" do + Stripe::TaxId.list + assert_requested :get, "#{Stripe.api_base}/v1/tax_ids?" + end + should "Test tax ids get 2" do + Stripe::TaxId.retrieve("taxid_123") + assert_requested :get, "#{Stripe.api_base}/v1/tax_ids/taxid_123?" + end + should "Test tax ids post" do + Stripe::TaxId.create({ + type: "eu_vat", + value: "123", + }) + assert_requested :post, "#{Stripe.api_base}/v1/tax_ids" + end should "Test tax rates get" do Stripe::TaxRate.list({ limit: 3 }) assert_requested :get, "#{Stripe.api_base}/v1/tax_rates?limit=3"