Skip to content

two-checkout

TwoCheckout payment.

Overview

k.payment.twoCheckout is used to create TwoCheckout payment requests, supporting card information and 3D verification jumps. TwoCheckout merchant information needs to be configured in the site CMS before use.

twoCheckout.charge()

Create a TwoCheckout payment request.

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

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

Parameter: TwoCheckoutParams

ParameterTypeRequiredDescription
cancelUrlstringyesJump address after cancellation of 3D verification
returnUrlstringyesJump address after successful 3D verification
cardCardyesCard information
cardTypestringyesCard type, such as Visa, Mastercard, Amex
billingAddressAddressyesbilling address
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.twoCheckout.checkStatus('request-id')
    return { paid: status.paid, failed: status.failed, status: status.status }
})

Return: PaymentStatusResponse

updateOrder()

Handle the TwoCheckout callback and update the order.

Parameters:

ParameterTypeRequiredDescription
contextobjectYesCurrent payment callback context, usually 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 }
})

Return: PaymentCallback

Card

PropertyTypeDescription
numberstringcard number
cvcstringCVC
expMonthstringExpiration month
expYearstringExpiration year
namestringCardholder name

Address

PropertyTypeDescription
firstNamestringname
lastNamestringsurname
countryCodestringcountry code
statestringstate or province
citystringCity
address1stringaddress
zipstringpost code
emailstringMail
phonestringTelephone

TwoCheckoutSetting

PropertyTypeDescription
baseUrlstringTwoCheckout interface address
merchantCodestringMerchant Code
secretKeystringSecret Key
testModebooleanWhether to test mode