Accéder directement au contenu
Créez un compte
ou
connecter-vous
Logo de la documentation Stripe
/
Ask AI
Créez un compte
Connectez-vous
Démarrer
Paiements
Automatisation des opérations financières
Plateformes et places de marché
Gestion de fonds
Outils de développement
Démarrer
Paiements
Automatisation des opérations financières
Démarrer
Paiements
Automatisation des opérations financières
Plateformes et places de marché
Gestion de fonds
Aperçu
Billing
    Présentation
    À propos des API Billing
    Abonnements
    Invoicing
    Facturation à la consommation
    Connect et Billing
    Tax et Billing
    Devis
    Recouvrement de revenus
    Automatisations
    Scripts
      Définition du langage de script
    Comptabilisation des revenus
    Gestion des clients
    Droits d'accès
    Tester votre intégration
Tax
Rapports
Données
Constitution de start-up
AccueilAutomatisation des opérations financièresBilling

Remarque

Cette page n'est pas encore disponible dans cette langue. Nous faisons tout notre possible pour proposer notre documentation dans davantage de langues et nous vous fournirons la version traduite dès qu'elle sera disponible.

Program your business logic directly on Stripe with scriptsVersion bêta privée

Use TypeScript to create custom logic and extend Stripe functionality.

Using a subset of Typescript, you can write and submit custom logic in Stripe. With scripts, you can:

  • Define your own logic for specific Stripe objects
  • Tailor your Stripe account for your specific business needs
  • Extend Stripe beyond its standard functionality

For example, you can use scripts to create custom discount logic on new coupons, and then apply the coupons to Subscriptions and Invoices.

Script lifecycle

See the following script lifecycle to understand how to use scripts:

  • Start by authoring custom logic for a supported use case.
  • As part of script-authoring, you can define configuration values. These are parameters that a script user passes when creating a custom object.
  • Stripe registers your script on the script service after you submit it for review.
  • You can then invoke the script when creating objects, such as a Coupon or Subscription object.

Function arguments

You can place the argument of the functions into two categories:

Author-defined values

You can think of author-defined values having two audiences:

  • Script author: The script author defines the function (that is, the actual logic) and the input values to the function. For example, you could write a “percent-up-to-a-maximum” script where the author defines two input values (percent and maximum).

  • Script user: After the script authore defines the values, the script user can define the values for the two inputs through the Dashboard or API (for example, 10% off a 100 USD maximum).

The script author decides what parts of the script to make customizable for the script user. The script user then applies their own values to the customizable parts of the script.

script configuration-1
export type scriptConfiguration = { max_discount_amount: { amount: number; currency: string; }, discount_percent: number; };

The SDK provides built-in types that you can use as part of your configuration definition. These built-in types render with a relevant input field UI in the Dashboard. If you have suggestions for new built-in types, contact scripts-preview@stripe.com or our Support team.

script configuration-2
import type {PositiveMonetaryAmount, Percent} from '@stripe/scripts'; export type scriptConfiguration = { max_discount_amount: PositiveMonetaryAmount; discount_percent: Percent; };

Configuration values have default schema validations when the script user tries to set the values. In addition, you can define custom validation by referencing the schema validations. If we don’t support your validation use case, we recommend building the validation check into your function definition and contacting scripts-preview@stripe.com.

Stripe-defined values

Stripe provides argument values, and you can’t customize them. We provide the values at function runtime, and they typically include Stripe objects such as the Customer or Line Item objects. The specific objects vary by function interface. If you’re missing any data you need, contact scripts-preview@stripe.com.

Stripe provided parameter example
/** * DiscountableLineItem data structure * * @typedef {Object} DiscountableLineItem * @property {MonetaryAmount} subtotal * @property {string | null} price_id * @property {number | null} quantity * @property {MonetaryAmount | null} unit_amount * @property {TimeRange} period * @property {Price | null} price */ export interface DiscountableLineItem { subtotal: MonetaryAmount; price_id?: string | null; quantity?: number | null; unit_amount?: MonetaryAmount | null; period: TimeRange; price?: Price | null; }

Function logic

The script author defines the customization used by the script function logic. All arguments are “pass by value,” which means any modifications made to the argument values within the function don’t affect the original value outside the function.

Handling runtime errors appropriately

In most cases, you want to catch the error and have fallback behavior. In rare cases, you might want to throw an exception. Throwing an exception halts the entire code execution associated with the script, so only throw an exception when no other option exists.

Write tests against your sandbox

Although we don’t mandate that you use an automated test suite with your script function, we recommend it. You can write tests against your sandbox environment, but the legacy test mode environment doesn’t support scripts. If you need guidance, contact scripts-preview@stripe.com.

Function return value

The return value of the function must abide by the interface, which varies by customization. Consult the SDK for the specific interface definition, and make sure your function abides by the interface.

Next steps

Learn more about script coupons and how to author your own scripts.

Cette page vous a-t-elle été utile ?
OuiNon
Besoin d'aide ? Contactez le service Support.
Rejoignez notre programme d'accès anticipé.
Consultez notre log des modifications.
Des questions ? Contactez l'équipe commerciale.
LLM ? Lire llms.txt.
Propulsé par Markdoc