Payment development

Payment integration for digital delivery platforms: signatures, idempotency, inventory locks and automated fulfillment

Automated digital delivery is more than sending a code after receiving a string that says “payment successful.” A reliable workflow connects trusted payment notifications, order states, inventory allocation and fulfillment jobs, while allowing network retries, process restarts and manual repair. This article presents a provider-independent design. Implement all fields, signature methods and acknowledgments according to the actual integration protocol; this is not the 稳付pay API specification.

Contents

Track payment and fulfillment as separate state dimensions

Distinguish at least awaiting payment, paid and refunded payment states, alongside awaiting allocation, allocated, delivered and fulfillment-error states. Otherwise, a stock shortage after payment leaves only “success” or “failure,” neither of which preserves the actual intermediate facts.

  1. Create orderFix the product, amount, currency and expiry on the server
  2. Confirm paymentVerify the signature, check fields and persist the payment fact
  3. Allocate inventoryLock the order and its code within a transaction
  4. Execute fulfillmentRetry persistent jobs and retain fulfillment results
The browser return page can display progress; payment facts come from a trusted server-side confirmation workflow.

The server calculates quantity, prices and discounts; it must not directly accept a final amount submitted by the browser. Store a price snapshot with the order so later product price increases do not change an existing payment requirement.

Verify signatures, then check merchant, amount and business ownership

Process callbacks on the backend. Follow the payment documentation to verify the signature, covered data, time window and key. If the provider requires the raw request body, preserve its original bytes before framework parsing or reserialization. Stripe's Webhook guide provides one concrete example of this mechanism; its fields and signature headers cannot simply be applied to another service.

A valid signature only establishes that a message meets the protocol for that key. Also verify merchant identity, order ownership, payment transaction ID, currency, actual amount and final successful status. Compare amounts as integers in an explicit smallest unit or exact fixed-point values, not approximate floating-point equality.

For USDT, also verify the network, receiving address and corresponding asset identifier rather than only the token's display name. A frontend return URL, payment screenshot or customer statement cannot replace these checks. Keep keys on the server, never in webpage scripts.

Deduplication needs database constraints, not just a preliminary query

Failure scenario one: Two notifications arrive simultaneously. Both processes find the order unfulfilled, so each sends a code. The gap between reading and writing creates a race, even on a single server. Deduplication must rely on database uniqueness constraints and transactions, not just an in-memory flag.

Consider event deduplication, payment-transaction deduplication and business-fulfillment deduplication separately. One payment may produce different event IDs, so a unique event ID alone can still allow the same payment to be claimed twice. Redelivering one event must not advance the state again. A duplicate already handled may be acknowledged according to the protocol after checking its persisted record.

The following are generic constraints for the notification, payment, fulfillment-job and inventory-allocation tables respectively, not a complete creation script for a single table. Design non-null fields, scope and actual syntax together. PostgreSQL's constraints documentation explains how database uniqueness constraints enforce this guarantee.

UNIQUE (provider, provider_event_id)
UNIQUE (provider, provider_transaction_id)
UNIQUE (order_id, fulfillment_kind)
UNIQUE (card_id)

Protect inventory allocation with transactions to prevent overselling the last item

When handling a successful payment, lock its order within a transaction and check whether inventory is already allocated. Use a row lock or a conditional atomic update for the code being allocated, and commit the allocation record together with the order state. Do not send the code first and then attempt to mark it sold in the database.

For compare-and-set, or CAS, include “still available” in the update condition and require exactly one affected row. If no row changes, select inventory again or enter the shortage workflow. Multi-item orders need explicit all-item allocation rules so partial delivery does not happen accidentally.

PostgreSQL's row-lock documentation demonstrates coordination of concurrent access. Hold locks briefly and keep external email or licensing calls outside long transactions. For deadlocks or retryable conflicts, retry the entire transaction according to database semantics while preserving idempotency.

Connect the database to external fulfillment with an Outbox

A transaction can save the order and inventory together, but cannot inherently make the database and an email provider succeed together. Write a persistent pending-fulfillment job, an Outbox entry, in the same transaction as the business data. A separate worker then sends the notification and records the result.

