createCharge

Creates a charge in Stripe. Under the hood, this action calls the create a charge API endpoint.

Configuration

This function type accepts the following parameters:

KeyTypeDefaultDescription
secretKeystring@stripe-secret-keyYour Stripe secret key

Run the following command to add your Stripe secret key:

statickit secrets add stripe-secret-key <your-secret-key> -k <your-deploy-key>

Example

{
"functions": {
"createCharge": {
"app": "stripe",
"type": "createCharge"
}
}
}

Arguments

This function type accepts the following client-side arguments when called:

KeyTypeDefaultDescription
amount *integerThe amount to charge (in cents). E.g. to charge $100, amount is 10000.
currencystringusdThree-letter ISO currency code, in lowercase.
descriptionstringAn arbitrary description for the charge.
metadataobjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata.
sourcestringA payment source token (e.g. generated from Stripe Elements).
customerTokenstringA customer token (returned from creating a customer)

Example

import { createClient, createCharge } from '@statickit/functions';
let client = createClient({ site: '{your-site-id}' });
let { status } = await createCharge(client, {
amount: 10000 // $100.00
source: "tok_XXXXX"
});

Response

Returns a status and the following properties when successful:

KeyTypeDescription
idstringA unique identifier for the charge
paymentStatusstringThe status of the payment: succeeded, pending, or failed.

Sandbox Limits

Only Stripe test keys are permitted on the Sandbox plan. Upgrade to production to use live keys.