mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-19 00:01:13 -05:00
Add support for the Person resource
This commit is contained in:
parent
9bc6ae85a5
commit
23d94005d3
@ -18,7 +18,7 @@ sudo: false
|
||||
env:
|
||||
global:
|
||||
# If changing this number, please also change it in `test/test_helper.rb`.
|
||||
- STRIPE_MOCK_VERSION=0.33.0
|
||||
- STRIPE_MOCK_VERSION=0.35.0
|
||||
|
||||
cache:
|
||||
directories:
|
||||
|
||||
@ -72,6 +72,7 @@ require "stripe/order"
|
||||
require "stripe/order_return"
|
||||
require "stripe/payment_intent"
|
||||
require "stripe/payout"
|
||||
require "stripe/person"
|
||||
require "stripe/plan"
|
||||
require "stripe/product"
|
||||
require "stripe/recipient"
|
||||
|
||||
@ -15,6 +15,8 @@ module Stripe
|
||||
nested_resource_class_methods :external_account,
|
||||
operations: %i[create retrieve update delete list]
|
||||
nested_resource_class_methods :login_link, operations: %i[create]
|
||||
nested_resource_class_methods :person,
|
||||
operations: %i[create retrieve update delete list]
|
||||
|
||||
# This method is deprecated. Please use `#external_account=` instead.
|
||||
save_nested_resource :bank_account
|
||||
@ -43,6 +45,11 @@ module Stripe
|
||||
super(id, opts)
|
||||
end
|
||||
|
||||
def persons(params = {}, opts = {})
|
||||
resp, opts = request(:get, resource_url + "/persons", params, Util.normalize_opts(opts))
|
||||
Util.convert_to_stripe_object(resp.data, opts)
|
||||
end
|
||||
|
||||
def reject(params = {}, opts = {})
|
||||
opts = Util.normalize_opts(opts)
|
||||
resp, opts = request(:post, resource_url + "/reject", params, opts)
|
||||
|
||||
26
lib/stripe/person.rb
Normal file
26
lib/stripe/person.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
class Person < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "person".freeze
|
||||
|
||||
def resource_url
|
||||
if !respond_to?(:account) || account.nil?
|
||||
raise NotImplementedError,
|
||||
"Persons cannot be accessed without an account ID."
|
||||
end
|
||||
"#{Account.resource_url}/#{CGI.escape(account)}/persons/#{CGI.escape(id)}"
|
||||
end
|
||||
|
||||
def self.retrieve(_id, _opts = {})
|
||||
raise NotImplementedError, "Persons cannot be retrieved without an account ID. Retrieve a person using account.persons.retrieve('person_id')"
|
||||
end
|
||||
|
||||
def self.update(_id, _params = nil, _opts = nil)
|
||||
raise NotImplementedError, "Persons cannot be updated without an account ID. Update a person using `p = account.persons.retrieve('person_id'); p.save`"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -82,6 +82,7 @@ module Stripe
|
||||
OrderReturn::OBJECT_NAME => OrderReturn,
|
||||
PaymentIntent::OBJECT_NAME => PaymentIntent,
|
||||
Payout::OBJECT_NAME => Payout,
|
||||
Person::OBJECT_NAME => Person,
|
||||
Plan::OBJECT_NAME => Plan,
|
||||
Product::OBJECT_NAME => Product,
|
||||
Recipient::OBJECT_NAME => Recipient,
|
||||
|
||||
70
test/stripe/account_persons_operations_test.rb
Normal file
70
test/stripe/account_persons_operations_test.rb
Normal file
@ -0,0 +1,70 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require ::File.expand_path("../../test_helper", __FILE__)
|
||||
|
||||
module Stripe
|
||||
class AccountPersonsOperationsTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@account_id = "acct_123"
|
||||
@person_id = "person_123"
|
||||
end
|
||||
|
||||
context "#create_person" do
|
||||
should "create a person" do
|
||||
person = Stripe::Account.create_person(
|
||||
@account_id,
|
||||
first_name: "John",
|
||||
last_name: "Doe"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{@account_id}/persons"
|
||||
assert person.is_a?(Stripe::Person)
|
||||
end
|
||||
end
|
||||
|
||||
context "#retrieve_person" do
|
||||
should "retrieve a person" do
|
||||
person = Stripe::Account.retrieve_person(
|
||||
@account_id,
|
||||
@person_id
|
||||
)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts/#{@account_id}/persons/#{@person_id}"
|
||||
assert person.is_a?(Stripe::Person)
|
||||
end
|
||||
end
|
||||
|
||||
context "#update_person" do
|
||||
should "update a person" do
|
||||
person = Stripe::Account.update_person(
|
||||
@account_id,
|
||||
@person_id,
|
||||
first_name: "John"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{@account_id}/persons/#{@person_id}"
|
||||
assert person.is_a?(Stripe::Person)
|
||||
end
|
||||
end
|
||||
|
||||
context "#delete_person" do
|
||||
should "delete an person" do
|
||||
person = Stripe::Account.delete_person(
|
||||
@account_id,
|
||||
@person_id
|
||||
)
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{@account_id}/persons/#{@person_id}"
|
||||
assert person.deleted
|
||||
assert_equal @person_id, person.id
|
||||
end
|
||||
end
|
||||
|
||||
context "#list_persons" do
|
||||
should "list the account's external accounts" do
|
||||
persons = Stripe::Account.list_persons(
|
||||
@account_id
|
||||
)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts/#{@account_id}/persons"
|
||||
assert persons.is_a?(Stripe::ListObject)
|
||||
assert persons.data.is_a?(Array)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -61,6 +61,14 @@ module Stripe
|
||||
assert account.is_a?(Stripe::Account)
|
||||
end
|
||||
|
||||
should "be able to list Persons" do
|
||||
account = Stripe::Account.retrieve("acct_123")
|
||||
persons = account.persons
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts/acct_123/persons"
|
||||
assert persons.data.is_a?(Array)
|
||||
assert persons.data[0].is_a?(Stripe::Person)
|
||||
end
|
||||
|
||||
context "#bank_account=" do
|
||||
should "warn that #bank_account= is deprecated" do
|
||||
old_stderr = $stderr
|
||||
|
||||
@ -17,19 +17,17 @@ module Stripe
|
||||
end
|
||||
|
||||
should "be creatable" do
|
||||
card = @customer.sources.create(
|
||||
@customer.sources.create(
|
||||
source: "tok_123"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
|
||||
assert card.is_a?(Stripe::BankAccount)
|
||||
end
|
||||
|
||||
should "be deletable" do
|
||||
card = Stripe::Card.construct_from(customer: @customer.id,
|
||||
id: "card_123")
|
||||
card = card.delete
|
||||
card.delete
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/card_123"
|
||||
assert card.is_a?(Stripe::Card)
|
||||
end
|
||||
|
||||
should "be saveable" do
|
||||
|
||||
@ -11,46 +11,42 @@ module Stripe
|
||||
|
||||
context "#create_source" do
|
||||
should "create a source" do
|
||||
source = Stripe::Customer.create_source(
|
||||
Stripe::Customer.create_source(
|
||||
@customer_id,
|
||||
source: "tok_123"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer_id}/sources"
|
||||
assert source.is_a?(Stripe::BankAccount)
|
||||
end
|
||||
end
|
||||
|
||||
context "#retrieve_source" do
|
||||
should "retrieve a source" do
|
||||
source = Stripe::Customer.retrieve_source(
|
||||
Stripe::Customer.retrieve_source(
|
||||
@customer_id,
|
||||
@source_id
|
||||
)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/customers/#{@customer_id}/sources/#{@source_id}"
|
||||
assert source.is_a?(Stripe::BankAccount)
|
||||
end
|
||||
end
|
||||
|
||||
context "#update_source" do
|
||||
should "update a source" do
|
||||
source = Stripe::Customer.update_source(
|
||||
Stripe::Customer.update_source(
|
||||
@customer_id,
|
||||
@source_id,
|
||||
metadata: { foo: "bar" }
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer_id}/sources/#{@source_id}"
|
||||
assert source.is_a?(Stripe::Card)
|
||||
end
|
||||
end
|
||||
|
||||
context "#delete_source" do
|
||||
should "delete a source" do
|
||||
source = Stripe::Customer.delete_source(
|
||||
Stripe::Customer.delete_source(
|
||||
@customer_id,
|
||||
@source_id
|
||||
)
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer_id}/sources/#{@source_id}"
|
||||
assert source.is_a?(Stripe::BankAccount)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -49,9 +49,7 @@ module Stripe
|
||||
context "#return_order" do
|
||||
should "return an order" do
|
||||
order = Stripe::Order.retrieve("or_123")
|
||||
order = order.return_order(items: [
|
||||
{ parent: "sku_123" },
|
||||
])
|
||||
order = order.return_order({})
|
||||
assert order.is_a?(Stripe::OrderReturn)
|
||||
end
|
||||
end
|
||||
|
||||
46
test/stripe/person_test.rb
Normal file
46
test/stripe/person_test.rb
Normal file
@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require ::File.expand_path("../../test_helper", __FILE__)
|
||||
|
||||
module Stripe
|
||||
class PersonTest < Test::Unit::TestCase
|
||||
context "#resource_url" do
|
||||
should "return a resource URL" do
|
||||
person = Stripe::Person.construct_from(
|
||||
id: "person_123",
|
||||
account: "acct_123"
|
||||
)
|
||||
assert_equal "/v1/accounts/acct_123/persons/person_123",
|
||||
person.resource_url
|
||||
end
|
||||
|
||||
should "raise without an account" do
|
||||
person = Stripe::Person.construct_from(id: "person_123")
|
||||
assert_raises NotImplementedError do
|
||||
person.resource_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "raise on #retrieve" do
|
||||
assert_raises NotImplementedError do
|
||||
Stripe::Person.retrieve("person_123")
|
||||
end
|
||||
end
|
||||
|
||||
should "raise on #update" do
|
||||
assert_raises NotImplementedError do
|
||||
Stripe::Person.update("person_123", {})
|
||||
end
|
||||
end
|
||||
|
||||
should "be saveable" do
|
||||
account = Stripe::Account.retrieve("acct_123")
|
||||
person = account.persons.retrieve("person_123")
|
||||
person.first_name = "John"
|
||||
person.save
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/accounts/#{person.account}/persons/#{person.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -16,7 +16,7 @@ PROJECT_ROOT = ::File.expand_path("../../", __FILE__)
|
||||
require ::File.expand_path("../test_data", __FILE__)
|
||||
|
||||
# If changing this number, please also change it in `.travis.yml`.
|
||||
MOCK_MINIMUM_VERSION = "0.33.0".freeze
|
||||
MOCK_MINIMUM_VERSION = "0.35.0".freeze
|
||||
MOCK_PORT = ENV["STRIPE_MOCK_PORT"] || 12_111
|
||||
|
||||
# Disable all real network connections except those that are outgoing to
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user