Skip to content

k.payment.stripeCheckout / stripe ​

Stripe payments (Checkout and PaymentIntent).

Execution ContextPrerequisitesTypical 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 CMSCreate Stripe Checkout or PaymentIntent charges, manage saved cards, and handle callbacks

Quick Start ​

js
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 / PropertyDescriptionReturns
stripeCheckout.charge(params)Create a Stripe Checkout hosted page chargeChargeResponse
stripe.charge(params)Create a Stripe PaymentIntent card chargeChargeResponse
<provider>.checkStatus(requestId)Check payment status by requestIdPaymentStatusResponse
stripe.getCardList(customer)List saved cards for a site customer identifierany
stripe.createCard(customer, card)Map a site customer identifier to a Stripe Customer and attach a new cardstring
stripe.removeCard(cardId)Detach a saved card from a customervoid

Payment Modes ​

APIDescription
k.payment.stripeCheckoutStripe Checkout hosted payment page
k.payment.stripeStripe PaymentIntent and card management

stripeCheckout.charge() ​

Create a Stripe Checkout payment request.

ParameterTypeRequiredDescription
cancelUrlstringYesCheckout back/cancel redirect URL
returnUrlstringYesReturn URL after successful payment
customerstringNoSite-side customer identifier (such as email or user ID, not a raw cus_... ID); Kooboo maps/creates the Stripe Customer by name
totalAmountnumberYesOrder amount
namestringYesOrder name
descriptionstringYesOrder description
currencystringYesCurrency, such as USD, EUR
orderstringNoCommerce order ID. Updates order payment status when paid
callbackCodeNamestringNoCallback code name executed after payment completes

Returns: ChargeResponse

js
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:

  • card and paymentMethodId are alternatives—provide one or the other (passing card creates a new Stripe PaymentMethod and silently overwrites paymentMethodId; omitting both fails Stripe confirmation).
  • customer is your site-side customer identifier (such as a user ID or email), not a raw Stripe cus_... ID. Kooboo looks up the mapping in its PaymentCustomer table and only attaches customer to the PaymentIntent if that identifier was previously registered via stripe.createCard(customer, card) (required when charging a saved paymentMethodId attached via createCard()).
ParameterTypeRequiredDescription
returnUrlstringYesReturn URL after 3DS or payment completion
cardCardNoOne-time card details (alternative to paymentMethodId; overrides paymentMethodId if both are passed)
paymentMethodIdstringNoSaved Stripe PaymentMethod ID (alternative to card)
customerstringNoSite-side customer identifier (not a raw cus_... ID; only attached to the PaymentIntent if previously registered via stripe.createCard())
totalAmountnumberYesOrder amount
namestringYesOrder name
descriptionstringYesOrder description
currencystringYesCurrency, such as USD, EUR
orderstringNoCommerce order ID. Updates order payment status when paid
callbackCodeNamestringNoCallback code name executed after payment completes

Returns: ChargeResponse

Option 1: Charge with one-time card details:

js
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):

js
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.

ParameterTypeRequiredDescription
requestIdstringYesrequestId returned by charge()

Returns: PaymentStatusResponse

js
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.

ParameterTypeRequiredDescription
customerstringYesSite-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

js
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.

ParameterTypeRequiredDescription
customerstringYesSite-side customer identifier (such as user ID or email—not a raw Stripe cus_... ID)
cardCardYesCard details to save

Returns: string

js
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.

ParameterTypeRequiredDescription
cardIdstringYesStripe card/PaymentMethod ID to remove

Returns: void

js
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 by stripeCheckout.charge() as Stripe Checkout's success_url. When the buyer returns, Kooboo checks the session status, invokes PaymentManager.CallBack(...), and redirects 302 to your returnUrl.
  • /_api/paymentcallback/Stripe_UpdateOrder: Automatically configured by stripe.charge() as the PaymentIntent 3DS return_url.
  • /_api/paymentcallback/StripeCheckout_Notify / /_api/paymentcallback/Stripe_Notify: Configure these webhook URLs in your Stripe dashboard along with webhookSigningSecret to 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 ​

PropertyTypeDescription
numberstringCard number
cvcstringCVC security code
expMonthstringExpiration month
expYearstringExpiration year
namestringCardholder name

StripeSetting / StripeCheckoutSetting ​

PropertyTypeDescription
secretKeystringStripe Secret Key
webhookSigningSecretstringWebhook signing key
paymentMethodsstringStripeCheckoutSetting only; allowed payment methods for Stripe Checkout

TypeScript Definitions ​

Show full TypeScript definitions
ts
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;
}