Gets current form state.
Useful, e.g. for submitting, when you don't want to keep a copy of the form state and use the component as the only source of truth instead.
Disables card form and begins payment.
If the payment process ends successfully, resolves the promise with EmbedPayResult.
Otherwise, if the process fails, the promise is rejected with EmbedError. It is essential to catch and handle any possible rejections.
Finally, if a 3DS challenge is required, the promise is never resolved nor rejected, instead, the user is redirected to the bank to authorize the payment. Afterwards, Paytool moves the user back to one of the redirectUrls (E.g. from the merchant's config) based on the result.
Simplified example:
/* once the form is valid */
const { token } = await cardForm.getFormState();
const transactionId = await getTransactionIdFromYourServer(token);
try {
const res = await cardForm.pay(transactionId);
console.log("Transaction complete, status:", res.status);
} catch (err) {
if (!Paytool.isEmbedError(err)) throw err;
console.log("Transaction failed with status:", err.status);
}
Tips:
CardFormEmbed is a web component that uses shadow DOM and iframes to properly encapsulate its styles and logic to keep the user safe and prevent CSS conflicts.
It displays the necessary text fields for the user to fill out to pay with the specified card. To initiate the payment after the user has entered the information, use the pay method.
It also extends
HTMLElement
, providing a familiar API for some custom needs, in addition to the API described on this page.Styling
You can make use of the component's selector
verestro-paytool-card-form-embed
to style it based on your needs.Keep in mind, that since we are working with iframes, the component won't be fully rendered immediately after it's attached to the DOM tree, therefore adding things like e.g.
padding
,border
ormargin
might create an empty space for a split second. This is also the main reason why embedCardForm returns a promise. To mitigate this issue, the component sets theinitialized
class once it's fully rendered.For most basic styles it's recommended to always use the
initialized
class in your CSS selectors, e.g.Events
Available custom event types:
statechange
, equivalent to CardFormEmbedOptions.onFormStateChangecardnumberchange
, equivalent to CardFormEmbedOptions.onCardNumberChangesubmit
, equivalent to CardFormEmbedOptions.onSubmitembedCardForm already allows you to set up event listeners, but if for some reason you don't want to set them up immediately or your framework makes it unnecessarily hard to do, you can use the standard
addEventListener
method instead, e.g.:All the data you would normally receive from the callback functions of CardFormEmbedOptions is available under the
CustomEvent.detail
property.