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:
status | Other fields | Description |
|---|---|---|
'succeeded' | ids: PaymentIds | Paid, or authorized for a session created with capture: false. |
'processing' | ids: PaymentIds | The 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' | None | The customer closed the 3DS or redirect screen, or the drop-in, and the SDK found no payment. |
'failed' | error: PayError | The payment failed. Inspect error.code for the failure reason. See Error codes. |
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.
| Field | Type | Description |
|---|---|---|
sessionId | string | The session's ID. |
transaction | string | null | The charge (chrg_…) or hold (hld_…) ID, when the API returned one. |
customer | string | null | The customer's ID (cust_…), when known. |
paymentMethod | string | null | The payment method's ID, when known. |
status | string | null | The 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.
| Property | Type | Description |
|---|---|---|
code | PayErrorCode | What went wrong. See Error codes. |
message | string | A description in English, for your logs. |
fields | PayCardFieldKind[] | The invalid fields for invalid_card_input ('number', 'expiry', 'cvc', or 'name'). Empty for other codes. |
status | string | null | The status reported by the API for session_already_completed and payment_ended. |
decline | PayDecline | null | Decline details for declined. See PayDecline. |
apiError | PayApiError | null | API 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.
| Code | Description |
|---|---|
invalid_client_secret | The client_secret is empty or isn't a token. |
invalid_card_input | The card fields, or a saved card's CVV, are incomplete or invalid, and fields lists them. Nothing was sent. |
payment_in_progress | Another payment on the checkout was running, or the drop-in was already showing. Nothing was sent. |
session_expired | Pay.com no longer accepts the session's token, because it expired or was retired after the session's last attempt. |
session_already_completed | The session was already paid, or has no attempts left. Check status to determine which occurred. |
amount_changed | The 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. |
declined | The payment was declined, and decline has the details. |
payment_ended | The payment ended without being paid. status indicates why, for example expired, cancelled, canceled, or error. |
request_rejected | The API rejected the request with a 4xx that isn't a decline, and apiError has the details. |
server | The API failed with a 5xx, or timed out (HTTP 408). apiError has the details. |
network | The request didn't reach Pay.com, or the response didn't arrive. |
unexpected_response | Pay.com or the native SDK returned a response this SDK version can't read. |
unsupported | The 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_unavailable | Client-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_screen | There was no screen available to present 3DS, a redirect, or the drop-in (no foreground activity on Android, or no view controller on iOS). |
released | The 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.
| Field | Type | Description |
|---|---|---|
code | string | null | The API's code, usually card_declined. |
declineCode | string | null | The issuer's or processor's decline code, when the API sends one, for example insufficient_funds. See Error codes. |
message | string | The API's message. It isn't localized. |
maxAttemptsReached | boolean | true when this was the session's last attempt, so your server needs a new session. |
transaction | string | null | The declined charge or hold's ID, when known. |
PayApiError
PayError.apiError describes the error response the API returned.
| Field | Type | Description |
|---|---|---|
httpStatus | number | The HTTP status of the API's response. |
type | string | null | The error's category, for example invalid_request_error. |
code | string | null | A machine-readable code, for example transaction_in_flight. |
message | string | The API's message. It isn't localized, so don't show it to customers as is. |
declineCode | string | null | A 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.
| Type | Described in |
|---|---|
PayCheckoutConfiguration, PayEnvironment, PaySession | Start a checkout |
PayPaymentMethod | List payment methods |
PayPaymentRequest | Pay |
PaySavedPaymentMethod | Let customers choose a payout method |
PayCardFieldsState, PayFieldStatus, PayCardBrand, PayCardFieldProps | Card fields |
PaySavedCardCvcState, PaySavedCardCvcFieldProps | Saved card CVV |
PayFieldStyle | Style the card fields |
PayDropInOptions | Present the drop-in |
PayApplePayOptions, PayGooglePayOptions | Pay with Apple Pay or Google Pay |
PayDropInAppearance, PayDropInColors, PayDropInPrimaryButton | Style the drop-in |
PayDropInStrings | Change the drop-in's text |
PayResult, PaymentIds, PayErrorCode, PayDecline, PayApiError, PayCardFieldKind | This page |
Next steps
- checkout.pay(): Pay from your own screen, and what it rejects with.
- checkout.presentDropIn(): Pay in the drop-in, and what it rejects with.
- Retrieve a payment session: Confirm a payment on your server.