Click-To-Pay Objects Reference (Request)

For complete sample code please refer here

Available dictionary objects

iStatus

const iStatus = {
    success: 100,
    unsupported: -100,
    error: -200
}

Use: iStatus.success

c2pEnvironment

const c2pEnvironment = {
    sandbox: 0,
    production: 1
}

Use: c2pEnvironment.sandbox

c2pReviewAction

const c2pReviewAction = {
    pay: "PAY",
    continue: "CONTINUE"
}

Use: c2pReviewAction.pay

Request objects

ClickToPayRequest

The Main object that contains all the information necessary to communicate with Click-To-Pay API.

onCPButtonLoaded callback example

onCPButtonLoaded: function(resp) {
    if (!resp) return;
    if (resp.status === iStatus.success) {
        showHide("click2payContainer", true);
    } else if (resp.reason) {
        console.log(resp.reason);
    }
}

onPaymentPrefill callback example

onPaymentPrefill: function(){
  const result = {
    merchantRequestId: "Merchant defined request ID",
    currencyCode: "USD",
    description: "...corp Product",
    orderId: "Merchant defined order ID",
    promoCode: "Merchant defined promo code",
    subtotal: roundTo(getAmount(), 2),
    shippingHandling: "2.00",
    tax: "2.00",
    discount: "1.00",
    giftWrap: "2.00",
    misc: "1.00",
    setTotal:  function() {
        this.total = roundTo(
            roundToNumber(this.subtotal, 2)
            + roundToNumber(this.shippingHandling, 2)
            + roundToNumber(this.tax, 2)
            + roundToNumber(this.giftWrap, 2)
            + roundToNumber(this.misc, 2)
            - roundToNumber(this.discount, 2)
        , 2);
        delete this.setTotal;
        return this;
    }
  }.setTotal();
  return result;
}

onPaymentValidate callback example

onPaymentValidate: function () {
    return new Promise(function (resolve, reject) {
        try {
            //Do some validation here
            resolve(iStatus.success);
        } catch (err) {
            reject(err);
        }
    });
}

onPaymentSuccess callback example

onPaymentSuccess: async function(clickToPayResponse) {
    return new Promise((resolve, reject) => {
        try {
            const response = await this.authorize(clickToPayResponse);
            console.log(response);
            const resp = JSON.parse(response);
            if (!resp)
                throw "Invalid response: "+ response;
            if (resp.xError) {
                throw resp;
            }
            resolve(response);
        } catch (err) {
            console.error("paymentSuccess error.", JSON.stringify(err));
            reject(err);
        }
    });
}

onPaymentCancel callback example

onPaymentCancel: function (payload) {
    logError("Click-To-Pay Cancelled", payload);
    //Do some custom logic here
}

onPaymentError callback example

onPaymentCancel: function (payload) {
    logError("Click-To-Pay Error", payload);
    //Do some custom logic here
}

CPButtonLoadedResult Object


Last updated