# Generic flow; adapt to the actual provider protocol.
event = verify_provider_request(raw_request)
with database_transaction():
    persist_inbox_event_once(event)
    record_verified_payment_once(event)
    allocate_inventory_if_needed(event.order_id)
    persist_outbox_job_once(event.order_id)
return protocol_ack_after_commit()

This is a workflow illustration that omits duplicate-event, validation-failure and stock-shortage branches. With no inventory available, commit “paid, awaiting handling” and a controlled manual job, not a false delivered record. If persistence fails, do not acknowledge business receipt as successful; use protocol-defined retries or an explicit compensating status check.

Acknowledging receipt need not wait for the email to be sent, provided the notification and follow-up job are reliably persisted. With only a nonpersistent in-memory queue, acknowledging early and then restarting can permanently lose fulfillment work.

Handle shortages, late payments and repeated execution separately

Failure scenario two: An order expires and releases its inventory, but the payment notification arrives late. Ignoring a closed order leaves a payment unhandled; reusing its old allocation may send an already-sold code to a second person. Record the payment, recheck inventory and order rules, and move to restocking, manual fulfillment or a refund.

A worker can crash after external fulfillment completes but before it records success. Reuse the same fulfillment ID on retries, and prefer the external system's idempotency key or result-query facility where available. Without those capabilities, provide reconciliation and manual branches; a local queue alone cannot guarantee that external operations never repeat.

The same allocated code can be shown again to the original order's customer through a controlled channel without consuming another inventory item. Resending an email and issuing a new product are different actions and need separate permissions and audit records in the administration system.

Keep the full refund and reconciliation history; do not delete payment records

A refund is a separate business event with states such as requested, successful, failed or partially refunded. Do not express it by deleting an order or changing it back to unpaid. Retain the original payment transaction, refund reference, amount and operator, and reconcile with the payment provider's final result.

Whether a digital product has been viewed or redeemed affects after-sales handling, but does not justify arbitrary automatic refunds or restocking. A nonrevocable license code cannot simply return to saleable inventory after a refund. For revocable licenses, confirm revocation before deciding the next action.

Regularly compare payment records against local paid orders to identify missing records, amount mismatches, paid-but-unfulfilled orders and incomplete refunds. On-chain notifications also need a unique business-order association; an equal transfer amount alone is not enough to guess ownership. Agree confirmation conditions and exceptional-transaction handling during integration.

Run failure checks before launch and establish API boundaries

  • Forged notifications, invalid signatures, wrong merchants and wrong amounts must never trigger fulfillment.
  • Repeated events and different events for the same transaction must not allocate inventory twice.
  • Concurrent purchases of the last item must produce only one valid allocation.
  • Do not acknowledge success if the transaction fails to commit; after a successful commit, processing must survive a worker restart.
  • Provide a reconciliation path for email timeouts, interrupted jobs and unknown external API results.
  • Keep traceable states for shortages, late payments, refunds and manual reissues.

The 稳付pay merchant backend remains under development; monitoring and callback services are already available. USDT currently supports Tron (TRC20) and Ethereum (ERC20), with funds sent directly to merchants' own addresses. Business notifications are sent within seconds after the configured on-chain confirmation conditions are met; this does not mean block confirmation itself takes only seconds.

This article does not provide actual 稳付pay API URLs, signature headers or key-issuance procedures. Before integrating, contact us to confirm the actual protocol, implement request verification, acknowledgments and order recovery accordingly, then test before launch.

References and technical documentation

The official sources below support protocol and implementation checks. Code and scenarios illustrate technical concepts; validate your environment and production integration protocol separately.

  1. Stripe: Webhook verification and duplicate events
  2. PostgreSQL: database constraints
  3. PostgreSQL: explicit and row-level locks
  4. PostgreSQL: transaction atomicity
  5. OWASP: transaction business-data validation

Keep improving your site

Check each step of networking, orders and funds notifications against your business scenario. Discuss payment integration and USDT monitoring through the contact page.

Contact 稳付pay ↗