Skip to content

Commit

Permalink
Merging from origin/master to sdk-release/next-major (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-stripe committed Mar 26, 2024
1 parent 800e45e commit d89054f
Show file tree
Hide file tree
Showing 42 changed files with 2,647 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,5 +7,6 @@ tags
coverage
.idea
testProjects/**/node_modules
testProjects/**/dist
testProjects/**/package-lock.json
testProjects/**/_worker.*
17 changes: 17 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,22 @@
# Changelog

## 14.22.0 - 2024-03-21
* [#2040](https://github.com/stripe/stripe-node/pull/2040) Update generated code
* Add support for new resources `ConfirmationToken` and `Forwarding.Request`
* Add support for `retrieve` method on resource `ConfirmationToken`
* Add support for `create`, `list`, and `retrieve` methods on resource `Request`
* Add support for `mobilepay_payments` on `Account.capabilities`, `AccountCreateParams.capabilities`, and `AccountUpdateParams.capabilities`
* Add support for new values `forwarding_api_inactive`, `forwarding_api_invalid_parameter`, `forwarding_api_upstream_connection_error`, and `forwarding_api_upstream_connection_timeout` on enums `Invoice.last_finalization_error.code`, `PaymentIntent.last_payment_error.code`, `SetupAttempt.setup_error.code`, `SetupIntent.last_setup_error.code`, and `StripeError.code`
* Add support for `mobilepay` on `Charge.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`, `PaymentMethod`, `SetupIntentConfirmParams.payment_method_data`, `SetupIntentCreateParams.payment_method_data`, and `SetupIntentUpdateParams.payment_method_data`
* Add support for `payment_reference` on `Charge.payment_method_details.us_bank_account`
* Add support for new value `mobilepay` on enums `CustomerListPaymentMethodsParams.type`, `PaymentMethodCreateParams.type`, and `PaymentMethodListParams.type`
* Add support for `confirmation_token` on `PaymentIntentConfirmParams`, `PaymentIntentCreateParams`, `SetupIntentConfirmParams`, and `SetupIntentCreateParams`
* Add support for new value `mobilepay` 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 `mobilepay` on enum `PaymentMethod.type`
* Add support for `name` on `Terminal.ConfigurationCreateParams`, `Terminal.ConfigurationUpdateParams`, and `Terminal.Configuration`
* Add support for `payout` on `Treasury.ReceivedDebit.linked_flows`
* [#2043](https://github.com/stripe/stripe-node/pull/2043) Don't mutate error.type during minification

## 14.21.0 - 2024-03-14
* [#2035](https://github.com/stripe/stripe-node/pull/2035) Update generated code
* Add support for new resources `Issuing.PersonalizationDesign` and `Issuing.PhysicalBundle`
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
@@ -1 +1 @@
v878
v896
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
14.21.0
14.22.0
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "stripe",
"version": "14.21.0",
"version": "14.22.0",
"description": "Stripe API wrapper",
"keywords": [
"stripe",
Expand Down
66 changes: 53 additions & 13 deletions src/Error.ts
Expand Up @@ -49,9 +49,9 @@ export class StripeError extends Error {
readonly setup_intent?: any;
readonly source?: any;

constructor(raw: StripeRawError = {}) {
constructor(raw: StripeRawError = {}, type: string | null = null) {
super(raw.message);
this.type = this.constructor.name;
this.type = type || this.constructor.name;

this.raw = raw;
this.rawType = raw.type;
Expand Down Expand Up @@ -86,47 +86,75 @@ export class StripeError extends Error {
* CardError is raised when a user enters a card that can't be charged for
* some reason.
*/
export class StripeCardError extends StripeError {}
export class StripeCardError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeCardError');
}
}

/**
* InvalidRequestError is raised when a request is initiated with invalid
* parameters.
*/
export class StripeInvalidRequestError extends StripeError {}
export class StripeInvalidRequestError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeInvalidRequestError');
}
}

/**
* APIError is a generic error that may be raised in cases where none of the
* other named errors cover the problem. It could also be raised in the case
* that a new error has been introduced in the API, but this version of the
* Node.JS SDK doesn't know how to handle it.
*/
export class StripeAPIError extends StripeError {}
export class StripeAPIError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeAPIError');
}
}

/**
* AuthenticationError is raised when invalid credentials are used to connect
* to Stripe's servers.
*/
export class StripeAuthenticationError extends StripeError {}
export class StripeAuthenticationError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeAuthenticationError');
}
}

/**
* PermissionError is raised in cases where access was attempted on a resource
* that wasn't allowed.
*/
export class StripePermissionError extends StripeError {}
export class StripePermissionError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripePermissionError');
}
}

/**
* RateLimitError is raised in cases where an account is putting too much load
* on Stripe's API servers (usually by performing too many requests). Please
* back off on request rate.
*/
export class StripeRateLimitError extends StripeError {}
export class StripeRateLimitError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeRateLimitError');
}
}

/**
* StripeConnectionError is raised in the event that the SDK can't connect to
* Stripe's servers. That can be for a variety of different reasons from a
* downed network to a bad TLS certificate.
*/
export class StripeConnectionError extends StripeError {}
export class StripeConnectionError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeConnectionError');
}
}

