Skip to content

k.payment.moneyBoxs ​

MoneyBoxs payments (USD only).

Execution ContextPrerequisitesTypical Use
KScript API (k.api.get / k.api.post), server-side <script env="server">Configure MoneyBoxsSetting (merchantNo, terminalNo, key, etc.) in site CMSCreate card charges (USD only), handle 3DS redirects, verify 3D Auth hashes, and confirm local payment status

k.payment.moneyBoxs creates MoneyBoxs payment requests with card details, billing/shipping addresses, and line item breakdowns.

Quick Start ​

js
k.api.get(() => {
    const status = k.payment.moneyBoxs.checkStatus("request-id")
    // Reads local PaymentRequest.Paid only (status is always "NotAvailable", failed is always false)
    return { paid: status.paid }
})

Quick Reference ​

Method / PropertyDescriptionReturns
moneyBoxs.charge(params)Create a MoneyBoxs payment request with card and item details (USD only)ChargeResponse
moneyBoxs.checkStatus(requestId)Read local PaymentRequest.Paid (does not query remote API; triggers callback when paid is true)PaymentStatusResponse
moneyBoxs.verify3DAuthCallback(...)Verify 3D Auth callback hash signature and update local PaymentRequest.Paidvoid
moneyBoxs.setting / contextSite MoneyBoxs settings and current request contextMoneyBoxsSetting / context

moneyBoxs.charge() ​

Create a MoneyBoxs payment request.

ParameterTypeRequiredDescription
returnUrlstringYesRedirect URL after successful 3D verification
cardCardYesCard information
billingAddressAddressYesBilling address
shipAddressAddressYesShipping address
goodsMoneyBoxsGood[]YesProduct item details
totalAmountnumberYesOrder amount
namestringYesOrder name
descriptionstringYesOrder description
currencystringYesCurrency (USD only; passing any other currency throws a validation error)
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.moneyBoxs.charge({
        name: "TEST order",
        description: "Order payment",
        totalAmount: 100,
        currency: "USD",
        order: "order-id",
        returnUrl: "/payment/success?orderId=order-id",
        card: {
            number: "378282246310005",
            expMonth: "03",
            expYear: "2030",
            cvc: "123",
            name: "John Doe"
        },
        billingAddress: {
            firstName: "Customer",
            lastName: "MoneyBoxs",
            countryCode: "US",
            state: "California",
            city: "LA",
            address1: "Test Address",
            zip: "12345",
            email: "testcustomer@example.com",
            phone: "13800138000"
        },
        shipAddress: {
            firstName: "Customer",
            lastName: "MoneyBoxs",
            countryCode: "US",
            state: "California",
            city: "LA",
            address1: "Test Address",
            zip: "12345",
            email: "testcustomer@example.com",
            phone: "13800138000"
        },
        goods: [
            { goodsName: "T-shirt", quantity: "1", goodsPrice: "100" }
        ]
    })

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

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

checkStatus() ​

Read local payment status. Note: moneyBoxs.checkStatus(requestId) does not query the MoneyBoxs remote API—it only returns the local PaymentRequest.Paid boolean, with status always "NotAvailable" and failed always false. When paid is true, it invokes PaymentManager.CallBack(...) to update any linked Commerce order and run callbackCodeName.

ParameterTypeRequiredDescription
requestIdstringYesrequestId returned by charge()

Returns: PaymentStatusResponse

js
k.api.get(() => {
    const status = k.payment.moneyBoxs.checkStatus("request-id")
    // status.status is always "NotAvailable" and status.failed is always false
    return { paid: status.paid }
})

Callback Handling & Limitations ​

moneyBoxs.charge() passes Kooboo's built-in /_api/paymentcallback/MoneyBoxs_UpdateOrder?requestid={requestId} URL as ReturnURL to MoneyBoxs. When the buyer returns, that route redirects via CallbackResponse (HTTP 302) to your returnUrl.

Limitation: Because MoneyBoxs.CheckStatus(request) only sets Paid = request.Paid without setting Status, MoneyBoxs.UpdateOrder always returns a PaymentCallback with status: "NotAvailable" and paid: false—even for paid orders—and does not mark the order paid. Do not call moneyBoxs.updateOrder(...) directly in KScript (it never calls PaymentManager.CallBack(...) and throws NullReferenceException when requestid is missing).

Use verify3DAuthCallback(...) followed by checkStatus(requestId) to handle 3D Auth callbacks and trigger order updates, or read the record with k.payment.getRequest(requestId).

verify3DAuthCallback() ​

Verify the 3D Auth callback signature and update local PaymentRequest.Paid:

  • orderNo must be the requestId GUID returned by charge() (passing a non-GUID string throws FormatException in Guid.Parse).
  • Throws "Verify hashCode error" if the hash signature check fails.
  • When valid, directly updates PaymentRequest.Paid = (respCode === "00") via UpdateRequest without triggering PaymentManager.CallBack(...)—so Commerce orders and callbackCodeName are not automatically updated unless you subsequently call k.payment.moneyBoxs.checkStatus(requestId).
ParameterTypeRequiredDescription
orderNostringYesrequestId GUID returned by charge() (not an arbitrary order string)
merchantNostringYesMerchant number
terminalNostringYesTerminal number
amountstringYesAmount
hashCodestringYesCallback hash
respCodestringYesResponse code ("00" indicates payment succeeded)

Returns: void

js
k.api.post(() => {
    const requestId = "00000000-0000-0000-0000-000000000000" // charge().requestId (GUID)

    k.payment.moneyBoxs.verify3DAuthCallback(
        requestId,
        "merchantNo",
        "terminalNo",
        "100.00",
        "hashCode",
        "00"
    )

    // Invoke PaymentManager.CallBack to update Commerce order and execute callbackCodeName
    const status = k.payment.moneyBoxs.checkStatus(requestId)
    const request = k.payment.getRequest(requestId)
    return { verified: true, paid: status.paid, order: request?.order }
})

Data & Configuration Structures ​

MoneyBoxsGood ​

PropertyTypeDescription
goodsNamestringProduct name
quantitystringQuantity
goodsPricestringProduct price

MoneyBoxsSetting ​

PropertyTypeDescription
baseUrlstringMoneyBoxs API URL
merchantNostringMerchant number
terminalNostringTerminal number
keystringSecret key
transactionURLstringTransaction endpoint URL
typestringIntegration type

TypeScript Definitions ​

Show full TypeScript definitions
ts
interface MoneyBoxs {
    setting: MoneyBoxsSetting;
    charge(params: MoneyBoxsParams): ChargeResponse;
    /** Internal callback handler (redirect only; always returns status NotAvailable / paid false); do not call directly in KScript */
    updateOrder(context: any): PaymentCallback;
    verify3DAuthCallback(
        orderNo: string,
        merchantNo: string,
        terminalNo: string,
        amount: string,
        hashCode: string,
        respCode: string
    ): void;
    checkStatus(requestId: string): PaymentStatusResponse;
}

interface MoneyBoxsParams extends ChargeParams {
    returnUrl: string;
    card: any;
    billingAddress: any;
    shipAddress: any;
    goods: MoneyBoxsGood[];
}

interface MoneyBoxsGood {
    goodsName: string;
    quantity: string;
    goodsPrice: string;
}

interface MoneyBoxsSetting {
    name: string;
    group: string;
    baseUrl: string;
    merchantNo: string;
    terminalNo: string;
    key: string;
    transactionURL: string;
    type: string;
}