forked from stripe/stripe-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flexible billing primitives and tests
- Loading branch information
1 parent
0b54bf7
commit c066c9c
Showing
6 changed files
with
82 additions
and
2 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,12 @@ | ||
module Stripe | ||
class UsageRecord < APIResource | ||
def self.create(params = {}, opts = {}) | ||
raise(ArgumentError, "Params must have a subscription_item key") unless params.key?(:subscription_item) | ||
req_params = params.clone.delete_if { |key, _value| key == :subscription_item } | ||
resp, opts = request(:post, "/v1/subscription_items/#{params[:subscription_item]}/usage_records", req_params, opts) | ||
Util.convert_to_stripe_object(resp.data, opts) | ||
end | ||
|
||
OBJECT_NAME = "usage_record".freeze | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class UsageRecordTest < Test::Unit::TestCase | ||
should "be creatable" do | ||
usage_record = Stripe::UsageRecord.create( | ||
quantity: 5000, | ||
subscription_item: "si_abc", | ||
timestamp: Time.now.to_i, | ||
action: "increment" | ||
) | ||
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/si_abc/usage_records" | ||
assert usage_record.is_a?(Stripe::UsageRecord) | ||
end | ||
|
||
should "raise when subscription_item is missing" do | ||
assert_raise ArgumentError do | ||
Stripe::UsageRecord.create( | ||
quantity: 5000, | ||
timestamp: Time.now.to_i, | ||
action: "increment" | ||
) | ||
end | ||
end | ||
end | ||
end |