payrails client. The client wires them together for you: the button stays disabled until the form is valid, and clicking it validates the form, encrypts the card data, and starts the authorization.
1. Add containers to your page
2. Mount the card form
CardFormOptions:
For the full option and event list see the
payrails reference and the events reference.
3. Mount the payment button
disabledByDefault: false if you want it clickable immediately (the form is still validated on click). While the payment is in flight the button shows a loading indicator and carries the .payrails-button--loading class.
4. Handle the payment result
Payment outcomes are instance events — subscribe on thepayrails client:
success— the payment was authorized.failed— the payment failed.e.data?.codeis one of theAuthorizationFailureReasonsvalues (VALIDATION_FAILED,AUTHORIZATION_ERROR,AUTHENTICATION_ERROR,USER_CANCELLED,UNKNOWN_ERROR), importable from@payrails/web-sdk.pending— the authorization is still processing and no further shopper action is required.
e.paymentMethodCode === 'card'.
3D Secure challenges are handled by the SDK automatically; to observe or take over the challenge, subscribe to payrails.on('actionRequired', ...) - see the events reference.
5. React to form and button state (optional)
Two button-specific events help you build custom UI around the flow:cardForm.focus(). cardForm.isValid exposes the current validity synchronously.