Skip to content

paypal

PayPal payment.

Overview

PayPal payment includes Checkout and Form. PayPal account or application information needs to be configured in the site CMS before use.

APIillustrate
k.payment.paypalCheckoutPayPal Checkout
k.payment.paypalFormPayPal form payment

paypalCheckout.charge()

Create a PayPal Checkout payment request.

ts
k.api.get(() => {
    const result = k.payment.paypalCheckout.charge({
        name: 'T-shirt',
        description: 'Order payment',
        totalAmount: 1.5,
        currency: 'USD',
        order: 'order-id',
        returnUrl: '/payment/success?orderId=order-id',
        cancelUrl: '/payment/cancel?orderId=order-id',
        brandName: 'Kooboo Store',
        customer: 'customer@example.com',
        callbackCodeName: 'PaymentCallback'
    })

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

Parameter: PaypalCheckoutParams

parametertypeRequiredillustrate
cancelUrlstringyesReturn address when canceling payment
returnUrlstringyesReturn address after successful payment
brandNamestringnoThe brand name displayed on the PayPal payment page
customerstringnoCustomer ID
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

paypalForm.charge()

Create a PayPal form payment request.

ts
k.api.get(() => {
    const result = k.payment.paypalForm.charge({
        name: 'T-shirt',
        description: 'Order payment',
        totalAmount: 1.5,
        currency: 'USD',
        order: 'order-id',
        returnUrl: '/payment/success?orderId=order-id',
        cancelUrl: '/payment/cancel?orderId=order-id'
    })

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

Parameter: PaypalFormParams

parametertypeRequiredillustrate
cancelUrlstringyesReturn address when canceling payment
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.

ts
k.api.get(() => {
    const status = k.payment.paypalCheckout.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. paypalCheckout provides this method.

Parameters:

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

Return: PaymentCallback

nofityUrl()

Handle PayPal Form notification callbacks. The method name is nofityUrl in the current type definition.

Parameters:

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

Return: PaymentCallback

Configuration structure

PaypalSetting

propertytypeillustrate
paypalUrlstringPayPal interface address
useSandBoxbooleanWhether to use sandbox
clientIdstringPayPal Client ID
secretstringPayPal Secret

PaypalFormSetting

propertytypeillustrate
paypalUrlstringPayPal interface address
iPNUrlstringIPN notification address
emailAddressstringPayment account email
logoImagestringPayment page logo
useSandBoxbooleanWhether to use sandbox