chore(payments): split payments-stripe into payments-customer

This commit is contained in:
julianpoyourow 2024-09-06 17:28:33 +00:00
Родитель 58f8e720b2
Коммит ba65ee49d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: EA0570ABC73D47D3
66 изменённых файлов: 401 добавлений и 184 удалений

Просмотреть файл

@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { Test } from '@nestjs/testing';
import { PriceManager, StripeClient, StripeConfig } from '@fxa/payments/stripe';
import { PriceManager } from '@fxa/payments/customer';
import { StripeClient, StripeConfig } from '@fxa/payments/stripe';
import {
CapabilityCapabilitiesResultFactory,
CapabilityOfferingResultFactory,

Просмотреть файл

@ -4,7 +4,7 @@
import { faker } from '@faker-js/faker';
import { TaxAddressFactory } from '@fxa/payments/stripe';
import { TaxAddressFactory } from '@fxa/payments/customer';
import {
CartEligibilityStatus,
CartErrorReasonId,

Просмотреть файл

@ -18,23 +18,25 @@ import {
PaypalCustomerManager,
} from '@fxa/payments/paypal';
import {
AccountCustomerManager,
CustomerManager,
InvoiceManager,
InvoicePreviewFactory,
MockStripeConfigProvider,
PaymentMethodManager,
PriceManager,
ProductManager,
PromotionCodeManager,
SubplatInterval,
SubscriptionManager,
TaxAddressFactory,
InvoicePreviewFactory,
} from '@fxa/payments/customer';
import {
ResultAccountCustomerFactory,
StripeClient,
StripeCustomerFactory,
StripePriceFactory,
StripeResponseFactory,
SubplatInterval,
SubscriptionManager,
TaxAddressFactory,
MockStripeConfigProvider,
AccountCustomerManager,
} from '@fxa/payments/stripe';
import {
MockStrapiClientConfigProvider,

Просмотреть файл

@ -7,13 +7,15 @@ import { Injectable } from '@nestjs/common';
import { EligibilityService } from '@fxa/payments/eligibility';
import { ProductConfigurationManager } from '@fxa/shared/cms';
import {
AccountCustomerManager,
AccountCustomerNotFoundError,
CustomerManager,
InvoiceManager,
StripeCustomer,
SubplatInterval,
PromotionCodeManager,
} from '@fxa/payments/customer';
import {
AccountCustomerManager,
AccountCustomerNotFoundError,
StripeCustomer,
} from '@fxa/payments/stripe';
import { CartErrorReasonId, CartState } from '@fxa/shared/db/mysql/account';
import { GeoDBManager } from '@fxa/shared/geodb';

Просмотреть файл

@ -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 { TaxAddress } from '@fxa/payments/stripe';
import { TaxAddress } from '@fxa/payments/customer';
import {
Cart,
CartEligibilityStatus,

Просмотреть файл

@ -25,17 +25,18 @@ import {
ResultPaypalCustomerFactory,
} from '@fxa/payments/paypal';
import {
AccountCustomerManager,
CustomerManager,
InvoiceManager,
InvoicePreviewFactory,
MockStripeConfigProvider,
PaymentMethodManager,
PriceManager,
ProductManager,
PromotionCodeManager,
ResultAccountCustomerFactory,
STRIPE_CUSTOMER_METADATA,
SubscriptionManager,
TaxAddressFactory,
} from '@fxa/payments/customer';
import {
StripeClient,
StripeConfig,
StripeCustomerFactory,
@ -46,8 +47,9 @@ import {
StripePromotionCodeFactory,
StripeResponseFactory,
StripeSubscriptionFactory,
SubscriptionManager,
TaxAddressFactory,
ResultAccountCustomerFactory,
MockStripeConfigProvider,
AccountCustomerManager,
} from '@fxa/payments/stripe';
import { AccountManager } from '@fxa/shared/account/account';
import {

Просмотреть файл

@ -11,18 +11,20 @@ import {
PaypalCustomerManager,
} from '@fxa/payments/paypal';
import {
AccountCustomerManager,
CustomerManager,
InvoiceManager,
PaymentMethodManager,
PromotionCodeManager,
STRIPE_CUSTOMER_METADATA,
StripeSubscription,
SubplatInterval,
SubscriptionManager,
TaxAddress,
type StripeCustomer,
type StripePromotionCode,
} from '@fxa/payments/customer';
import {
AccountCustomerManager,
StripeSubscription,
StripeCustomer,
StripePromotionCode,
} from '@fxa/payments/stripe';
import { AccountManager } from '@fxa/shared/account/account';
import { ProductConfigurationManager } from '@fxa/shared/cms';

Просмотреть файл

@ -0,0 +1,18 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}

Просмотреть файл

@ -0,0 +1,14 @@
{
"jsc": {
"target": "es2017",
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
# payments-customer
This library was generated with [Nx](https://nx.dev).
## Building
Run `nx build payments-customer` to build the library.
## Running unit tests
Run `nx run payments-customer:test-unit` to execute the unit tests via [Jest](https://jestjs.io).
## Running integration tests
Run `nx run payments-customer:test-integration` to execute the integration tests via [Jest](https://jestjs.io).

Просмотреть файл

@ -0,0 +1,30 @@
/* eslint-disable */
import { readFileSync } from 'fs';
// Reading the SWC compilation config and remove the "exclude"
// for the test files to be compiled by SWC
const { exclude: _, ...swcJestConfig } = JSON.parse(
readFileSync(`${__dirname}/.swcrc`, 'utf-8')
);
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
if (swcJestConfig.swcrc === undefined) {
swcJestConfig.swcrc = false;
}
// Uncomment if using global setup/teardown files being transformed via swc
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
// jest needs EsModule Interop to find the default exported setup/teardown functions
// swcJestConfig.module.noInterop = false;
export default {
displayName: 'payments-customer',
preset: '../../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
},
moduleFileExtensions: ['ts', 'js', 'html'],
testEnvironment: 'node',
coverageDirectory: '../../../coverage/libs/payments/customer',
};

Просмотреть файл

@ -0,0 +1,4 @@
{
"name": "payments/customer",
"version": "0.0.0"
}

Просмотреть файл

@ -0,0 +1,63 @@
{
"name": "payments-customer",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/payments/customer/src",
"projectType": "library",
"tags": ["scope:shared:lib:payments"],
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"main": "libs/payments/customer/src/index.ts",
"outputPath": "dist/libs/payments/customer",
"outputFileName": "main.js",
"tsConfig": "libs/payments/customer/tsconfig.lib.json",
"declaration": true,
"assets": [
{
"glob": "libs/payments/customer/README.md",
"input": ".",
"output": "."
}
],
"platform": "node"
},
"configurations": {
"development": {
"minify": false
},
"production": {
"minify": true
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/payments/customer/**/*.ts",
"libs/payments/customer/package.json"
]
}
},
"test-unit": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/payments/customer/jest.config.ts",
"testPathPattern": ["^(?!.*\\.in\\.spec\\.ts$).*$"]
}
},
"test-integration": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/payments/customer/jest.config.ts",
"testPathPattern": ["\\.in\\.spec\\.ts$"]
}
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
export * from './lib/customer.manager';
export * from './lib/invoice.manager';
export * from './lib/invoice.factories';
export * from './lib/paymentMethod.manager';
export * from './lib/price.manager';
export * from './lib/product.manager';
export * from './lib/promotionCode.manager';
export * from './lib/subscription.manager';
export * from './lib/types';
export * from './lib/factories/tax-address.factory';
export * from './lib/error';

Просмотреть файл

@ -5,13 +5,15 @@
import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { StripeResponseFactory } from './factories/api-list.factory';
import { StripeCustomerFactory } from './factories/customer.factory';
import {
StripeClient,
StripeResponseFactory,
StripeCustomerFactory,
MockStripeConfigProvider,
MOZILLA_TAX_ID,
} from '@fxa/payments/stripe';
import { TaxAddressFactory } from './factories/tax-address.factory';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import { CustomerManager } from './customer.manager';
import { MOZILLA_TAX_ID } from './stripe.constants';
describe('CustomerManager', () => {
let customerManager: CustomerManager;

Просмотреть файл

@ -5,11 +5,13 @@
import { Injectable } from '@nestjs/common';
import { Stripe } from 'stripe';
import { StripeClient } from './stripe.client';
import { MOZILLA_TAX_ID } from './stripe.constants';
import { CustomerDeletedError } from './stripe.error';
import { TaxAddress } from './stripe.types';
import { StripeCustomer } from './stripe.client.types';
import {
StripeClient,
StripeCustomer,
MOZILLA_TAX_ID,
} from '@fxa/payments/stripe';
import { CustomerDeletedError } from './error';
import { TaxAddress } from './types';
import { isCustomerTaxEligible } from './util/isCustomerTaxEligible';
@Injectable()

Просмотреть файл

@ -4,7 +4,7 @@
import { BaseError } from '@fxa/shared/error';
export class StripeError extends BaseError {
export class PaymentsCustomerError extends BaseError {
constructor(message: string, cause?: Error) {
super(message, {
cause,
@ -12,25 +12,25 @@ export class StripeError extends BaseError {
}
}
export class CustomerDeletedError extends StripeError {
export class CustomerDeletedError extends PaymentsCustomerError {
constructor() {
super('Customer deleted');
}
}
export class CustomerNotFoundError extends StripeError {
export class CustomerNotFoundError extends PaymentsCustomerError {
constructor() {
super('Customer not found');
}
}
export class PlanIntervalMultiplePlansError extends StripeError {
export class PlanIntervalMultiplePlansError extends PaymentsCustomerError {
constructor() {
super('Interval has mulitple plans');
}
}
export class PromotionCodeCouldNotBeAttachedError extends StripeError {
export class PromotionCodeCouldNotBeAttachedError extends PaymentsCustomerError {
customerId?: string;
subscriptionId?: string;
promotionId?: string;
@ -51,7 +51,7 @@ export class PromotionCodeCouldNotBeAttachedError extends StripeError {
}
}
export class StripeNoMinimumChargeAmountAvailableError extends StripeError {
export class StripeNoMinimumChargeAmountAvailableError extends PaymentsCustomerError {
constructor() {
super('Currency does not have a minimum charge amount available.');
}

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { faker } from '@faker-js/faker';
import { TaxAddress } from '../stripe.types';
import { TaxAddress } from '../types';
export const TaxAddressFactory = (
override?: Partial<TaxAddress>

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { faker } from '@faker-js/faker';
import { InvoicePreview } from './stripe.types';
import { InvoicePreview } from './types';
export const InvoicePreviewFactory = (
override?: Partial<InvoicePreview>

Просмотреть файл

@ -4,15 +4,17 @@
import { Test } from '@nestjs/testing';
import { StripeResponseFactory } from './factories/api-list.factory';
import { StripeCustomerFactory } from './factories/customer.factory';
import { StripeInvoiceFactory } from './factories/invoice.factory';
import { StripePriceFactory } from './factories/price.factory';
import { StripeUpcomingInvoiceFactory } from './factories/upcoming-invoice.factory';
import {
StripeClient,
StripeResponseFactory,
StripeCustomerFactory,
StripeInvoiceFactory,
StripePriceFactory,
StripeUpcomingInvoiceFactory,
MockStripeConfigProvider,
} from '@fxa/payments/stripe';
import { TaxAddressFactory } from './factories/tax-address.factory';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import { InvoicePreviewFactory } from './stripe.factories';
import { InvoicePreviewFactory } from './invoice.factories';
import { InvoiceManager } from './invoice.manager';
import { stripeInvoiceToFirstInvoicePreviewDTO } from '../lib/util/stripeInvoiceToFirstInvoicePreviewDTO';
import { getMinimumChargeAmountForCurrency } from '../lib/util/getMinimumChargeAmountForCurrency';

Просмотреть файл

@ -5,9 +5,12 @@
import { Injectable } from '@nestjs/common';
import { Stripe } from 'stripe';
import { StripeClient } from './stripe.client';
import { StripeCustomer, StripeInvoice } from './stripe.client.types';
import { TaxAddress } from './stripe.types';
import {
StripeClient,
StripeCustomer,
StripeInvoice,
} from '@fxa/payments/stripe';
import { TaxAddress } from './types';
import { isCustomerTaxEligible } from './util/isCustomerTaxEligible';
import { stripeInvoiceToFirstInvoicePreviewDTO } from './util/stripeInvoiceToFirstInvoicePreviewDTO';
import { getMinimumChargeAmountForCurrency } from './util/getMinimumChargeAmountForCurrency';

Просмотреть файл

@ -5,11 +5,13 @@
import { Test } from '@nestjs/testing';
import { PaymentMethodManager } from './paymentMethod.manager';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import { StripeResponseFactory } from './factories/api-list.factory';
import { StripeCustomerFactory } from './factories/customer.factory';
import { StripePaymentMethodFactory } from './factories/payment-method.factory';
import {
StripeClient,
MockStripeConfigProvider,
StripeResponseFactory,
StripeCustomerFactory,
StripePaymentMethodFactory,
} from '@fxa/payments/stripe';
describe('PaymentMethodManager', () => {
let paymentMethodManager: PaymentMethodManager;

Просмотреть файл

@ -4,7 +4,7 @@
import { Injectable } from '@nestjs/common';
import { Stripe } from 'stripe';
import { StripeClient } from './stripe.client';
import { StripeClient } from '@fxa/payments/stripe';
@Injectable()
export class PaymentMethodManager {

Просмотреть файл

@ -4,16 +4,16 @@
import { Test } from '@nestjs/testing';
import { StripeResponseFactory } from './factories/api-list.factory';
import {
StripeClient,
StripeResponseFactory,
StripePriceFactory,
StripePriceRecurringFactory,
} from './factories/price.factory';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import { PlanIntervalMultiplePlansError } from './stripe.error';
MockStripeConfigProvider,
} from '@fxa/payments/stripe';
import { PlanIntervalMultiplePlansError } from './error';
import { PriceManager } from './price.manager';
import { SubplatInterval } from './stripe.types';
import { SubplatInterval } from './types';
describe('PriceManager', () => {
let priceManager: PriceManager;

Просмотреть файл

@ -4,10 +4,9 @@
import { Injectable } from '@nestjs/common';
import { StripeClient } from './stripe.client';
import { StripePrice } from './stripe.client.types';
import { PlanIntervalMultiplePlansError } from './stripe.error';
import { SubplatInterval } from './stripe.types';
import { StripeClient, StripePrice } from '@fxa/payments/stripe';
import { PlanIntervalMultiplePlansError } from './error';
import { SubplatInterval } from './types';
import { doesPriceMatchSubplatInterval } from './util/doesPriceMatchSubplatInterval';
@Injectable()

Просмотреть файл

@ -4,10 +4,12 @@
import { Test } from '@nestjs/testing';
import { StripeResponseFactory } from './factories/api-list.factory';
import { StripeProductFactory } from './factories/product.factory';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import {
StripeClient,
StripeResponseFactory,
StripeProductFactory,
MockStripeConfigProvider,
} from '@fxa/payments/stripe';
import { ProductManager } from './product.manager';
describe('ProductManager', () => {

Просмотреть файл

@ -4,7 +4,7 @@
import { Injectable } from '@nestjs/common';
import { StripeClient } from './stripe.client';
import { StripeClient } from '@fxa/payments/stripe';
@Injectable()
export class ProductManager {

Просмотреть файл

@ -6,24 +6,22 @@ import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { Stripe } from 'stripe';
import {
StripeApiListFactory,
StripeResponseFactory,
} from './factories/api-list.factory';
import { StripeCustomerFactory } from './factories/customer.factory';
import { StripePriceFactory } from './factories/price.factory';
import { StripeProductFactory } from './factories/product.factory';
import { StripePromotionCodeFactory } from './factories/promotion-code.factory';
import {
StripeSubscriptionFactory,
StripeSubscriptionItemFactory,
} from './factories/subscription.factory';
import { ProductManager } from './product.manager';
import { PromotionCodeManager } from './promotionCode.manager';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import { PromotionCodeCouldNotBeAttachedError } from './stripe.error';
import { STRIPE_PRICE_METADATA } from './stripe.types';
import {
StripeClient,
StripeApiListFactory,
StripeResponseFactory,
StripeCustomerFactory,
StripePriceFactory,
StripeProductFactory,
StripePromotionCodeFactory,
StripeSubscriptionFactory,
StripeSubscriptionItemFactory,
MockStripeConfigProvider,
} from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from './error';
import { STRIPE_PRICE_METADATA } from './types';
import { SubscriptionManager } from './subscription.manager';
import { assertPromotionCodeActive } from '../lib/util/assertPromotionCodeActive';

Просмотреть файл

@ -4,12 +4,15 @@
import { Injectable } from '@nestjs/common';
import { StripeClient } from './stripe.client';
import { PromotionCodeCouldNotBeAttachedError } from './stripe.error';
import {
StripeClient,
StripePrice,
StripePromotionCode,
} from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from './error';
import { assertPromotionCodeApplicableToPrice } from './util/assertPromotionCodeApplicableToPrice';
import { assertPromotionCodeActive } from './util/assertPromotionCodeActive';
import { getPriceFromSubscription } from './util/getPriceFromSubscription';
import type { StripePrice, StripePromotionCode } from './stripe.client.types';
@Injectable()
export class PromotionCodeManager {

Просмотреть файл

@ -6,16 +6,16 @@ import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import {
StripeClient,
StripeApiListFactory,
StripeResponseFactory,
} from './factories/api-list.factory';
import { StripeCustomerFactory } from './factories/customer.factory';
import { StripeInvoiceFactory } from './factories/invoice.factory';
import { StripePaymentIntentFactory } from './factories/payment-intent.factory';
import { StripeSubscriptionFactory } from './factories/subscription.factory';
import { StripeClient } from './stripe.client';
import { MockStripeConfigProvider } from './stripe.config';
import { STRIPE_CUSTOMER_METADATA } from './stripe.types';
StripeCustomerFactory,
StripeInvoiceFactory,
StripePaymentIntentFactory,
StripeSubscriptionFactory,
MockStripeConfigProvider,
} from '@fxa/payments/stripe';
import { STRIPE_CUSTOMER_METADATA } from './types';
import { SubscriptionManager } from './subscription.manager';
describe('SubscriptionManager', () => {

Просмотреть файл

@ -5,10 +5,9 @@
import { Injectable } from '@nestjs/common';
import { Stripe } from 'stripe';
import { StripeClient } from './stripe.client';
import { StripeSubscription } from './stripe.client.types';
import { ACTIVE_SUBSCRIPTION_STATUSES } from './stripe.constants';
import { STRIPE_CUSTOMER_METADATA } from './stripe.types';
import { StripeClient, StripeSubscription } from '@fxa/payments/stripe';
import { ACTIVE_SUBSCRIPTION_STATUSES } from '@fxa/payments/stripe';
import { STRIPE_CUSTOMER_METADATA } from './types';
@Injectable()
export class SubscriptionManager {

Просмотреть файл

@ -2,10 +2,12 @@
* 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 { StripeResponseFactory } from '../factories/api-list.factory';
import { StripeCouponFactory } from '../factories/coupon.factory';
import { StripePromotionCodeFactory } from '../factories/promotion-code.factory';
import { PromotionCodeCouldNotBeAttachedError } from '../stripe.error';
import {
StripeResponseFactory,
StripeCouponFactory,
StripePromotionCodeFactory,
} from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from '../error';
import { assertPromotionCodeActive } from './assertPromotionCodeActive';
describe('assertPromotionCodeActive', () => {

Просмотреть файл

@ -2,8 +2,8 @@
* 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 type { StripePromotionCode } from '../stripe.client.types';
import { PromotionCodeCouldNotBeAttachedError } from '../stripe.error';
import type { StripePromotionCode } from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from '../error';
export const assertPromotionCodeActive = (code: StripePromotionCode) => {
const nowSecs = Date.now() / 1000;

Просмотреть файл

@ -2,14 +2,13 @@
* 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 { StripePriceFactory } from '../factories/price.factory';
import { StripeProductFactory } from '../factories/product.factory';
import { StripePromotionCodeFactory } from '../factories/promotion-code.factory';
import { PromotionCodeCouldNotBeAttachedError } from '../stripe.error';
import {
STRIPE_PRICE_METADATA,
STRIPE_PRODUCT_METADATA,
} from '../stripe.types';
StripePriceFactory,
StripeProductFactory,
StripePromotionCodeFactory,
} from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from '../error';
import { STRIPE_PRICE_METADATA, STRIPE_PRODUCT_METADATA } from '../types';
import { assertPromotionCodeApplicableToPrice } from './assertPromotionCodeApplicableToPrice';
describe('assertPromotionCodeApplicableToPrice', () => {

Просмотреть файл

@ -2,16 +2,13 @@
* 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 type {
import {
StripePrice,
StripeProduct,
StripePromotionCode,
} from '../stripe.client.types';
import { PromotionCodeCouldNotBeAttachedError } from '../stripe.error';
import {
STRIPE_PRICE_METADATA,
STRIPE_PRODUCT_METADATA,
} from '../stripe.types';
} from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from '../error';
import { STRIPE_PRICE_METADATA, STRIPE_PRODUCT_METADATA } from '../types';
export const assertPromotionCodeApplicableToPrice = (
code: StripePromotionCode,

Просмотреть файл

@ -5,8 +5,8 @@
import {
StripePriceFactory,
StripePriceRecurringFactory,
} from '../factories/price.factory';
import { SubplatInterval } from '../stripe.types';
} from '@fxa/payments/stripe';
import { SubplatInterval } from '../types';
import { doesPriceMatchSubplatInterval } from './doesPriceMatchSubplatInterval';
describe('doesPriceMatchSubplatInterval', () => {

Просмотреть файл

@ -2,8 +2,8 @@
* 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 { StripePrice } from '../stripe.client.types';
import { SubplatInterval } from '../stripe.types';
import { StripePrice } from '@fxa/payments/stripe';
import { SubplatInterval } from '../types';
interface Interval {
interval: NonNullable<StripePrice['recurring']>['interval'];

Просмотреть файл

@ -2,8 +2,8 @@
* 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 { STRIPE_MINIMUM_CHARGE_AMOUNTS } from '../stripe.constants';
import { StripeNoMinimumChargeAmountAvailableError } from '../stripe.error';
import { STRIPE_MINIMUM_CHARGE_AMOUNTS } from '@fxa/payments/stripe';
import { StripeNoMinimumChargeAmountAvailableError } from '../error';
/**
* Returns minimum charge amount for currency

Просмотреть файл

@ -2,13 +2,13 @@
* 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 { StripeApiListFactory } from '../factories/api-list.factory';
import { StripePriceFactory } from '../factories/price.factory';
import {
StripeApiListFactory,
StripePriceFactory,
StripeSubscriptionFactory,
StripeSubscriptionItemFactory,
} from '../factories/subscription.factory';
import { PromotionCodeCouldNotBeAttachedError } from '../stripe.error';
} from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from '../error';
import { getPriceFromSubscription } from './getPriceFromSubscription';
describe('getPriceFromSubscription', () => {

Просмотреть файл

@ -2,8 +2,8 @@
* 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 type { StripeSubscription } from '../stripe.client.types';
import { PromotionCodeCouldNotBeAttachedError } from '../stripe.error';
import type { StripeSubscription } from '@fxa/payments/stripe';
import { PromotionCodeCouldNotBeAttachedError } from '../error';
export const getPriceFromSubscription = (subscription: StripeSubscription) => {
const item = subscription.items.data.at(0);

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { isCustomerTaxEligible } from './isCustomerTaxEligible';
import { StripeCustomerFactory } from '../factories/customer.factory';
import { StripeCustomerFactory } from '@fxa/payments/stripe';
import { faker } from '@faker-js/faker';
describe('isCustomerTaxEligible', () => {

Просмотреть файл

@ -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 { StripeCustomer } from '../stripe.client.types';
import { StripeCustomer } from '@fxa/payments/stripe';
export const isCustomerTaxEligible = (customer: StripeCustomer) => {
return (

Просмотреть файл

@ -3,10 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { stripeInvoiceToFirstInvoicePreviewDTO } from './stripeInvoiceToFirstInvoicePreviewDTO';
import { StripeResponseFactory } from '../factories/api-list.factory';
import { StripeUpcomingInvoiceFactory } from '../factories/upcoming-invoice.factory';
import { StripeTotalDiscountAmountsFactory } from '../factories/total-discount-amounts.factory';
import { StripeTotalTaxAmountsFactory } from '../factories/total-tax-amounts.factory';
import {
StripeResponseFactory,
StripeUpcomingInvoiceFactory,
StripeTotalDiscountAmountsFactory,
StripeTotalTaxAmountsFactory,
} from '@fxa/payments/stripe';
describe('stripeInvoiceToFirstInvoicePreviewDTO', () => {
it('formats invoice', () => {

Просмотреть файл

@ -2,8 +2,8 @@
* 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 { StripeUpcomingInvoice } from '../stripe.client.types';
import { InvoicePreview } from '../stripe.types';
import { StripeUpcomingInvoice } from '@fxa/payments/stripe';
import { InvoicePreview } from '../types';
/**
* Formats a Stripe Invoice to the FirstInvoicePreview DTO format.

Просмотреть файл

@ -0,0 +1,22 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}

Просмотреть файл

@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

Просмотреть файл

@ -4,14 +4,13 @@
import { Test } from '@nestjs/testing';
import { PriceManager, SubplatInterval } from '@fxa/payments/customer';
import {
PriceManager,
StripeClient,
StripeConfig,
StripePrice,
StripePriceFactory,
StripePriceRecurringFactory,
SubplatInterval,
} from '@fxa/payments/stripe';
import {
EligibilityContentByPlanIdsResultFactory,

Просмотреть файл

@ -4,11 +4,8 @@
import { Injectable } from '@nestjs/common';
import {
PriceManager,
StripePrice,
SubplatInterval,
} from '@fxa/payments/stripe';
import { PriceManager, SubplatInterval } from '@fxa/payments/customer';
import { StripePrice } from '@fxa/payments/stripe';
import {
EligibilityContentOfferingResult,
ProductConfigurationManager,

Просмотреть файл

@ -5,11 +5,13 @@ import { Test } from '@nestjs/testing';
import {
PriceManager,
SubplatInterval,
SubscriptionManager,
} from '@fxa/payments/customer';
import {
StripeClient,
StripeConfig,
StripeCustomerFactory,
SubplatInterval,
SubscriptionManager,
} from '@fxa/payments/stripe';
import {
EligibilityContentByOfferingResultFactory,

Просмотреть файл

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { Injectable } from '@nestjs/common';
import { SubscriptionManager, SubplatInterval } from '@fxa/payments/stripe';
import { SubscriptionManager, SubplatInterval } from '@fxa/payments/customer';
import { ProductConfigurationManager } from '@fxa/shared/cms';
import { EligibilityManager } from './eligibility.manager';
import { EligibilityStatus } from './eligibility.types';

Просмотреть файл

@ -5,8 +5,8 @@
import { Test } from '@nestjs/testing';
import { Stripe } from 'stripe';
import { PriceManager } from '@fxa/payments/customer';
import {
PriceManager,
StripeClient,
StripeConfig,
StripePlanFactory,

Просмотреть файл

@ -7,10 +7,9 @@ import { Test } from '@nestjs/testing';
import {
CustomerManager,
InvoiceManager,
MockStripeConfigProvider,
StripeClient,
SubscriptionManager,
} from '@fxa/payments/stripe';
} from '@fxa/payments/customer';
import { MockStripeConfigProvider, StripeClient } from '@fxa/payments/stripe';
import { MockAccountDatabaseNestFactory } from '@fxa/shared/db/mysql/account';
import {

Просмотреть файл

@ -1,4 +1,4 @@
{
"name": "@fxa/payments/stripe",
"name": "payments/stripe",
"version": "0.0.0"
}

Просмотреть файл

@ -28,7 +28,6 @@ export {
export { StripePromotionCodeFactory } from './lib/factories/promotion-code.factory';
export { StripePaymentMethodFactory } from './lib/factories/payment-method.factory';
export { StripePaymentIntentFactory } from './lib/factories/payment-intent.factory';
export { TaxAddressFactory } from './lib/factories/tax-address.factory';
export { StripeTaxRateFactory } from './lib/factories/tax-rate.factory';
export { StripeTotalDiscountAmountsFactory } from './lib/factories/total-discount-amounts.factory';
export { StripeTotalTaxAmountsFactory } from './lib/factories/total-tax-amounts.factory';
@ -37,14 +36,3 @@ export * from './lib/stripe.client';
export * from './lib/stripe.client.types';
export * from './lib/stripe.config';
export * from './lib/stripe.constants';
export * from './lib/stripe.error';
export * from './lib/stripe.factories';
export * from './lib/stripe.service';
export * from './lib/stripe.types';
export * from './lib/customer.manager';
export * from './lib/invoice.manager';
export * from './lib/paymentMethod.manager';
export * from './lib/price.manager';
export * from './lib/product.manager';
export * from './lib/promotionCode.manager';
export * from './lib/subscription.manager';

Просмотреть файл

@ -17,16 +17,15 @@ import {
PaypalCustomerManager,
} from '@fxa/payments/paypal';
import {
AccountCustomerManager,
CustomerManager,
InvoiceManager,
PaymentMethodManager,
PriceManager,
ProductManager,
PromotionCodeManager,
StripeClient,
SubscriptionManager,
} from '@fxa/payments/stripe';
} from '@fxa/payments/customer';
import { AccountCustomerManager, StripeClient } from '@fxa/payments/stripe';
import { AccountManager } from '@fxa/shared/account/account';
import { ProductConfigurationManager, StrapiClient } from '@fxa/shared/cms';
import { FirestoreProvider } from '@fxa/shared/db/firestore';

Просмотреть файл

@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 { SubplatInterval } from '@fxa/payments/stripe';
import { SubplatInterval } from '@fxa/payments/customer';
import { IsOptional, IsString } from 'class-validator';
export class SetupCartActionArgs {

Просмотреть файл

@ -4,14 +4,13 @@
import { Test } from '@nestjs/testing';
import { StatsD } from 'hot-shots';
import { PriceManager, SubplatInterval } from '@fxa/payments/customer';
import {
PriceManager,
StripeClient,
StripeConfig,
StripePlanFactory,
StripePriceFactory,
StripeResponseFactory,
SubplatInterval,
} from '@fxa/payments/stripe';
import { MockFirestoreProvider } from '@fxa/shared/db/firestore';
import { MockStatsDProvider, StatsDService } from '@fxa/shared/metrics/statsd';

Просмотреть файл

@ -6,7 +6,7 @@ import { getOperationName } from '@apollo/client/utilities';
import { Inject, Injectable } from '@nestjs/common';
import { StatsD } from 'hot-shots';
import { PriceManager, SubplatInterval } from '@fxa/payments/stripe';
import { PriceManager, SubplatInterval } from '@fxa/payments/customer';
import { StatsDService } from '@fxa/shared/metrics/statsd';
import {
EligibilityContentByPlanIdsQuery,

Просмотреть файл

@ -5,6 +5,7 @@
"paths": {
"@fxa/payments/legacy": ["libs/payments/legacy/src/index"],
"@fxa/payments/stripe": ["libs/payments/stripe/src/index"],
"@fxa/payments/customer": ["libs/payments/customer/src/index"],
"@fxa/shared/cms": ["libs/shared/cms/src/index"],
"@fxa/shared/cloud-tasks": ["libs/shared/cloud-tasks/src/index"],
"@fxa/shared/db/firestore": ["libs/shared/db/firestore/src/index"],

Просмотреть файл

@ -12,12 +12,12 @@ const { config } = require('../config');
const { CapabilityManager } = require('@fxa/payments/capability');
const { EligibilityManager } = require('@fxa/payments/eligibility');
const {
StripeClient,
ProductManager,
PriceManager,
SubscriptionManager,
PromotionCodeManager,
} = require('@fxa/payments/stripe');
} = require('@fxa/payments/customer');
const { StripeClient } = require('@fxa/payments/stripe');
const {
ProductConfigurationManager,
StrapiClient,

Просмотреть файл

@ -6,7 +6,10 @@ import { ServerRoute } from '@hapi/hapi';
import isA from 'joi';
import * as Sentry from '@sentry/node';
import { SeverityLevel } from '@sentry/types';
import { PromotionCodeManager, StripeError } from '@fxa/payments/stripe';
import {
PaymentsCustomerError,
PromotionCodeManager,
} from '@fxa/payments/customer';
import { getAccountCustomerByUid } from 'fxa-shared/db/models/auth';
import {
AbbrevPlan,
@ -558,7 +561,7 @@ export class StripeHandler {
uid,
});
if (err instanceof StripeError) {
if (err instanceof PaymentsCustomerError) {
throw error.subscriptionPromotionCodeNotApplied(err, err.message);
} else {
throw err;

Просмотреть файл

@ -16,7 +16,10 @@ const {
STRIPE_PRICE_METADATA,
} = require('../../../../lib/payments/stripe');
const { CurrencyHelper } = require('../../../../lib/payments/currencies');
const { PromotionCodeManager, StripeError } = require('@fxa/payments/stripe');
const {
PromotionCodeManager,
PaymentsCustomerError,
} = require('@fxa/payments/customer');
const WError = require('verror').WError;
const uuidv4 = require('uuid').v4;
const proxyquire = require('proxyquire').noPreserveCache();
@ -1012,7 +1015,7 @@ describe('DirectStripeRoutes', () => {
}
});
it('errors with AppError subscriptionPromotionCodeNotApplied if StripeError returned from StripeService', async () => {
it('errors with AppError subscriptionPromotionCodeNotApplied if PaymentsCustomerError returned from StripeService', async () => {
const sentryScope = { setContext: sandbox.stub() };
sandbox.stub(Sentry, 'withScope').callsFake((cb) => cb(sentryScope));
sandbox.stub(Sentry, 'captureMessage');
@ -1041,7 +1044,7 @@ describe('DirectStripeRoutes', () => {
subscriptionId: mockSubscription.id,
};
const stripeError = new StripeError('Oh no.');
const stripeError = new PaymentsCustomerError('Oh no.');
mockPromotionCodeManager.applyPromoCodeToSubscription = sinon.stub();
mockPromotionCodeManager.applyPromoCodeToSubscription.rejects(
stripeError

Просмотреть файл

@ -74,7 +74,8 @@
"@fxa/vendored/jwtool": ["libs/vendored/jwtool/src/index.ts"],
"@fxa/vendored/typesafe-node-firestore": [
"libs/vendored/typesafe-node-firestore/src/index.ts"
]
],
"@fxa/payments/customer": ["libs/payments/customer/src/index.ts"]
},
"typeRoots": [
"./types",