Function initApplePayButton

  • Introduction

    Function to render the Apple Pay button and initialize an instance of ICardApplePay.

    ⚠️ To use the Apple Pay integration, you must first configure a secure domain in the Kushki Backoffice console and coordinate with Kushki to integrate the required certificates on your website for the payment flow to function properly.

    For this method to work correctly, you must include the following container in your project’s HTML:

    <div id="kushki-apple-pay-button"></div>
    

    Parameters

    • kushkiInstance: IKushki

      Object that implements IKushki.

    • options: ApplePayOptions

      Visual and behavioral options for the Apple Pay button:

      • style: "black" | "white" → button style.
      • locale: "en-US" | "es-ES" | "es-MX" | "pt-BR" → language/region for the button.
      • type: "add-money" | "book" | "buy" | "check-out" | "continue" | "contribute" | "donate" | "order" | "pay" | "plain" | "reload" | "rent" | "set-up" | "subscribe" | "support" | "tip" | "top-up" → defines the text/action displayed on the button.

    Returns Promise<ICardApplePay>

    Instance of ICardApplePay.

    Throws

    Example

    HTML container:

    <div id="kushki-apple-pay-button"></div>
    

    Initialize Kushki instance:

    const kushkiOptions: KushkiOptions = {
    publicCredentialId: 'public-merchant-id',
    inTest: true
    };

    Initialize CardApplePay instance:

    const options: ApplePayOptions = {
    style: "black",
    locale: "es-MX",
    type: "pay"
    };

    try {
    const kushkiInstance: IKushki = await init(kushkiOptions);
    const cardApplePay: ICardApplePay = await initApplePayButton(kushkiInstance, options);
    } catch (e: any) {
    console.error(e.message);
    }

    Example

    Using events and requesting the Apple Pay token:

    try {
    const cardApplePay: ICardApplePay = await initApplePayButton(kushkiInstance, options);

    cardApplePay.onCancel(() => {
    console.log("Payment canceled");
    });

    cardApplePay.onClick(async () => {
    try {
    const token = await cardApplePay.requestApplePayToken({
    displayName: "DEMO",
    countryCode: "EC",
    currencyCode: "USD",
    amount: 20
    });

    console.log(token);
    } catch (error) {
    console.log("Error requesting token: ", error);
    }
    });
    } catch (e: any) {
    console.error(e.message);
    }

Generated using TypeDoc