Skip to content

moneyboxs ​

MoneyBoxs 支付。

概述 ​

k.payment.moneyBoxs 用于创建 MoneyBoxs 支付请求,支持卡信息、账单地址、收货地址和商品明细。使用前需要在站点 CMS 中配置 MoneyBoxs 商户信息。

moneyBoxs.charge() ​

创建 MoneyBoxs 支付请求。

ts
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?.redirectUrl) {
        k.response.redirect(result.nextAction.redirectUrl)
        return
    }

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

参数: MoneyBoxsParams

参数类型必填说明
returnUrlstring是3D 验证成功后的跳转地址
cardCard是卡信息
billingAddressAddress是账单地址
shipAddressAddress是收货地址
goodsGood[]是商品明细
totalAmountnumber是订单金额
namestring是订单名称
descriptionstring是订单描述
currencystring是货币,如 USD
orderstring否Commerce 订单 ID。提供后支付成功会更新订单支付状态
callbackCodeNamestring否支付完成后执行的回调代码名称

返回: ChargeResponse

checkStatus() ​

检查支付状态。

参数:

参数类型必填说明
requestIdstring是charge() 返回的 requestId。
ts
k.api.get(() => {
    const status = k.payment.moneyBoxs.checkStatus('request-id')
    return { paid: status.paid, failed: status.failed, status: status.status }
})

返回: PaymentStatusResponse

updateOrder() ​

处理 MoneyBoxs 回调并更新订单。

参数:

参数类型必填说明
contextobject是当前支付回调上下文,通常传入 k.payment.moneyBoxs.context。
ts
k.api.post(() => {
    const callback = k.payment.moneyBoxs.updateOrder(k.payment.moneyBoxs.context)
    return { paid: callback.paid, status: callback.status }
})

返回: PaymentCallback

verify3DAuthCallback() ​

验证 3D Auth 回调。

ts
k.api.post(() => {
    k.payment.moneyBoxs.verify3DAuthCallback(
        'orderNo',
        'merchantNo',
        'terminalNo',
        '100',
        'hashCode',
        '00'
    )
    return 'success'
})

参数:

参数类型必填说明
orderNostring是订单号
merchantNostring是商户号
terminalNostring是终端号
amountstring是金额
hashCodestring是回调 Hash
respCodestring是响应码

返回: void

Good ​

属性类型说明
goodsNamestring商品名称
quantitystring数量
goodsPricestring商品价格

MoneyBoxsSetting ​

属性类型说明
baseUrlstringMoneyBoxs API 地址
merchantNostring商户号
terminalNostring终端号
keystring密钥
transactionURLstring交易地址
typestring类型