diff --git a/examples/meter_event_stream.rb b/examples/meter_event_stream.rb index 4d69ea47..3f75ad4f 100644 --- a/examples/meter_event_stream.rb +++ b/examples/meter_event_stream.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "stripe" require "date" diff --git a/examples/new_example.rb b/examples/new_example.rb index 1b432e26..a358995f 100644 --- a/examples/new_example.rb +++ b/examples/new_example.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "stripe" require "date" @@ -17,7 +19,6 @@ end # Send meter events api_key = "{{API_KEY}}" -customer_id = "{{CUSTOMER_ID}}" example = NewExample.new(api_key) example.do_something_great diff --git a/lib/stripe/api_resource.rb b/lib/stripe/api_resource.rb index 449567a3..7ac3f3cc 100644 --- a/lib/stripe/api_resource.rb +++ b/lib/stripe/api_resource.rb @@ -25,6 +25,12 @@ module Stripe end def self.resource_url + if name.include?("Stripe::V2") + raise NotImplementedError, + "V2 resources do not have a defined URL. Please use the StripeClient " \ + "to make V2 requests" + end + if self == APIResource raise NotImplementedError, "APIResource is an abstract class. You should perform actions " \ @@ -86,12 +92,21 @@ module Stripe "#{self.class.resource_url}/#{CGI.escape(id)}" end - # TODO: v2 objects can be refreshed -- the api mode should depend on the object here. def refresh + if self.class.name.include?("Stripe::V2") + raise NotImplementedError, + "It is not possible to refresh v2 objects. Please retrieve the object using the StripeClient instead." + end + @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params) end def self.retrieve(id, opts = {}) + if name.include?("Stripe::V2") + raise NotImplementedError, + "It is not possible to retrieve v2 objects on the resource. Please use the StripeClient instead." + end + opts = Util.normalize_opts(opts) instance = new(id, opts) instance.refresh diff --git a/test/stripe/api_resource_test.rb b/test/stripe/api_resource_test.rb index 5e0e8358..8f282a1c 100644 --- a/test/stripe/api_resource_test.rb +++ b/test/stripe/api_resource_test.rb @@ -894,6 +894,31 @@ module Stripe end end + context "v2 resources" do + should "raise an NotImplementedError on resource_url" do + assert_raises NotImplementedError do + Stripe::V2::Event.resource_url + end + end + + should "raise an NotImplementedError on retrieve" do + assert_raises NotImplementedError do + Stripe::V2::Event.retrieve("acct_123") + end + end + + should "raise an NotImplementedError on refresh" do + stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v2/billing/meter_event_session") + .to_return(body: JSON.generate(object: "billing.meter_event_session")) + + client = Stripe::StripeClient.new("sk_test_123") + session = client.v2.billing.meter_event_session.create + assert_raises NotImplementedError do + session.refresh + end + end + end + @@fixtures = {} # rubocop:disable Style/ClassVars setup do if @@fixtures.empty?