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
| Parameter | Type | Required | Description |
|---|---|---|---|
method | PaySavedPaymentMethod | null | undefined | Yes | The 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.
| Field | Type | Description |
|---|---|---|
cvc | PaySavedCardCvc | The CVV input. Pass it to PaySavedCardCvcField, and to checkout.pay(). |
state | PaySavedCardCvcState | The 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.
| Field | Type | Description |
|---|---|---|
status | PayFieldStatus | 'empty', 'incomplete', 'invalid', or 'valid', for the card's brand. Turn on your Pay button when it's 'valid'. |
isEmpty | boolean | true while nothing is typed. |
PaySavedCardCvc
cvc is a PaySavedCardCvc:
| Member | Type | Description |
|---|---|---|
state | PaySavedCardCvcState | The current state. |
brand | string | null | The 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) => () => void | Calls listener whenever the state changes. Returns the function that stops it. |
clear() | () => void | Empties the input. |
release() | () => void | Frees 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. |
isReleased | boolean | true once the input is released. |
id | string | Opaque, 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.
| Prop | Type | Required | Description |
|---|---|---|---|
cvc | PaySavedCardCvc | Yes | The 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
- Pay with a saved payment method: List the saved methods and pay with one.
- Style the card fields: Change the input's colors, border, font, and size.
- checkout.pay(): The
'savedPaymentMethod'request, and what it rejects with.