mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-27 00:03:06 -05:00
Fix TaxId tests to support top-level TaxId methods (#1334)
This commit is contained in:
parent
64afe4a398
commit
3e18ad6338
@ -7,45 +7,43 @@ module Stripe
|
|||||||
#
|
#
|
||||||
# Related guides: [Customer tax identification numbers](https://stripe.com/docs/billing/taxes/tax-ids), [Account tax IDs](https://stripe.com/docs/invoicing/connect#account-tax-ids)
|
# Related guides: [Customer tax identification numbers](https://stripe.com/docs/billing/taxes/tax-ids), [Account tax IDs](https://stripe.com/docs/invoicing/connect#account-tax-ids)
|
||||||
class TaxId < APIResource
|
class TaxId < APIResource
|
||||||
|
extend Stripe::APIOperations::Create
|
||||||
include Stripe::APIOperations::Delete
|
include Stripe::APIOperations::Delete
|
||||||
|
extend Stripe::APIOperations::List
|
||||||
|
|
||||||
OBJECT_NAME = "tax_id"
|
OBJECT_NAME = "tax_id"
|
||||||
def self.object_name
|
def self.object_name
|
||||||
"tax_id"
|
"tax_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_url
|
# Creates a new account or customer tax_id object.
|
||||||
if !respond_to?(:customer) || customer.nil?
|
def self.create(params = {}, opts = {})
|
||||||
raise NotImplementedError,
|
request_stripe_object(method: :post, path: "/v1/tax_ids", params: params, opts: opts)
|
||||||
"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('customer_id', " \
|
|
||||||
"'tax_id_id')`"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deletes an existing account or customer tax_id object.
|
||||||
def self.delete(id, params = {}, opts = {})
|
def self.delete(id, params = {}, opts = {})
|
||||||
request_stripe_object(
|
request_stripe_object(
|
||||||
method: :delete,
|
method: :delete,
|
||||||
path: "#{resource_url}/#{id}",
|
path: format("/v1/tax_ids/%<id>s", { id: CGI.escape(id) }),
|
||||||
params: params,
|
params: params,
|
||||||
opts: opts
|
opts: opts
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deletes an existing account or customer tax_id object.
|
||||||
def delete(params = {}, opts = {})
|
def delete(params = {}, opts = {})
|
||||||
request_stripe_object(
|
request_stripe_object(
|
||||||
method: :delete,
|
method: :delete,
|
||||||
path: resource_url.to_s,
|
path: format("/v1/tax_ids/%<id>s", { id: CGI.escape(self["id"]) }),
|
||||||
params: params,
|
params: params,
|
||||||
opts: opts
|
opts: opts
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a list of tax IDs.
|
||||||
|
def self.list(filters = {}, opts = {})
|
||||||
|
request_stripe_object(method: :get, path: "/v1/tax_ids", params: filters, opts: opts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,21 +10,47 @@ module Stripe
|
|||||||
id: "txi_123",
|
id: "txi_123",
|
||||||
customer: "cus_123"
|
customer: "cus_123"
|
||||||
)
|
)
|
||||||
assert_equal "/v1/customers/cus_123/tax_ids/txi_123",
|
assert_equal "/v1/tax_ids/txi_123",
|
||||||
tax_id.resource_url
|
tax_id.resource_url
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
should "raise on #retrieve" do
|
should "be listable" do
|
||||||
assert_raises NotImplementedError do
|
tax_ids = Stripe::TaxId.list
|
||||||
Stripe::TaxId.retrieve("txi_123")
|
assert_requested :get, "#{Stripe.api_base}/v1/tax_ids"
|
||||||
|
assert tax_ids.data.is_a?(Array)
|
||||||
|
assert tax_ids.first.is_a?(Stripe::TaxId)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be retrievable" do
|
||||||
|
tax_id = Stripe::TaxId.retrieve("txi_123")
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/tax_ids/txi_123"
|
||||||
|
assert tax_id.is_a?(Stripe::TaxId)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
tax_id = Stripe::TaxId.create(
|
||||||
|
type: "eu_vat",
|
||||||
|
value: "DE123456789"
|
||||||
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/tax_ids"
|
||||||
|
assert tax_id.is_a?(Stripe::TaxId)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#delete" do
|
||||||
|
should "be deletable" do
|
||||||
|
tax_id = Stripe::TaxId.retrieve("txi_123")
|
||||||
|
tax_id = tax_id.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/tax_ids/#{tax_id.id}"
|
||||||
|
assert tax_id.is_a?(Stripe::TaxId)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".delete" do
|
||||||
|
should "be deletable" do
|
||||||
|
tax_id = Stripe::TaxId.delete("txi_123")
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/tax_ids/txi_123"
|
||||||
|
assert tax_id.is_a?(Stripe::TaxId)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user