Skip to content

stripe

Stripe payments.

Overview

Stripe payment includes Checkout and PaymentIntent. The Stripe key and Webhook signing key need to be configured in the site CMS before use.

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

stripeCheckout.charge()

Create a Stripe Checkout payment request.

ts
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'
    })

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

Parameter: StripeCheckoutParams

parametertypeRequiredillustrate
cancelUrlstringyesCheckout return button or cancel payment address
returnUrlstringyesReturn address after successful payment
customerstringnoCustomer ID. Provided to automatically create a Stripe Customer
totalAmountnumberyesOrder amount
namestringyesOrder name
descriptionstringyesOrder description
currencystringyesCurrency, such as USD, EUR
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

stripe.charge()

Create a Stripe PaymentIntent payment request.

ts
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: 'customer-id',
        paymentMethodId: 'payment-method-id',
        card: {
            number: '4242424242424242',
            expMonth: '12',
            expYear: '2030',
            cvc: '123',
            name: 'John Doe'
        }
    })

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

Parameter: StripePaymentIntentParams

parametertypeRequiredillustrate
returnUrlstringyesReturn address after payment is completed
cardCardnoCard information
paymentMethodIdstringnoSaved Stripe PaymentMethod ID
customerstringnoStripe Customer ID or customer identification
totalAmountnumberyesOrder amount
namestringyesOrder name
descriptionstringyesOrder description
currencystringyesCurrency, such as USD, EUR
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.stripeCheckout.checkStatus('request-id')
    return { paid: status.paid, failed: status.failed, status: status.status }
})

Return: PaymentStatusResponse

getCardList()

Get the list of cards saved by the specified customer.

ts
k.api.get(() => {
    return k.payment.stripe.getCardList('customer-id')
})

parameter:

parametertypeRequiredillustrate
customerstringyesStripe Customer ID

Return: any

createCard()

Create cards for customers.

Parameters:

ParameterTypeRequiredDescription
customerstringYesStripe Customer ID.
cardCardYesCard information to save.
ts
k.api.post(() => {
    return k.payment.stripe.createCard('customer-id', {
        number: '4242424242424242',
        expMonth: '12',
        expYear: '2030',
        cvc: '123',
        name: 'John Doe'
    })
})

Return: string

removeCard()

Remove the card from the customer.

Parameters:

ParameterTypeRequiredDescription
cardIdstringYesStripe card ID to remove.
ts
k.api.post(() => {
    k.payment.stripe.removeCard('card-id')
    return 'success'
})

Return: void

updateOrder()

Handle Stripe Checkout callbacks and update orders.

Parameters:

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

Return: PaymentCallback

Card

propertytypeillustrate
numberstringcard number
cvcstringCVC
expMonthstringExpiration month
expYearstringExpiration year
namestringCardholder name

StripeSetting

propertytypeillustrate
secretKeystringStripe Secret Key
webhookSigningSecretstringWebhook signing key