From 34eb7d8309c5b7ed66eaa7782df3ae2767f7e25c Mon Sep 17 00:00:00 2001 From: Randy Schott <1815175+schottra@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:23:51 -0400 Subject: [PATCH 1/3] Consume stripe error messages from Identity and pipe to analytics --- packages/common/src/models/Analytics.ts | 17 +++++++ packages/common/src/store/buy-usdc/utils.ts | 2 +- .../common/src/store/ui/stripe-modal/sagas.ts | 44 +++++++++++++++++-- .../common/src/store/ui/stripe-modal/types.ts | 17 +++++++ .../src/services/identity/IdentityService.ts | 2 + 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/packages/common/src/models/Analytics.ts b/packages/common/src/models/Analytics.ts index bc839d6a582..185501d0a4f 100644 --- a/packages/common/src/models/Analytics.ts +++ b/packages/common/src/models/Analytics.ts @@ -335,6 +335,9 @@ export enum Name { BUY_USDC_RECOVERY_SUCCESS = 'Buy USDC: Recovery Success', BUY_USDC_RECOVERY_FAILURE = 'Buy USDC: Recovery Failure', + // Stripe Tracking + STRIPE_SESSION_CREATION_ERROR = 'Stripe: Session Creation Error', + // Purchase Content PURCHASE_CONTENT_STARTED = 'Purchase Content: Started', PURCHASE_CONTENT_SUCCESS = 'Purchase Content: Success', @@ -1574,6 +1577,7 @@ type BuyAudioRecoveryFailure = { error: string } +// Buy USDC type BuyUSDCOnRampOpened = { eventName: Name.BUY_USDC_ON_RAMP_OPENED provider: string @@ -1623,6 +1627,18 @@ type BuyUSDCRecoveryFailure = { error: string } +// Stripe +type StripeSessionCreationError = { + eventName: Name.STRIPE_SESSION_CREATION_ERROR + amount: string + destinationCurrency: string + code: string + message: string + type: string +} + +// Content Purchase + type ContentPurchaseMetadata = { price: number contentId: number @@ -1983,6 +1999,7 @@ export type AllTrackingEvents = | BuyUSDCRecoveryInProgress | BuyUSDCRecoverySuccess | BuyUSDCRecoveryFailure + | StripeSessionCreationError | PurchaseContentStarted | PurchaseContentSuccess | PurchaseContentFailure diff --git a/packages/common/src/store/buy-usdc/utils.ts b/packages/common/src/store/buy-usdc/utils.ts index 341f30ed20e..4795538a316 100644 --- a/packages/common/src/store/buy-usdc/utils.ts +++ b/packages/common/src/store/buy-usdc/utils.ts @@ -1,7 +1,7 @@ import { call, select } from 'typed-redux-saga' import { createUserBankIfNeeded } from 'services/audius-backend/solana' -import { IntKeys } from 'services/index' +import { IntKeys } from 'services/remote-config' import { MAX_CONTENT_PRICE_CENTS, MAX_USDC_PURCHASE_AMOUNT_CENTS, diff --git a/packages/common/src/store/ui/stripe-modal/sagas.ts b/packages/common/src/store/ui/stripe-modal/sagas.ts index 20c91343bb0..3a76034817b 100644 --- a/packages/common/src/store/ui/stripe-modal/sagas.ts +++ b/packages/common/src/store/ui/stripe-modal/sagas.ts @@ -1,5 +1,8 @@ +import { IdentityRequestError } from '@audius/sdk' import { call, takeEvery, put, select } from 'typed-redux-saga' +import { Name } from 'models/Analytics' +import { ErrorLevel } from 'models/ErrorReporting' import { createStripeSession } from 'services/audius-backend/stripe' import { getContext } from 'store/effects' @@ -12,11 +15,17 @@ import { stripeSessionCreated, stripeSessionStatusChanged } from './slice' +import { + StripeSessionCreationError, + StripeSessionCreationErrorResponseData +} from './types' function* handleInitializeStripeModal({ payload: { amount, destinationCurrency, destinationWallet } }: ReturnType) { const audiusBackendInstance = yield* getContext('audiusBackendInstance') + const reportToSentry = yield* getContext('reportToSentry') + const { track, make } = yield* getContext('analytics') const { onrampFailed } = yield* select(getStripeModalState) try { const res = yield* call(createStripeSession, audiusBackendInstance, { @@ -26,13 +35,40 @@ function* handleInitializeStripeModal({ }) yield* put(stripeSessionCreated({ clientSecret: res.client_secret })) } catch (e) { - // TODO: When we have better error messages from identity, we should extract them here so - // they make it into analytics. - // https://linear.app/audius/issue/PAY-2041/[usdc]-we-should-pipe-the-stripe-session-creation-error-back-from + const { code, message, type } = ((e as IdentityRequestError).response + ?.data ?? {}) as StripeSessionCreationErrorResponseData + + const error = new StripeSessionCreationError(code, message, type) + if (onrampFailed) { - yield* put({ type: onrampFailed.type, payload: { error: e } }) + yield* put({ + type: onrampFailed.type, + payload: { error } + }) } yield* put(setVisibility({ modal: 'StripeOnRamp', visible: 'closing' })) + yield* call(reportToSentry, { + level: ErrorLevel.Error, + error, + additionalInfo: { + code, + message, + type, + amount, + destinationCurrency + } + }) + yield* call( + track, + make({ + eventName: Name.STRIPE_SESSION_CREATION_ERROR, + amount, + code, + destinationCurrency, + message, + type + }) + ) } } diff --git a/packages/common/src/store/ui/stripe-modal/types.ts b/packages/common/src/store/ui/stripe-modal/types.ts index 0c4ec79253a..ce6724d8ece 100644 --- a/packages/common/src/store/ui/stripe-modal/types.ts +++ b/packages/common/src/store/ui/stripe-modal/types.ts @@ -16,3 +16,20 @@ export type StripeModalState = { stripeSessionStatus?: StripeSessionStatus stripeClientSecret?: string } + +export type StripeSessionCreationErrorResponse = { + error: string + code: string + message: string + type: string +} + +export class StripeSessionCreationError extends Error { + constructor( + public code: string, + public message: string, + public type: string + ) { + super(`Failed to create Stripe session: ${message}`) + } +} diff --git a/packages/libs/src/services/identity/IdentityService.ts b/packages/libs/src/services/identity/IdentityService.ts index acbe4365154..55e102a77b9 100644 --- a/packages/libs/src/services/identity/IdentityService.ts +++ b/packages/libs/src/services/identity/IdentityService.ts @@ -46,6 +46,8 @@ export type RelayTransactionData = { lookupTableAddresses?: string[] } +export type IdentityRequestError = AxiosError + type AttestationResult = { status: string userId: string From c271536fa852f5518f05e39b4ea47c18976be2dd Mon Sep 17 00:00:00 2001 From: Randy Schott <1815175+schottra@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:42:28 -0400 Subject: [PATCH 2/3] fixes --- packages/common/src/models/Analytics.ts | 2 +- packages/common/src/store/ui/stripe-modal/sagas.ts | 14 +++++++++----- packages/common/src/store/ui/stripe-modal/types.ts | 7 ++++--- packages/libs/src/AudiusLibs.ts | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/common/src/models/Analytics.ts b/packages/common/src/models/Analytics.ts index 185501d0a4f..333d566cad8 100644 --- a/packages/common/src/models/Analytics.ts +++ b/packages/common/src/models/Analytics.ts @@ -1633,7 +1633,7 @@ type StripeSessionCreationError = { amount: string destinationCurrency: string code: string - message: string + errorMessage: string type: string } diff --git a/packages/common/src/store/ui/stripe-modal/sagas.ts b/packages/common/src/store/ui/stripe-modal/sagas.ts index 3a76034817b..63168249429 100644 --- a/packages/common/src/store/ui/stripe-modal/sagas.ts +++ b/packages/common/src/store/ui/stripe-modal/sagas.ts @@ -35,10 +35,14 @@ function* handleInitializeStripeModal({ }) yield* put(stripeSessionCreated({ clientSecret: res.client_secret })) } catch (e) { - const { code, message, type } = ((e as IdentityRequestError).response - ?.data ?? {}) as StripeSessionCreationErrorResponseData + const { + code, + message: errorMessage, + type + } = ((e as IdentityRequestError).response?.data ?? + {}) as StripeSessionCreationErrorResponseData - const error = new StripeSessionCreationError(code, message, type) + const error = new StripeSessionCreationError(code, errorMessage, type) if (onrampFailed) { yield* put({ @@ -52,7 +56,7 @@ function* handleInitializeStripeModal({ error, additionalInfo: { code, - message, + errorMessage, type, amount, destinationCurrency @@ -65,7 +69,7 @@ function* handleInitializeStripeModal({ amount, code, destinationCurrency, - message, + errorMessage, type }) ) diff --git a/packages/common/src/store/ui/stripe-modal/types.ts b/packages/common/src/store/ui/stripe-modal/types.ts index ce6724d8ece..e1b06b75409 100644 --- a/packages/common/src/store/ui/stripe-modal/types.ts +++ b/packages/common/src/store/ui/stripe-modal/types.ts @@ -17,7 +17,7 @@ export type StripeModalState = { stripeClientSecret?: string } -export type StripeSessionCreationErrorResponse = { +export type StripeSessionCreationErrorResponseData = { error: string code: string message: string @@ -27,9 +27,10 @@ export type StripeSessionCreationErrorResponse = { export class StripeSessionCreationError extends Error { constructor( public code: string, - public message: string, + // Avoiding `message` to not shadow the `message` property on Error + public errorMessage: string, public type: string ) { - super(`Failed to create Stripe session: ${message}`) + super(`Failed to create Stripe session: ${errorMessage}`) } } diff --git a/packages/libs/src/AudiusLibs.ts b/packages/libs/src/AudiusLibs.ts index d6fb1b7bc31..4e56525f4c9 100644 --- a/packages/libs/src/AudiusLibs.ts +++ b/packages/libs/src/AudiusLibs.ts @@ -27,6 +27,7 @@ import { EthContracts } from './services/ethContracts' import { EthWeb3Config, EthWeb3Manager } from './services/ethWeb3Manager' import { Hedgehog, HedgehogConfig } from './services/hedgehog' import { IdentityService } from './services/identity' +import type { IdentityRequestError } from './services/identity' import { Schemas, SchemaValidator } from './services/schemaValidator' import { SolanaWeb3Manager, @@ -637,6 +638,7 @@ export class AudiusLibs { } export { AudiusABIDecoder, Utils, SolanaUtils, CreatorNode } +export { IdentityRequestError } export { SanityChecks } from './sanityChecks' export { RewardsAttester, DEFAULT_MINT, MintName } from './services/solana' From a93b5578a63b3e6b3ff431f1b594c7210a819691 Mon Sep 17 00:00:00 2001 From: Randy Schott <1815175+schottra@users.noreply.github.com> Date: Thu, 26 Oct 2023 10:55:22 -0400 Subject: [PATCH 3/3] use stripeErrorMessage for more clarity --- packages/common/src/models/Analytics.ts | 2 +- packages/common/src/store/ui/stripe-modal/sagas.ts | 8 ++++---- packages/common/src/store/ui/stripe-modal/types.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/common/src/models/Analytics.ts b/packages/common/src/models/Analytics.ts index 333d566cad8..63e766c449f 100644 --- a/packages/common/src/models/Analytics.ts +++ b/packages/common/src/models/Analytics.ts @@ -1633,7 +1633,7 @@ type StripeSessionCreationError = { amount: string destinationCurrency: string code: string - errorMessage: string + stripeErrorMessage: string type: string } diff --git a/packages/common/src/store/ui/stripe-modal/sagas.ts b/packages/common/src/store/ui/stripe-modal/sagas.ts index 63168249429..7b49da188eb 100644 --- a/packages/common/src/store/ui/stripe-modal/sagas.ts +++ b/packages/common/src/store/ui/stripe-modal/sagas.ts @@ -37,12 +37,12 @@ function* handleInitializeStripeModal({ } catch (e) { const { code, - message: errorMessage, + message: stripeErrorMessage, type } = ((e as IdentityRequestError).response?.data ?? {}) as StripeSessionCreationErrorResponseData - const error = new StripeSessionCreationError(code, errorMessage, type) + const error = new StripeSessionCreationError(code, stripeErrorMessage, type) if (onrampFailed) { yield* put({ @@ -56,7 +56,7 @@ function* handleInitializeStripeModal({ error, additionalInfo: { code, - errorMessage, + stripeErrorMessage, type, amount, destinationCurrency @@ -69,7 +69,7 @@ function* handleInitializeStripeModal({ amount, code, destinationCurrency, - errorMessage, + stripeErrorMessage, type }) ) diff --git a/packages/common/src/store/ui/stripe-modal/types.ts b/packages/common/src/store/ui/stripe-modal/types.ts index e1b06b75409..7ae390270b1 100644 --- a/packages/common/src/store/ui/stripe-modal/types.ts +++ b/packages/common/src/store/ui/stripe-modal/types.ts @@ -28,9 +28,9 @@ export class StripeSessionCreationError extends Error { constructor( public code: string, // Avoiding `message` to not shadow the `message` property on Error - public errorMessage: string, + public stripeErrorMessage: string, public type: string ) { - super(`Failed to create Stripe session: ${errorMessage}`) + super(`Failed to create Stripe session: ${stripeErrorMessage}`) } }