Skip to Content
Docs

Saved card CVV

Show an SDK-owned input for a saved card's CVV, follow its validation state, and pay the saved card with it.

usePaySavedCardCvc() gives the calling component an input for a saved card's CVV, for paying with a saved card whose requiresCvc is true. Render PaySavedCardCvcField with its cvc, then pay with { type: 'savedPaymentMethod', id: method.id, cvc } in checkout.pay().

Like the card fields, the input is the native SDKs' own. The CVV stays in native code and goes from there to Pay.com's vault, so it never reaches JavaScript. JavaScript sees only the input's validation state.

const { cvc, state } = usePaySavedCardCvc(method)

return <PaySavedCardCvcField cvc={cvc} placeholder="CVV" />

Parameters

ParameterTypeRequiredDescription
methodPaySavedPaymentMethod | null | undefinedYesThe saved method the customer chose, from checkout.savedPaymentMethods(), or null while none is chosen. The input expects the length for its card's brand (4 digits for American Express, 3 for other brands). When the customer chooses another method, the input is emptied.

Returns

usePaySavedCardCvc() returns the input and its validation state.

FieldTypeDescription
cvcPaySavedCardCvcThe CVV input. Pass it to PaySavedCardCvcField, and to checkout.pay().
statePaySavedCardCvcStateThe input's validation state. The component renders again whenever it changes.

The hook releases the input when the component unmounts.

PaySavedCardCvcState

state indicates whether the entered CVV is valid for the card's brand.

FieldTypeDescription
statusPayFieldStatus'empty', 'incomplete', 'invalid', or 'valid', for the card's brand. Turn on your Pay button when it's 'valid'.
isEmptybooleantrue while nothing is typed.

PaySavedCardCvc

cvc is a PaySavedCardCvc:

MemberTypeDescription
statePaySavedCardCvcStateThe current state.
brandstring | nullThe card's brand as the API names it, for example visa or american_express. It sets the length the input expects. usePaySavedCardCvc() sets it from the method's card.brand.
subscribe(listener)(listener: (state: PaySavedCardCvcState) => void) => () => voidCalls listener whenever the state changes. Returns the function that stops it.
clear()() => voidEmpties the input.
release()() => voidFrees the native input, and a PaySavedCardCvcField showing it goes blank. It's safe to call more than once. usePaySavedCardCvc() calls it when the component unmounts.
isReleasedbooleantrue once the input is released.
idstringOpaque, process-scoped identifier for the native input view.

Outside a component, create one with new PaySavedCardCvc(brand), with the card's brand or null. It lives until you call its release().

Props

PaySavedCardCvcField shows the input. Its props, PaySavedCardCvcFieldProps, are the card fields' props with cvc instead of fields.

PropTypeRequiredDescription
cvcPaySavedCardCvcYesThe input to show, from usePaySavedCardCvc().

Its other props are placeholder, enabled, onFocusChange, fieldStyle, and style, as for the card fields, and the other View props except children. To change how the input looks, see Style the card fields.

On iOS, the input is a single native view, so show it in one place at a time.

Example

An empty input sends nothing, so you can pass cvc for a card that doesn't need it.

import { Button, Text, View } from 'react-native'
import {
  PaySavedCardCvcField,
  usePaySavedCardCvc,
  type PaySavedCardCvc,
  type PaySavedPaymentMethod,
} from '@pay-com/react-native'

export function SavedCardCvc({
  method,
  onPay,
}: {
  method: PaySavedPaymentMethod
  onPay: (cvc: PaySavedCardCvc) => void
}) {
  const { cvc, state } = usePaySavedCardCvc(method)

  if (!method.requiresCvc) return <Button title="Pay" onPress={() => onPay(cvc)} />

  return (
    <View>
      <PaySavedCardCvcField cvc={cvc} placeholder="CVV" />
      {state.status === 'invalid' ? <Text>Check the CVV.</Text> : null}
      <Button title="Pay" disabled={state.status !== 'valid'} onPress={() => onPay(cvc)} />
    </View>
  )
}

Next steps

Was this page helpful?