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 BillingPortal namespace and Session resource and APIs #911

Merged
merged 1 commit into from Apr 22, 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.79.0
- STRIPE_MOCK_VERSION=0.88.0

cache:
directories:
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/object_types.rb
Expand Up @@ -19,6 +19,7 @@ def self.object_names_to_classes
Balance::OBJECT_NAME => Balance,
BalanceTransaction::OBJECT_NAME => BalanceTransaction,
BankAccount::OBJECT_NAME => BankAccount,
BillingPortal::Session::OBJECT_NAME => BillingPortal::Session,
BitcoinReceiver::OBJECT_NAME => BitcoinReceiver,
BitcoinTransaction::OBJECT_NAME => BitcoinTransaction,
Capability::OBJECT_NAME => Capability,
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/resources.rb
Expand Up @@ -9,6 +9,7 @@
require "stripe/resources/balance"
require "stripe/resources/balance_transaction"
require "stripe/resources/bank_account"
require "stripe/resources/billing_portal/session"
require "stripe/resources/bitcoin_receiver"
require "stripe/resources/bitcoin_transaction"
require "stripe/resources/capability"
Expand Down
11 changes: 11 additions & 0 deletions lib/stripe/resources/billing_portal/session.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Stripe
module BillingPortal
class Session < APIResource
extend Stripe::APIOperations::Create

OBJECT_NAME = "billing_portal.session"
end
end
end
18 changes: 18 additions & 0 deletions test/stripe/billing_portal/session_test.rb
@@ -0,0 +1,18 @@
# frozen_string_literal: true

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

module Stripe
module BillingPortal
class SessionTest < Test::Unit::TestCase
should "be creatable" do
session = Stripe::BillingPortal::Session.create(
customer: "cus_123",
return_url: "https://stripe.com/return"
)
assert_requested :post, "#{Stripe.api_base}/v1/billing_portal/sessions"
assert session.is_a?(Stripe::BillingPortal::Session)
end
end
end
end
14 changes: 13 additions & 1 deletion test/stripe/issuing/card_test.rb
Expand Up @@ -43,6 +43,10 @@ class CardTest < Test::Unit::TestCase

context "#details" do
should "retrieve a card's details" do
# The /details endpoint is deprecated and not in the spec so we mock
stub_request(:get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details")
.to_return(body: JSON.generate(object: "issuing.card_details"))

card_details = Stripe::Issuing::Card.details("ic_123")
assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details"
assert card_details.is_a?(Stripe::Issuing::CardDetails)
Expand All @@ -51,8 +55,16 @@ class CardTest < Test::Unit::TestCase

context ".details" do
should "retrieve a card's details" do
card = Stripe::Issuing::Card.retrieve("ic_123")
# The /details endpoint is deprecated and not in the spec so we mock
stub_request(:get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details")
.to_return(body: JSON.generate(object: "issuing.card_details"))

card = Stripe::Issuing::Card.construct_from(
id: "ic_123",
object: "issuing.card_details"
)
card_details = card.details

assert_requested :get, "#{Stripe.api_base}/v1/issuing/cards/ic_123/details"
assert card_details.is_a?(Stripe::Issuing::CardDetails)
end
Expand Down
16 changes: 3 additions & 13 deletions test/stripe/issuing/dispute_test.rb
Expand Up @@ -6,10 +6,8 @@ module Stripe
module Issuing
class DisputeTest < Test::Unit::TestCase
should "be creatable" do
dispute = Stripe::Issuing::Dispute.create(
reason: "fraudulent",
disputed_transaction: "ipi_123"
)
dispute = Stripe::Issuing::Dispute.create

assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes"
assert dispute.is_a?(Stripe::Issuing::Dispute)
end
Expand All @@ -27,16 +25,8 @@ class DisputeTest < Test::Unit::TestCase
assert dispute.is_a?(Stripe::Issuing::Dispute)
end

should "be saveable" do
dispute = Stripe::Issuing::Dispute.retrieve("ich_123")
dispute.metadata["key"] = "value"
dispute.save
assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes/#{dispute.id}"
assert dispute.is_a?(Stripe::Issuing::Dispute)
end

should "be updateable" do
dispute = Stripe::Issuing::Dispute.update("ich_123", metadata: { foo: "bar" })
dispute = Stripe::Issuing::Dispute.update("ich_123", {})
assert_requested :post, "#{Stripe.api_base}/v1/issuing/disputes/ich_123"
assert dispute.is_a?(Stripe::Issuing::Dispute)
end
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.79.0"
MOCK_MINIMUM_VERSION = "0.88.0"
MOCK_PORT = Stripe::StripeMock.start

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