Skip to content
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
3 changes: 3 additions & 0 deletions apps/payments/next/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
const { getApp } = await import('@fxa/payments/ui/server');
const { monkeyPatchServerLogging } = await import('@fxa/shared/log');

await getApp().initialize();

monkeyPatchServerLogging();
}
}
36 changes: 36 additions & 0 deletions libs/payments/cart/src/lib/cart.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,32 @@ export class CartError extends BaseError {
cause,
info,
});
this.name = 'CartError';
Object.setPrototypeOf(this, CartError.prototype);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious and for logging purposes, why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.setPrototype is used for instanceof checks, which comes into play for several of our tests. instanceof check are inconsistent otherwise

}
}

export class CartNotCreatedError extends CartError {
constructor(data: SetupCart, cause: Error) {
super('Cart not created', data, cause);
this.name = 'CartNotCreatedError';
Object.setPrototypeOf(this, CartNotCreatedError.prototype);
}
}

export class CartNotFoundError extends CartError {
constructor(cartId: string, cause: Error) {
super('Cart not found', { cartId }, cause);
this.name = 'CartNotFoundError';
Object.setPrototypeOf(this, CartNotFoundError.prototype);
}
}

export class CartVersionMismatchError extends CartError {
constructor(cartId: string) {
super('Cart version mismatch', { cartId });
this.name = 'CartVersionMismatchError';
Object.setPrototypeOf(this, CartVersionMismatchError.prototype);
}
}

Expand All @@ -57,30 +65,40 @@ export class CartNotUpdatedError extends CartError {
},
cause
);
this.name = 'CartNotUpdatedError';
Object.setPrototypeOf(this, CartNotUpdatedError.prototype);
}
}

export class CartStateProcessingError extends CartError {
constructor(cartId: string, cause: Error) {
super('Cart state not changed to processing', { cartId }, cause);
this.name = 'CartStateProcessingError';
Object.setPrototypeOf(this, CartStateProcessingError.prototype);
}
}

export class CartStateFinishedError extends CartError {
constructor() {
super('Cart state is already finished', {});
this.name = 'CartStateFinishedError';
Object.setPrototypeOf(this, CartStateFinishedError.prototype);
}
}

export class CartNotDeletedError extends CartError {
constructor(cartId: string, cause?: Error) {
super('Cart not deleted', { cartId }, cause);
this.name = 'CartNotDeletedError';
Object.setPrototypeOf(this, CartNotDeletedError.prototype);
}
}

export class CartNotRestartedError extends CartError {
constructor(previousCartId: string, cause: Error) {
super('Cart not created', { previousCartId }, cause);
this.name = 'CartNotRestartedError';
Object.setPrototypeOf(this, CartNotRestartedError.prototype);
}
}

Expand All @@ -91,12 +109,16 @@ export class CartInvalidStateForActionError extends CartError {
state,
action,
});
this.name = 'CartInvalidStateForActionError';
Object.setPrototypeOf(this, CartInvalidStateForActionError.prototype);
}
}

export class CartTotalMismatchError extends CartError {
constructor(cartId: string, cartAmount: number, invoiceAmount: number) {
super('Cart total mismatch', { cartId, cartAmount, invoiceAmount });
this.name = 'CartTotalMismatchError';
Object.setPrototypeOf(this, CartTotalMismatchError.prototype);
}
}

Expand All @@ -111,6 +133,8 @@ export class CartEligibilityMismatchError extends CartError {
cartEligibility,
incomingEligibility,
});
this.name = 'CartEligibilityMismatchError';
Object.setPrototypeOf(this, CartEligibilityMismatchError.prototype);
}
}

Expand All @@ -119,6 +143,8 @@ export class CartAccountNotFoundError extends CartError {
super('Cart account not found for uid', {
cartId,
});
this.name = 'CartAccountNotFoundError';
Object.setPrototypeOf(this, CartAccountNotFoundError.prototype);
}
}

