k.payment.moneyBoxs
MoneyBoxs payments (
USDonly).
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Configure MoneyBoxsSetting (merchantNo, terminalNo, key, etc.) in site CMS | Create 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
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 / Property | Description | Returns |
|---|---|---|
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.Paid | void |
moneyBoxs.setting / context | Site MoneyBoxs settings and current request context | MoneyBoxsSetting / context |
moneyBoxs.charge()
Create a MoneyBoxs payment request.
| Parameter | Type | Required | Description |
|---|---|---|---|
returnUrl | string | Yes | Redirect URL after successful 3D verification |
card | Card | Yes | Card information |
billingAddress | Address | Yes | Billing address |
shipAddress | Address | Yes | Shipping address |
goods | MoneyBoxsGood[] | Yes | Product item details |
totalAmount | number | Yes | Order amount |
name | string | Yes | Order name |
description | string | Yes | Order description |
currency | string | Yes | Currency (USD only; passing any other currency throws a validation error) |
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.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.
| Parameter | Type | Required | Description |
|---|---|---|---|
requestId | string | Yes | requestId returned by charge() |
Returns: PaymentStatusResponse
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:
orderNomust be therequestIdGUID returned bycharge()(passing a non-GUID string throwsFormatExceptioninGuid.Parse).- Throws
"Verify hashCode error"if the hash signature check fails. - When valid, directly updates
PaymentRequest.Paid = (respCode === "00")viaUpdateRequestwithout triggeringPaymentManager.CallBack(...)—so Commerce orders andcallbackCodeNameare not automatically updated unless you subsequently callk.payment.moneyBoxs.checkStatus(requestId).
| Parameter | Type | Required | Description |
|---|---|---|---|
orderNo | string | Yes | requestId GUID returned by charge() (not an arbitrary order string) |
merchantNo | string | Yes | Merchant number |
terminalNo | string | Yes | Terminal number |
amount | string | Yes | Amount |
hashCode | string | Yes | Callback hash |
respCode | string | Yes | Response code ("00" indicates payment succeeded) |
Returns: void
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
| Property | Type | Description |
|---|---|---|
goodsName | string | Product name |
quantity | string | Quantity |
goodsPrice | string | Product price |
MoneyBoxsSetting
| Property | Type | Description |
|---|---|---|
baseUrl | string | MoneyBoxs API URL |
merchantNo | string | Merchant number |
terminalNo | string | Terminal number |
key | string | Secret key |
transactionURL | string | Transaction endpoint URL |
type | string | Integration type |
TypeScript Definitions
Show full TypeScript definitions
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;
}