# 4.3 Supported events

The wallet SDK will trigger an event every time a specific action has been done. It helps the wrapping client to be informed about different states, actions and receive information from the wallet SDK.

Listening to an event:

function handleEvent(name){
    return function (value) { 
        console.log(`event-`,name); 
        if (value){ 
        console.log(`value-`,JSON.stringify(value)); 
        } 
    } 
}
window.mycheck.wallet.on("<event name>",handleEvent("<event name>")); 

Example

window.mycheck.wallet.on("paymentCompleted", handleEvent("paymentCompleted")); 
 

Or by using an anonymous function:

mycheck.wallet.on("paymentCompleted", function (paymentDetails){ 

console.log(paymentDetails); 

}); 

# 4.3.1 Init event

Called after the wallet started initialization.

mycheck.wallet.on("init", function () {
    console.log('wallet initialized');

}); 

# 4.3.2 Ready event

Called when wallet is mounted and loaded.

mycheck.wallet.on("ready", function () {

    console.log('wallet is ready');

});

# 4.3.3 CheckoutReady event

Will return the status (whether a payment can be initiated) and a payment details JSON object containing the following:

mycheck.wallet.on("checkoutReady", function (status, paymentDetails) {
    console.log(status);
    console.log(paymentDetails);
}); 

Payload:

{
    "status": false, 
    "paymentDetails": {
    "cc_token": "<TOKEN>",
        "encrypted_cvv": null,
        "type": "traditional",
        "fingerprint": {
        "ip": "147.161.131.31",
            "screenHeight": 764,
            "screenWidth": 1123,
            "timezoneOffset": -180,
            "browserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
            "walletSdkSessionId": "917eb11c-8437-4a07-a01a-587b89ecf403"
    }
  }
}
  • cc_token – the token of the payment method (in the format of JWT)

  • type – the selected payment method type (instant | traditional | alternative)

  • encrypted_cvv – when applicable

  • fingerprint – when applicable

This event will fire constantly based on the interactions of the user with the wallet, affected by and not only:

  • The selected payment type (traditional| alternative | instant)

  • Upon adding a payment method by a traditional card or by an alternative payment (Applepay, Googlepay, Paypal, Amazonpay, SRC …)

  • User already has a payment method in the wallet (the default payment method will be returned) – for a returning customers flow.

  • When a payment method is selected by a user from a list of existing payment methods.

  • Encrypted cvv is generated (whether it is by add card flow, or by generating a new one after it is expired on checkout page)

  • Etc

# 4.3.3.1 Using the checkout ready object

Based on the response you should do the following when a payment is initiated:

  • If status = false

    • Payment is impossible at this point (UI indications are displayed to the end user).
  • If status = true

    • Take a decision based on the payment type.

      • If it is an instant – call mycheck.wallet.makeInstantPayment()

      • If it is a traditional/alternative call to your server to perform the billing call using the payment_details provided

# 4.3.4 PaymentCompleted event

Is triggered when a 3DS or an instant payment is completed

mycheck.wallet.on("paymentCompleted", function (paymentDetails) {
    console.log(paymentDetails);
}); 

Payload:

 {
    "method":"SALE_3DS",
    "status":"SUCCESS",
    "transaction_id":"SPS_ECOMMERCE-0279d4fb-c3e0-4391-9c6a-da37674ff8b5"
  }