Function requestDeviceToken

  • Function to get device token for one-click payment or subscription on-demand

    Parameters

    • kushkiInstance: IKushki

      Object that that was previously initialized with init Kushki method

    • body: DeviceTokenRequest

      Object with subscriptionId and optional amount or currency

    Returns Promise<TokenResponse>

    • Object that contains the device token validated

    Throws

    • if options.publicCredentialId into kushkiInstance is not valid or the request fails 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 the merchant have 3DS configurations and JWT request fails then throw ERRORS.E004
    • if the merchant have 3DS configurations and validation challenge fails then throw ERRORS.E005
    • if the merchant have 3DS configurations and request token validation fails then throw ERRORS.E006

    Example

    Request Device Token
    import { init, IKushki } from "@kushki/js-sdk";
    import { requestDeviceToken, DeviceTokenRequest, TokenResponse } from "@kushki/js-sdk/Card";

    const onRequestDeviceToken = async () => {
    try {
    const kushkiInstance: IKushki = await init({
    inTest: true,
    publicCredentialId: "merchantId"
    });
    const body: DeviceTokenRequest={
    subscriptionId: "subscriptionId"
    amount:{ //amount and currency optionals, but required for 3DS transactions
    subtotalIva: 20,
    subtotalIva0: 0,
    iva: 10,
    },
    currency: "USD",
    }

    const response: TokenResponse = await requestDeviceToken(kushkiInstance, body);

    // On Success, can get device token for one-click payment, ex. {"token":"31674e78f88b41ffaf47998151fb465d"}
    console.log(response);
    } catch (error: any) {
    // On Error, catch response, ex. {code:"E017", message: "Error en solicitud de Token de subscripción bajo demanda"}
    console.error(error.message);
    }
    };

Generated using TypeDoc