Expand All @@ -127,6 +153,8 @@ export class CartUidNotFoundError extends CartError {
super('Cart uid not found', {
cartId,
});
this.name = 'CartUidNotFoundError';
Object.setPrototypeOf(this, CartUidNotFoundError.prototype);
}
}

Expand All @@ -141,6 +169,8 @@ export class CartInvalidPromoCodeError extends CartError {
undefined,
'CartInvalidPromoCodeError'
);
this.name = 'CartInvalidPromoCodeError';
Object.setPrototypeOf(this, CartInvalidPromoCodeError.prototype);
}
}

Expand All @@ -155,6 +185,8 @@ export class CartCurrencyNotFoundError extends CartError {
currency,
country,
});
this.name = 'CartCurrencyNotFoundError';
Object.setPrototypeOf(this, CartCurrencyNotFoundError.prototype);
}
}

Expand All @@ -163,6 +195,8 @@ export class CartNoTaxAddressError extends CartError {
super('Cart tax address not found', {
cartId,
});
this.name = 'CartNoTaxAddressError';
Object.setPrototypeOf(this, CartNoTaxAddressError.prototype);
}
}

Expand All @@ -171,5 +205,7 @@ export class CartSubscriptionNotFoundError extends CartError {
super('Cart subscription not found', {
cartId,
});
this.name = 'CartSubscriptionNotFoundError';
Object.setPrototypeOf(this, CartSubscriptionNotFoundError.prototype);
}
}
17 changes: 11 additions & 6 deletions libs/payments/cart/src/lib/cart.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { NotFoundError } from 'objection';
import { v4 as uuidv4 } from 'uuid';

import type { LoggerService } from '@nestjs/common';
import { AccountDbProvider, CartState } from '@fxa/shared/db/mysql/account';
import { Inject, Injectable } from '@nestjs/common';
import { Inject, Injectable, Logger } from '@nestjs/common';

