agentleFS
StripeKnown publisherstripe/stripe-commercetools-checkout-app/CLAUDE.md

stripe-commercetools-checkout-app

CLAUDE.md7 starsChanged 8 months agoMITView on GitHub

Two initialization paths: - Session flow (_Setup): fetches /config-element/payment + /operations/config + /customer/session using x-session-id header - Express no-session flow (_SetupExpress): fetches POST /express-config (CORS-only, no session needed) Supported builders: - createDropinBuilder('embedded') → Stripe Payment Element - createExpressBuilder('dropin') → Stripe Express Checkout Element - createComponentBuilder(type) → individual components (currently empty)

  • Reads credentials
  • Installs packages

The file

We split this CLAUDE.md into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Default: checkout-stripe (configurable via PAYMENT_INTERFACE)

    line 114
  2. Very specific:

    All keys are configurable via CT_CUSTOM_TYPE_* / CT_PRODUCT_TYPE_* env vars.

    line 127

≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Stripe + commercetools Checkout Connector

What This Is

A commercetools Connect payment connector that integrates Stripe into the commercetools Checkout product (pre-built checkout, part of their Payment Hub framework). It supports the Stripe Payment Element and Express Checkout Element via commercetools' drop-in framework.

What This Is NOT

  • This is NOT a storefront or commerce solution — merchants build their own
  • This does NOT manage order state — commercetools Checkout handles that automatically
  • This does NOT enforce a reference architecture for order flows
  • Source code is public; merchants can use it natively from the Connect marketplace or fork it as a "custom connect application"

Two-Module Architecture

Enabler (enabler/) — Frontend Assets

Vite-bundled library deployed as assets via Connect. Wraps Stripe.js elements for commercetools' drop-in framework.

FileRole
src/main.tsEntry point — exports MockPaymentEnabler as Enabler
src/payment-enabler/payment-enabler.tsInterfaces: PaymentEnabler, builders, components, ExpressOptions
src/payment-enabler/payment-enabler-mock.tsMain class: MockPaymentEnabler — setup, Stripe SDK loading, element creation
src/dropin/dropin-embedded.tsDropinEmbeddedBuilder + DropinComponents — Payment Element drop-in
src/express/dropin-express.tsStripeExpressBuilder + StripeExpressComponent — Express Checkout
src/express/base.tsDefaultExpressComponent — abstract base with callback delegation
src/components/base.tsBaseComponent — abstract base for individual components

Two initialization paths:

  • Session flow (_Setup): fetches /config-element/payment + /operations/config + /customer/session using x-session-id header
  • Express no-session flow (_SetupExpress): fetches POST /express-config (CORS-only, no session needed)

Supported builders:

  • createDropinBuilder('embedded') → Stripe Payment Element
  • createExpressBuilder('dropin') → Stripe Express Checkout Element
  • createComponentBuilder(type) → individual components (currently empty)

Processor (processor/) — Backend Service

Fastify HTTP service deployed as service via Connect.

