@bates-solutions/squareup API Reference - v3.2.0
    Preparing search index...

    Function declineReason

    • Classify a failed charge: Square's decline code and whether charging the same card again later can succeed.

      Returns undefined when error is not a card decline (not a SquarePaymentError, and no PAYMENT_METHOD_ERROR entry on a SquareApiError), and for Square's TEMPORARY_ERROR, which is a transient failure rather than a decline. Unknown codes are not retryable.

      Code retryable
      INSUFFICIENT_FUNDS true, after a few days
      TRANSACTION_LIMIT true, later
      GENERIC_DECLINE, CVV_FAILURE, CARD_EXPIRED, INVALID_ACCOUNT, ... false
      any other code false

      This is about the card. Network failures, 5xx responses and Square's TEMPORARY_ERROR are a separate question: see isRetryableSquareError, and retry those with the same idempotency key.

      Parameters

      • error: unknown

      Returns DeclineReason | undefined

      try {
      await square.payments.create({ sourceId: cardId, customerId, amount, idempotencyKey });
      } catch (error) {
      const decline = declineReason(error);
      if (decline?.retryable) {
      await scheduleRetry(subscriptionId, { inDays: 3, reason: decline.code });
      } else if (decline) {
      await askForNewCard(customerId, decline.code);
      } else {
      throw error;
      }
      }