Skip to content

Commit

Permalink
API Updates (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym-stripe authored Mar 28, 2022
1 parent fc480cd commit 90fae49
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 0 deletions.
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

0 comments on commit 90fae49

Please sign in to comment.