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 for beta branch #1479

Merged
merged 13 commits into from
Jul 19, 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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 9.14.0 - 2022-07-18
* [#1477](https://github.com/stripe/stripe-node/pull/1477) API Updates
* Add support for `blik_payments` on `Account.capabilities`, `AccountCreateParams.capabilities`, and `AccountUpdateParams.capabilities`
* Add support for `blik` on `Charge.payment_method_details`, `Mandate.payment_method_details`, `PaymentIntent.payment_method_options`, `PaymentIntentConfirmParams.payment_method_data`, `PaymentIntentConfirmParams.payment_method_options`, `PaymentIntentCreateParams.payment_method_data`, `PaymentIntentCreateParams.payment_method_options`, `PaymentIntentUpdateParams.payment_method_data`, `PaymentIntentUpdateParams.payment_method_options`, `PaymentMethodCreateParams`, `PaymentMethodUpdateParams`, `PaymentMethod`, `SetupAttempt.payment_method_details`, `SetupIntent.payment_method_options`, `SetupIntentConfirmParams.payment_method_data`, `SetupIntentConfirmParams.payment_method_options`, `SetupIntentCreateParams.payment_method_data`, `SetupIntentCreateParams.payment_method_options`, `SetupIntentUpdateParams.payment_method_data`, and `SetupIntentUpdateParams.payment_method_options`
* Change type of `Checkout.Session.consent_collection.promotions`, `CheckoutSessionCreateParams.consent_collection.promotions`, `PaymentLink.consent_collection.promotions`, and `PaymentLinkCreateParams.consent_collection.promotions` from `literal('auto')` to `enum('auto'|'none')`
* Add support for new value `blik` on enum `CheckoutSessionCreateParams.payment_method_types[]`
* Add support for new value `blik` on enums `CustomerListPaymentMethodsParams.type` and `PaymentMethodListParams.type`
* Add support for new value `blik` on enums `PaymentIntentConfirmParams.payment_method_data.type`, `PaymentIntentCreateParams.payment_method_data.type`, `PaymentIntentUpdateParams.payment_method_data.type`, `SetupIntentConfirmParams.payment_method_data.type`, `SetupIntentCreateParams.payment_method_data.type`, and `SetupIntentUpdateParams.payment_method_data.type`
* Add support for new value `blik` on enums `PaymentLink.payment_method_types[]`, `PaymentLinkCreateParams.payment_method_types[]`, and `PaymentLinkUpdateParams.payment_method_types[]`
* Add support for new value `blik` on enum `PaymentMethodCreateParams.type`
* Add support for new value `blik` on enum `PaymentMethod.type`
* [#1476](https://github.com/stripe/stripe-node/pull/1476) fix: Include trailing slash when passing empty query parameters.
* [#1475](https://github.com/stripe/stripe-node/pull/1475) Move @types/node to devDependencies

## 9.13.0 - 2022-07-12
* [#1473](https://github.com/stripe/stripe-node/pull/1473) API Updates
* Add support for `customer_details` on `CheckoutSessionListParams`
* Change `LineItem.amount_discount` and `LineItem.amount_tax` to be required
* Change `Transfer.source_type` to be optional and not nullable
* [#1471](https://github.com/stripe/stripe-node/pull/1471) Update readme to include a note on beta packages

## 9.13.0-beta.1 - 2022-07-07
* [#1469](https://github.com/stripe/stripe-node/pull/1469) API Updates for beta branch
- Include `server_side_confirmation_beta=v1` beta
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v163
v166
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ npm install stripe --save
yarn add stripe
```

### Beta version

Stripe has features in the beta phase that can be accessed via the beta version of this package.
We would love for you to try these and share feedback with us before these features reach the stable phase.
The beta versions can be installed in one of two ways
- To install the latest beta version, run the command `npm install stripe@beta --save`
- To install a specific beta version, replace the term "beta" in the above command with the version number like `npm install stripe@1.2.3-beta.1 --save`

> Note: There can be breaking changes between beta versions. Therefore we recommend pinning the package version to a specific beta version in your package.json file. This way you can install the same version each time without breaking changes unless you are intentionally looking for the latest beta version.

We highly recommend keeping an eye on when the beta feature you are interested in goes from beta to stable so that you can move from using a beta version of the SDK to the stable version.

The versions tab on the [stripe page on npm](https://www.npmjs.com/package/stripe) lists the current tags in use. The `beta` tag here corresponds to the the latest beta version of the package.

## Usage

The package needs to be configured with your account's secret key, which is
Expand Down
34 changes: 23 additions & 11 deletions lib/StripeResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,42 @@ StripeResource.prototype = {
validateRequest: null,

createFullPath(commandPath, urlData) {
return this._joinUrlParts([
this.basePath(urlData),
this.path(urlData),
typeof commandPath == 'function' ? commandPath(urlData) : commandPath,
]);
const urlParts = [this.basePath(urlData), this.path(urlData)];

if (typeof commandPath === 'function') {
const computedCommandPath = commandPath(urlData);
// If we have no actual command path, we just omit it to avoid adding a
// trailing slash. This is important for top-level listing requests, which
// do not have a command path.
if (computedCommandPath) {
urlParts.push(computedCommandPath);
}
} else {
urlParts.push(commandPath);
}

return this._joinUrlParts(urlParts);
},

// Creates a relative resource path with symbols left in (unlike
// createFullPath which takes some data to replace them with). For example it
// might produce: /invoices/{id}
createResourcePathWithSymbols(pathWithSymbols) {
return `/${this._joinUrlParts([this.resourcePath, pathWithSymbols || ''])}`;
// If there is no path beyond the resource path, we want to produce just
// /<resource path> rather than /<resource path>/.
if (pathWithSymbols) {
return `/${this._joinUrlParts([this.resourcePath, pathWithSymbols])}`;
} else {
return `/${this.resourcePath}`;
}
},

_joinUrlParts(parts) {
// Replace any accidentally doubled up slashes. This previously used
// path.join, which would do this as well. Unfortunately we need to do this
// as the functions for creating paths are technically part of the public
// interface and so we need to preserve backwards compatibility.
const path = parts.join('/').replace(/\/{2,}/g, '/');

// If the path ends with a /, we preserve the behavior of path.join and
// strip off the trailing / (eg. /v1/customers/ -> /v1/customers).
return path.endsWith('/') ? path.slice(0, -1) : path;
return parts.join('/').replace(/\/{2,}/g, '/');
},

// DEPRECATED: Here for backcompat in case users relied on this.
Expand Down
1 change: 1 addition & 0 deletions lib/makeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function getRequestOpts(self, requestArgs, spec, overrideData) {
const requestPath = isUsingFullPath
? commandPath(urlData)
: self.createFullPath(commandPath, urlData);

const headers = Object.assign(options.headers, spec.headers);

if (spec.validator) {
Expand Down
5 changes: 5 additions & 0 deletions lib/resources/SubscriptionSchedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module.exports = StripeResource.extend({
methodType: 'list',
}),

amend: stripeMethod({
method: 'POST',
path: '/{schedule}/amend',
}),

cancel: stripeMethod({
method: 'POST',
path: '/{schedule}/cancel',
Expand Down
5 changes: 5 additions & 0 deletions lib/resources/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module.exports = StripeResource.extend({
methodType: 'list',
}),

cancel: stripeMethod({
method: 'DELETE',
path: '/{subscriptionExposedId}',
}),

del: stripeMethod({
method: 'DELETE',
path: '/{subscriptionExposedId}',
Expand Down
79 changes: 76 additions & 3 deletions test/StripeResource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ const {

describe('StripeResource', () => {
describe('createResourcePathWithSymbols', () => {
it('Generates a path', () => {
it('Generates a path when there is a symbol', () => {
stripe.invoices.create({});
const path = stripe.invoices.createResourcePathWithSymbols('{id}');
expect(path).to.equal('/invoices/{id}');
});

it('Generates a path when there is nothing beyond the resource path', () => {
stripe.invoices.create({});
const path = stripe.invoices.createResourcePathWithSymbols('');
// This explicitly shouldn't have a trailing slash.
expect(path).to.equal('/invoices');
});

it('Handles accidental double slashes', () => {
stripe.invoices.create({});
const path = stripe.invoices.createResourcePathWithSymbols('/{id}');
Expand All @@ -36,9 +43,9 @@ describe('StripeResource', () => {
});

describe('_joinUrlParts', () => {
it('handles trailing empty values correctly', () => {
it('includes trailing empty values', () => {
const path = stripe.invoices._joinUrlParts(['a', '']);
expect(path).to.equal('a');
expect(path).to.equal('a/');
});

it('joins parts', () => {
Expand Down Expand Up @@ -132,6 +139,72 @@ describe('StripeResource', () => {
});
});

it('handles .. as a query param', (done) => {
const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`)
.get('/v1/customers/..', '')
.reply(200, '{}');

realStripe.customers.retrieve('..', (err, response) => {
done(err);
scope.done();
});
});

it('handles empty string as a query param', (done) => {
const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`)
// Note this should always have a trailing space to avoid calling the
// top level list endpoint (/v1/customers) and returning all customers.
.get('/v1/customers/', '')
.reply(200, '{}');

realStripe.customers.retrieve('', (err, response) => {
done(err);
scope.done();
});
});

it('handles empty string as a query param for namespaced resources', (done) => {
const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`)
// Note this should always have a trailing space to avoid calling the
// top level list endpoint (/v1/customers) and returning all customers.
.get('/v1/checkout/sessions/', '')
.reply(200, '{}');

realStripe.checkout.sessions.retrieve('', (err, response) => {
done(err);
scope.done();
});
});

it('handles empty string as a query param for nested resources', (done) => {
const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`)
// Note this should always have a trailing space to avoid calling the
// top level list endpoint (/v1/customers) and returning all customers.
.get('/v1/customers/cus_123/balance_transactions/', '')
.reply(200, '{}');

realStripe.customers.retrieveBalanceTransaction(
'cus_123',
'',
(err, response) => {
done(err);
scope.done();
}
);
});

it('does not include trailing slash for endpoints without query parameters', (done) => {
const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`)
// Note that no trailing slash is present.
.get('/v1/customers', '')
.reply(200, '{}');

realStripe.customers.list((err, response) => {
done(err);
scope.done();
});
});

it('works correctly with undefined optional arguments', (done) => {
const scope = nock(`https://${stripe.getConstant('DEFAULT_HOST')}`)
.get('/v1/accounts/acct_123')
Expand Down
4 changes: 2 additions & 2 deletions test/resources/generated_examples_test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2492,8 +2492,8 @@ describe('Subscription', function() {
expect(subscription).not.to.be.null;
});

it('del method', async function() {
const subscription = await stripe.subscriptions.del('sub_xxxxxxxxxxxxx');
it('cancel method', async function() {
const subscription = await stripe.subscriptions.cancel('sub_xxxxxxxxxxxxx');
expect(subscription).not.to.be.null;
});

Expand Down
33 changes: 32 additions & 1 deletion types/2020-08-27/Accounts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ declare module 'stripe' {
*/
bank_transfer_payments?: Capabilities.BankTransferPayments;

/**
* The status of the blik payments capability of the account, or whether the account can directly process blik charges.
*/
blik_payments?: Capabilities.BlikPayments;

/**
* The status of the boleto payments capability of the account, or whether the account can directly process boleto charges.
*/
Expand Down Expand Up @@ -332,6 +337,8 @@ declare module 'stripe' {

type BankTransferPayments = 'active' | 'inactive' | 'pending';

type BlikPayments = 'active' | 'inactive' | 'pending';

type BoletoPayments = 'active' | 'inactive' | 'pending';

type CardIssuing = 'active' | 'inactive' | 'pending';
Expand Down Expand Up @@ -1299,6 +1306,11 @@ declare module 'stripe' {
*/
bank_transfer_payments?: Capabilities.BankTransferPayments;

/**
* The blik_payments capability.
*/
blik_payments?: Capabilities.BlikPayments;

/**
* The boleto_payments capability.
*/
Expand Down Expand Up @@ -1475,6 +1487,13 @@ declare module 'stripe' {
requested?: boolean;
}

interface BlikPayments {
/**
* Passing true requests the capability for the account, if it is not already requested. A requested capability may not immediately become active. Any requirements to activate the capability are returned in the `requirements` arrays.
*/
requested?: boolean;
}

interface BoletoPayments {
/**
* Passing true requests the capability for the account, if it is not already requested. A requested capability may not immediately become active. Any requirements to activate the capability are returned in the `requirements` arrays.
Expand Down Expand Up @@ -1894,7 +1913,7 @@ declare module 'stripe' {

interface ExternalAccount {
/**
* The type of external account.
* The type of external account. Should be bank_account.
*/
object: string;

Expand Down Expand Up @@ -2520,6 +2539,11 @@ declare module 'stripe' {
*/
bank_transfer_payments?: Capabilities.BankTransferPayments;

/**
* The blik_payments capability.
*/
blik_payments?: Capabilities.BlikPayments;

/**
* The boleto_payments capability.
*/
Expand Down Expand Up @@ -2696,6 +2720,13 @@ declare module 'stripe' {
requested?: boolean;
}

interface BlikPayments {
/**
* Passing true requests the capability for the account, if it is not already requested. A requested capability may not immediately become active. Any requirements to activate the capability are returned in the `requirements` arrays.
*/
requested?: boolean;
}

interface BoletoPayments {
/**
* Passing true requests the capability for the account, if it is not already requested. A requested capability may not immediately become active. Any requirements to activate the capability are returned in the `requirements` arrays.
Expand Down
4 changes: 4 additions & 0 deletions types/2020-08-27/Charges.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ declare module 'stripe' {

bancontact?: PaymentMethodDetails.Bancontact;

blik?: PaymentMethodDetails.Blik;

boleto?: PaymentMethodDetails.Boleto;

card?: PaymentMethodDetails.Card;
Expand Down Expand Up @@ -672,6 +674,8 @@ declare module 'stripe' {
type PreferredLanguage = 'de' | 'en' | 'fr' | 'nl';
}

interface Blik {}

interface Boleto {
/**
* The tax ID of the customer (CPF for individuals consumers or CNPJ for businesses consumers)
Expand Down
Loading