Solution: payments and refunds
A charge through Stripe, and the refund that undoes it
An agent charges a card through Stripe. A rule holds the charge from an amount. If a later step of the plan fails, Sefra refunds the charge, and if the answer from Stripe never arrives, a person settles it.
This integration operates in Stripe's test mode. The connector refuses any key that is not a test key, and does not trust an answer that says it is live.
What happens
A two-step plan: charge a card, then create a vendor in your ERP. If the ERP refuses the vendor, the charge has already taken effect, so Sefra refunds it.
| Step | What Sefra does | Result |
|---|---|---|
| Charge | Sefra sends the charge with its own idempotency token | Stripe records a succeeded payment, in test mode |
| Later step fails | The ERP refuses the new vendor with a 422 | The plan stops, and the charge has already taken effect |
| Refund | Sefra calls the declared compensation | Stripe refunds the whole amount |
| A repeat | Sefra sends the same token again | Stripe returns the same payment, with Idempotent-Replayed: true |
| The agent's own token | Tried directly against Stripe, once revoked | 401, and no payment created |
stripe: type: http base_url: https://api.stripe.com auth: type: bearer secret: stripe_secret_key secret_prefixes: [sk_test_, rk_test_] body_encoding: form fail_closed_on: { "/livemode": true }Scroll sideways for long lines.
The rule
The threshold applies to the charge. From 50000 minor units (500.00) a finance approver decides, and the approver cannot be the requester. Above 100000 (1,000.00) the charge is denied.
max_charge_minor := 100000 # 1,000.00 in minor units: no larger test charge approval_charge_minor := 50000 # 500.00: a finance approver above thisScroll sideways for long lines.
The approval rule includes 50000 itself, and the limit allows 100000 itself.
# payments.large_chargerequire_approval contains { "rule": "payments.large_charge", "message": sprintf("The charge of %d minor units is at least %d.", [input.input.amount_minor, approval_charge_minor]), "approver": {"role": "finance_approver"}, "distinct_from_requester": true,} if { input.intent.type == "payments.charge_card" input.input.amount_minor >= approval_charge_minor}Scroll sideways for long lines.
The refund is the undo
In this bundle a refund is the declared compensation of a charge. It runs when a later step of the same plan fails, for the whole amount, with its own idempotency token. It counts as done only when the answer from Stripe says succeeded. If Stripe refuses the refund, or the answer stays anything else, the execution waits in needs_intervention and an operator is alerted.
compensate: connector: stripe method: POST path: /v1/refunds # The whole amount. A repeat with the same key returns the first refund; # Stripe's "already refunded" is a 400 that other refusals share, so it is # not listed under already_undone. body: { payment_intent: "${output.payment_intent_id}" } idempotency: { mode: header, header: Idempotency-Key } success: [200] # A 200 can carry a refund that is pending, needs action or failed. Only a # finished one undoes the charge; anything else reaches an operator. success_when: { "/status": succeeded }Scroll sideways for long lines.
An agent cannot ask for a refund on its own here, because this bundle has no such intent. The pack for Stripe adds one, payments.refund_payment, and holds every refund for a person. The rest of the catalogue is still to come:
Recipe catalogueIn build
The idempotency token
Sefra sends Stripe a token built from the execution and the step. Stripe answers a repeat from the saved result of that token and refuses it with other parameters, so repeating an unclear attempt while Stripe still holds the key, at least 24 hours, does not charge twice.
Sent as Idempotency-Key
cx-<execution id>-<step>-fwdSent again, it returns the same payment with Idempotent-Replayed: true, so only one payment exists.
When the answer never arrives
A timeout after the request was sent says nothing about whether the card was charged. Sefra repeats with the same token. If that does not settle it, a person does.
| Case | What happens |
|---|---|
| The connection drops after the charge | The repeat with the same token is replayed: one payment, one refund |
| Every answer is ambiguous | After five attempts the step is unknown and the execution waits in needs_intervention. Nothing is refunded yet |
| A 200 for a charge that is not paid | The output schema requires status succeeded, so the answer counts as ambiguous and cannot pass as paid |
| An answer that says it is live | Not trusted on any repeat. The execution waits in needs_intervention |
| The operator records | Value |
|---|---|
| Outcome | succeeded |
| Output | payment_intent_id pi_…, status succeeded, amount_received 1234 |
| Note | Seen in the Stripe dashboard. |
Scope of this release
- This integration is available for pilots in Stripe's test mode, with test data. Live payments are outside the current release, and customer deployments have not started.
- Production use with Stripe will follow a legal review of its terms on automated use.
- A refund that Stripe reports as succeeded and that fails later is not tracked. The execution stays rolled_back.
- Policy tests verify the approval threshold on both sides of the value. Validation with a held charge at Stripe is still to come.
- Dropped connections and live-mode answers are validated in simulation rather than against Stripe.
- The bundle shown here has no refund an agent can request, no partial refund and no payouts.
- There is no probe for a lost charge, because search on Stripe is eventually consistent and could call a committed charge absent.