-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #634 from stripe/alexander/flexible-billing
Flexible/Metered Billing API support
- Loading branch information
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 |