-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Subscription Schedules
- Loading branch information
1 parent
94bafb4
commit d784819
Showing
11 changed files
with
269 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class SubscriptionSchedule < APIResource | ||
extend Stripe::APIOperations::List | ||
extend Stripe::APIOperations::Create | ||
include Stripe::APIOperations::Save | ||
extend Stripe::APIOperations::NestedResource | ||
|
||
OBJECT_NAME = "subscription_schedule".freeze | ||
|
||
nested_resource_class_methods :revision, | ||
operations: %i[retrieve list] | ||
|
||
def cancel(params = {}, opts = {}) | ||
url = resource_url + "/cancel" | ||
resp, opts = request(:post, url, params, opts) | ||
initialize_from(resp.data, opts) | ||
end | ||
|
||
def release(params = {}, opts = {}) | ||
url = resource_url + "/release" | ||
resp, opts = request(:post, url, params, opts) | ||
initialize_from(resp.data, opts) | ||
end | ||
|
||
def revisions(params = {}, opts = {}) | ||
resp, opts = request(:get, resource_url + "/revisions", params, Util.normalize_opts(opts)) | ||
Util.convert_to_stripe_object(resp.data, opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class SubscriptionScheduleRevision < APIResource | ||
extend Stripe::APIOperations::List | ||
|
||
OBJECT_NAME = "subscription_schedule_revision".freeze | ||
|
||
def resource_url | ||
if !respond_to?(:schedule) || schedule.nil? | ||
raise NotImplementedError, | ||
"Subscription Schedule Revisions cannot be accessed without a Subscription Schedule ID." | ||
end | ||
"#{SubscriptionSchedule.resource_url}/#{CGI.escape(schedule)}/revisions/#{CGI.escape(id)}" | ||
end | ||
|
||
def self.retrieve(_id, _opts = {}) | ||
raise NotImplementedError, "Subscription Schedule Revisions cannot be retrieved without a Subscription Schedule ID. Retrieve it using schedule.revisions.retrieve('revision_id')" | ||
end | ||
|
||
def self.list(_id, _opts = {}) | ||
raise NotImplementedError, "Subscription Schedule Revisions cannot be listed without a Subscription Schedule ID. List those using schedule.revisions" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class SubscriptionScheduleRevisionTest < Test::Unit::TestCase | ||
context "#resource_url" do | ||
should "return a resource URL" do | ||
revision = Stripe::SubscriptionScheduleRevision.construct_from( | ||
id: "sub_sched_rev_123", | ||
schedule: "sub_sched_123" | ||
) | ||
assert_equal "/v1/subscription_schedules/sub_sched_123/revisions/sub_sched_rev_123", | ||
revision.resource_url | ||
end | ||
|
||
should "raise without a subscription schedule" do | ||
revision = Stripe::SubscriptionScheduleRevision.construct_from(id: "sub_sched_rev_123") | ||
assert_raises NotImplementedError do | ||
revision.resource_url | ||
end | ||
end | ||
end | ||
|
||
should "raise on #retrieve" do | ||
assert_raises NotImplementedError do | ||
Stripe::SubscriptionScheduleRevision.retrieve("sub_sched_rev_123") | ||
end | ||
end | ||
|
||
should "raise on #list" do | ||
assert_raises NotImplementedError do | ||
Stripe::SubscriptionScheduleRevision.list("sub_sched_rev_123", {}) | ||
end | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
test/stripe/subscription_schedule_revisions_operations_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class SubscriptionScheduleRevisionsOperationsTest < Test::Unit::TestCase | ||
setup do | ||
@schedule_id = "sub_sched_123" | ||
@revision_id = "sub_sched_rev_123" | ||
end | ||
|
||
context "#retrieve_revision" do | ||
should "retrieve a subscription schedule revision" do | ||
revision = Stripe::SubscriptionSchedule.retrieve_revision( | ||
@schedule_id, | ||
@revision_id | ||
) | ||
assert_requested :get, "#{Stripe.api_base}/v1/subscription_schedules/#{@schedule_id}/revisions/#{@revision_id}" | ||
assert revision.is_a?(Stripe::SubscriptionScheduleRevision) | ||
end | ||
end | ||
|
||
context "#list_revisions" do | ||
should "list a subscription schedule's revisions" do | ||
revisions = Stripe::SubscriptionSchedule.list_revisions( | ||
@schedule_id | ||
) | ||
assert_requested :get, "#{Stripe.api_base}/v1/subscription_schedules/#{@schedule_id}/revisions" | ||
assert revisions.is_a?(Stripe::ListObject) | ||
assert revisions.data.is_a?(Array) | ||
assert revisions.data[0].is_a?(Stripe::SubscriptionScheduleRevision) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class SubscriptionScheduleTest < Test::Unit::TestCase | ||
should "be listable" do | ||
subscriptions = Stripe::SubscriptionSchedule.list | ||
assert_requested :get, "#{Stripe.api_base}/v1/subscription_schedules" | ||
assert subscriptions.data.is_a?(Array) | ||
assert subscriptions.data[0].is_a?(Stripe::SubscriptionSchedule) | ||
end | ||
|
||
should "be retrievable" do | ||
schedule = Stripe::SubscriptionSchedule.retrieve("sub_sched_123") | ||
assert_requested :get, | ||
"#{Stripe.api_base}/v1/subscription_schedules/sub_sched_123" | ||
assert schedule.is_a?(Stripe::SubscriptionSchedule) | ||
end | ||
|
||
should "be creatable" do | ||
schedule = Stripe::SubscriptionSchedule.create( | ||
customer: "cus_123" | ||
) | ||
assert_requested :post, "#{Stripe.api_base}/v1/subscription_schedules" | ||
assert schedule.is_a?(Stripe::SubscriptionSchedule) | ||
end | ||
|
||
should "be saveable" do | ||
schedule = Stripe::SubscriptionSchedule.retrieve("sub_sched_123") | ||
schedule.metadata["key"] = "value" | ||
schedule.save | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/subscription_schedules/#{schedule.id}" | ||
end | ||
|
||
should "be updateable" do | ||
schedule = Stripe::SubscriptionSchedule.update("sub_sched_123", metadata: { foo: "bar" }) | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/subscription_schedules/sub_sched_123" | ||
assert schedule.is_a?(Stripe::SubscriptionSchedule) | ||
end | ||
|
||
context "#cancel" do | ||
should "cancel a subscription schedule" do | ||
schedule = Stripe::SubscriptionSchedule.retrieve("sub_sched_123") | ||
schedule = schedule.cancel | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/subscription_schedules/#{schedule.id}/cancel" | ||
assert schedule.is_a?(Stripe::SubscriptionSchedule) | ||
end | ||
end | ||
|
||
context "#release" do | ||
should "release a subscription schedule" do | ||
schedule = Stripe::SubscriptionSchedule.retrieve("sub_sched_123") | ||
schedule = schedule.release | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/subscription_schedules/#{schedule.id}/release" | ||
assert schedule.is_a?(Stripe::SubscriptionSchedule) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters