k.payment.twoCheckout
TwoCheckout payments.
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Configure TwoCheckoutSetting (Merchant Code and Secret Key) in site CMS | Create 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
k.api.get(() => {
const status = k.payment.twoCheckout.checkStatus("request-id")
return { paid: status.paid, failed: status.failed, status: status.status }
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
twoCheckout.charge(params) | Create a TwoCheckout card payment request | ChargeResponse |
twoCheckout.checkStatus(requestId) | Check payment status by requestId (triggers order/callback updates on paid/failed) | PaymentStatusResponse |
twoCheckout.setting / context | Site settings and current request context | TwoCheckoutSetting / context |
twoCheckout.charge()
Create a TwoCheckout payment request.
| Parameter | Type | Required | Description |
|---|---|---|---|
cancelUrl | string | Yes | Redirect URL when canceling 3D verification (must be an absolute http:// or https:// URL; sent verbatim to 2Checkout) |
returnUrl | string | Yes | Redirect 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) |
card | Card | Yes | Card details |
cardType | string | Yes | Card brand, such as Visa, Mastercard, Amex |
billingAddress | Address | Yes | Billing address |
totalAmount | number | Yes | Order amount |
name | string | Yes | Order name |
description | string | Yes | Order description |
currency | string | Yes | Currency, such as USD |
order | string | No | Commerce order ID. Updates order payment status when paid |
callbackCodeName | string | No | Callback code name executed after payment completes |
Returns: ChargeResponse
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.
| Parameter | Type | Required | Description |
|---|---|---|---|
requestId | string | Yes | requestId returned by charge() |
Returns: PaymentStatusResponse
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:
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
| Property | Type | Description |
|---|---|---|
number | string | Card number |
cvc | string | CVC security code |
expMonth | string | Expiration month |
expYear | string | Expiration year |
name | string | Cardholder name |
Address
| Property | Type | Description |
|---|---|---|
firstName | string | First name |
lastName | string | Last name |
countryCode | string | Country code |
state | string | State or province |
city | string | City |
address1 | string | Street address |
zip | string | Postal code |
email | string | |
phone | string | Phone number |
TwoCheckoutSetting
| Property | Type | Description |
|---|---|---|
baseUrl | string | TwoCheckout API endpoint |
merchantCode | string | Merchant code |
secretKey | string | Secret key |
testMode | boolean | Whether test mode is enabled |
TypeScript Definitions
Show full TypeScript definitions
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;
}