Skip to content

k.payment.twoCheckout ​

TwoCheckout payments.

Execution ContextPrerequisitesTypical Use
KScript API (k.api.get / k.api.post), server-side <script env="server">Configure TwoCheckoutSetting (Merchant Code and Secret Key) in site CMSCreate TwoCheckout card charges, handle 3DS redirects, check status, and update orders

k.payment.twoCheckout creates TwoCheckout payment requests supporting card details and 3D Secure verification redirects.

Quick Start ​

js
k.api.get(() => {
    const status = k.payment.twoCheckout.checkStatus("request-id")
    return { paid: status.paid, failed: status.failed, status: status.status }
})

Quick Reference ​

Method / PropertyDescriptionReturns
twoCheckout.charge(params)Create a TwoCheckout card payment requestChargeResponse
twoCheckout.checkStatus(requestId)Check payment status by requestId (triggers order/callback updates on paid/failed)PaymentStatusResponse
twoCheckout.setting / contextSite settings and current request contextTwoCheckoutSetting / context

twoCheckout.charge() ​

Create a TwoCheckout payment request.

ParameterTypeRequiredDescription
cancelUrlstringYesRedirect URL when canceling 3D verification (must be an absolute http:// or https:// URL; sent verbatim to 2Checkout)
returnUrlstringYesRedirect URL after successful 3D verification (must be an absolute http:// or https:// URL; 2Checkout redirects straight here after 3DS without invoking Kooboo's callback route, so call checkStatus(requestId) in this handler)
cardCardYesCard details
cardTypestringYesCard brand, such as Visa, Mastercard, Amex
billingAddressAddressYesBilling address
totalAmountnumberYesOrder amount
namestringYesOrder name
descriptionstringYesOrder description
currencystringYesCurrency, such as USD
orderstringNoCommerce order ID. Updates order payment status when paid
callbackCodeNamestringNoCallback code name executed after payment completes

Returns: ChargeResponse

js
k.api.post(() => {
    const result = k.payment.twoCheckout.charge({
        name: "TEST order",
        description: "Order payment",
        totalAmount: 100,
        currency: "USD",
        order: "order-id",
        returnUrl: "https://example.com/payment/success?orderId=order-id",
        cancelUrl: "https://example.com/payment/cancel?orderId=order-id",
        card: {
            number: "378282246310005",
            expMonth: "03",
            expYear: "2030",
            cvc: "123",
            name: "John Doe"
        },
        cardType: "Amex",
        billingAddress: {
            firstName: "Customer",
            lastName: "2Checkout",
            countryCode: "US",
            state: "California",
            city: "LA",
            address1: "Test Address",
            zip: "12345",
            email: "testcustomer@2checkout.com",
            phone: "13800138000"
        }
    })

    if (result.nextAction && result.nextAction.redirectUrl) {
        k.response.redirect(result.nextAction.redirectUrl)
        return
    }

    return { paid: result.paid, requestId: result.requestId }
})

checkStatus() ​

Check payment status.

ParameterTypeRequiredDescription
requestIdstringYesrequestId returned by charge()

Returns: PaymentStatusResponse

js
k.api.get(() => {
    const status = k.payment.twoCheckout.checkStatus("request-id")
    return { paid: status.paid, failed: status.failed, status: status.status }
})

Callbacks & 3DS Status Confirmation ​

twoCheckout.charge() sends your returnUrl and cancelUrl verbatim to 2Checkout as Vendor3DSReturnURL and Vendor3DSCancelURL without wrapping them in /_api/paymentcallback/TwoCheckout_UpdateOrder. As a result, 2Checkout redirects straight to your returnUrl after 3DS verification instead of hitting Kooboo's built-in callback route.

twoCheckout.updateOrder(context) is an internal callback handler—do not call it directly in KScript to update orders (direct calls never invoke PaymentManager.CallBack(...) and throw NullReferenceException when requestid is missing). Store result.requestId before redirecting to 3DS, and call k.payment.twoCheckout.checkStatus(requestId) in your returnUrl handler so Kooboo verifies the transaction and runs PaymentManager.CallBack(...) to finalize PaymentRequest, Commerce order, and callbackCodeName:

js
k.api.get(() => {
    const orderId = k.request.queryString.get("orderId")
    const saved = k.DB.keyValue.get(`payment:${orderId}`)
    const requestId = saved ? saved.toString() : null
    if (!requestId) {
        return { paid: false, error: "requestId not found" }
    }

    const status = k.payment.twoCheckout.checkStatus(requestId)
    return { paid: status.paid, failed: status.failed, status: status.status }
})

Data & Configuration Structures ​

Card ​

PropertyTypeDescription
numberstringCard number
cvcstringCVC security code
expMonthstringExpiration month
expYearstringExpiration year
namestringCardholder name

Address ​

PropertyTypeDescription
firstNamestringFirst name
lastNamestringLast name
countryCodestringCountry code
statestringState or province
citystringCity
address1stringStreet address
zipstringPostal code
emailstringEmail
phonestringPhone number

TwoCheckoutSetting ​

PropertyTypeDescription
baseUrlstringTwoCheckout API endpoint
merchantCodestringMerchant code
secretKeystringSecret key
testModebooleanWhether test mode is enabled

TypeScript Definitions ​

Show full TypeScript definitions
ts
interface TwoCheckout {
    setting: TwoCheckoutSetting;
    charge(params: TwoCheckoutParams): ChargeResponse;
    /** Internal callback handler; do not call directly in KScript—use checkStatus(requestId) on 3DS return */
    updateOrder(context: any): PaymentCallback;
    checkStatus(requestId: string): PaymentStatusResponse;
}

interface TwoCheckoutParams extends ChargeParams {
    cancelUrl: string;
    returnUrl: string;
    card: any;
    cardType: string;
    billingAddress: any;
}

interface TwoCheckoutSetting {
    name: string;
    group: string;
    baseUrl: string;
    merchantCode: string;
    secretKey: string;
    testMode: boolean;
}