payrails client instance. If you haven’t, start with the quick start.
The form renders inside a Payrails-hosted iframe, so the shopper’s details are never part of your page’s DOM. The fields come from the payment method’s configuration, so you don’t declare them yourself.
Supported payment methods
Pass the code as
paymentMethodCode. The result type determines which events fire after the shopper clicks the pay button, as described in Handle the payment result.
Before you start
- Use
@payrails/web-sdk6.6.0 or later. - Ask your Payrails account manager to enable the payment method for in-page collection. Until they do,
payrails.apmForm()throws aPayrailsErrorbecause the session has no form for that method. - For SEPA Direct Debit, send the shopper’s IP address, user agent and email when you create the execution, in
meta.clientContext.ipAddress,meta.clientContext.userAgentandmeta.customer.email. Payrails rejects the payment without them.
1. Add containers to your page
2. Mount the form
form.mount() returns a promise. It rejects when the selector doesn’t match an element, or when the SDK can’t draw the form. In the second case, the error’s context.reason is 'unrenderable-schema'. Use it to offer the shopper another way to pay.
3. Mount the pay button
validate with isValid: false, and the SDK doesn’t submit the payment:
buttonClicked and requestStart instance events run after the form validates, the same as for card payments. A check you already run there also covers these methods.
4. Handle the payment result
Outcomes are instance events, so subscribe on thepayrails client:
e.paymentMethodCode.
Which events fire depends on the method’s result type in the supported payment methods table:
Approve-in-app methods
The shopper approves the payment in another app, such as their MB WAY app. The SDK handles the wait for you: the form switches to a screen with the payment method’s logo and instructions, the SDK removes the button, and then waits for the shopper to approve. When they do, the wait screen goes away andsuccess fires. Show your own confirmation.
Pending methods
The payment completes after checkout, so the SDK doesn’t have the result yet when the shopper clicks. Treatpending as “order placed” and rely on your webhook for the final status.
5. Handle a declined or expired approve-in-app payment
If the shopper declines in the app, or doesn’t approve in time, the wait screen switches back to the form. The form keeps the shopper’s details, and the button reappears. The SDK then firessessionExpired, followed by failed with AUTHORIZATION_ERROR. Return fresh init options from sessionExpired so the shopper’s retry starts a new payment:
failed carries AUTHENTICATION_ERROR or UNKNOWN_ERROR. The shopper may still approve in their app afterwards, so check the payment’s status before you let them retry, or they could pay twice:
6. Customize the form and button
The form and the button each take their ownappearance. Form rules cross into the iframe and apply to the .payrails-* classes, and rules under actionScreen style only the wait screen of an approve-in-app method:
translations.errors replaces the form’s default error messages. The appearance reference lists every class.
Offer more than one method
Create a form and button pair per method, each in its own containers. Element ids default to one per payment method, so two methods on the same page don’t collide. Passid only if you mount two forms for the same method.
payrails reference and the events reference.