Skip to content

Commit

Permalink
Add support for the Price resource and APIs (#917)
Browse files Browse the repository at this point in the history
* Codegen for openapi f75fd88

* Fix test suite
  • Loading branch information
remi-stripe committed Apr 29, 2020
1 parent 07f58ca commit 622db9d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -17,7 +17,7 @@ sudo: false
env:
global:
# If changing this number, please also change it in `test/test_helper.rb`.
- STRIPE_MOCK_VERSION=0.88.0
- STRIPE_MOCK_VERSION=0.89.0

cache:
directories:
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/object_types.rb
Expand Up @@ -58,6 +58,7 @@ def self.object_names_to_classes
Payout::OBJECT_NAME => Payout,
Person::OBJECT_NAME => Person,
Plan::OBJECT_NAME => Plan,
Price::OBJECT_NAME => Price,
Product::OBJECT_NAME => Product,
Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
Radar::ValueList::OBJECT_NAME => Radar::ValueList,
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/resources.rb
Expand Up @@ -47,6 +47,7 @@
require "stripe/resources/payout"
require "stripe/resources/person"
require "stripe/resources/plan"
require "stripe/resources/price"
require "stripe/resources/product"
require "stripe/resources/radar/early_fraud_warning"
require "stripe/resources/radar/value_list"
Expand Down
11 changes: 11 additions & 0 deletions lib/stripe/resources/price.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Stripe
class Price < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save

OBJECT_NAME = "price"
end
end
48 changes: 48 additions & 0 deletions test/stripe/price_test.rb
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require ::File.expand_path("../test_helper", __dir__)

module Stripe
class PriceTest < Test::Unit::TestCase
should "be listable" do
prices = Stripe::Price.list
assert_requested :get, "#{Stripe.api_base}/v1/prices"
assert prices.data.is_a?(Array)
assert prices.data[0].is_a?(Stripe::Price)
end

should "be retrievable" do
price = Stripe::Price.retrieve("price_123")
assert_requested :get, "#{Stripe.api_base}/v1/prices/price_123"
assert price.is_a?(Stripe::Price)
end

should "be creatable" do
price = Stripe::Price.create(
unit_amount: 5000,
currency: "usd",
recurring: {
interval: "month",
},
product_data: {
name: "Product name",
}
)
assert_requested :post, "#{Stripe.api_base}/v1/prices"
assert price.is_a?(Stripe::Price)
end

should "be saveable" do
price = Stripe::Price.retrieve("price_123")
price.metadata["key"] = "value"
price.save
assert_requested :post, "#{Stripe.api_base}/v1/prices/#{price.id}"
end

should "be updateable" do
price = Stripe::Price.update("price_123", metadata: { foo: "bar" })
assert_requested :post, "#{Stripe.api_base}/v1/prices/price_123"
assert price.is_a?(Stripe::Price)
end
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -16,7 +16,7 @@
require ::File.expand_path("stripe_mock", __dir__)

# If changing this number, please also change it in `.travis.yml`.
MOCK_MINIMUM_VERSION = "0.88.0"
MOCK_MINIMUM_VERSION = "0.89.0"
MOCK_PORT = Stripe::StripeMock.start

# Disable all real network connections except those that are outgoing to
Expand Down

0 comments on commit 622db9d

Please sign in to comment.