Task flow · Owner-issued payment link
Owner-issued payment link
The owner mints a payment link for a quote or expense settlement and sends it to the buyer.
Flow
flowchart TD
A["Owner opens quote console"] --> B["Clicks issue payment link"]
B --> C["POST /owner/quote/<ref>/lien-paiement"]
C --> D{"Staff authenticated?"}
D -- No --> E["404"]
D -- Yes --> F{"Target?"}
F -- "mission" --> G["payment_for_quote"]
F -- "expenses" --> H["payment_for_settlement"]
G --> I["Create Payment row with reference"]
H --> I
I --> J["AuditEvent: payment_link_issued"]
J --> K["Show absolute URL to owner"]
K --> L["Owner sends URL to buyer"]
L --> M["Buyer opens /paiement/<ref>/"]
M --> N{"Already settled?"}
N -- Yes --> O["Redirect to return page"]
N -- No --> P["Show payment page + identity form"]
P --> Q["Visitor corrects details if needed"]
Q --> R["POST /paiement/<ref>/demarrer/"]
R --> S["Create Stripe Checkout session"]
S --> T["Redirect to Stripe"]
T --> U{"Buyer action"}
U -- "Pays" --> V["Webhook settles + grant entitlement"]
U -- "Cancels" --> W["Nothing charged"]
V --> X{"Subscription?"]
X -- Yes --> Y["Show billing portal link"]
X -- No --> Z["Show receipt + download links"]
Payment states and transitions
| State | Set by | Next |
|---|---|---|
| PENDING | View creates the row | → PROCESSING (checkout started) |
| PROCESSING | View after Stripe session created | → PAID (webhook) or FAILED (provider error) |
| PAID | Webhook only | → settled; entitlements granted |
| CANCELLED | Buyer action on Stripe | → terminal; row stays open |
| FAILED | Provider outage or invalid signature | → terminal; owner may retry |
| EXPIRED | Time or terms window | → terminal; owner must reissue |
Security and integrity rules
| Rule | Enforcement |
|---|---|
| Amount authority | Amount is frozen at link creation; browser input is never charged. |
| Terms freeze | terms_version is stamped at payment creation. |
| Settlement authority | Only the signed Stripe webhook writes PAID. |
| Reference secrecy | Payment references are unguessable; holding the reference grants the right to pay. |
| No card data on server | Stripe hosts the checkout page. |
| Robots exclusion | /paiement/ is blocked by robots.txt. |
Validation and recovery
| Condition | System response |
|---|---|
| Staff not authenticated | 404; no link is created. |
| Payment is already settled | Redirect to the return page; no second charge is created. |
| Webhook signature is invalid | 400; nothing is written. Stripe retries. |
| Payment link is expired or failed | Error message; the owner must issue a new link from the console. |
Entitlement and delivery
When the webhook records a settled payment, grant_entitlements() creates the corresponding Entitlement row. For subscriptions, the buyer also receives a link to the Stripe customer portal for cancellation, card updates, and invoice history.