Skip to Content
Docs

Start a checkout

Check a session's client_secret, load the session from Pay.com, and get the checkout that pays it.

PayCheckout.create() checks the client_secret of a session your server created, loads the session from Pay.com, and resolves with a PayCheckout for it. Call it first. The checkout then lists the session's methods with checkout.paymentMethods(), shows the drop-in with checkout.presentDropIn(), or pays with checkout.pay(). One checkout pays one session. Release it when you're done with it.

Your server creates the session with Create a payment session, or with Create a setup session to save a payment method without paying. It sets the session's return_url to the app's returnUrl, and sends only the session's client_secret to the app, never your API key.

const checkout = await PayCheckout.create(clientSecret, { returnUrl: 'myshop://pay' })

Parameters

ParameterTypeRequiredDescription
clientSecretstringYesThe session's client_secret, from your server.
configurationPayCheckoutConfigurationYesHow the checkout runs.
configuration.returnUrlstringYesThe URL where redirect payment methods return to the app (a custom scheme such as myshop://pay, a universal link on iOS, or an App Link on Android). Create the session with return_url set to the same URL, and set up a deep link for it.
configuration.environmentPayEnvironmentNoThe Pay.com environment the SDK connects to. Keep the default, 'production', for both live and sandbox sessions. See Environments.
configuration.challengeTimeoutSecondsnumberNoHow long the 3DS challenge screen may stay open, in seconds, before the SDK reads the outcome from the payment's status instead. Default: 600.
configuration.threeDSAppReturnModebooleanNoAsks the 3DS challenge to end with a redirect to returnUrl. Default: false.
configuration.clientSideEncryptionbooleanNoEncrypts the card on the device and sends it encrypted, instead of the raw card fields. Leave it off until Pay.com turns on client-side encryption for your account. With it on, a card the SDK can't encrypt fails with encryption_unavailable. The SDK never falls back to sending the raw fields. Default: false.

Environments

PayEnvironment is 'production', 'development', or { apiBaseUrl, scaBaseUrl }. Use 'production', the default, for both live and sandbox sessions.

The other two are for other deployments. In { apiBaseUrl, scaBaseUrl }, apiBaseUrl is the prefix of the client API's paths and scaBaseUrl serves 3DS. Both must be http or https URLs with a host.

Returns

PayCheckout.create() returns a promise that resolves with a PayCheckout:

MemberTypeDescription
sessionPaySessionThe session the checkout pays. See The session.
acceptedCardBrandsreadonly string[]The card brands the session accepts. See Accepted card brands.
paymentMethods()() => PayPaymentMethod[]Lists the methods the session accepts. See List payment methods.
savedPaymentMethods()() => PaySavedPaymentMethod[]Lists the customer's saved methods the session can use. See Let customers choose a payout method and Pay with a saved payment method.
pay(request)(request: PayPaymentRequest) => Promise<PayResult>Pays from your own screen. See Pay.
presentDropIn(options)(options?: PayDropInOptions) => Promise<PayResult>Shows the drop-in. See Present the drop-in.
release()() => voidFrees the native checkout. See Release a checkout.

PayCheckout also has a static PayCheckout.handleReturn(). Its constructor is private, so PayCheckout.create() is the only way to get one.

The session

checkout.session is a PaySession:

FieldTypeDescription
idstringThe session's ID.
kind'sale' | 'authorization' | 'setup' | 'unknown''sale' charges now. 'authorization' authorizes now, for your server to capture later. 'setup' saves a payment method without paying. 'unknown' is a flow the SDK doesn't recognize. It may charge, so its total is checked as a sale's is.
amountstring | nullThe amount in major units, as the client API sends it, for example "10.00". Your server created the session in minor units (1000). pay() and presentDropIn() update it when they find the total changed.
currencystring | nullThe ISO 4217 alpha-3 currency code.
isLivebooleanWhether the session is live.
expiresAtnumber | nullWhen the client_secret stops working, in milliseconds since the epoch, as for new Date(expiresAt).
setupFutureUsagestring | null'on_session' or 'off_session' when the session saves the card whatever the customer picks.
isRecurringbooleantrue for a recurring session, which always keeps the card for later charges.
isPayoutbooleantrue for a setup session your server created with payout: true, where a recipient chooses where their payouts go. See Let customers choose a payout method.

Errors

PayCheckout.create() rejects with a PayError when it can't start the checkout:

Error codeWhen
invalid_client_secretThe client_secret is empty or isn't a token.
session_expiredPay.com no longer accepts the session's token, because the session expired or its last attempt retired it. Your server needs a new session.
request_rejectedThe API rejected the request. error.apiError has the details.
serverThe API failed with a 5xx, or returned a 408.
networkThe request didn't reach Pay.com, or the response didn't arrive.
unsupportedThe native SDK rejected the configuration, for example a returnUrl without a scheme, or an environment whose URLs aren't http or https URLs with a host.
unexpected_responsePay.com or the native SDK returned a response this SDK version can't read.

PayCheckout.create() rejects with a TypeError instead, before anything is sent, when the configuration has an invalid type, such as a returnUrl that isn't a non-empty string, an environment that isn't 'production', 'development', or { apiBaseUrl, scaBaseUrl }, or a challengeTimeoutSeconds that isn't a positive number.

Example

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

export async function startCheckout(orderId: string): Promise<PayCheckout | null> {
  // Your own server creates the session, with return_url myshop://pay,
  // and returns only its client_secret.
  const clientSecret = await fetchClientSecret(orderId)

  try {
    const checkout = await PayCheckout.create(clientSecret, { returnUrl: 'myshop://pay' })
    console.log(checkout.session.kind, checkout.session.amount) // 'sale' '10.00'
    return checkout // release it once the customer is done
  } catch (error) {
    if (error instanceof PayError && error.code === 'session_expired') {
      return null // this session can't be paid: ask your server for a new one
    }
    throw error
  }
}

Next steps

Was this page helpful?