From 40596cbbf6f9ba5fdbf7f5451a2403018434792b Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 28 Mar 2022 11:16:06 -0700 Subject: [PATCH 1/2] Codegen for openapi 2956fca --- lib/stripe/resources/charge.rb | 9 +++++++++ lib/stripe/resources/customer.rb | 9 +++++++++ lib/stripe/resources/invoice.rb | 9 +++++++++ lib/stripe/resources/payment_intent.rb | 9 +++++++++ lib/stripe/resources/price.rb | 9 +++++++++ lib/stripe/resources/product.rb | 9 +++++++++ lib/stripe/resources/subscription.rb | 9 +++++++++ 7 files changed, 63 insertions(+) diff --git a/lib/stripe/resources/charge.rb b/lib/stripe/resources/charge.rb index 4f3a2e4f4..bd0091679 100644 --- a/lib/stripe/resources/charge.rb +++ b/lib/stripe/resources/charge.rb @@ -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" @@ -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 diff --git a/lib/stripe/resources/customer.rb b/lib/stripe/resources/customer.rb index bb9f2244b..aa7605fdb 100644 --- a/lib/stripe/resources/customer.rb +++ b/lib/stripe/resources/customer.rb @@ -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 @@ -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 diff --git a/lib/stripe/resources/invoice.rb b/lib/stripe/resources/invoice.rb index 47651253e..14c8695df 100644 --- a/lib/stripe/resources/invoice.rb +++ b/lib/stripe/resources/invoice.rb @@ -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" @@ -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 diff --git a/lib/stripe/resources/payment_intent.rb b/lib/stripe/resources/payment_intent.rb index ea22b040e..b10f369ee 100644 --- a/lib/stripe/resources/payment_intent.rb +++ b/lib/stripe/resources/payment_intent.rb @@ -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" @@ -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 diff --git a/lib/stripe/resources/price.rb b/lib/stripe/resources/price.rb index f2c1092bc..d743a03a9 100644 --- a/lib/stripe/resources/price.rb +++ b/lib/stripe/resources/price.rb @@ -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 diff --git a/lib/stripe/resources/product.rb b/lib/stripe/resources/product.rb index acdcc8d26..f430028a4 100644 --- a/lib/stripe/resources/product.rb +++ b/lib/stripe/resources/product.rb @@ -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 diff --git a/lib/stripe/resources/subscription.rb b/lib/stripe/resources/subscription.rb index 0325bf35f..cd67a43bc 100644 --- a/lib/stripe/resources/subscription.rb +++ b/lib/stripe/resources/subscription.rb @@ -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" @@ -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 From cb681dbb09d55cb3a6fdbab590e0d11e349df466 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 28 Mar 2022 11:29:00 -0700 Subject: [PATCH 2/2] test and total_count --- test/stripe/charge_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/stripe/charge_test.rb b/test/stripe/charge_test.rb index 9fe327a36..2cbcf0e6a 100644 --- a/test/stripe/charge_test.rb +++ b/test/stripe/charge_test.rb @@ -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"