Repository: stripe/stripe-node
Pull request #1109 (2021-01-19 22:27:24)

Add link to YouTube playlist from readme
r? @richardm-stripe 


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bb0d2cd1..ba054577 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,16 +1,5 @@
 # CHANGELOG
 
-## 8.131.1 - 2021-01-15
-* [#1104](https://github.com/stripe/stripe-node/pull/1104) Make request timeout errors eligible for retry
-
-## 8.131.0 - 2021-01-14
-* [#1108](https://github.com/stripe/stripe-node/pull/1108) Multiple API Changes
-  * Added support for `dynamic_tax_rates` on `Checkout.SessionCreateParams.line_items`
-  * Added support for `customer_details` on `Checkout.Session`
-  * Added support for `type` on `Issuing.TransactionListParams`
-  * Added support for `country` and `state` on `TaxRateUpdateParams`, `TaxRateCreateParams` and `TaxRate`
-* [#1107](https://github.com/stripe/stripe-node/pull/1107) More consistent type definitions
-
 ## 8.130.0 - 2021-01-07
 * [#1105](https://github.com/stripe/stripe-node/pull/1105) API Updates
   * Added support for `company_registration_verification`, `company_ministerial_decree`, `company_memorandum_of_association`, `company_license` and `company_tax_id_verification` on AccountUpdateParams.documents and AccountCreateParams.documents
diff --git a/README.md b/README.md
index 9e47c982..5bd80ec9 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,8 @@ For collecting customer and payment information in the browser, use [Stripe.js][
 
 See the [`stripe-node` API docs](https://stripe.com/docs/api?lang=node) for Node.js.
 
+See [video demonstrations][youtube-playlist] covering how to use the library.
+
 ## Requirements
 
 Node 8, 10 or higher.
@@ -510,6 +512,7 @@ $ yarn fix
 [expanding_objects]: https://stripe.com/docs/api/expanding_objects
 [https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
 [stripe-js]: https://stripe.com/docs/stripe.js
+[youtube-playlist]: https://www.youtube.com/playlist?list=PLy1nL-pvL2M5xNIuNapwmABwEy2uifAlY
 
 <!--
 # vim: set tw=79:
diff --git a/VERSION b/VERSION
index 738da84a..a28828de 100644
--- a/VERSION
+++ b/VERSION
@@ -1,1 +1,1 @@
-8.131.1
+8.130.0
diff --git a/lib/StripeResource.js b/lib/StripeResource.js
index 8550721a..036812dc 100644
--- a/lib/StripeResource.js
+++ b/lib/StripeResource.js
@@ -98,7 +98,17 @@ StripeResource.prototype = {
       const timeoutErr = new TypeError('ETIMEDOUT');
       timeoutErr.code = 'ETIMEDOUT';
 
-      req.destroy(timeoutErr);
+      req._isAborted = true;
+      req.abort();
+
+      callback.call(
+        this,
+        new StripeConnectionError({
+          message: `Request aborted due to timeout being reached (${timeout}ms)`,
+          detail: timeoutErr,
+        }),
+        null
+      );
     };
   },
 
@@ -214,7 +224,11 @@ StripeResource.prototype = {
   },
 
   _errorHandler(req, requestRetries, callback) {
-    return (message, detail) => {
+    return (error) => {
+      if (req._isAborted) {
+        // already handled
+        return;
+      }
       callback.call(
         this,
         new StripeConnectionError({
@@ -472,23 +486,7 @@ StripeResource.prototype = {
             null
           );
         } else {
-          if (error.code === 'ETIMEDOUT') {
-            return callback.call(
-              this,
-              new StripeConnectionError({
-                message: `Request aborted due to timeout being reached (${timeout}ms)`,
-                detail: error,
-              })
-            );
-          }
-          return callback.call(
-            this,
-            new StripeConnectionError({
-              message: this._generateConnectionErrorMessage(requestRetries),
-              detail: error,
-            }),
-            null
-          );
+          return this._errorHandler(req, requestRetries, callback)(error);
         }
       });
 
diff --git a/package.json b/package.json
index ad9bc024..d8a93b05 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "stripe",
-  "version": "8.131.1",
+  "version": "8.130.0",
   "description": "Stripe API wrapper",
   "keywords": [
     "stripe",
diff --git a/types/2020-08-27/Accounts.d.ts b/types/2020-08-27/Accounts.d.ts
index 484820a6..a05fc289 100644
--- a/types/2020-08-27/Accounts.d.ts
+++ b/types/2020-08-27/Accounts.d.ts
@@ -70,9 +70,6 @@ declare module 'stripe' {
       /**
        * This is an object representing a person associated with a Stripe account.
        *
-       * A platform cannot access a Standard or Express account's persons after the account starts onboarding, such as after generating an account link for the account.
-       * See the [Standard onboarding](https://stripe.com/docs/connect/standard-accounts) or [Express onboarding documentation](https://stripe.com/docs/connect/express-accounts) for information about platform pre-filling and account onboarding steps.
-       *
        * Related guide: [Handling Identity Verification with the API](https://stripe.com/docs/connect/identity-verification-api#person-information).
        */
       individual?: Stripe.Person;
diff --git a/types/2020-08-27/Checkout/Sessions.d.ts b/types/2020-08-27/Checkout/Sessions.d.ts
index 658e6308..01802b29 100644
--- a/types/2020-08-27/Checkout/Sessions.d.ts
+++ b/types/2020-08-27/Checkout/Sessions.d.ts
@@ -64,11 +64,6 @@ declare module 'stripe' {
          */
         customer: string | Stripe.Customer | Stripe.DeletedCustomer | null;
 
-        /**
-         * The customer details including the customer's tax exempt status and the customer's tax IDs.
-         */
-        customer_details: Session.CustomerDetails | null;
-
         /**
          * If provided, this value will be used when the Customer object is created.
          * If not provided, customers will be asked to enter their email address.
@@ -163,76 +158,6 @@ declare module 'stripe' {
       namespace Session {
         type BillingAddressCollection = 'auto' | 'required';
 
-        interface CustomerDetails {
-          /**
-           * The customer's email at time of checkout.
-           */
-          email: string | null;
-
-          /**
-           * The customer's tax exempt status at time of checkout.
-           */
-          tax_exempt: CustomerDetails.TaxExempt | null;
-
-          /**
-           * The customer's tax IDs at time of checkout.
-           */
-          tax_ids: Array<CustomerDetails.TaxId> | null;
-        }
-
-        namespace CustomerDetails {
-          type TaxExempt = 'exempt' | 'none' | 'reverse';
-
-          interface TaxId {
-            /**
-             * The type of the tax ID, one of `eu_vat`, `br_cnpj`, `br_cpf`, `nz_gst`, `au_abn`, `in_gst`, `no_vat`, `za_vat`, `ch_vat`, `mx_rfc`, `sg_uen`, `ru_inn`, `ru_kpp`, `ca_bn`, `hk_br`, `es_cif`, `tw_vat`, `th_vat`, `jp_cn`, `jp_rn`, `li_uid`, `my_itn`, `us_ein`, `kr_brn`, `ca_qst`, `my_sst`, `sg_gst`, `ae_trn`, `cl_tin`, `sa_vat`, `id_npwp`, `my_frp`, or `unknown`
-             */
-            type: TaxId.Type;
-
-            /**
-             * The value of the tax ID.
-             */
-            value: string | null;
-          }
-
-          namespace TaxId {
-            type Type =
-              | 'ae_trn'
-              | 'au_abn'
-              | 'br_cnpj'
-              | 'br_cpf'
-              | 'ca_bn'
-              | 'ca_qst'
-              | 'ch_vat'
-              | 'cl_tin'
-              | 'es_cif'
-              | 'eu_vat'
-              | 'hk_br'
-              | 'id_npwp'
-              | 'in_gst'
-              | 'jp_cn'
-              | 'jp_rn'
-              | 'kr_brn'
-              | 'li_uid'
-              | 'mx_rfc'
-              | 'my_frp'
-              | 'my_itn'
-              | 'my_sst'
-              | 'no_vat'
-              | 'nz_gst'
-              | 'ru_inn'
-              | 'ru_kpp'
-              | 'sa_vat'
-              | 'sg_gst'
-              | 'sg_uen'
-              | 'th_vat'
-              | 'tw_vat'
-              | 'unknown'
-              | 'us_ein'
-              | 'za_vat';
-          }
-        }
-
         type Locale =
           | 'auto'
           | 'bg'
@@ -770,11 +695,6 @@ declare module 'stripe' {
            */
           description?: string;
 
-          /**
-           * The [tax rates](https://stripe.com/docs/api/tax_rates) that will be applied to this line item depending on the customer's billing/shipping address. We currently support the following countries: US, GB, AU, and all countries in the EU.
-           */
-          dynamic_tax_rates?: Array<string>;
-
           /**
            * A list of image URLs representing this line item. Each image can be up to 5 MB in size. If passing `price` or `price_data`, specify images on the associated product instead.
            */
@@ -801,7 +721,7 @@ declare module 'stripe' {
           quantity: number;
 
           /**
-           * The [tax rates](https://stripe.com/docs/api/tax_rates) which apply to this line item.
+           * The [tax rates](https://stripe.com/docs/api/tax_rates) which apply to this line item. This is only allowed in subscription mode.
            */
           tax_rates?: Array<string>;
         }
@@ -961,17 +881,10 @@ declare module 'stripe' {
            * Indicates that you intend to make future payments with the payment
            * method collected by this Checkout Session.
            *
-           * When setting this to `on_session`, Checkout will show a notice to the
-           * customer that their payment details will be saved.
-           *
            * When setting this to `off_session`, Checkout will show a notice to the
            * customer that their payment details will be saved and used for future
            * payments.
            *
-           * For both values, Checkout will attach the payment method to either the
-           * provided Customer for the session, or a new Customer created by Checkout
-           * if one has not been provided.
-           *
            * When processing card payments, Checkout also uses `setup_future_usage`
            * to dynamically optimize your payment flow and comply with regional
            * legislation and network rules, such as SCA.
diff --git a/types/2020-08-27/Customers.d.ts b/types/2020-08-27/Customers.d.ts
index 2f78fa07..169320b2 100644
--- a/types/2020-08-27/Customers.d.ts
+++ b/types/2020-08-27/Customers.d.ts
@@ -698,7 +698,7 @@ declare module 'stripe' {
         id: string,
         params: CustomerSourceCreateParams,
         options?: RequestOptions
-      ): Promise<Stripe.Response<Stripe.CustomerSource>>;
+      ): Promise<Stripe.Response<CustomerSource>>;
 
       /**
        * Retrieve a specified source for a given customer.
@@ -708,12 +708,12 @@ declare module 'stripe' {
         id: string,
         params?: CustomerSourceRetrieveParams,
         options?: RequestOptions
-      ): Promise<Stripe.Response<Stripe.CustomerSource>>;
+      ): Promise<Stripe.Response<CustomerSource>>;
       retrieveSource(
         customerId: string,
         id: string,
         options?: RequestOptions
-      ): Promise<Stripe.Response<Stripe.CustomerSource>>;
+      ): Promise<Stripe.Response<CustomerSource>>;
 
       /**
        * Update a specified source for a given customer.
@@ -726,6 +726,13 @@ declare module 'stripe' {
       ): Promise<
         Stripe.Response<Stripe.Card | Stripe.BankAccount | Stripe.Source>
       >;
+      updateSource(
+        customerId: string,
+        id: string,
+        options?: RequestOptions
+      ): Promise<
+        Stripe.Response<Stripe.Card | Stripe.BankAccount | Stripe.Source>
+      >;
 
       /**
        * List sources for a specified customer.
@@ -734,11 +741,11 @@ declare module 'stripe' {
         id: string,
         params?: CustomerSourceListParams,
         options?: RequestOptions
-      ): ApiListPromise<Stripe.CustomerSource>;
+      ): ApiListPromise<CustomerSource>;
       listSources(
         id: string,
         options?: RequestOptions
-      ): ApiListPromise<Stripe.CustomerSource>;
+      ): ApiListPromise<CustomerSource>;
 
       /**
        * Delete a specified source for a given customer.
@@ -750,7 +757,7 @@ declare module 'stripe' {
         options?: RequestOptions
       ): Promise<
         Stripe.Response<
-          | Stripe.CustomerSource
+          | CustomerSource
           | Stripe.DeletedAlipayAccount
           | Stripe.DeletedBankAccount
           | Stripe.DeletedBitcoinReceiver
@@ -763,7 +770,7 @@ declare module 'stripe' {
         options?: RequestOptions
       ): Promise<
         Stripe.Response<
-          | Stripe.CustomerSource
+          | CustomerSource
           | Stripe.DeletedAlipayAccount
           | Stripe.DeletedBankAccount
           | Stripe.DeletedBitcoinReceiver
diff --git a/types/2020-08-27/Issuing/Transactions.d.ts b/types/2020-08-27/Issuing/Transactions.d.ts
index 2912c2ef..ba91637f 100644
--- a/types/2020-08-27/Issuing/Transactions.d.ts
+++ b/types/2020-08-27/Issuing/Transactions.d.ts
@@ -328,15 +328,6 @@ declare module 'stripe' {
          * Specifies which fields in the response should be expanded.
          */
         expand?: Array<string>;
-
-        /**
-         * Only return transactions that have the given type. One of `capture` or `refund`.
-         */
-        type?: TransactionListParams.Type;
-      }
-
-      namespace TransactionListParams {
-        type Type = 'capture' | 'refund';
       }
 
       class TransactionsResource {
diff --git a/types/2020-08-27/Refunds.d.ts b/types/2020-08-27/Refunds.d.ts
index 6a1d4048..99b27df1 100644
--- a/types/2020-08-27/Refunds.d.ts
+++ b/types/2020-08-27/Refunds.d.ts
@@ -127,6 +127,13 @@ declare module 'stripe' {
       expand?: Array<string>;
     }
 
+    interface RefundRetrieveParams {
+      /**
+       * Specifies which fields in the response should be expanded.
+       */
+      expand?: Array<string>;
+    }
+
     interface RefundUpdateParams {
       /**
        * Specifies which fields in the response should be expanded.
@@ -139,6 +146,13 @@ declare module 'stripe' {
       metadata?: Stripe.Emptyable<Stripe.MetadataParam>;
     }
 
+    interface RefundListParams extends PaginationParams {
+      /**
+       * Specifies which fields in the response should be expanded.
+       */
+      expand?: Array<string>;
+    }
+
     interface RefundListParams extends PaginationParams {
       /**
        * Only return refunds for the charge specified by this charge ID.
@@ -168,6 +182,21 @@ declare module 'stripe' {
       ): Promise<Stripe.Response<Stripe.Refund>>;
       create(options?: RequestOptions): Promise<Stripe.Response<Stripe.Refund>>;
 
+      /**
+       * Retrieves the details of an existing refund.
+       */
+      retrieve(
+        chargeId: string,
+        id: string,
+        params?: RefundRetrieveParams,
+        options?: RequestOptions
+      ): Promise<Stripe.Response<Stripe.Refund>>;
+      retrieve(
+        chargeId: string,
+        id: string,
+        options?: RequestOptions
+      ): Promise<Stripe.Response<Stripe.Refund>>;
+
       /**
        * Retrieves the details of an existing refund.
        */
@@ -192,6 +221,16 @@ declare module 'stripe' {
         options?: RequestOptions
       ): Promise<Stripe.Response<Stripe.Refund>>;
 
+      /**
+       * You can see a list of the refunds belonging to a specific charge. Note that the 10 most recent refunds are always available by default on the charge object. If you need more than those 10, you can use this API method and the limit and starting_after parameters to page through additional refunds.
+       */
+      list(
+        id: string,
+        params?: RefundListParams,
+        options?: RequestOptions
+      ): ApiListPromise<Stripe.Refund>;
+      list(id: string, options?: RequestOptions): ApiListPromise<Stripe.Refund>;
+
       /**
        * Returns a list of all refunds you've previously created. The refunds are returned in sorted order, with the most recent refunds appearing first. For convenience, the 10 most recent refunds are always available by default on the charge object.
        */
diff --git a/types/2020-08-27/SubscriptionSchedules.d.ts b/types/2020-08-27/SubscriptionSchedules.d.ts
index 38dc9cc9..36eee404 100644
--- a/types/2020-08-27/SubscriptionSchedules.d.ts
+++ b/types/2020-08-27/SubscriptionSchedules.d.ts
@@ -220,7 +220,7 @@ declare module 'stripe' {
         end_date: number;
 
         /**
-         * The invoice settings applicable during this phase.
+         * The subscription schedule's default invoice settings.
          */
         invoice_settings: Phase.InvoiceSettings | null;
 
diff --git a/types/2020-08-27/TaxRates.d.ts b/types/2020-08-27/TaxRates.d.ts
index c3a67f7f..5d78a758 100644
--- a/types/2020-08-27/TaxRates.d.ts
+++ b/types/2020-08-27/TaxRates.d.ts
@@ -21,11 +21,6 @@ declare module 'stripe' {
        */
       active: boolean;
 
-      /**
-       * Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
-       */
-      country: string | null;
-
       /**
        * Time at which the object was created. Measured in seconds since the Unix epoch.
        */
@@ -65,11 +60,6 @@ declare module 'stripe' {
        * This represents the tax rate percent out of 100.
        */
       percentage: number;
-
-      /**
-       * [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States.
-       */
-      state: string | null;
     }
 
     interface TaxRateCreateParams {
@@ -93,11 +83,6 @@ declare module 'stripe' {
        */
       active?: boolean;
 
-      /**
-       * Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
-       */
-      country?: string;
-
       /**
        * An arbitrary string attached to the tax rate for your internal use only. It will not be visible to your customers.
        */
@@ -117,11 +102,6 @@ declare module 'stripe' {
        * Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
        */
       metadata?: Stripe.MetadataParam;
-
-      /**
-       * [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States.
-       */
-      state?: string;
     }
 
     interface TaxRateRetrieveParams {
@@ -137,11 +117,6 @@ declare module 'stripe' {
        */
       active?: boolean;
 
-      /**
-       * Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
-       */
-      country?: string;
-
       /**
        * An arbitrary string attached to the tax rate for your internal use only. It will not be visible to your customers.
        */
@@ -166,11 +141,6 @@ declare module 'stripe' {
        * Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
        */
       metadata?: Stripe.Emptyable<Stripe.MetadataParam>;
-
-      /**
-       * [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States.
-       */
-      state?: string;
     }
 
     interface TaxRateListParams extends PaginationParams {


Test patch:
diff --git a/test/StripeResource.spec.js b/test/StripeResource.spec.js
index 69adf309..78bcdb6d 100644
--- a/test/StripeResource.spec.js
+++ b/test/StripeResource.spec.js
@@ -185,46 +185,6 @@ describe('StripeResource', () => {
         });
       });
 
-      it('throws an error on connection timeout', (done) => {
-        return utils.getTestServerStripe(
-          {timeout: 10},
-          (req, res) => {
-            // Do nothing. This will trigger a timeout.
-          },
-          (err, stripe) => {
-            if (err) {
-              return done(err);
-            }
-            stripe.charges.create(options.data, (err, result) => {
-              expect(err.detail.message).to.deep.equal('ETIMEDOUT');
-              done();
-            });
-          }
-        );
-      });
-
-      it('retries connection timeout errors', (done) => {
-        let nRequestsReceived = 0;
-        return utils.getTestServerStripe(
-          {timeout: 10, maxNetworkRetries: 2},
-          (req, res) => {
-            nRequestsReceived += 1;
-            // Do nothing. This will trigger a timeout.
-            return {shouldStayOpen: nRequestsReceived < 3};
-          },
-          (err, stripe) => {
-            if (err) {
-              return done(err);
-            }
-            stripe.charges.create(options.data, (err, result) => {
-              expect(err.detail.message).to.deep.equal('ETIMEDOUT');
-              expect(nRequestsReceived).to.equal(3);
-              done();
-            });
-          }
-        );
-      });
-
       it('should retry the request if max retries are set', (done) => {
         nock(`https://${options.host}`)
           .post(options.path, options.params)
diff --git a/testUtils/index.js b/testUtils/index.js
index 581345be..78a86938 100644
--- a/testUtils/index.js
+++ b/testUtils/index.js
@@ -6,33 +6,9 @@ require('mocha');
 // Ensure we are using the 'as promised' libs before any tests are run:
 require('chai').use(require('chai-as-promised'));
 
-const http = require('http');
-
 const ResourceNamespace = require('../lib/ResourceNamespace').ResourceNamespace;
 
 const utils = (module.exports = {
-  getTestServerStripe: (clientOptions, handler, callback) => {
-    const server = http.createServer((req, res) => {
-      const {shouldStayOpen} = handler(req, res) || {};
-      if (!shouldStayOpen) {
-        res.on('close', () => server.close());
-      }
-    });
-    server.listen(0, () => {
-      const {port} = server.address();
-      const stripe = require('../lib/stripe')(
-        module.exports.getUserStripeKey(),
-        {
-          host: 'localhost',
-          port,
-          protocol: 'http',
-          ...clientOptions,
-        }
-      );
-      return callback(null, stripe);
-    });
-  },
-
   getUserStripeKey: () => {
     const key =
       process.env.STRIPE_TEST_API_KEY || 'tGN0bIwXnHdwOa85VABjPdSn8nWY7G7I';