k.payment.stripeCheckout / stripe
Stripe payments (Checkout and PaymentIntent).
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
KScript API (k.api.get / k.api.post), server-side <script env="server"> | Configure StripeSetting / StripeCheckoutSetting (Secret Key and Webhook Signing Secret) in site CMS | Create Stripe Checkout or PaymentIntent charges, manage saved cards, and handle callbacks |
Quick Start
k.api.get(() => {
const result = k.payment.stripeCheckout.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 |
|---|---|---|
stripeCheckout.charge(params) | Create a Stripe Checkout hosted page charge | ChargeResponse |
stripe.charge(params) | Create a Stripe PaymentIntent card charge | ChargeResponse |
<provider>.checkStatus(requestId) | Check payment status by requestId | PaymentStatusResponse |
stripe.getCardList(customer) | List saved cards for a site customer identifier | any |
stripe.createCard(customer, card) | Map a site customer identifier to a Stripe Customer and attach a new card | string |
stripe.removeCard(cardId) | Detach a saved card from a customer | void |
Payment Modes
| API | Description |
|---|---|
k.payment.stripeCheckout | Stripe Checkout hosted payment page |
k.payment.stripe | Stripe PaymentIntent and card management |
stripeCheckout.charge()
Create a Stripe Checkout payment request.
| Parameter | Type | Required | Description |
|---|---|---|---|
cancelUrl | string | Yes | Checkout back/cancel redirect URL |
returnUrl | string | Yes | Return URL after successful payment |
customer | string | No | Site-side customer identifier (such as email or user ID, not a raw cus_... ID); Kooboo maps/creates the Stripe Customer by name |
totalAmount | number | Yes | Order amount |
name | string | Yes | Order name |
description | string | Yes | Order description |
currency | string | Yes | Currency, such as USD, EUR |
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.stripeCheckout.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",
customer: "customer@example.com",
callbackCodeName: "PaymentCallback"
})
k.response.setHeader("Content-Type", "text/html; charset=utf-8")
k.response.write(result.nextAction.renderHtml)
})stripe.charge()
Create a Stripe PaymentIntent payment request.
Important:
cardandpaymentMethodIdare alternatives—provide one or the other (passingcardcreates a new Stripe PaymentMethod and silently overwritespaymentMethodId; omitting both fails Stripe confirmation).customeris your site-side customer identifier (such as a user ID or email), not a raw Stripecus_...ID. Kooboo looks up the mapping in itsPaymentCustomertable and only attachescustomerto the PaymentIntent if that identifier was previously registered viastripe.createCard(customer, card)(required when charging a savedpaymentMethodIdattached viacreateCard()).
| Parameter | Type | Required | Description |
|---|---|---|---|
returnUrl | string | Yes | Return URL after 3DS or payment completion |
card | Card | No | One-time card details (alternative to paymentMethodId; overrides paymentMethodId if both are passed) |
paymentMethodId | string | No | Saved Stripe PaymentMethod ID (alternative to card) |
customer | string | No | Site-side customer identifier (not a raw cus_... ID; only attached to the PaymentIntent if previously registered via stripe.createCard()) |
totalAmount | number | Yes | Order amount |
name | string | Yes | Order name |
description | string | Yes | Order description |
currency | string | Yes | Currency, such as USD, EUR |
order | string | No | Commerce order ID. Updates order payment status when paid |
callbackCodeName | string | No | Callback code name executed after payment completes |
Returns: ChargeResponse
Option 1: Charge with one-time card details:
k.api.post(() => {
const result = k.payment.stripe.charge({
name: "T-shirt",
description: "Order payment",
totalAmount: 1.5,
currency: "USD",
order: "order-id",
returnUrl: "/payment/success?orderId=order-id",
card: {
number: "4242424242424242",
expMonth: "12",
expYear: "2030",
cvc: "123",
name: "John Doe"
}
})
return { paid: result.paid, requestId: result.requestId, nextAction: result.nextAction }
})Option 2: Charge a saved paymentMethodId previously attached via stripe.createCard() (with matching customer identifier):
k.api.post(() => {
const result = k.payment.stripe.charge({
name: "T-shirt",
description: "Order payment",
totalAmount: 1.5,
currency: "USD",
order: "order-id",
returnUrl: "/payment/success?orderId=order-id",
customer: "user-1001", // Must have been registered via stripe.createCard("user-1001", card)
paymentMethodId: "pm_xxx"
})
return { paid: result.paid, requestId: result.requestId, nextAction: result.nextAction }
})checkStatus()
Check payment status.
| Parameter | Type | Required | Description |
|---|---|---|---|
requestId | string | Yes | requestId returned by charge() |
Returns: PaymentStatusResponse
k.api.get(() => {
const status = k.payment.stripeCheckout.checkStatus("request-id")
return { paid: status.paid, failed: status.failed, status: status.status }
})getCardList()
Get the list of cards saved for a site customer identifier.
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | Yes | Site-side customer identifier (such as user ID or email) matching the key used in createCard()—not a raw Stripe cus_... ID (unmapped keys return []) |
Returns: any
k.api.get(() => {
return k.payment.stripe.getCardList("user-1001")
})createCard()
Look up or create a Stripe Customer by name for a site-side customer identifier, store the mapping in Kooboo's PaymentCustomer table, and attach a new card.
| Parameter | Type | Required | Description |
|---|---|---|---|
customer | string | Yes | Site-side customer identifier (such as user ID or email—not a raw Stripe cus_... ID) |
card | Card | Yes | Card details to save |
Returns: string
k.api.post(() => {
return k.payment.stripe.createCard("user-1001", {
number: "4242424242424242",
expMonth: "12",
expYear: "2030",
cvc: "123",
name: "John Doe"
})
})removeCard()
Detach a saved card from a customer.
| Parameter | Type | Required | Description |
|---|---|---|---|
cardId | string | Yes | Stripe card/PaymentMethod ID to remove |
Returns: void
k.api.post(() => {
k.payment.stripe.removeCard("card-id")
return { cards: k.payment.stripe.getCardList("user-1001") }
})Callback Handling
Kooboo automatically registers and handles the following Stripe callback endpoints, calling PaymentManager.CallBack(...) to update PaymentRequest, mark linked Commerce orders as paid, and run callbackCodeName:
/_api/paymentcallback/StripeCheckout_UpdateOrder: Automatically configured bystripeCheckout.charge()as Stripe Checkout'ssuccess_url. When the buyer returns, Kooboo checks the session status, invokesPaymentManager.CallBack(...), and redirects 302 to yourreturnUrl./_api/paymentcallback/Stripe_UpdateOrder: Automatically configured bystripe.charge()as the PaymentIntent 3DSreturn_url./_api/paymentcallback/StripeCheckout_Notify//_api/paymentcallback/Stripe_Notify: Configure these webhook URLs in your Stripe dashboard along withwebhookSigningSecretto process asynchronous Stripe events automatically.
stripeCheckout.updateOrder(context) is an internal callback handler—do not invoke it directly in KScript to update orders (direct calls bypass PaymentManager.CallBack(...) and throw NullReferenceException when requestid is missing). For custom post-payment handling in KScript, configure callbackCodeName in charge() or call checkStatus(requestId) in your returnUrl handler.
Data & Configuration Structures
Card
| Property | Type | Description |
|---|---|---|
number | string | Card number |
cvc | string | CVC security code |
expMonth | string | Expiration month |
expYear | string | Expiration year |
name | string | Cardholder name |
StripeSetting / StripeCheckoutSetting
| Property | Type | Description |
|---|---|---|
secretKey | string | Stripe Secret Key |
webhookSigningSecret | string | Webhook signing key |
paymentMethods | string | StripeCheckoutSetting only; allowed payment methods for Stripe Checkout |
TypeScript Definitions
Show full TypeScript definitions
interface StripeCheckout {
setting: StripeCheckoutSetting;
charge(params: StripeCheckoutParams): ChargeResponse;
/** Internal callback handler invoked by /_api/paymentcallback/StripeCheckout_UpdateOrder; do not call directly in KScript */
updateOrder(context: any): PaymentCallback;
checkStatus(requestId: string): PaymentStatusResponse;
}
interface StripePaymentIntent {
setting: StripeSetting;
charge(params: StripePaymentIntentParams): ChargeResponse;
getCardList(customer: string): any;
createCard(customer: string, card: any): string;
removeCard(cardId: string): void;
checkStatus(requestId: string): PaymentStatusResponse;
}
interface StripeCheckoutParams extends ChargeParams {
cancelUrl: string;
returnUrl: string;
customer: string;
}
interface StripePaymentIntentParams extends ChargeParams {
returnUrl: string;
card: any;
paymentMethodId: string;
customer: string;
}
interface StripeSetting {
name: string;
secretKey: string;
webhookSigningSecret: string;
group: string;
}
interface StripeCheckoutSetting extends StripeSetting {
paymentMethods: string;
}