-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bc6ae8
commit f256e0d
Showing
10 changed files
with
162 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class Person < APIResource | ||
extend Stripe::APIOperations::List | ||
include Stripe::APIOperations::Save | ||
|
||
OBJECT_NAME = "person".freeze | ||
|
||
def resource_url | ||
"#{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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class PersonTest < Test::Unit::TestCase | ||
setup do | ||
@account = Stripe::Account.retrieve("acct_123") | ||
end | ||
|
||
should "be listable" do | ||
persons_tmp = @account.persons | ||
WebMock::RequestRegistry.instance.reset! | ||
persons = persons_tmp.list | ||
assert_requested :get, | ||
"#{Stripe.api_base}/v1/accounts/#{@account.id}/persons" | ||
assert persons.data.is_a?(Array) | ||
assert persons.data[0].is_a?(Stripe::Person) | ||
end | ||
|
||
should "be retrievable" do | ||
person = @account.persons.retrieve("person_123") | ||
assert_requested :get, | ||
"#{Stripe.api_base}/v1/accounts/#{@account.id}/persons/person_123" | ||
assert person.is_a?(Stripe::Person) | ||
end | ||
|
||
should "be creatable" do | ||
person = @account.persons.create( | ||
first_name: "John" | ||
) | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/accounts/#{@account.id}/persons" | ||
assert person.is_a?(Stripe::Person) | ||
end | ||
|
||
should "be saveable" do | ||
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 |