Skip to content

Commit

Permalink
refactor(auth): move google-play and apple-app-store dirs to lib/paym…
Browse files Browse the repository at this point in the history
…ents/iap

Also:
* move lib/payments/google-play/types/firestore.ts to lib/payments/iap/types, since the types are shared with apple-app-store.
* move test/local/payments/google-play to test/local/payments/iap/google-play
  • Loading branch information
biancadanforth committed Apr 14, 2022
1 parent dfb406c commit bb52af3
Show file tree
Hide file tree
Showing 40 changed files with 59 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/bin/key_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const jwtool = require('fxa-jwtool');
const { StatsD } = require('hot-shots');
const { Container } = require('typedi');
const { StripeHelper } = require('../lib/payments/stripe');
const { PlayBilling } = require('../lib/payments/google-play');
const { PlayBilling } = require('../lib/payments/iap/google-play');
const { CurrencyHelper } = require('../lib/payments/currencies');
const {
AuthLogger,
Expand Down
6 changes: 3 additions & 3 deletions packages/fxa-auth-server/lib/payments/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { commaSeparatedListToArray } from './utils';
import error from '../error';
import { authEvents } from '../events';
import { AuthLogger, AuthRequest, ProfileClient } from '../types';
import { PlayBilling } from './google-play/play-billing';
import { SubscriptionPurchase } from './google-play/subscription-purchase';
import { PurchaseQueryError } from './google-play/types';
import { PlayBilling } from './iap/google-play/play-billing';
import { SubscriptionPurchase } from './iap/google-play/subscription-purchase';
import { PurchaseQueryError } from './iap/google-play/types';
import { StripeHelper } from './stripe';

function hex(blob: Buffer | string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { AppStoreServerAPI, Environment } from 'app-store-server-api';
import { Container } from 'typedi';
import { TypedCollectionReference } from 'typesafe-node-firestore';

import { AppConfig, AuthFirestore, AuthLogger } from '../../types';
// TODO: promote this to a shared dir
import { IapConfig } from '../google-play/types';
import { AppConfig, AuthFirestore, AuthLogger } from '../../../types';
import { IapConfig } from '../types';
import { PurchaseManager } from './purchase-manager';

export class AppleIAP {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Auth, google } from 'googleapis';
import { Container } from 'typedi';
import { TypedCollectionReference } from 'typesafe-node-firestore';

import { AppConfig, AuthFirestore, AuthLogger } from '../../types';
import { AppConfig, AuthFirestore, AuthLogger } from '../../../types';
import { PurchaseManager } from './purchase-manager';
import { IapConfig } from './types';
import { IapConfig } from '../types';
import { UserManager } from './user-manager';

export class PlayBilling {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CollectionReference } from '@google-cloud/firestore';
import { androidpublisher_v3 } from 'googleapis';
import Container from 'typedi';

import { AuthLogger } from '../../types';
import { AuthLogger } from '../../../types';
import {
mergePurchaseWithFirestorePurchaseRecord,
SubscriptionPurchase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from 'fxa-shared/subscriptions/types';
import Container from 'typedi';

import { internalValidationError } from '../../../lib/error';
import { AppConfig } from '../../types';
import { StripeHelper } from '../stripe';
import { internalValidationError } from '../../../../lib/error';
import { AppConfig } from '../../../types';
import { StripeHelper } from '../../stripe';
import { PlayBilling } from './play-billing';
import { SubscriptionPurchase } from './subscription-purchase';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* 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 { PurchaseQueryError, PurchaseUpdateError } from './errors';
export { IapConfig } from './firestore';
export {
DeveloperNotification,
NotificationType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { CollectionReference } from '@google-cloud/firestore';
import Container from 'typedi';

import { AuthLogger } from '../../types';
import { AuthLogger } from '../../../types';
import { PurchaseManager } from './purchase-manager';
import {
GOOGLE_PLAY_FORM_OF_PAYMENT,
Expand Down
5 changes: 5 additions & 0 deletions packages/fxa-auth-server/lib/payments/iap/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* 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 { IapConfig } from './firestore';
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/lib/payments/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
import { AppConfig, AuthFirestore, AuthLogger } from '../types';
import { PaymentConfigManager } from './configuration/manager';
import { CurrencyHelper } from './currencies';
import { SubscriptionPurchase } from './google-play/subscription-purchase';
import { SubscriptionPurchase } from './iap/google-play/subscription-purchase';
import { FirestoreStripeError, StripeFirestore } from './stripe-firestore';

// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/lib/routes/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getClientById } from '../oauth/client';
import { generateAccessToken } from '../oauth/grant';
import jwt from '../oauth/jwt';
import { CapabilityService } from '../payments/capability';
import { PlaySubscriptions } from '../payments/google-play/subscriptions';
import { PlaySubscriptions } from '../payments/iap/google-play/subscriptions';
import { PayPalHelper } from '../payments/paypal/helper';
import { StripeHelper } from '../payments/stripe';
import { AuthLogger, AuthRequest } from '../types';
Expand Down
6 changes: 3 additions & 3 deletions packages/fxa-auth-server/lib/routes/subscriptions/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { Container } from 'typedi';

import error from '../../error';
import { CapabilityService } from '../../payments/capability';
import { PlayBilling } from '../../payments/google-play/play-billing';
import { PurchaseUpdateError } from '../../payments/google-play/types/errors';
import { SkuType } from '../../payments/google-play/types/purchases';
import { PlayBilling } from '../../payments/iap/google-play/play-billing';
import { PurchaseUpdateError } from '../../payments/iap/google-play/types/errors';
import { SkuType } from '../../payments/iap/google-play/types/purchases';
import { AuthLogger, AuthRequest } from '../../types';
import { handleAuthScoped } from './utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ServerRoute } from '@hapi/hapi';
import { MozillaSubscription } from 'fxa-shared/subscriptions/types';
import { Container } from 'typedi';
import { PlaySubscriptions } from '../../../lib/payments/google-play/subscriptions';
import { PlaySubscriptions } from '../../../lib/payments/iap/google-play/subscriptions';
import error from '../../error';
import { PaymentBillingDetails, StripeHelper } from '../../payments/stripe';
import { AuthLogger, AuthRequest } from '../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Container } from 'typedi';

import error from '../../error';
import { CapabilityService } from '../../payments/capability';
import { PlayBilling } from '../../payments/google-play/play-billing';
import { DeveloperNotification } from '../../payments/google-play/types';
import { PlayBilling } from '../../payments/iap/google-play/play-billing';
import { DeveloperNotification } from '../../payments/iap/google-play/types';
import { reportSentryError } from '../../sentry';
import { AuthLogger, AuthRequest } from '../../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/lib/routes/support-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import isA from '@hapi/joi';
import { MozillaSubscriptionTypes } from 'fxa-shared/subscriptions/types';
import { Container } from 'typedi';
import { ConfigType } from '../../config';
import { PlaySubscriptions } from '../../lib/payments/google-play/subscriptions';
import { PlaySubscriptions } from '../../lib/payments/iap/google-play/subscriptions';
import { StripeHelper } from '../payments/stripe';
import { AuthLogger, AuthRequest } from '../types';
import validators from './validators';
Expand Down
6 changes: 3 additions & 3 deletions packages/fxa-auth-server/test/local/payments/capability.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ const { Container } = require('typedi');
const { mockLog } = require('../../mocks');
const { AuthLogger } = require('../../../lib/types');
const { StripeHelper } = require('../../../lib/payments/stripe');
const { PlayBilling } = require('../../../lib/payments/google-play');
const { PlayBilling } = require('../../../lib/payments/iap/google-play');

const subscriptionCreated =
require('./fixtures/stripe/subscription_created.json').data.object;

const { ProfileClient } = require('../../../lib/types');
const {
SubscriptionPurchase,
} = require('../../../lib/payments/google-play/subscription-purchase');
} = require('../../../lib/payments/iap/google-play/subscription-purchase');
const proxyquire = require('proxyquire').noPreserveCache();

const authDbModule = require('fxa-shared/db/models/auth');
const {
PurchaseQueryError,
} = require('../../../lib/payments/google-play/types');
} = require('../../../lib/payments/iap/google-play/types');

const mockAuthEvents = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const sinon = require('sinon');
const { assert } = require('chai');
const { default: Container } = require('typedi');

const { mockLog } = require('../../../mocks');
const { mockLog } = require('../../../../mocks');
const {
AuthFirestore,
AuthLogger,
AppConfig,
} = require('../../../../lib/types');
const { PlayBilling } = require('../../../../lib/payments/google-play');
} = require('../../../../../lib/types');
const { PlayBilling } = require('../../../../../lib/payments/iap/google-play');

const mockConfig = {
authFirestore: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ const { assert } = require('chai');
const { default: Container } = require('typedi');
const proxyquire = require('proxyquire').noPreserveCache();

const { mockLog } = require('../../../mocks');
const { AuthLogger } = require('../../../../lib/types');
const { mockLog } = require('../../../../mocks');
const { AuthLogger } = require('../../../../../lib/types');
const {
PurchaseQueryError,
SkuType,
PurchaseUpdateError,
NotificationType,
} = require('../../../../lib/payments/google-play/types');
} = require('../../../../../lib/payments/iap/google-play/types');

const mockSubscriptionPurchase = {};
const mockMergePurchase = sinon.fake.returns({});
const { PurchaseManager } = proxyquire(
'../../../../lib/payments/google-play/purchase-manager',
'../../../../../lib/payments/iap/google-play/purchase-manager',
{
'./subscription-purchase': {
SubscriptionPurchase: mockSubscriptionPurchase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const { assert } = require('chai');
const {
SubscriptionPurchase,
GOOGLE_PLAY_FORM_OF_PAYMENT,
} = require('../../../../lib/payments/google-play/subscription-purchase');
const { SkuType } = require('../../../../lib/payments/google-play/types');
} = require('../../../../../lib/payments/iap/google-play/subscription-purchase');
const {
SkuType,
} = require('../../../../../lib/payments/iap/google-play/types');

describe('SubscriptionPurchase', () => {
beforeEach(() => {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
const sinon = require('sinon');
const assert = { ...sinon.assert, ...require('chai').assert };
const { Container } = require('typedi');
const { PlayBilling } = require('../../../../lib/payments/google-play');
const { PlayBilling } = require('../../../../../lib/payments/iap/google-play');
const {
PlaySubscriptions,
abbrevPlayPurchaseFromSubscriptionPurchase,
} = require('../../../../lib/payments/google-play/subscriptions');
} = require('../../../../../lib/payments/iap/google-play/subscriptions');
const { MozillaSubscriptionTypes } = require('fxa-shared/subscriptions/types');
const { AppConfig } = require('../../../../lib/types');
const { StripeHelper } = require('../../../../lib/payments/stripe');
const { AppConfig } = require('../../../../../lib/types');
const { StripeHelper } = require('../../../../../lib/payments/stripe');

describe('PlaySubscriptions', () => {
const mockConfig = { subscriptions: { enabled: true } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ const sinon = require('sinon');
const { assert } = require('chai');
const { default: Container } = require('typedi');

const { mockLog } = require('../../../mocks');
const { mockLog } = require('../../../../mocks');

const {
UserManager,
} = require('../../../../lib/payments/google-play/user-manager');
const { AuthLogger } = require('../../../../lib/types');
} = require('../../../../../lib/payments/iap/google-play/user-manager');
const { AuthLogger } = require('../../../../../lib/types');
const {
SubscriptionPurchase,
} = require('../../../../lib/payments/google-play/subscription-purchase');
} = require('../../../../../lib/payments/iap/google-play/subscription-purchase');
const {
PurchaseQueryError,
} = require('../../../../lib/payments/google-play/types');
} = require('../../../../../lib/payments/iap/google-play/types');

const USER_ID = 'testUser';
const VALID_SUB_API_RESPONSE = {
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/test/local/payments/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const {
} = require('fxa-shared/db/models/auth');
const {
SubscriptionPurchase,
} = require('../../../lib/payments/google-play/subscription-purchase');
} = require('../../../lib/payments/iap/google-play/subscription-purchase');
const { AuthFirestore, AuthLogger, AppConfig } = require('../../../lib/types');
const {
INVOICES_RESOURCE,
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/test/local/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const { normalizeEmail } = require('fxa-shared').email.helpers;
const { MozillaSubscriptionTypes } = require('fxa-shared/subscriptions/types');
const {
PlaySubscriptions,
} = require('../../../lib/payments/google-play/subscriptions');
} = require('../../../lib/payments/iap/google-play/subscriptions');

const { AccountHandler } = require('../../../lib/routes/account');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const {
} = require('../../../../lib/routes/subscriptions/google');
const {
PurchaseUpdateError,
} = require('../../../../lib/payments/google-play/types/errors');
} = require('../../../../lib/payments/iap/google-play/types/errors');
const error = require('../../../../lib/error');
const { AuthLogger } = require('../../../../lib/types');
const { PlayBilling } = require('../../../../lib/payments/google-play');
const { PlayBilling } = require('../../../../lib/payments/iap/google-play');
const { OAUTH_SCOPE_SUBSCRIPTIONS_IAP } = require('fxa-shared/oauth/constants');
const { CapabilityService } = require('../../../../lib/payments/capability');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const buildRoutes = require('../../../../lib/routes/subscriptions');
const ACCOUNT_LOCALE = 'en-US';
const { OAUTH_SCOPE_SUBSCRIPTIONS } = require('fxa-shared/oauth/constants');
const { CapabilityService } = require('../../../../lib/payments/capability');
const { PlayBilling } = require('../../../../lib/payments/google-play');
const { PlayBilling } = require('../../../../lib/payments/iap/google-play');
const TEST_EMAIL = '[email protected]';
const UID = uuid.v4({}, Buffer.alloc(16)).toString('hex');
const MOCK_SCOPES = ['profile:email', OAUTH_SCOPE_SUBSCRIPTIONS];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
const { default: Container } = require('typedi');
const { mockLog } = require('../../../mocks');
const { AuthLogger } = require('../../../../lib/types');
const { PlayBilling } = require('../../../../lib/payments/google-play');
const { PlayBilling } = require('../../../../lib/payments/iap/google-play');
const { CapabilityService } = require('../../../../lib/payments/capability');

const ACCOUNT_LOCALE = 'en-US';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { StripeHandler: DirectStripeRoutes } = proxyquire(

const { AuthLogger, AppConfig } = require('../../../../lib/types');
const { CapabilityService } = require('../../../../lib/payments/capability');
const { PlayBilling } = require('../../../../lib/payments/google-play');
const { PlayBilling } = require('../../../../lib/payments/iap/google-play');
const {
stripeInvoiceToFirstInvoicePreviewDTO,
stripeInvoicesToSubsequentInvoicePreviewsDTO,
Expand Down
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/test/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,6 @@ function mockPayPalHelper(methods) {
function mockPlaySubscriptions(methods) {
return mockObject(
methods,
require('../lib/payments/google-play/subscriptions').PlaySubscriptions
require('../lib/payments/iap/google-play/subscriptions').PlaySubscriptions
);
}
2 changes: 1 addition & 1 deletion packages/fxa-auth-server/test/remote/subscription_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { StripeHelper } = require('../../lib/payments/stripe');
const { AuthLogger } = require('../../lib/types');
const {
PlaySubscriptions,
} = require('../../lib/payments/google-play/subscriptions');
} = require('../../lib/payments/iap/google-play/subscriptions');

const validClients = config.oauthServer.clients.filter(
(client) => client.trusted && client.canGrant && client.publicClient
Expand Down

0 comments on commit bb52af3

Please sign in to comment.