Interface ICardSubscriptions

This interface contains all methods to use when resolve initSecureDeviceToken

Hierarchy

  • ICardSubscriptions

Methods

  • Focus cvv hosted field

    This method asynchronously focus cvv field, otherwise it will throw an exception

    Returns Promise<void>

    Throws

    Example

    // 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

    Returns FormValidity

    FormValidity object with validation info of cvv field

    Example

    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

    Parameters

    • event: ((fieldEvent) => void)

      Callback is executed when the cvv field is blurred

        • (fieldEvent): void
        • Parameters

          Returns void

    • Optional fieldType: FieldTypeEnum

      (optional) Set type of field if you want handle event blur and get FieldValidity of cvv field

    Returns void

    Example

    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

    Parameters

    • event: ((fieldEvent) => void)

      Callback is executed when the cvv field is focused

        • (fieldEvent): void
        • Parameters

          Returns void

    • Optional fieldType: FieldTypeEnum

      (optional) Set type of field if you want handle event focus and get FieldValidity of cvv field

    Returns void

    Example

    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.

    Parameters

    • event: ((fieldEvent) => void)

      Callback is executed when the cvv field is submitted

        • (fieldEvent): void
        • Parameters

          Returns void

    • Optional fieldType: FieldTypeEnum

      (optional) Set type of field if you want handle event submit and get FieldValidity of cvv field

    Returns void

    Example

    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

    Parameters

    • event: ((fieldEvent) => void)

      Callback is executed when the cvv field changes his validity

        • (fieldEvent): void
        • Parameters

          Returns void

    • Optional fieldType: FieldTypeEnum

      (optional) Set type cvv field if you want handle event to get FieldValidity

    Returns void

    Example

    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

    Parameters

    • Optional body: DeviceTokenRequest

      object with subscriptionId and other params for specific cases, see Object documentation

    Returns Promise<TokenResponse>

    TokenResponse object with token

    Throws

    KushkiErrorResponse object with code and message of error

    • if error on request device token endpoint then throw ERRORS.E002
    • if error on request merchant settings endpoint, then throw ERRORS.E003
    • if the merchant have SiftScience configurations and options.subscriptionId into body is not found or the request fails then throw ERRORS.E016
    • if merchant is configured with 3DS rule and error on request JWT endpoint, then throw ERRORS.E004
    • if merchant is configured with 3DS rule and error on 3DS authentication, then throw ERRORS.E005
    • if merchant is configured with 3DS rule and error on 3DS session validation, then throw ERRORS.E006
    • if cvv field is invalid, then throw ERRORS.E007
    • if DeviceTokenRequest body is not defined, then throw ERRORS.E020

    Example

    // 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);
    }

    Example

    // 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

    Returns Promise<void>

    Throws

    Example

    // 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