FileRole
src/main.tsEntry point
src/config/config.tsAll environment variable configuration
src/payment-sdk.tsCT Payment SDK singleton setup
src/server/app.tsWires StripePaymentService with CT SDK services
src/routes/stripe-payment.route.tsPayment, webhook, config, customer, express routes
src/routes/operation.route.ts/operations/* endpoints
src/services/stripe-payment.service.tsCore business logic (~900 lines)
src/services/converters/stripeEventConverter.tsStripe events → CT transaction data
src/services/commerce-tools/CT client helpers (customer, custom types, product types)
src/clients/stripe.client.tsStripe API client factory (includes partner ID pp_partner_c0mmercet00lsc0NNect)
src/connectors/actions.tsPost-deploy / pre-undeploy actions
src/connectors/post-deploy.tsCreates custom types, updates Stripe webhook URL
src/connectors/pre-undeploy.tsRemoves custom types
src/custom-types/custom-types.tsCT TypeDraft/ProductTypeDraft definitions
src/constants.tsCT_CUSTOM_FIELD_TAX_CALCULATIONS
src/libs/fastify/cors/cors.tsCORS origin validation hook
src/libs/fastify/hooks/stripe-header-auth.hook.tsStripe webhook signature check

API Endpoints

Stripe Payment Routes

MethodPathAuthPurpose
GET/paymentsSessionCreate PaymentIntent (supports x-express-checkout header)
POST/confirmPayments/:idSessionConfirm payment in CT after Stripe confirms
GET/config-element/:paymentComponentSessionElement config (appearance, layout, cart info)
GET/customer/sessionSessionGet/create Stripe customer session
POST/stripe/webhooksStripe signatureReceive Stripe webhook events
POST/express-configCORSPublic config for express buttons (no session)
GET/applePayConfigNoneApple Pay domain association file

Operation Routes

MethodPathAuthPurpose
GET/operations/configSessionpublishableKey + environment
GET/operations/statusJWTHealth check
GET/operations/payment-componentsJWTSupported components list
POST/operations/payment-intents/:idOAuth2 + AuthZModify payment (capture/refund/cancel)

Webhook Event → CT Transaction Mapping

Stripe EventCT Transaction TypeCT StateAmount Source
payment_intent.canceledAuthorizationFailurePI amount
payment_intent.canceledCancelAuthorizationSuccessPI amount
payment_intent.succeededChargeSuccessPI amount_received
payment_intent.payment_failedAuthorizationFailurePI amount_received
charge.succeededAuthorizationSuccessCharge amount_refunded
charge.refundedRefund + ChargebackSuccessCharge amount_refunded
charge.updatedChargeSuccessCharge amount (multicapture only)

Events route through StripeEventConverter.convert() which extracts ct_payment_id from metadata.

Key Patterns and Conventions

CT ↔ Stripe Linking

  • metadata.ct_payment_id on PaymentIntent links to commercetools payment ID
  • stripeConnector_stripeCustomerId custom field on CT customer stores Stripe customer ID
  • connectorStripeTax_calculationReferences cart custom field feeds Stripe Tax

Feature Flag: STRIPE_ENABLE_MULTI_OPERATIONS

When true:

  • charge.refunded → enhanced processStripeEventRefunded() (queries Stripe for latest refund)
  • charge.updated → processStripeEventMultipleCaptured() (partial capture tracking)
  • PaymentIntent created with request_multicapture: 'if_available'
  • Partial captures use final_capture: false

When false (default):

  • charge.refunded → basic converter flow
  • charge.updated → skipped
  • Partial capture attempts throw error

Payment Interface

Default: checkout-stripe (configurable via PAYMENT_INTERFACE)

Stripe API Version

Default: 2025-12-15.clover (configurable via STRIPE_API_VERSION)

Custom Types (managed by deploy scripts)

KeyResourceFields
payment-launchpad-purchase-orderpaymentpurchaseOrderNumber, invoiceMemo
payment-connector-stripe-customer-idcustomerstripeConnector_stripeCustomerId
payment-connector-subscription-line-item-typeline-itemproductSubscriptionId, stripeSubscriptionId, stripeSubscriptionError
payment-connector-subscription-informationproduct typerecurring interval, collection method, trial, billing cycle attributes

All keys are configurable via CT_CUSTOM_TYPE_* / CT_PRODUCT_TYPE_* env vars.

Payment Flows

Drop-in (Payment Element)

  1. Enabler fetches config → loads Stripe SDK → creates Elements + PaymentElement
  2. Checkout mounts PaymentElement to DOM
  3. On submit: elements.submit() → GET /payments (creates PI) → sdk.confirmPayment() → POST /confirmPayments/:id
  4. Webhooks update CT payment with transaction states

Express Checkout

  1. Enabler creates ExpressCheckoutElement (with initialAmount)
  2. User clicks pay → onPayButtonClick gets session → modal opens
  3. User selects address → shippingaddresschange → callbacks update cart
  4. User selects shipping → shippingratechange → callbacks update cart + amount
  5. User confirms → elements.submit() → GET /payments (with x-express-checkout: true, no shipping on PI) → sdk.confirmPayment() → POST /confirmPayments/:id

BNPL Return Flow

For redirect-based methods (BNPL), Stripe appends payment_intent to MERCHANT_RETURN_URL. Merchant must extract ct_payment_id from PI metadata and pass as paymentReference to CT Checkout SDK.

Connect Deployment (connect.yaml)

  • Enabler: applicationType: assets
  • Processor: applicationType: service, endpoint /
    • postDeploy: creates custom types + updates Stripe webhook URL
    • preUndeploy: removes custom types (subscription product type, line item type, customer type)

Dev Commands

Processor

cd processor
cp .env.template .env  # fill in values
npm install
npm run build
npm run dev            # local development
npm run test
npm run lint:fix
npm run connector:post-deploy
npm run connector:pre-undeploy

Enabler

cd enabler
cp .env.template .env
npm install
npm run build
npm run dev            # http://127.0.0.1:3000/

Docker (all services + JWT mock server)

docker compose up      # starts JWT server, enabler, processor

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.