k.payment.paypalCheckout / paypalForm
PayPal payments (Checkout and Form modes).
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Configure PaypalSetting or PaypalFormSetting in site CMS | Create PayPal Checkout / Form charges and handle completion or IPN callbacks |
Quick Start
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"
})
k.response.setHeader("Content-Type", "text/html; charset=utf-8")
k.response.write(result.nextAction.renderHtml)
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
paypalCheckout.charge(params) | Create a PayPal Checkout payment request | ChargeResponse |
paypalForm.charge(params) | Create a PayPal form payment request | ChargeResponse |
paypalCheckout.checkStatus(requestId) | Check payment status (paypalForm throws on call) | PaymentStatusResponse |
Payment Modes
| API | Description |
|---|---|
k.payment.paypalCheckout | PayPal Checkout |
k.payment.paypalForm | PayPal form payment |
paypalCheckout.charge()
Create a PayPal Checkout payment request.
| Parameter | Type | Required | Description |
|---|---|---|---|
cancelUrl | string | Yes | Return URL when canceling payment |
returnUrl | string | Yes | Return URL after successful payment |
brandName | string | No | Brand name displayed on the PayPal checkout page |
customer | string | No | Customer identifier (currently unused by the PaypalCheckout implementation; kept for parameter compatibility) |
totalAmount | number | Yes | Order amount |
name | string | Yes | Order name |
description | string | Yes | Order description |
currency | string | Yes | Currency, such as USD |
order | string | No | Commerce order ID. Updates order payment status when paid |
callbackCodeName | string | No | Callback code name executed after payment completes |
Returns: ChargeResponse
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",
callbackCodeName: "PaymentCallback"
})
k.response.setHeader("Content-Type", "text/html; charset=utf-8")
k.response.write(result.nextAction.renderHtml)
})paypalForm.charge()
Create a PayPal form payment request.
| Parameter | Type | Required | Description |
|---|---|---|---|
cancelUrl | string | Yes | Return URL when canceling payment |
returnUrl | string | Yes | Return URL after successful payment |
totalAmount | number | Yes | Order amount |
name | string | Yes | Order name |
description | string | Yes | Order description |
currency | string | Yes | Currency, such as USD |
order | string | No | Commerce order ID. Updates order payment status when paid |
callbackCodeName | string | No | Callback code name executed after payment completes |
Returns: ChargeResponse
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"
})
k.response.setHeader("Content-Type", "text/html; charset=utf-8")
k.response.write(result.nextAction.renderHtml)
})checkStatus()
Check payment status. Only paypalCheckout supports this method; calling paypalForm.checkStatus() throws "Check status not support in paypal form basic payment method".
| Parameter | Type | Required | Description |
|---|---|---|---|
requestId | string | Yes | requestId returned by charge() |
Returns: PaymentStatusResponse
k.api.get(() => {
const status = k.payment.paypalCheckout.checkStatus("request-id")
return { paid: status.paid, failed: status.failed, status: status.status }
})Callback Handling
Kooboo automatically registers and handles the following built-in callback routes for PayPal:
/_api/paymentcallback/PaypalCheckout_UpdateOrder: Automatically sent bypaypalCheckout.charge()asreturn_url. When the buyer returns, Kooboo verifies/captures the PayPal order, invokesPaymentManager.CallBack(...)to updatePaymentRequest, mark any linked Commerceorderpaid, and executecallbackCodeName, then redirects 302 to yourreturnUrl./_api/paymentcallback/PaypalForm_NofityUrl: Automatically set bypaypalForm.charge()as the form'snotify_url(note theNofityUrlspelling). When PayPal posts an IPN message, Kooboo verifies it back against PayPal, checks receiver email, currency, and amount, and invokesPaymentManager.CallBack(...)to updatePaymentRequestand linked Commerce orders.
paypalCheckout.updateOrder(context) and paypalForm.nofityUrl(context) are internal callback handlers—do not invoke them directly inside KScript to update orders. Direct calls do not trigger PaymentManager.CallBack(...); furthermore, paypalCheckout.updateOrder throws NullReferenceException when requestid is missing, and paypalForm.nofityUrl returns PaymentCallback | null (null on IPN verification failure or field mismatch).
For custom post-payment handling in KScript, configure callbackCodeName, or call k.payment.paypalCheckout.checkStatus(requestId) (Checkout) / k.payment.getRequest(requestId) (Form or Checkout) in your return handler.
Configuration Structure
PaypalSetting
| Property | Type | Description |
|---|---|---|
paypalUrl | string | PayPal API endpoint |
useSandBox | boolean | Whether sandbox mode is enabled |
clientId | string | PayPal Client ID |
secret | string | PayPal Secret |
PaypalFormSetting
| Property | Type | Description |
|---|---|---|
paypalUrl | string | PayPal API endpoint |
iPNUrl | string | Read-only computed URL of PayPal's own IPN verification endpoint (https://ipnpb.paypal.com/cgi-bin/webscr in live mode or https://www.sandbox.paypal.com/cgi-bin/webscr in sandbox), not a configurable site callback URL |
emailAddress | string | Merchant account email |
logoImage | string | Checkout page logo URL |
useSandBox | boolean | Whether sandbox mode is enabled |
TypeScript Definitions
Show full TypeScript definitions
interface PaypalCheckout {
setting: PaypalSetting;
charge(params: PaypalCheckoutParams): ChargeResponse;
/** Internal callback handler invoked by /_api/paymentcallback/PaypalCheckout_UpdateOrder; do not call directly in KScript */
updateOrder(context: any): PaymentCallback;
checkStatus(requestId: string): PaymentStatusResponse;
}
interface PaypalForm {
setting: PaypalFormSetting;
charge(params: PaypalFormParams): ChargeResponse;
/** Internal IPN handler invoked by /_api/paymentcallback/PaypalForm_NofityUrl; do not call directly in KScript */
nofityUrl(context: any): PaymentCallback | null;
/** Not supported by PaypalForm; throws at runtime */
checkStatus(requestId: string): PaymentStatusResponse;
}
interface PaypalCheckoutParams extends ChargeParams {
cancelUrl: string;
returnUrl: string;
brandName: string;
customer: string;
}
interface PaypalFormParams extends ChargeParams {
cancelUrl: string;
returnUrl: string;
}
interface PaypalSetting {
name: string;
group: string;
paypalUrl: string;
useSandBox: boolean;
clientId: string;
secret: string;
}
interface PaypalFormSetting {
name: string;
group: string;
readonly paypalUrl: string;
readonly iPNUrl: string;
emailAddress: string;
logoImage: string;
useSandBox: boolean;
}