Skip to Content
Docs

Types

The payment result, PayError and its codes, and where to find every other type the React Native SDK exports.

@pay-com/react-native is written in TypeScript and exports the types its methods take and return. Several methods share PayResult and PayError (along with its error codes). Every other type is described with the method that uses it. See Every exported type.

import { PayError, type PayResult } from '@pay-com/react-native'

PayResult

checkout.pay() and checkout.presentDropIn() resolve with a PayResult, which reflects only client-side state. Check status to determine the payment outcome:

statusOther fieldsDescription
'succeeded'ids: PaymentIdsPaid, or authorized for a session created with capture: false.
'processing'ids: PaymentIdsThe SDK didn't get a final outcome, because the method is still pending, the status check reached its deadline, or the session's token was retired before the result could be read. Your server confirms the outcome.
'canceled'NoneThe customer closed the 3DS or redirect screen, or the drop-in, and the SDK found no payment.
'failed'error: PayErrorThe payment failed. Inspect error.code for the failure reason. See Error codes.

A PayResult is a hint for your UI, never the source of truth. Before you fulfill an order, your server retrieves the session with Retrieve a payment session, or receives the signed payment_session.completed webhook. For a setup session, it uses Retrieve a setup session or the setup_session.completed webhook. Your server looks the session up by the ID it stored when it created the session.

switch (result.status) {
  case 'succeeded':
  case 'processing':
    showReceipt(result.ids) // your server confirms the payment before you fulfill the order
    break
  case 'canceled':
    break
  case 'failed':
    showError(result.error.code)
    break
}

PaymentIds

PaymentIds holds the payment's identifiers, for your server to check.

FieldTypeDescription
sessionIdstringThe session's ID.
transactionstring | nullThe charge (chrg_…) or hold (hld_…) ID, when the API returned one.
customerstring | nullThe customer's ID (cust_…), when known.
paymentMethodstring | nullThe payment method's ID, when known.
statusstring | nullThe raw status the API reported, for example succeeded, requires_capture, or pending.

PayError

PayError is the SDK's error class. It extends Error, its name is 'PayError', and its code indicates what went wrong. A method rejects with a PayError when a call fails before sending a request, and a 'failed' result carries one as error. Its message is in English and isn't meant for customers. Show your own text, chosen by code.

PropertyTypeDescription
codePayErrorCodeWhat went wrong. See Error codes.
messagestringA description in English, for your logs.
fieldsPayCardFieldKind[]The invalid fields for invalid_card_input ('number', 'expiry', 'cvc', or 'name'). Empty for other codes.
statusstring | nullThe status reported by the API for session_already_completed and payment_ended.
declinePayDecline | nullDecline details for declined. See PayDecline.
apiErrorPayApiError | nullAPI error details for request_rejected and server. See PayApiError.

Tell it apart from other errors with instanceof:

try {
  handleResult(await checkout.pay({ type: 'card', card: fields }))
} catch (error) {
  if (error instanceof PayError && error.code === 'invalid_card_input') {
    highlight(error.fields) // for example ['expiry', 'cvc']
  }
}

A method called with arguments of the wrong type rejects with a TypeError instead, not a PayError. Each method's page lists when.

Error codes

PayErrorCode is one of these. The page of each method lists the ones it rejects with.

CodeDescription
invalid_client_secretThe client_secret is empty or isn't a token.
invalid_card_inputThe card fields, or a saved card's CVV, are incomplete or invalid, and fields lists them. Nothing was sent.
payment_in_progressAnother payment on the checkout was running, or the drop-in was already showing. Nothing was sent.
session_expiredPay.com no longer accepts the session's token, because it expired or was retired after the session's last attempt.
session_already_completedThe session was already paid, or has no attempts left. Check status to determine which occurred.
amount_changedThe session's total changed, so this payment wasn't charged. checkout.session has the new amount and currency. Show them, then let the customer pay again. See When the amount changes.
declinedThe payment was declined, and decline has the details.
payment_endedThe payment ended without being paid. status indicates why, for example expired, cancelled, canceled, or error.
request_rejectedThe API rejected the request with a 4xx that isn't a decline, and apiError has the details.
serverThe API failed with a 5xx, or timed out (HTTP 408). apiError has the details.
networkThe request didn't reach Pay.com, or the response didn't arrive.
unexpected_responsePay.com or the native SDK returned a response this SDK version can't read.
unsupportedThe flow requires something the SDK can't do, such as a saved method not in checkout.savedPaymentMethods(), a configuration rejected by the native SDK, or a drop-in with no available methods.
encryption_unavailableClient-side encryption is on, but the card couldn't be encrypted. The SDK never falls back to sending the raw card fields. Nothing was sent, and the payment comes back as a 'failed' result.
no_screenThere was no screen available to present 3DS, a redirect, or the drop-in (no foreground activity on Android, or no view controller on iOS).
releasedThe checkout, the card fields, or a saved card's CVV were released, or belong to an earlier run of the app.

PayDecline

PayError.decline has the details of a decline.

FieldTypeDescription
codestring | nullThe API's code, usually card_declined.
declineCodestring | nullThe issuer's or processor's decline code, when the API sends one, for example insufficient_funds. See Error codes.
messagestringThe API's message. It isn't localized.
maxAttemptsReachedbooleantrue when this was the session's last attempt, so your server needs a new session.
transactionstring | nullThe declined charge or hold's ID, when known.

PayApiError

PayError.apiError describes the error response the API returned.

FieldTypeDescription
httpStatusnumberThe HTTP status of the API's response.
typestring | nullThe error's category, for example invalid_request_error.
codestring | nullA machine-readable code, for example transaction_in_flight.
messagestringThe API's message. It isn't localized, so don't show it to customers as is.
declineCodestring | nullA finer reason, for example cse_expired for a rejected encrypted card.

PayCardFieldKind

PayCardFieldKind is 'number' | 'expiry' | 'cvc' | 'name'. Each value is one of the card inputs, as PayError.fields names them.

Every exported type

Each exported type is described on one page, usually the page of the method that uses it.

TypeDescribed in
PayCheckoutConfiguration, PayEnvironment, PaySessionStart a checkout
PayPaymentMethodList payment methods
PayPaymentRequestPay
PaySavedPaymentMethodLet customers choose a payout method
PayCardFieldsState, PayFieldStatus, PayCardBrand, PayCardFieldPropsCard fields
PaySavedCardCvcState, PaySavedCardCvcFieldPropsSaved card CVV
PayFieldStyleStyle the card fields
PayDropInOptionsPresent the drop-in
PayApplePayOptions, PayGooglePayOptionsPay with Apple Pay or Google Pay
PayDropInAppearance, PayDropInColors, PayDropInPrimaryButtonStyle the drop-in
PayDropInStringsChange the drop-in's text
PayResult, PaymentIds, PayErrorCode, PayDecline, PayApiError, PayCardFieldKindThis page

Next steps

Was this page helpful?