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 the card form and begins payment.
Simplified example using getFormState
:
/* once the form is valid */
const { token, paymentMethodData } = await cardForm.getFormState();
let transactionId;
// Prefer using `paymentMethodData`; `token` is deprecated and will be removed.
if (paymentMethodData) {
transactionId = await initTransactionInYourServer(paymentMethodData);
} else {
transactionId = await initTransactionInYourServer(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 and their payloads (
event.detail
):statechange
— same as CardFormEmbedOptions.onFormStateChange. Fires when the form validation changes.cardnumberchange
— same as CardFormEmbedOptions.onCardNumberChangepaymentMethods
:{ token: string | null }
— Deprecated and will be removed in a future release.paymentMethods
:CardNumberInfo
— covers both typing a new card and selecting a saved card. Prefer supplyingpaymentMethods
and rely on CardFormEmbedState.cardNumberInfo / CardFormEmbedState.paymentMethodData.submit
— same as 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.