Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Updates #1040

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/stripe/resources/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Stripe
class Charge < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save

OBJECT_NAME = "charge"
Expand All @@ -19,5 +20,13 @@ def capture(params = {}, opts = {})
opts: opts
)
end

def self.search(params = {}, opts = {})
_search("/v1/charges/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Customer < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save
extend Stripe::APIOperations::NestedResource

Expand Down Expand Up @@ -48,5 +49,13 @@ def delete_discount
resp, opts = execute_resource_request(:delete, resource_url + "/discount")
Util.convert_to_stripe_object(resp.data, opts)
end

def self.search(params = {}, opts = {})
_search("/v1/customers/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/resources/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Invoice < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save

OBJECT_NAME = "invoice"
Expand Down Expand Up @@ -70,5 +71,13 @@ def self.list_upcoming_line_items(params, opts = {})
resp, opts = execute_resource_request(:get, resource_url + "/upcoming/lines", params, opts)
Util.convert_to_stripe_object(resp.data, opts)
end

def self.search(params = {}, opts = {})
_search("/v1/invoices/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/resources/payment_intent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Stripe
class PaymentIntent < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save

OBJECT_NAME = "payment_intent"
Expand Down Expand Up @@ -49,5 +50,13 @@ def verify_microdeposits(params = {}, opts = {})
opts: opts
)
end

def self.search(params = {}, opts = {})
_search("/v1/payment_intents/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/resources/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ module Stripe
class Price < APIResource
extend Stripe::APIOperations::Create
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save

OBJECT_NAME = "price"

def self.search(params = {}, opts = {})
_search("/v1/prices/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/resources/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ class Product < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save

OBJECT_NAME = "product"

def self.search(params = {}, opts = {})
_search("/v1/products/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
9 changes: 9 additions & 0 deletions lib/stripe/resources/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Subscription < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save

OBJECT_NAME = "subscription"
Expand All @@ -22,5 +23,13 @@ def delete_discount(params = {}, opts = {})
end

save_nested_resource :source

def self.search(params = {}, opts = {})
_search("/v1/subscriptions/search", params, opts)
end

def self.search_auto_paging_each(params = {}, opts = {}, &blk)
search(params, opts).auto_paging_each(&blk)
end
end
end
15 changes: 15 additions & 0 deletions test/stripe/charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ class ChargeTest < Test::Unit::TestCase
assert charges.data[0].is_a?(Stripe::Charge)
end

should "be searchable" do
charges = Stripe::Charge.search(query: 'currency:"USD"')
assert_requested :get, "#{Stripe.api_base}/v1/charges/search?query=currency:%22USD%22"
assert charges.total_count == 1
assert charges.data.is_a?(Array)
assert charges.data[0].is_a?(Stripe::Charge)

cnt = 0
charges.auto_paging_each do |c|
assert c.is_a?(Stripe::Charge)
cnt += 1
end
assert cnt == 1
end

should "be retrievable" do
charge = Stripe::Charge.retrieve("ch_123")
assert_requested :get, "#{Stripe.api_base}/v1/charges/ch_123"
Expand Down