Skip to content

square

Square Payments.

Overview

k.payment.square is used to create Square Checkout payment requests. Square application and Location information need to be configured in the site CMS before use.

square.charge()

Create a Square Checkout payment request.

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

    return k.response.redirect(result.nextAction.redirectUrl)
})

Parameter: SquareCheckoutParams

ParameterTypeRequiredDescription
returnUrlstringyesReturn address after successful payment
totalAmountnumberyesOrder amount
namestringyesOrder name
descriptionstringyesOrder description
currencystringyesCurrency, such as USD
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.

Parameters:

ParameterTypeRequiredDescription
requestIdstringYesrequestId returned by charge().
ts
k.api.get(() => {
    const status = k.payment.square.checkStatus('request-id')
    return { paid: status.paid, failed: status.failed, status: status.status }
})

Return: PaymentStatusResponse

notify()

Handle Square notification callbacks.

Parameters:

ParameterTypeRequiredDescription
contextobjectYesCurrent payment notification context, usually k.payment.square.context.
ts
k.api.post(() => {
    const callback = k.payment.square.notify(k.payment.square.context)
    return { paid: callback.paid, status: callback.status }
})

Return: PaymentCallback

updateOrder()

Handle Square callbacks and update orders.

Parameters:

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

Return: PaymentCallback

SquareSetting

PropertyTypeDescription
useSandBoxbooleanWhether to use sandbox
applicationIdstringSquare Application ID
accessTokenstringSquare Access Token
locationIdstringSquare Location ID
baseURLstringSquare API address