← All examples
PlaceOrder
examples/PlaceOrder.intent
PlaceOrder.intent
1# PlaceOrder.intent2# Domain: ecommerce checkout. Turning a cart into an order is where money, stock,3# and trust all meet. One order per submission, never oversell, never charge before4# stock is reserved. The checkout gate runs as a decision.56mission PlaceOrder7use product89title "Place an order from a cart safely and exactly once"10for StorefrontTeam1112note pm:13 A double-click at checkout must never become two orders or two charges.1415goal16 Convert a valid cart into exactly one order, with stock reserved before payment17 is captured.1819why20 Overselling, double charges, and duplicate orders each turn a sale into a refund,21 a support ticket, and lost trust.2223requires24 Cart25 PaymentMethod2627input28 cart: Cart29 idempotencyKey: IdempotencyKey30 inStock: Flag31 paymentValid: Flag3233output34 order: Order3536guarantee a resubmitted checkout with the same key returns the first order37 because customers double-submit, and each retry must not create a new order38 verify idempotent checkout test3940guarantee stock is reserved before the customer is charged41 because charging for stock you cannot ship is the worst checkout failure42 verify reserve before charge test4344never45 create a second order for the same idempotency key46 sell more units than are in stock47 capture payment before stock is reserved4849never create a second order for the same idempotency key50 because that is a duplicate order and a duplicate charge51 verify idempotent checkout test5253never sell more units than are in stock54 because overselling forces cancellations and breaks delivery promises55 verify oversell prevention test5657never capture payment before stock is reserved58 because a charge without reserved stock guarantees a refund59 verify reserve before charge test6061# The checkout gate as a decision. `intent run` / `intent test`.62decision CanPlaceOrder63 inputs64 keySeen65 inStock66 paymentValid67 rule replay68 when keySeen == true69 return ReturnExisting70 rule outOfStock71 when inStock == false72 return RejectOutOfStock73 rule badPayment74 when paymentValid == false75 return RejectPayment76 default77 return CreateOrder7879target80 TypeScript81 OpenAPI82 Tests8384test CanPlaceOrder85 case first valid checkout creates the order86 given keySeen false, inStock true, paymentValid true87 expect CreateOrder88 case retry returns the existing order89 given keySeen true, inStock true, paymentValid true90 expect ReturnExisting91 case out of stock is rejected92 given keySeen false, inStock false, paymentValid true93 expect RejectOutOfStock94 case invalid payment is rejected95 given keySeen false, inStock true, paymentValid false96 expect RejectPayment97 case a seen key wins over stock and payment checks98 given keySeen true, inStock false, paymentValid false99 expect ReturnExistingDraft syntax. This file is illustrative and does not run yet.
More examples
AlertRoutingApiGatewayBillingServiceCalculateRiskScoreCertificationAttemptCertificationCheckoutCertificationEligibilityCertificationStudyPlanCreateInvoiceCreateStudyPlanCustomerDataRequestDuplicateInvoicePreventionGroundedAnswerIngestClickstreamInvoiceCreatedNetworkEgressPolicyResearchAgentRunResetPasswordStorefrontStyleSubscriptionUpgradeTenantIsolationUploadStudyMaterial