← Back to Projects

Payment Gateway Automation (Authorize.Net + Slack + Asana)

Every card charge is logged and posted to Slack automatically, and only the failures that need a person become Asana tasks.

Card charge goes to Authorize.Net, the outcome is classified, and every transaction is written to the ledger and posted to Slack. Only gateway errors, held or unanswered charges, declines of $100 or more, and a customer's third failure become Asana tasks.

Project Overview

A Python integration across four APIs. This is a personal proof of concept, not client or production work. It runs entirely against Authorize.Net's public sandbox using their published test card numbers, so no real card, charge, or money is involved anywhere.

The Design Decision

Calling four APIs is not the interesting part. The interesting part is deciding what each outcome should turn into.

OutcomeLedger rowSlackAsana task
Approved✓✓–
Declined, routine✓✓–
Declined, high value or repeated✓✓✓
Error (e.g. duplicate transaction)✓✓✓
Held for review✓✓✓
Gateway unreachable✓✓✓

An approved payment is not work. It is a line in a ledger.

The routine-decline row is the one that matters. A generic decline is usually insufficient funds, which is the cardholder's problem and tends to resolve itself when they retry with another card. Raising a task for every one of them buries the queue, and a noisy integration gets muted within a week. In operations automation, alert fatigue is the real failure mode, not missed alerts.

The escalation policy. A decline only becomes work when it is expensive, repeated, or not really a decline at all:

RuleTrigger
Always escalateGateway error, held for review, or unknown settlement state
High valueA decline at or above $100.00
Repeat failureTwo or more prior failures for the same customer reference
Never escalateApprovals and routine low-value declines

Repeat detection reads the reconciliation log itself, so the ledger doubles as the signal: one decline is noise, three in a row is a pattern. Escalated rows also record the URL of the Asana task raised for them, so the ledger points at its own follow-up.

Engineering Decisions

Reading the right field on a decline. When Authorize.Net declines a charge, the response's top-level envelope still says resultCode: "Ok" with the text "Successful.", because the API call succeeded even though the charge did not. The real verdict is in transactionResponse.responseCode, and the decline reason is in transactionResponse.errors. The first version of this script fell back to the envelope and would have logged a declined payment as "Successful." I caught it by inspecting a live sandbox response. The parser now reads the errors field first, and a unit test pins that behavior so it can't regress. This is documented behavior on Authorize.Net's side, not something I discovered, but it is easy to get wrong.

The ledger never depends on the notifiers. Slack and Asana each handle their own failures. If Slack is unreachable, the reconciliation log still gets its row. The ledger write is not gated behind either notification succeeding.

A gateway timeout is a reconciliation event. When the gateway doesn't respond, the charge may or may not have gone through. That is the most awkward outcome, not the most ignorable one, so it is logged as "No Response" and escalated rather than disappearing into a stack trace.

Runnable without any accounts. A --simulate flag feeds a canned gateway response through the same downstream path, and --dry-run skips Slack and Asana while still writing the ledger. A reviewer can see the routing, ledger, and message formatting work without signing up for anything.

Testing & Security

  • 29 unit tests, needing no network access or credentials, covering response parsing (including the decline trap above), every escalation tier plus the cases that must not escalate, the CSV contents, and the Slack payload.
  • Live end-to-end runs against real sandbox credentials for the approval path, the decline path, each escalation tier, Slack delivery, and the Asana task round trip.
  • A committed sample ledger exercises every branch of the escalation policy, with the reason for each routing decision on the row.

On security:

  • Credentials load from environment variables. Only an example env file is committed.
  • The gateway endpoint is pinned to the sandbox host, and a test asserts it is never the production host.
  • Only Authorize.Net's published test card number appears in the source.
  • No cardholder data is written to the ledger, Slack, or Asana. The ledger stores the gateway's transaction ID, not the card.

Scope & Tech Stack

  • Sandbox only. Moving to production would need real credentials management, PCI scope review, and idempotency handling for retried submissions.
  • The ledger is a CSV file, which suits a proof of concept but would be a database table in a multi-user setting.
  • Escalation thresholds ($100.00, two prior failures) are fixed in code rather than configurable per business.

Tech stack: Python, Authorize.Net Sandbox API, Slack Incoming Webhooks (Block Kit), Asana REST API, CSV reconciliation logging. Dependencies are deliberately limited to requests and python-dotenv.