Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the PromotionCode resource and APIs #937

Merged
merged 2 commits into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.94.0
- STRIPE_MOCK_VERSION=0.95.0

cache:
directories:
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/object_types.rb
Expand Up @@ -61,6 +61,7 @@ def self.object_names_to_classes
Plan::OBJECT_NAME => Plan,
Price::OBJECT_NAME => Price,
Product::OBJECT_NAME => Product,
PromotionCode::OBJECT_NAME => PromotionCode,
Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
Radar::ValueList::OBJECT_NAME => Radar::ValueList,
Radar::ValueListItem::OBJECT_NAME => Radar::ValueListItem,
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/resources.rb
Expand Up @@ -50,6 +50,7 @@
require "stripe/resources/plan"
require "stripe/resources/price"
require "stripe/resources/product"
require "stripe/resources/promotion_code"
require "stripe/resources/radar/early_fraud_warning"
require "stripe/resources/radar/value_list"
require "stripe/resources/radar/value_list_item"
Expand Down
12 changes: 12 additions & 0 deletions lib/stripe/resources/promotion_code.rb
@@ -0,0 +1,12 @@
# File generated from our OpenAPI spec
# frozen_string_literal: true

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

OBJECT_NAME = "promotion_code"
end
end
42 changes: 42 additions & 0 deletions test/stripe/promotion_code_test.rb
@@ -0,0 +1,42 @@
# frozen_string_literal: true

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

module Stripe
class PromotionCodeTest < Test::Unit::TestCase
should "be listable" do
promotion_codes = Stripe::PromotionCode.list
assert_requested :get, "#{Stripe.api_base}/v1/promotion_codes"
assert promotion_codes.data.is_a?(Array)
assert promotion_codes.first.is_a?(Stripe::PromotionCode)
end

should "be retrievable" do
coupon = Stripe::PromotionCode.retrieve("PROMO_123")
assert_requested :get, "#{Stripe.api_base}/v1/promotion_codes/PROMO_123"
assert coupon.is_a?(Stripe::PromotionCode)
end

should "be creatable" do
coupon = Stripe::PromotionCode.create(
coupon: "co_123",
code: "MYCODE"
)
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes"
assert coupon.is_a?(Stripe::PromotionCode)
end

should "be saveable" do
coupon = Stripe::PromotionCode.retrieve("PROMO_123")
coupon.metadata["key"] = "value"
coupon.save
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/#{coupon.id}"
end

should "be updateable" do
coupon = Stripe::PromotionCode.update("PROMO_123", metadata: { key: "value" })
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/PROMO_123"
assert coupon.is_a?(Stripe::PromotionCode)
end
end
end
2 changes: 1 addition & 1 deletion test/stripe/subscription_item_test.rb
Expand Up @@ -22,7 +22,7 @@ class SubscriptionItemTest < Test::Unit::TestCase

should "be creatable" do
item = Stripe::SubscriptionItem.create(
plan: "sapphire-elite",
price: "sapphire-elite",
quantity: 3,
subscription: "sub_123"
)
Expand Down
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.94.0"
MOCK_MINIMUM_VERSION = "0.95.0"
MOCK_PORT = Stripe::StripeMock.start

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