mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-09-27 00:01:20 -04:00
Add support for TaxId resource and APIs
This commit is contained in:
parent
5416f020d8
commit
b5cd9e3682
@ -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.52.0
|
||||
- STRIPE_MOCK_VERSION=0.54.0
|
||||
|
||||
cache:
|
||||
directories:
|
||||
|
@ -97,6 +97,7 @@ require "stripe/subscription"
|
||||
require "stripe/subscription_item"
|
||||
require "stripe/subscription_schedule"
|
||||
require "stripe/subscription_schedule_revision"
|
||||
require "stripe/tax_id"
|
||||
require "stripe/terminal/connection_token"
|
||||
require "stripe/terminal/location"
|
||||
require "stripe/terminal/reader"
|
||||
|
@ -16,6 +16,9 @@ module Stripe
|
||||
nested_resource_class_methods :source,
|
||||
operations: %i[create retrieve update delete list]
|
||||
|
||||
nested_resource_class_methods :tax_id,
|
||||
operations: %i[create retrieve delete list]
|
||||
|
||||
# The API request for deleting a card or bank account and for detaching a
|
||||
# source object are the same.
|
||||
class << self
|
||||
|
22
lib/stripe/tax_id.rb
Normal file
22
lib/stripe/tax_id.rb
Normal file
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
class TaxId < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Delete
|
||||
|
||||
OBJECT_NAME = "tax_id".freeze
|
||||
|
||||
def resource_url
|
||||
if !respond_to?(:customer) || customer.nil?
|
||||
raise NotImplementedError,
|
||||
"Tax Ids cannot be accessed without a customer ID."
|
||||
end
|
||||
"#{Customer.resource_url}/#{CGI.escape(customer)}/tax_ids/#{CGI.escape(id)}"
|
||||
end
|
||||
|
||||
def self.retrieve(_id, _opts = {})
|
||||
raise NotImplementedError, "Tax Ids cannot be retrieved without a customer ID. Retrieve a tax id using Customer.retrieve_tax_id('tax_id')"
|
||||
end
|
||||
end
|
||||
end
|
@ -107,6 +107,7 @@ module Stripe
|
||||
SubscriptionItem::OBJECT_NAME => SubscriptionItem,
|
||||
SubscriptionSchedule::OBJECT_NAME => SubscriptionSchedule,
|
||||
SubscriptionScheduleRevision::OBJECT_NAME => SubscriptionScheduleRevision,
|
||||
TaxId::OBJECT_NAME => TaxId,
|
||||
Terminal::ConnectionToken::OBJECT_NAME => Terminal::ConnectionToken,
|
||||
Terminal::Location::OBJECT_NAME => Terminal::Location,
|
||||
Terminal::Reader::OBJECT_NAME => Terminal::Reader,
|
||||
|
@ -180,5 +180,47 @@ module Stripe
|
||||
assert_equal true, c.source.save_with_parent
|
||||
end
|
||||
end
|
||||
|
||||
context "#create_tax_id" do
|
||||
should "create a tax id" do
|
||||
Stripe::Customer.create_tax_id(
|
||||
"cus_123",
|
||||
type: "eu_vat",
|
||||
value: "11111"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/cus_123/tax_ids"
|
||||
end
|
||||
end
|
||||
|
||||
context "#retrieve_tax_id" do
|
||||
should "retrieve a tax id" do
|
||||
Stripe::Customer.retrieve_tax_id(
|
||||
"cus_123",
|
||||
"txi_123"
|
||||
)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/customers/cus_123/tax_ids/txi_123"
|
||||
end
|
||||
end
|
||||
|
||||
context "#delete_tax_id" do
|
||||
should "delete a tax id" do
|
||||
Stripe::Customer.delete_tax_id(
|
||||
"cus_123",
|
||||
"txi_123"
|
||||
)
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/customers/cus_123/tax_ids/txi_123"
|
||||
end
|
||||
end
|
||||
|
||||
context "#list_tax_ids" do
|
||||
should "list the customer's tax ids" do
|
||||
sources = Stripe::Customer.list_tax_ids(
|
||||
"cus_123"
|
||||
)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/customers/cus_123/tax_ids"
|
||||
assert sources.is_a?(Stripe::ListObject)
|
||||
assert sources.data.is_a?(Array)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
31
test/stripe/tax_id_test.rb
Normal file
31
test/stripe/tax_id_test.rb
Normal file
@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require ::File.expand_path("../../test_helper", __FILE__)
|
||||
|
||||
module Stripe
|
||||
class TaxIdTest < Test::Unit::TestCase
|
||||
context "#resource_url" do
|
||||
should "return a resource URL" do
|
||||
tax_id = Stripe::TaxId.construct_from(
|
||||
id: "txi_123",
|
||||
customer: "cus_123"
|
||||
)
|
||||
assert_equal "/v1/customers/cus_123/tax_ids/txi_123",
|
||||
tax_id.resource_url
|
||||
end
|
||||
|
||||
should "raise without a customer" do
|
||||
tax_id = Stripe::TaxId.construct_from(id: "txi_123")
|
||||
assert_raises NotImplementedError do
|
||||
tax_id.resource_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "raise on #retrieve" do
|
||||
assert_raises NotImplementedError do
|
||||
Stripe::TaxId.retrieve("txi_123")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -17,7 +17,7 @@ require ::File.expand_path("../test_data", __FILE__)
|
||||
require ::File.expand_path("../stripe_mock", __FILE__)
|
||||
|
||||
# If changing this number, please also change it in `.travis.yml`.
|
||||
MOCK_MINIMUM_VERSION = "0.52.0".freeze
|
||||
MOCK_MINIMUM_VERSION = "0.54.0".freeze
|
||||
MOCK_PORT = Stripe::StripeMock.start
|
||||
|
||||
# Disable all real network connections except those that are outgoing to
|
||||
|
Loading…
x
Reference in New Issue
Block a user