callCash()by riverrr
Get early access
Open as .md

Errors

Every failure is a CallCashError:

TypeScript
import { isCallCashError } from "callcash";

try {
  await cash.payments.create({ amount, reference });
} catch (e) {
  if (isCallCashError(e)) {
    e.code;       // "amount_invalid"
    e.status;     // 422
    e.message;    // says what went wrong and what to do
    e.retryable;  // true when nothing was charged and trying again is safe
  }
  throw e;
}

Retry only when retryable is true. Messages are written for developers; show your customers your own words.

Codes#

CodeStatusRetryWhenWhat to do
amount_invalid422Noamount is not rand above 0 with at most two decimals, or is over R9,999,999.99Send rand, like 250 or 99.50. If you store cents, divide by 100.
reference_invalid422Noreference is empty or longer than 100 charactersUse your own order number.
reference_used409NoThe reference was already paid, or is open for a different amountUse a new reference, or read the existing payment.
gateway_down503YesA gateway did not answer: network error, a 15 second timeout, a 5xx or 429, or Netcash's status check failedRetry. Routing already tried your backup gateway. In a webhook, the 503 makes the gateway retry.
gateway_rejected502NoYoco refused to open a checkout or a refundRead the message, which includes Yoco's answer. The payment is left failed.
signature_invalid400NoA Yoco event's signature did not match, it was over three minutes old, or it was not JSONCheck webhookSecret is the secret for this webhook. Check your server clock.
not_found404NoThere is no payment with that idCheck the id.
refund_invalid400NoThe payment is not paid, is fully refunded, or you asked for more than is leftRefund only what is left.
refund_unsupported400NoNetcash payments, or Yoco payments made with test keysNetcash: refund in the portal, then recordRefund().
config_invalid500NoThe setup is wrong: see belowFix the config.
api_errorvariesWhen 5xxThe hosted API (planned) answered without a code; also the body of a webhook response when the request could not be read or the store failedRetry when the status is 5xx.
gateway_limit402NoDeclared for a gateway's transaction limit. Not thrown by version 0.1.0.Netcash's R100 limit shows as a missing card option, not an error. See Netcash.

config_invalid, in detail#

  • Real gateways without a store.
  • Both key and gateways given.
  • A gateway named in routes or gateway that is not in gateways.
  • An empty Yoco secretKey or Netcash serviceKey.
  • A Yoco payment with no returnUrl or return_url.
  • A Yoco event arriving with no webhookSecret configured.
  • cash.test.pay() on a payment that is not on the test gateway.
  • A cc_ key that does not start with cc_test_ or cc_live_.
  • Calling a hosted-only method (webhooks.delete) without a key, or a direct-only method (webhooks.handle, recordRefund, events.deliver, test.*) with one.

handler_failed#

Not a thrown error. It is the code in the 500 response webhooks.handle gives the gateway when your handler throws. The event stays owed and is delivered again.