diff --git a/.travis.yml b/.travis.yml index b9d2c1479..8b4eb531c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/lib/stripe/object_types.rb b/lib/stripe/object_types.rb index cd685d3d8..9f6e9c787 100644 --- a/lib/stripe/object_types.rb +++ b/lib/stripe/object_types.rb @@ -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, diff --git a/lib/stripe/resources.rb b/lib/stripe/resources.rb index fc58b8d01..7c35ee63c 100644 --- a/lib/stripe/resources.rb +++ b/lib/stripe/resources.rb @@ -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" diff --git a/lib/stripe/resources/price.rb b/lib/stripe/resources/price.rb new file mode 100644 index 000000000..9323a59a3 --- /dev/null +++ b/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 diff --git a/test/stripe/price_test.rb b/test/stripe/price_test.rb new file mode 100644 index 000000000..fdaf3d4f3 --- /dev/null +++ b/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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 80b079a0d..bfb0a4153 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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