From 19d0e34c0d87b1ea2ab07ac67c8c8c4950d6ba4b Mon Sep 17 00:00:00 2001 From: pakrym-stripe <99349468+pakrym-stripe@users.noreply.github.com> Date: Mon, 28 Mar 2022 12:57:50 -0700 Subject: [PATCH] API Updates (#1383) --- .gitignore | 1 + lib/resources/Charges.js | 6 ++++++ lib/resources/Customers.js | 6 ++++++ lib/resources/Invoices.js | 6 ++++++ lib/resources/PaymentIntents.js | 6 ++++++ lib/resources/Prices.js | 6 ++++++ lib/resources/Products.js | 6 ++++++ lib/resources/Subscriptions.js | 6 ++++++ test/resources/Integration.spec.js | 28 ++++++++++++++++++++++++++ types/2020-08-27/Charges.d.ts | 30 ++++++++++++++++++++++++++++ types/2020-08-27/Customers.d.ts | 30 ++++++++++++++++++++++++++++ types/2020-08-27/Invoices.d.ts | 30 ++++++++++++++++++++++++++++ types/2020-08-27/PaymentIntents.d.ts | 30 ++++++++++++++++++++++++++++ types/2020-08-27/Prices.d.ts | 30 ++++++++++++++++++++++++++++ types/2020-08-27/Products.d.ts | 30 ++++++++++++++++++++++++++++ types/2020-08-27/Subscriptions.d.ts | 30 ++++++++++++++++++++++++++++ types/lib.d.ts | 6 ++++++ 17 files changed, 287 insertions(+) diff --git a/.gitignore b/.gitignore index 6acb6b74a7..ee483f2f9d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules tags .nyc_output coverage +.idea diff --git a/lib/resources/Charges.js b/lib/resources/Charges.js index 99ef97d79a..f4546063f7 100644 --- a/lib/resources/Charges.js +++ b/lib/resources/Charges.js @@ -33,4 +33,10 @@ module.exports = StripeResource.extend({ method: 'POST', path: '/{charge}/capture', }), + + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), }); diff --git a/lib/resources/Customers.js b/lib/resources/Customers.js index 2976bd3a20..660cfa78f9 100644 --- a/lib/resources/Customers.js +++ b/lib/resources/Customers.js @@ -45,6 +45,12 @@ module.exports = StripeResource.extend({ methodType: 'list', }), + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), + createBalanceTransaction: stripeMethod({ method: 'POST', path: '/{customer}/balance_transactions', diff --git a/lib/resources/Invoices.js b/lib/resources/Invoices.js index 489190f892..7103c96813 100644 --- a/lib/resources/Invoices.js +++ b/lib/resources/Invoices.js @@ -54,6 +54,12 @@ module.exports = StripeResource.extend({ path: '/upcoming', }), + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), + sendInvoice: stripeMethod({ method: 'POST', path: '/{invoice}/send', diff --git a/lib/resources/PaymentIntents.js b/lib/resources/PaymentIntents.js index af61bab8c0..decb9250a4 100644 --- a/lib/resources/PaymentIntents.js +++ b/lib/resources/PaymentIntents.js @@ -44,6 +44,12 @@ module.exports = StripeResource.extend({ path: '/{intent}/confirm', }), + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), + verifyMicrodeposits: stripeMethod({ method: 'POST', path: '/{intent}/verify_microdeposits', diff --git a/lib/resources/Prices.js b/lib/resources/Prices.js index 862e946d22..c509fdcbc0 100644 --- a/lib/resources/Prices.js +++ b/lib/resources/Prices.js @@ -28,4 +28,10 @@ module.exports = StripeResource.extend({ path: '', methodType: 'list', }), + + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), }); diff --git a/lib/resources/Products.js b/lib/resources/Products.js index ba46de32e0..3886020cf8 100644 --- a/lib/resources/Products.js +++ b/lib/resources/Products.js @@ -33,4 +33,10 @@ module.exports = StripeResource.extend({ method: 'DELETE', path: '/{id}', }), + + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), }); diff --git a/lib/resources/Subscriptions.js b/lib/resources/Subscriptions.js index 03dee40377..e757534107 100644 --- a/lib/resources/Subscriptions.js +++ b/lib/resources/Subscriptions.js @@ -38,4 +38,10 @@ module.exports = StripeResource.extend({ method: 'DELETE', path: '/{subscriptionExposedId}/discount', }), + + search: stripeMethod({ + method: 'GET', + path: '/search', + methodType: 'search', + }), }); diff --git a/test/resources/Integration.spec.js b/test/resources/Integration.spec.js index 23a4f9ca4f..c35a013481 100644 --- a/test/resources/Integration.spec.js +++ b/test/resources/Integration.spec.js @@ -14,3 +14,31 @@ describe('Customers Resource', () => { }); }); }); + +describe('Charges Resource', () => { + describe('search', () => { + it('Retrieves first page', async () => { + const result = await stripe.charges.search({query: 'currency:"USD"'}); + expect(result.total_count).to.equal(1); + expect(result.data.length).to.equal(1); + expect(result.data[0]).to.not.be.null; + }); + it('Retrieves all as array', async () => { + const result = await stripe.charges + .search({query: 'currency:"USD"'}) + .autoPagingToArray({limit: 1000}); + expect(result.length).to.equal(1); + expect(result[0]).to.not.be.null; + }); + it('Retrieves all foreach', async () => { + let cnt = 0; + await stripe.charges + .search({query: 'currency:"USD"'}) + .autoPagingEach((item) => { + expect(item).to.not.be.null; + cnt += 1; + }); + expect(cnt).to.equal(1); + }); + }); +}); diff --git a/types/2020-08-27/Charges.d.ts b/types/2020-08-27/Charges.d.ts index 0dfff16846..aa1952f0e0 100644 --- a/types/2020-08-27/Charges.d.ts +++ b/types/2020-08-27/Charges.d.ts @@ -2057,6 +2057,28 @@ declare module 'stripe' { } } + interface ChargeSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for charges](https://stripe.com/docs/search#query-fields-for-charges). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + class ChargesResource { /** * To charge a credit card or other payment source, you create a Charge object. If your API key is in test mode, the supplied payment source (e.g., card) won't actually be charged, although everything else will occur as if in live mode. (Stripe assumes that the charge would have completed successfully). @@ -2112,6 +2134,14 @@ declare module 'stripe' { id: string, options?: RequestOptions ): Promise>; + + /** + * Search for charges you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: ChargeSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; } } } diff --git a/types/2020-08-27/Customers.d.ts b/types/2020-08-27/Customers.d.ts index 87a5643130..7f52cb96c0 100644 --- a/types/2020-08-27/Customers.d.ts +++ b/types/2020-08-27/Customers.d.ts @@ -724,6 +724,28 @@ declare module 'stripe' { | 'wechat_pay'; } + interface CustomerSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for customers](https://stripe.com/docs/search#query-fields-for-customers). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + class CustomersResource { /** * Creates a new customer object. @@ -804,6 +826,14 @@ declare module 'stripe' { options?: RequestOptions ): ApiListPromise; + /** + * Search for customers you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: CustomerSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; + /** * Creates an immutable transaction that updates the customer's credit [balance](https://stripe.com/docs/billing/customer/balance). */ diff --git a/types/2020-08-27/Invoices.d.ts b/types/2020-08-27/Invoices.d.ts index c9938a22a5..e3b57c6f01 100644 --- a/types/2020-08-27/Invoices.d.ts +++ b/types/2020-08-27/Invoices.d.ts @@ -2011,6 +2011,28 @@ declare module 'stripe' { | 'none'; } + interface InvoiceSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for invoices](https://stripe.com/docs/search#query-fields-for-invoices). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + interface InvoiceSendInvoiceParams { /** * Specifies which fields in the response should be expanded. @@ -2140,6 +2162,14 @@ declare module 'stripe' { options?: RequestOptions ): Promise>; + /** + * Search for invoices you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: InvoiceSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; + /** * Stripe will automatically send invoices to customers according to your [subscriptions settings](https://dashboard.stripe.com/account/billing/automatic). However, if you'd like to manually send an invoice to your customer out of the normal schedule, you can do so. When sending invoices that have already been paid, there will be no reference to the payment in the email. * diff --git a/types/2020-08-27/PaymentIntents.d.ts b/types/2020-08-27/PaymentIntents.d.ts index e198f3b89b..74cd855163 100644 --- a/types/2020-08-27/PaymentIntents.d.ts +++ b/types/2020-08-27/PaymentIntents.d.ts @@ -5824,6 +5824,28 @@ declare module 'stripe' { } } + interface PaymentIntentSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for payment intents](https://stripe.com/docs/search#query-fields-for-payment-intents). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + interface PaymentIntentVerifyMicrodepositsParams { /** * Two positive integers, in *cents*, equal to the values of the microdeposits sent to the bank account. @@ -5971,6 +5993,14 @@ declare module 'stripe' { options?: RequestOptions ): Promise>; + /** + * Search for PaymentIntents you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: PaymentIntentSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; + /** * Verifies microdeposits on a PaymentIntent object. */ diff --git a/types/2020-08-27/Prices.d.ts b/types/2020-08-27/Prices.d.ts index 4a3b0d1420..e105817016 100644 --- a/types/2020-08-27/Prices.d.ts +++ b/types/2020-08-27/Prices.d.ts @@ -556,6 +556,28 @@ declare module 'stripe' { type Type = 'one_time' | 'recurring'; } + interface PriceSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for prices](https://stripe.com/docs/search#query-fields-for-prices). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + class PricesResource { /** * Creates a new price for an existing product. The price can be recurring or one-time. @@ -595,6 +617,14 @@ declare module 'stripe' { options?: RequestOptions ): ApiListPromise; list(options?: RequestOptions): ApiListPromise; + + /** + * Search for prices you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: PriceSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; } } } diff --git a/types/2020-08-27/Products.d.ts b/types/2020-08-27/Products.d.ts index 35e67dbeee..5f5588f968 100644 --- a/types/2020-08-27/Products.d.ts +++ b/types/2020-08-27/Products.d.ts @@ -427,6 +427,28 @@ declare module 'stripe' { interface ProductDeleteParams {} + interface ProductSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for products](https://stripe.com/docs/search#query-fields-for-products). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + class ProductsResource { /** * Creates a new product object. @@ -479,6 +501,14 @@ declare module 'stripe' { id: string, options?: RequestOptions ): Promise>; + + /** + * Search for products you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: ProductSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; } } } diff --git a/types/2020-08-27/Subscriptions.d.ts b/types/2020-08-27/Subscriptions.d.ts index baeb7e9a28..e8f4a31aef 100644 --- a/types/2020-08-27/Subscriptions.d.ts +++ b/types/2020-08-27/Subscriptions.d.ts @@ -1606,6 +1606,28 @@ declare module 'stripe' { interface SubscriptionDeleteDiscountParams {} + interface SubscriptionSearchParams { + /** + * The search query string. See [search query language](https://stripe.com/docs/search#search-query-language) and the list of supported [query fields for subscriptions](https://stripe.com/docs/search#query-fields-for-subscriptions). + */ + query: string; + + /** + * Specifies which fields in the response should be expanded. + */ + expand?: Array; + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. + */ + limit?: number; + + /** + * A cursor for pagination across multiple pages of results. Do not include this parameter on the first call. Use the next_page value returned in a response to request subsequent results. + */ + page?: string; + } + class SubscriptionsResource { /** * Creates a new subscription on an existing customer. Each customer can have up to 500 active or scheduled subscriptions. @@ -1681,6 +1703,14 @@ declare module 'stripe' { id: string, options?: RequestOptions ): Promise>; + + /** + * Search for subscriptions you've previously created using Stripe's [Search Query Language](https://stripe.com/docs/search#search-query-language) + */ + search( + params: SubscriptionSearchParams, + options?: RequestOptions + ): ApiSearchResultPromise; } } } diff --git a/types/lib.d.ts b/types/lib.d.ts index 1117452766..be1b5afa03 100644 --- a/types/lib.d.ts +++ b/types/lib.d.ts @@ -252,6 +252,12 @@ declare module 'stripe' { * true, this will be set to a concrete string value. */ next_page: string | null; + + /** + * The total number of search results. Only present when `expand` request + * parameter contains `total_count`. + */ + total_count?: number; } export interface ApiSearchResultPromise extends Promise>>,