/**
* SignatureVerificationError is raised when the signature verification for a
Expand All @@ -141,7 +169,7 @@ export class StripeSignatureVerificationError extends StripeError {
payload: string | Uint8Array,
raw: StripeRawError = {}
) {
super(raw);
super(raw, 'StripeSignatureVerificationError');
this.header = header;
this.payload = payload;
}
Expand All @@ -151,17 +179,29 @@ export class StripeSignatureVerificationError extends StripeError {
* IdempotencyError is raised in cases where an idempotency key was used
* improperly.
*/
export class StripeIdempotencyError extends StripeError {}
export class StripeIdempotencyError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeIdempotencyError');
}
}

/**
* InvalidGrantError is raised when a specified code doesn't exist, is
* expired, has been used, or doesn't belong to you; a refresh token doesn't
* exist, or doesn't belong to you; or if an API key's mode (live or test)
* doesn't match the mode of a code or refresh token.
*/
export class StripeInvalidGrantError extends StripeError {}
export class StripeInvalidGrantError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeInvalidGrantError');
}
}

/**
* Any other error from Stripe not specifically captured above
*/
export class StripeUnknownError extends StripeError {}
export class StripeUnknownError extends StripeError {
constructor(raw: StripeRawError = {}) {
super(raw, 'StripeUnknownError');
}
}
7 changes: 7 additions & 0 deletions src/resources.ts
Expand Up @@ -10,6 +10,7 @@ import {Cards as TestHelpersIssuingCards} from './resources/TestHelpers/Issuing/
import {Cards as IssuingCards} from './resources/Issuing/Cards.js';
import {Configurations as BillingPortalConfigurations} from './resources/BillingPortal/Configurations.js';
import {Configurations as TerminalConfigurations} from './resources/Terminal/Configurations.js';
import {ConfirmationTokens as TestHelpersConfirmationTokens} from './resources/TestHelpers/ConfirmationTokens.js';
import {ConnectionTokens as TerminalConnectionTokens} from './resources/Terminal/ConnectionTokens.js';
import {CreditReversals as TreasuryCreditReversals} from './resources/Treasury/CreditReversals.js';
import {Customers as TestHelpersCustomers} from './resources/TestHelpers/Customers.js';
Expand Down Expand Up @@ -39,6 +40,7 @@ import {Refunds as TestHelpersRefunds} from './resources/TestHelpers/Refunds.js'
import {Registrations as TaxRegistrations} from './resources/Tax/Registrations.js';
import {ReportRuns as ReportingReportRuns} from './resources/Reporting/ReportRuns.js';
import {ReportTypes as ReportingReportTypes} from './resources/Reporting/ReportTypes.js';
import {Requests as ForwardingRequests} from './resources/Forwarding/Requests.js';
import {ScheduledQueryRuns as SigmaScheduledQueryRuns} from './resources/Sigma/ScheduledQueryRuns.js';
import {Secrets as AppsSecrets} from './resources/Apps/Secrets.js';
import {Sessions as BillingPortalSessions} from './resources/BillingPortal/Sessions.js';
Expand Down Expand Up @@ -67,6 +69,7 @@ export {ApplicationFees} from './resources/ApplicationFees.js';
export {Balance} from './resources/Balance.js';
export {BalanceTransactions} from './resources/BalanceTransactions.js';
export {Charges} from './resources/Charges.js';
export {ConfirmationTokens} from './resources/ConfirmationTokens.js';
export {CountrySpecs} from './resources/CountrySpecs.js';
export {Coupons} from './resources/Coupons.js';
export {CreditNotes} from './resources/CreditNotes.js';
Expand Down Expand Up @@ -127,6 +130,9 @@ export const FinancialConnections = resourceNamespace('financialConnections', {
Sessions: FinancialConnectionsSessions,
Transactions: FinancialConnectionsTransactions,
});
export const Forwarding = resourceNamespace('forwarding', {
Requests: ForwardingRequests,
});
export const Identity = resourceNamespace('identity', {
VerificationReports: IdentityVerificationReports,
VerificationSessions: IdentityVerificationSessions,
Expand Down Expand Up @@ -166,6 +172,7 @@ export const Terminal = resourceNamespace('terminal', {
Readers: TerminalReaders,
});
export const TestHelpers = resourceNamespace('testHelpers', {
ConfirmationTokens: TestHelpersConfirmationTokens,
Customers: TestHelpersCustomers,
Refunds: TestHelpersRefunds,
TestClocks: TestHelpersTestClocks,
Expand Down
10 changes: 10 additions & 0 deletions src/resources/ConfirmationTokens.ts
@@ -0,0 +1,10 @@
// File generated from our OpenAPI spec

import {StripeResource} from '../StripeResource.js';
const stripeMethod = StripeResource.method;
export const ConfirmationTokens = StripeResource.extend({
retrieve: stripeMethod({
method: 'GET',
fullPath: '/v1/confirmation_tokens/{confirmation_token}',
}),
});
16 changes: 16 additions & 0 deletions src/resources/Forwarding/Requests.ts
@@ -0,0 +1,16 @@
// File generated from our OpenAPI spec

import {StripeResource} from '../../StripeResource.js';
const stripeMethod = StripeResource.method;
export const Requests = StripeResource.extend({
create: stripeMethod({method: 'POST', fullPath: '/v1/forwarding/requests'}),
retrieve: stripeMethod({
method: 'GET',
fullPath: '/v1/forwarding/requests/{id}',
}),
list: stripeMethod({
method: 'GET',
fullPath: '/v1/forwarding/requests',
methodType: 'list',
}),
});
10 changes: 10 additions & 0 deletions src/resources/TestHelpers/ConfirmationTokens.ts
@@ -0,0 +1,10 @@
// File generated from our OpenAPI spec

import {StripeResource} from '../../StripeResource.js';
const stripeMethod = StripeResource.method;
export const ConfirmationTokens = StripeResource.extend({
create: stripeMethod({
method: 'POST',
fullPath: '/v1/test_helpers/confirmation_tokens',
}),
});
2 changes: 1 addition & 1 deletion src/stripe.core.ts
Expand Up @@ -49,7 +49,7 @@ export function createStripe(
platformFunctions: PlatformFunctions,
requestSender: RequestSenderFactory = defaultRequestSenderFactory
): typeof Stripe {
Stripe.PACKAGE_VERSION = '14.21.0';
Stripe.PACKAGE_VERSION = '14.22.0';
Stripe.USER_AGENT = {
bindings_version: Stripe.PACKAGE_VERSION,
lang: 'node',
Expand Down
12 changes: 11 additions & 1 deletion test/Error.spec.ts
Expand Up @@ -58,7 +58,17 @@ describe('Error', () => {
expect(e).to.have.property('statusCode', 400);
});

it('has subclasses which provide `.type` as their name', () => {
it('respects subclasses overriding `.type` in constructor', () => {
class Foo extends Error.StripeError {
constructor(raw: any) {
super(raw, 'Foo');
}
}
const err = new Foo({message: 'hi'});
expect(err).to.have.property('type', 'Foo');
});

it('defaults setting `.type` to subclass name', () => {
class Foo extends Error.StripeError {}
const err = new Foo({message: 'hi'});
expect(err).to.have.property('type', 'Foo');
Expand Down
16 changes: 16 additions & 0 deletions test/Integration.spec.ts
Expand Up @@ -55,6 +55,22 @@ describe('Integration test', function() {
await runTestProject('mjs-ts');
});

describe('esbuild', () => {
it('should not change error.type when minified', async function() {
// Node supports ES Modules starting at v12
if (nodeVersion <= 12) {
this.skip();
}

await testExec(`
cd testProjects/esbuild && rm -rf node_modules && rm -rf dist
npm install &&
npm run build &&
npm run start
`);
});
});

const runTestCloudflareProject = (projectName: string): Promise<void> => {
if (process.versions.node < '16.13') {
console.log('Wrangler requires at least node.js v16.13.0, skipping test');
Expand Down
2 changes: 1 addition & 1 deletion test/resources/generated_examples_test.spec.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions testProjects/esbuild/index.js
@@ -0,0 +1,36 @@
import {Stripe} from 'stripe';
import assert from 'assert';

// API key is null to trigger an authentication error
const stripe = new Stripe("i'm not a real key", {
host: process.env.STRIPE_MOCK_HOST || 'localhost',
port: process.env.STRIPE_MOCK_PORT || 12111,
protocol: 'http',
});

try {
throw new stripe.errors.StripeUnknownError({
charge: 'foo',
unknown_prop: 'bar',
});
} catch (e) {
assert (e instanceof stripe.errors.StripeUnknownError);
assert (e.type === 'StripeUnknownError');
}

async function exampleFunction(args) {
try {
await stripe.paymentIntents.create(args);
throw new Error('Expected an error');
} catch (e) {
assert (e instanceof stripe.errors.StripeAuthenticationError);
assert (e.type === 'StripeAuthenticationError');
}
}

exampleFunction({
// The required parameter currency is missing
amount: 2000,
confirm: true,
payment_method: 'pm_card_visa',
});
17 changes: 17 additions & 0 deletions testProjects/esbuild/package.json
@@ -0,0 +1,17 @@
{
"name": "mjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"stripe": "file:../../"
},
"scripts": {
"clean": "rm -rf node_modules && rm -rf dist",
"build": "esbuild index.js --bundle --platform=node --minify --target=es2020 --outdir=dist",
"start": "node dist/index.js"
},
"devDependencies": {
"esbuild": "^0.20.2"
}
}
7 changes: 7 additions & 0 deletions types/Accounts.d.ts
Expand Up @@ -328,6 +328,11 @@ declare module 'stripe' {
*/
link_payments?: Capabilities.LinkPayments;

/**
* The status of the MobilepPay capability of the account, or whether the account can directly process MobilePay charges.
*/
mobilepay_payments?: Capabilities.MobilepayPayments;

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

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

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

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

type P24Payments = 'active' | 'inactive' | 'pending';
Expand Down

0 comments on commit d89054f

Please sign in to comment.