Destroys the component, cleanly unmounting it from the DOM.
Disables card form, grays out its fields and prevents the user from changing the data.
Has no effect if the form is already disabled.
Enables card form.
Has no effect if the form is already enabled.
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 { paymentMethodData } = await cardForm.getFormState();
let transactionId = await initTransactionInYourServer(paymentMethodData);
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:
Notifies the embedded card form iframe about the outcome of a saved card removal. Call this after handling CardFormEmbedOptions.onRemoveSavedCard in your application.
The stored payment method id that was requested to be removed.
Whether the removal succeeded.
OptionalerrorMessage: stringOptional custom error text. If omitted and removal failed.
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-embedto 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,borderormarginmight 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 theinitializedclass once it's fully rendered.For most basic styles it's recommended to always use the
initializedclass 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 supplyingpaymentMethodsand 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
addEventListenermethod instead, e.g.:All the data you would normally receive from the callback functions of CardFormEmbedOptions is available under the
CustomEvent.detailproperty.