import {
CartInvalidStateForActionError,
Expand Down Expand Up @@ -35,7 +35,11 @@ import type {
CartErrorReasonId,
} from '@fxa/shared/db/mysql/account';
import assert from 'assert';
import { CaptureTimingWithStatsD, StatsDService, type StatsD } from '@fxa/shared/metrics/statsd';
import {
CaptureTimingWithStatsD,
StatsDService,
type StatsD,
} from '@fxa/shared/metrics/statsd';
// For an action to be executed, the cart state needs to be in one of
// valid states listed in the array of CartStates below
const ACTIONS_VALID_STATE = {
Expand All @@ -60,7 +64,8 @@ const isAction = (action: string): action is keyof typeof ACTIONS_VALID_STATE =>
export class CartManager {
constructor(
@Inject(AccountDbProvider) private db: AccountDatabase,
@Inject(StatsDService) public statsd: StatsD
@Inject(StatsDService) public statsd: StatsD,
@Inject(Logger) private log: LoggerService
) {}

/**
Expand Down Expand Up @@ -123,7 +128,7 @@ export class CartManager {
currency: cart.currency,
};
} catch (error) {
console.log(error);
this.log.error(error);
throw new CartNotCreatedError(input, error);
}
}
Expand Down Expand Up @@ -159,7 +164,7 @@ export class CartManager {
currency: cart.currency,
};
} catch (error) {
console.log(error);
this.log.error(error);
throw new CartNotCreatedError(input, error);
}
}
Expand Down
19 changes: 10 additions & 9 deletions libs/payments/cart/src/lib/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Inject, Injectable } from '@nestjs/common';
import { Inject, Injectable, Logger } from '@nestjs/common';
import type { LoggerService } from '@nestjs/common';
import * as Sentry from '@sentry/node';
import assert from 'assert';
Expand Down Expand Up @@ -51,7 +51,6 @@ import {
CartState,
} from '@fxa/shared/db/mysql/account';
import { SanitizeExceptions } from '@fxa/shared/error';
import { LOGGER_PROVIDER } from '@fxa/shared/log';
import { StatsDService } from '@fxa/shared/metrics/statsd';

import {
Expand Down Expand Up @@ -99,7 +98,7 @@ export class CartService {
private customerSessionManager: CustomerSessionManager,
private eligibilityService: EligibilityService,
private invoiceManager: InvoiceManager,
@Inject(LOGGER_PROVIDER) private log: LoggerService,
@Inject(Logger) private log: LoggerService,
private paymentMethodManager: PaymentMethodManager,
private paymentIntentManager: PaymentIntentManager,
private priceManager: PriceManager,
Expand Down Expand Up @@ -220,11 +219,14 @@ export class CartService {
'checkout_failure_subscription_not_cancelled'
);

this.log.log('checkout failed, subscription not canceled', {
eligibility_status: cart.eligibilityStatus,
offering_id: cart.offeringConfigId,
interval: cart.interval,
});
this.log.log(
'cartService.wrapWithCartCatch.subscriptionNotCancelled',
{
eligibilityStatus: cart.eligibilityStatus,
offeringId: cart.offeringConfigId,
interval: cart.interval,
}
);
}
}
} catch (e) {
Expand Down Expand Up @@ -358,7 +360,6 @@ export class CartService {
CartErrorReasonId.IAP_BLOCKED_CONTACT_SUPPORT
);
}

return this.cartManager.createCart(createCartParams);
}

Expand Down
8 changes: 8 additions & 0 deletions libs/payments/cart/src/lib/checkout.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ import { BaseError } from '@fxa/shared/error';
export class CheckoutError extends BaseError {
constructor(...args: ConstructorParameters<typeof BaseError>) {
super(...args);
this.name = 'CheckoutError';
Object.setPrototypeOf(this, CheckoutError.prototype);
}
}

export class CheckoutPaymentError extends BaseError {
constructor(...args: ConstructorParameters<typeof BaseError>) {
super(...args);
this.name = 'CheckoutPaymentError';
Object.setPrototypeOf(this, CheckoutPaymentError.prototype);
}
}

export class CheckoutFailedError extends CheckoutError {
constructor(...args: ConstructorParameters<typeof BaseError>) {
super(...args);
this.name = 'CheckoutFailedError';
Object.setPrototypeOf(this, CheckoutFailedError.prototype);
}
}

export class CheckoutUpgradeError extends BaseError {
constructor(...args: ConstructorParameters<typeof BaseError>) {
super(...args);
this.name = 'CheckoutUpgradeError';
Object.setPrototypeOf(this, CheckoutUpgradeError.prototype);
}
}
8 changes: 8 additions & 0 deletions libs/payments/currency/src/lib/currency.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { BaseError } from '@fxa/shared/error';
export class CurrencyError extends BaseError {
constructor(...args: ConstructorParameters<typeof BaseError>) {
super(...args);
this.name = 'CurrencyError';
Object.setPrototypeOf(this, CurrencyError.prototype);
}
}

Expand All @@ -18,6 +20,8 @@ export class CurrencyCodeInvalidError extends CurrencyError {
},
cause,
});
this.name = 'CurrencyCodeInvalidError';
Object.setPrototypeOf(this, CurrencyCodeInvalidError.prototype);
}
}

Expand All @@ -29,6 +33,8 @@ export class CountryCodeInvalidError extends CurrencyError {
},
cause,
});
this.name = 'CountryCodeInvalidError';
Object.setPrototypeOf(this, CountryCodeInvalidError.prototype);
}
}

Expand All @@ -41,5 +47,7 @@ export class CurrencyCountryMismatchError extends CurrencyError {
},
cause,
});
this.name = 'CurrencyCountryMismatchError';
Object.setPrototypeOf(this, CurrencyCountryMismatchError.prototype);
}
}
Loading