Common interface for all vault SDK adapters.
Methods
on()
on<K>(event, callback): void;
Registers an event listener for the specified event.
Type Parameters
Parameters
| Parameter | Type |
|---|
event | K |
callback | (data) => void |
Returns
void
Properties
destroy()
Destroys the SDK instance and removes all event listeners.
This is terminal; the instance cannot be used after this call.
Returns
void
getCardInfo()
getCardInfo: () => Promise<CardInfo | null>;
Gets card information such as BIN, detected brands, and last four digits.
Returns
Promise<CardInfo | null>
Card info or Null if the form is not complete enough.
Example
const info = await hostedFields.getCardInfo();
if (info) {
console.log(info.bin);
console.log(info.detected_brands);
console.log(info.last_four_digit);
}
render()
Renders the fields in the targets specified in the config.
Returns
void
Throws
SecureFieldsErrors.FIELD_RENDER_FAILED If the target element for the field is not found.
Throws
SecureFieldsErrors.INSTANCE_DESTROYED If the instance has been destroyed.
See
SecureFieldsErrors
submit()
submit: (payload?) => Promise<SubmitResult>;
Triggers validation and tokenization of the form.
Parameters
| Parameter | Type | Description |
|---|
payload? | SubmitOptions | SubmitOptions- This param is not passed when tokenizing a cvv, otherwise this payload contains the expiry month, expiry year, cardholder name, and selected network. |
Returns
Promise<SubmitResult>
Throws
SecureFieldsErrors.TOKENIZATION_FAILED If the form is invalid or if there is an error during the process.
Throws
SecureFieldsErrors.INVALID_FORM If the form is not valid.
Example
const result = await hostedFields.submit({
expiryMonth: 12;
expiryYear: 25;
cardHolderName: 'Joe Dawn';
selectedNetwork: 'VISA';
saveToken: false;
});
See
SecureFieldsErrors
Events
success Emitted when the form is successfully tokenized.
error Emitted when there is an error during the tokenization process.