Skip to content

two-checkout ​

TwoCheckout 支付。

概述 ​

k.payment.twoCheckout 用于创建 TwoCheckout 支付请求,支持卡信息和 3D 验证跳转。使用前需要在站点 CMS 中配置 TwoCheckout 商户信息。

twoCheckout.charge() ​

创建 TwoCheckout 支付请求。

ts
k.api.post(() => {
    const result = k.payment.twoCheckout.charge({
        name: 'TEST order',
        description: 'Order payment',
        totalAmount: 100,
        currency: 'USD',
        order: 'order-id',
        returnUrl: '/payment/success?orderId=order-id',
        cancelUrl: '/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?.redirectUrl) {
        k.response.redirect(result.nextAction.redirectUrl)
        return
    }

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

参数: TwoCheckoutParams

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

返回: ChargeResponse

checkStatus() ​

检查支付状态。

参数:

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

返回: PaymentStatusResponse

updateOrder() ​

处理 TwoCheckout 回调并更新订单。

参数:

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

返回: PaymentCallback

Card ​

属性类型说明
numberstring卡号
cvcstringCVC
expMonthstring过期月份
expYearstring过期年份
namestring持卡人姓名

Address ​

属性类型说明
firstNamestring名
lastNamestring姓
countryCodestring国家代码
statestring州或省
citystring城市
address1string地址
zipstring邮编
emailstring邮箱
phonestring电话

TwoCheckoutSetting ​

属性类型说明
baseUrlstringTwoCheckout 接口地址
merchantCodestring商户 Code
secretKeystringSecret Key
testModeboolean是否测试模式