-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Customer Balance Transaction resource and APIs
- Loading branch information
1 parent
cd05d36
commit b3cc38e
Showing
6 changed files
with
89 additions
and
0 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
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class CustomerBalanceTransaction < APIResource | ||
OBJECT_NAME = "customer_balance_transaction".freeze | ||
|
||
def resource_url | ||
if !respond_to?(:customer) || customer.nil? | ||
raise NotImplementedError, | ||
"Customer Balance Transactions cannot be accessed without a customer ID." | ||
end | ||
"#{Customer.resource_url}/#{CGI.escape(customer)}/customer_balance_transactions/#{CGI.escape(id)}" | ||
end | ||
|
||
def self.retrieve(_id, _opts = {}) | ||
raise NotImplementedError, | ||
"Customer Balance Transactions cannot be retrieved without a customer ID. " \ | ||
"Retrieve a Customer Balance Transaction using Customer.retrieve_customer_balance_transaction('cus_123', 'cbtxn_123')" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class CustomerBalanceTransactionTest < Test::Unit::TestCase | ||
context "#resource_url" do | ||
should "return a resource URL" do | ||
transaction = Stripe::CustomerBalanceTransaction.construct_from( | ||
id: "cbtxn_123", | ||
customer: "cus_123" | ||
) | ||
assert_equal "/v1/customers/cus_123/customer_balance_transactions/cbtxn_123", | ||
transaction.resource_url | ||
end | ||
|
||
should "raise without a customer" do | ||
transaction = Stripe::CustomerBalanceTransaction.construct_from(id: "cbtxn_123") | ||
assert_raises NotImplementedError do | ||
transaction.resource_url | ||
end | ||
end | ||
end | ||
|
||
should "raise on #retrieve" do | ||
assert_raises NotImplementedError do | ||
Stripe::CustomerBalanceTransaction.retrieve("cbtxn_123") | ||
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