LCOV - code coverage report
Current view: top level - packages/account-core/src/core/billing - paymentCopy.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 0.0 % 8 0
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : /**
       2              :  * The copy keys behind the payment projection, with a default English table
       3              :  * a host may override — except the safety line, which only the projection's
       4              :  * `noChargeConfirmed` may ever unlock.
       5              :  */
       6              : import type {
       7              :   BillingDeclineReason,
       8              :   BillingRecoveryAction
       9              : } from './operationState'
      10              : import type {
      11              :   PaymentProjection,
      12              :   PaymentReasonKey,
      13              :   PaymentStep
      14              : } from './paymentProjection'
      15              : 
      16              : export type PaymentCopyKey =
      17              :   | `billing.step.${PaymentStep}.header`
      18              :   | `billing.step.${PaymentStep}.body`
      19              :   | `billing.reason.${PaymentReasonKey}`
      20              :   | `billing.recovery.${BillingRecoveryAction}`
      21              :   | 'billing.action.retry'
      22              :   | 'billing.action.replace_payment_method'
      23              :   | 'billing.action.contact_support'
      24              :   | 'billing.action.continue_verification'
      25              :   | 'billing.safety.nothing_was_charged'
      26              : 
      27              : const SAFETY_KEY = 'billing.safety.nothing_was_charged'
      28              : 
      29              : export const DEFAULT_PAYMENT_COPY: Readonly<Record<PaymentCopyKey, string>> = {
      30              :   'billing.step.select.header': 'Choose an option',
      31              :   'billing.step.select.body': 'Select a plan or credit amount.',
      32              :   'billing.step.preview.header': 'Review payment',
      33              :   'billing.step.preview.body': 'Confirm your selection.',
      34              :   'billing.step.verifying.header': 'Verify your payment',
      35              :   'billing.step.verifying.body': 'Complete verification to continue.',
      36              :   'billing.step.canceled.header': 'Payment canceled',
      37              :   'billing.step.canceled.body': 'The payment was canceled.',
      38              :   'billing.step.declined.header': 'Payment declined',
      39              :   'billing.step.declined.body': 'Try another payment method.',
      40              :   'billing.step.processing_error.header': 'Payment could not be processed',
      41              :   'billing.step.processing_error.body': 'Please try again.',
      42              :   'billing.step.payment_received_hold.header': 'Payment received',
      43              :   'billing.step.payment_received_hold.body':
      44              :     'We are finishing your account update.',
      45              :   'billing.step.success.header': 'Payment complete',
      46              :   'billing.step.success.body': 'Your account is updated.',
      47              :   'billing.reason.generic': 'Something went wrong.',
      48              :   'billing.reason.checkout_expired':
      49              :     'This checkout expired. Start again when you are ready.',
      50              :   'billing.reason.card_declined': 'Your bank declined the payment.',
      51              :   'billing.reason.insufficient_funds': 'Your bank reported insufficient funds.',
      52              :   'billing.reason.expired_card': 'This card has expired.',
      53              :   'billing.reason.incorrect_cvc': 'The security code did not match.',
      54              :   'billing.reason.authentication_required':
      55              :     'Your bank requires authentication.',
      56              :   'billing.reason.authentication_failed':
      57              :     'Authentication with your bank did not complete.',
      58              :   'billing.reason.payment_not_completed': 'The payment was not completed.',
      59              :   'billing.reason.processing_error':
      60              :     'The payment could not be processed right now.',
      61              :   'billing.recovery.retry': 'Please try again.',
      62              :   'billing.recovery.replace_payment_method':
      63              :     'Try again with a different payment method.',
      64              :   'billing.recovery.authenticate_payment':
      65              :     'Try again and complete the verification your bank asks for.',
      66              :   'billing.recovery.contact_support':
      67              :     'This payment cannot be retried. Contact support@comfy.org and we will help you finish it.',
      68              :   'billing.action.retry': 'Try again',
      69              :   'billing.action.replace_payment_method': 'Use a different payment method',
      70              :   'billing.action.contact_support': 'Contact support',
      71              :   'billing.action.continue_verification': 'Continue verification',
      72              :   [SAFETY_KEY]: 'Nothing was charged.'
      73              : }
      74              : 
      75              : /** The host's toast detail for a payment the server declined. */
      76              : export type DeclineDetailKey =
      77              :   | 'insufficientFundsDetail'
      78              :   | 'expiredCardDetail'
      79              :   | 'incorrectCvcDetail'
      80              :   | 'authenticationFailedDetail'
      81              :   | 'processingErrorDetail'
      82              :   | 'paymentDeclinedDetail'
      83              : 
      84            0 : export function declineDetailKey(
      85              :   reason: BillingDeclineReason
      86              : ): DeclineDetailKey {
      87            0 :   switch (reason) {
      88              :     case 'insufficient_funds':
      89            0 :       return 'insufficientFundsDetail'
      90              :     case 'expired_card':
      91            0 :       return 'expiredCardDetail'
      92              :     case 'incorrect_cvc':
      93            0 :       return 'incorrectCvcDetail'
      94              :     case 'authentication_required':
      95              :     case 'authentication_failed':
      96              :     case 'payment_not_completed':
      97            0 :       return 'authenticationFailedDetail'
      98              :     case 'processing_error':
      99            0 :       return 'processingErrorDetail'
     100              :     case 'card_declined':
     101              :     case 'generic':
     102            0 :       return 'paymentDeclinedDetail'
     103              :   }
     104              : }
     105              : 
     106              : export function createPaymentCopy(
     107              :   overrides: Partial<Record<PaymentCopyKey, string>> = {}
     108              : ): Readonly<Record<PaymentCopyKey, string>> {
     109              :   const { [SAFETY_KEY]: _protected, ...safe } = overrides
     110              :   return { ...DEFAULT_PAYMENT_COPY, ...safe }
     111              : }
     112              : 
     113              : export interface PaymentCopyKeys {
     114              :   readonly header: PaymentCopyKey
     115              :   /** The server's recovery line when it names one, else the step's own body. */
     116              :   readonly body: PaymentCopyKey
     117              :   readonly reason?: PaymentCopyKey
     118              :   readonly safety?: typeof SAFETY_KEY
     119              : }
     120              : 
     121              : function recoveryCopyKey(
     122              :   action: BillingRecoveryAction | undefined
     123              : ): PaymentCopyKey | undefined {
     124              :   if (action === undefined) return undefined
     125              :   const key = `billing.recovery.${action}` as const
     126              :   return key in DEFAULT_PAYMENT_COPY ? key : undefined
     127              : }
     128              : 
     129              : export function paymentCopyKeys(
     130              :   projection: PaymentProjection
     131              : ): PaymentCopyKeys {
     132              :   return {
     133              :     header: `billing.step.${projection.step}.header`,
     134              :     body:
     135              :       recoveryCopyKey(projection.recoveryAction) ??
     136              :       `billing.step.${projection.step}.body`,
     137              :     ...(projection.reasonKey === undefined
     138              :       ? {}
     139              :       : { reason: `billing.reason.${projection.reasonKey}` as const }),
     140              :     ...(projection.step === 'canceled' && projection.noChargeConfirmed
     141              :       ? { safety: SAFETY_KEY }
     142              :       : {})
     143              :   }
     144              : }
        

Generated by: LCOV version 2.0-1