Focus cvv hosted field
This method asynchronously focus cvv field, otherwise it will throw an exception
// Basic example
try {
await cardSubscription.focus();
// On Success, can focus field
} catch (error: any) {
// On Error, catch response, ex. {code:"E010", message: "Error al realizar focus en el campo"}
console.error("Catch error on focus field", error.code, error.message);
}
This function returns an FormValidity that represents the validation state of cvv field
FormValidity object with validation info of cvv field
Get field validity of cvv field
const event: FormValidity = cardSubscription.getFormValidity()
// On Success, can get FormValidity, ex. FormValidity: { isFormValid: true, triggeredBy: cvv, fields: Fields}
// Implement your logic to handle the event , here
if (event.isFormValid) {
console.log("Form valid", event);
} else {
console.log("Form invalid", event);
}
This event is emitted when the field loses focus
Callback is executed when the cvv field is blurred
Optional
fieldType: FieldTypeEnum(optional) Set type of field if you want handle event blur and get FieldValidity of cvv field
Handling events 'blur' to get FormValidity
try {
cardSubscription.onFieldBlur((event: FormValidity) => {
// Implement your logic to handle the event FormValidity here
if (event.fields[event.triggeredBy].isValid) {
console.log("Form valid", event);
} else {
console.log("Form invalid", event);
}
});
// On Success, can get onFieldBlur, ex. FormValidity: { isFormValid: true, triggeredBy: cvv, fields: Fields}
} catch (error: any) {
console.error("Catch error on onFieldBlur", error.code, error.message);
}
Handling event 'blur' to get cvv FieldValidity
try {
cardSubscription.onFieldBlur((event: FieldValidity) => {
if (event.isValid) {
console.log("Form field is valid", event);
} else {
console.log("Form field is invalid", event);
console.log("this is error", event.errorType);
}
}, FieldTypeEnum.cvv);
// On Success, can get onFieldBlur, ex. FieldValidity : { isValid: false, errorType: "empty"}
} catch (error: any) {
console.error("Catch error on onFieldBlur", error.code, error.message);
}
This event is emitted when the cvv field gains focus
Callback is executed when the cvv field is focused
Optional
fieldType: FieldTypeEnum(optional) Set type of field if you want handle event focus and get FieldValidity of cvv field
Handling events 'focus' to get FormValidity
try {
cardSubscription.onFieldFocus((event: FormValidity) => {
// Implement your logic to handle the event FormValidity here
if (event.fields[event.triggeredBy].isValid) {
console.log("Form valid", event);
} else {
console.log("Form invalid", event);
}
});
// On Success, can get onFieldFocus, ex. FormValidity: { isFormValid: true, triggeredBy: cvv, fields: Fields}
} catch (error: any) {
console.error("Catch error on onFieldFocus", error.code, error.message);
}
Handling event 'focus' to get cvv FieldValidity
try {
cardSubscription.onFieldFocus((event: FieldValidity) => {
if (event.isValid) {
console.log("Form field is valid", event);
} else {
console.log("Form field is invalid", event);
console.log("this is error", event.errorType);
}
}, FieldTypeEnum.cvv);
// On Success, can get onFieldFocus, ex. FieldValidity : { isValid: false, errorType: "empty"}
} catch (error: any) {
console.error("Catch error on onFieldFocus", error.code, error.message);
}
This event is emitted when the field has submitted.
Callback is executed when the cvv field is submitted
Optional
fieldType: FieldTypeEnum(optional) Set type of field if you want handle event submit and get FieldValidity of cvv field
Handling events 'submit' to get FormValidity
try {
cardSubscription.onFieldSubmit((event: FormValidity) => {
// Implement your logic to handle the event FormValidity here
if (event.fields[event.triggeredBy].isValid) {
console.log("Form valid", event);
} else {
console.log("Form invalid", event);
}
});
// On Success, can get onFieldSubmit, ex. FormValidity: { isFormValid: true, triggeredBy: cvv, fields: Fields}
} catch (error: any) {
console.error("Catch error on onFieldSubmit", error.code, error.message);
}
Handling event 'submit' to get FieldValidity
try {
cardSubscription.onFieldSubmit((event: FieldValidity) => {
if (event.isValid) {
console.log("Form field is valid", event);
} else {
console.log("Form field is invalid", event);
console.log("this is error", event.errorType);
}
}, FieldTypeEnum.cvv);
// On Success, can get onFieldSubmit, ex. FieldValidity : { isValid: false, errorType: "empty"}
} catch (error: any) {
console.error("Catch error on onFieldSubmit", error.code, error.message);
}
This event is emitted when the field validity changes
Callback is executed when the cvv field changes his validity
Optional
fieldType: FieldTypeEnum(optional) Set type cvv field if you want handle event to get FieldValidity
Handling events 'FormValidity' of cvv field
try {
cardSubscription.onFieldValidity((event: FormValidity) => {
// Implement your logic to handle the event FormValidity here
if (event.fields[event.triggeredBy].isValid) {
console.log("Form valid", event);
} else {
console.log("Form invalid", event);
}
});
// On Success, can get FormValidity, ex. FormValidity: { isFormValid: true, triggeredBy: cvv, fields: Fields}
} catch (error: any) {
console.error("Catch error on onFieldValidity", error.code, error.message);
}
Handling event 'FieldValidity' of cvv field
try {
cardSubscription.onFieldValidity((event: FieldValidity) => {
if (event.isValid) {
console.log("Form field is valid", event);
} else {
console.log("Form field is invalid", event);
console.log("this is error", event.errorType);
}
}, FieldTypeEnum.cvv);
// On Success, can get onFieldValidity, ex. FieldValidity : { isValid: false, errorType: "empty"}
} catch (error: any) {
console.error("Catch error on onFieldValidity", error.code, error.message);
}
Get a secure device token for subscriptions on demand or one-click payment
This method validates if cvv field is valid and obtains a device token, otherwise it will throw an exception
If the merchant and subscription needs 3DS or SiftScience service, this method automatically do validations for each rule
Optional
body: DeviceTokenRequestobject with subscriptionId and other params for specific cases, see Object documentation
TokenResponse object with token
KushkiErrorResponse object with code and message of error
DeviceTokenRequest
body is not defined, then throw ERRORS.E020// Basic example
try {
const tokenResponse: TokenResponse = await cardSubscription.requestDeviceToken({
subscriptionId: "{subscriptionId}",
});
// On Success, can get device token response, ex. {token: "a2b74b7e3cf24e368a20380f16844d16"}
console.log("This is a device Token", tokenResponse.token)
} catch (error: any) {
// On Error, catch response, ex. {code:"E002", message: "Error en solicitud de token"}
// On Error, catch response, ex. {code:"E007", message: "Error en la validación del formulario"}
console.error("Catch error on request device Token", error.code, error.message);
}
// Body with params
// For 3DS transactions, currency and amount are required
try {
const tokenResponse: TokenResponse = await cardSubscription.requestDeviceToken({
amount: { //amount and currency required for 3DS transactions
iva: 10000,
subtotalIva: 0,
subtotalIva0: 0
},
currency: "{currency}",
subscriptionId: "{subscriptionId}",
userId: "{userId}", //when use preloaded SiftScience service
sessionId: "{sessionId}" //when use preloaded SiftScience service
});
// On Success, can get device token response, ex. {token: "a2b74b7e3cf24e368a20380f16844d16"}
console.log("This is a device Token", tokenResponse.token)
} catch (error: any) {
console.error("Catch error on request device Token", error.code, error.message);
}
Reset cvv hosted field
This method asynchronously reset cvv field to its default state, otherwise it will throw an exception
// Basic example
try {
await cardSubscription.reset();
// On Success, can reset field
} catch (error: any) {
// On Error, catch response, ex. {code:"E009", message: "Error al limpiar el campo"}
console.error("Catch error on reset field", error.code, error.message);
}
Generated using TypeDoc
This interface contains all methods to use when resolve initSecureDeviceToken