Skip to content

alipay

Alipay payment.

Overview

Alipay payment includes three methods: App, web form and H5. Alipay application information needs to be configured in the site CMS before use.

APIillustrate
k.payment.alipayAppAlipay App Payment
k.payment.alipayFormAlipay web payment, usually rendered nextAction.renderHtml
k.payment.alipayH5Alipay H5 payment

alipayApp.charge()

Create an Alipay App payment request.

ts
k.api.post(() => {
    const result = k.payment.alipayApp.charge({
        name: 'Test Alipay App',
        description: 'Order payment',
        totalAmount: 1.5,
        currency: 'CNY',
        order: 'order-id',
        callbackCodeName: 'PaymentCallback'
    })

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

Parameter: ChargeParams

parametertypeRequiredillustrate
totalAmountnumberyesOrder amount
namestringyesOrder name
descriptionstringyesOrder description
currencystringyesCurrency, such as CNY
orderstringnoCommerce order ID. Once the payment is successful, the order payment status will be updated.
callbackCodeNamestringnoThe name of the callback code executed after payment is completed

Return: ChargeResponse

alipayForm.charge()

Create an Alipay web payment request.

ts
k.api.get(() => {
    const result = k.payment.alipayForm.charge({
        name: 'Test Alipay Form',
        description: 'Order payment',
        totalAmount: 1.5,
        currency: 'CNY',
        order: 'order-id',
        returnUrl: '/payment/success?orderId=order-id',
        callbackCodeName: 'PaymentCallback'
    })

    return k.response.renderView(result.nextAction.renderHtml)
})

Parameter: AlipayFormParams

parametertypeRequiredillustrate
returnUrlstringyesJump address after payment is completed
totalAmountnumberyesOrder amount
namestringyesOrder name
descriptionstringyesOrder description
currencystringyesCurrency, such as CNY
orderstringnoCommerce order ID. Once the payment is successful, the order payment status will be updated.
callbackCodeNamestringnoThe name of the callback code executed after payment is completed

Return: ChargeResponse

alipayH5.charge()

Create Alipay H5 payment request.

ts
k.api.get(() => {
    const result = k.payment.alipayH5.charge({
        name: 'Test Alipay H5',
        description: 'Order payment',
        totalAmount: 1.5,
        currency: 'CNY',
        order: 'order-id',
        returnUrl: '/payment/success?orderId=order-id'
    })

    return k.response.renderView(result.nextAction.renderHtml)
})

Parameter: AlipayFormParams

parametertypeRequiredillustrate
returnUrlstringyesJump address after payment is completed
totalAmountnumberyesOrder amount
namestringyesOrder name
descriptionstringyesOrder description
currencystringyesCurrency, such as CNY
orderstringnoCommerce order ID. Once the payment is successful, the order payment status will be updated.
callbackCodeNamestringnoThe name of the callback code executed after payment is completed

Return: ChargeResponse

checkStatus()

Check payment status.

ts
k.api.get(() => {
    const status = k.payment.alipayForm.checkStatus('request-id')
    return { paid: status.paid, failed: status.failed, status: status.status }
})

parameter:

parametertypeRequiredillustrate
requestIdstringyescharge() returns requestId

Return: PaymentStatusResponse

updateOrder()

Handle payment callbacks and update orders. This method is only provided by alipayForm.

ts
k.api.post(() => {
    const callback = k.payment.alipayForm.updateOrder(k.payment.alipayForm.context)
    return { paid: callback.paid, status: callback.status }
})

parameter:

parametertypeRequiredillustrate
contextobjectyesCurrent payment callback context

Return: PaymentCallback

AlipaySetting

propertytypeillustrate
useSandBoxbooleanWhether to use a sandbox environment
appIdstringAlipay application ID
appPrivateKeystringApply private key
alipayPublicKeystringAlipay public key
signTypestringsignature type
charsetstringcoding
serverUrlstringAlipay gateway address