Skip to content
ALTRONIXSOFTWARE — home
E-commerce · Payments

Order and payment platform

An order and payment flow across two Spring Boot services and Kafka, with Stripe, built to survive failures.

Commercial project under NDA

Engineering work

Engineering of event-driven ordering and payments, with idempotency and recovery scenarios.

MicroservicesWeb interfaceNext.jsKeycloakOIDC · JWT · PKCEStripewebhooks · testOrder serviceorders · catalog · sagaApache Kafkaevents · outbox · inboxPayment servicepayments · refunds · webhooksPostgreSQLorders · payments · outboxBack officeorders · filters · refundsOperationsdead letters · reconciliationOrder paid: card accepted → webhook → PAIDRefund → Stripe → webhook → order updatedMicroservicesWebKeycloakOrder serviceorders · catalog · sagaApache Kafkaevents · outbox · inboxPayment servicepayments · refunds · webhooksStripePostgreSQLOperationsOrder paid: card accepted → webhook → PAIDRefund → Stripe → webhook → order updated
Industry
E-commerce · Payments
Technologies and integrations
  • Java 21
  • Spring Boot
  • Apache Kafka
  • PostgreSQL
  • Keycloak
  • Stripe
  • Next.js
  • Testcontainers

Overview

The order and payment flow of an online shop, with separate customer, admin and operations roles.

Challenge

Taking a payment crosses systems that fail halfway: a webhook arrives twice or out of order, Kafka goes down, a process crashes. The flow had to avoid charging or refunding twice, and an order had to reflect the truth about its payment.

Key areas of work

The order and payment flow was implemented as two Spring Boot services that communicate through Kafka, without direct calls between them. The work covered six areas.

  1. 01

    Order service

    A catalog, a cart, orders with a status history and cancellation. An order stays PENDING_PAYMENT until a PaymentSucceeded event arrives from Kafka.

  2. 02

    Payment service

    Payments with Stripe: PaymentIntents, 3-D Secure, declines and retries, full refunds and disputes. Stripe is called only by background workers, never inside a database transaction.

  3. 03

    Event-driven saga

    A choreography saga over Kafka, with a transactional outbox and inbox so that no event is lost or handled twice.

  4. 04

    Idempotency and recovery

    Idempotency at every boundary, including an HTTP Idempotency-Key. Duplicate requests, repeated or out-of-order webhooks, a crash or a Kafka outage mid-payment do not charge or refund twice, and a late payment on a cancelled order is refunded automatically.

  5. 05

    Back office and operations

    Admins see every order with filters and refund it; operations staff work with dead letters and reconciliation against Stripe.

  6. 06

    Access and testing

    Sign-in through Keycloak (OIDC, JWT, PKCE) with the services as Spring Security resource servers. Unit, architecture and integration tests, plus end-to-end scenarios and chaos tests, none of which needs a Stripe account.

Architecture and implementation details

Architecture

  1. 01

    Web interface

    A Next.js app for the shop, the order page, the back office and operations, with Stripe Elements for card entry.

  2. 02

    Keycloak

    Sign-in through OIDC with PKCE; both services check the JWT as Spring Security resource servers.

  3. 03

    Order service

    Orders, the catalog and the saga participant; an order waits in PENDING_PAYMENT for the payment event.

  4. 04

    Kafka

    The only way the two services talk: events through a transactional outbox and inbox.

  5. 05

    Payment service

    Payments, refunds, the Stripe gateway, webhooks and reconciliation; Stripe is called by background workers, outside transactions.

  6. 06

    PostgreSQL

    State, outbox and inbox live in PostgreSQL, migrated with Flyway.

Outcome

Six scenarios run end to end: a successful payment, a decline followed by a retry, 3-D Secure, a late payment that is refunded automatically, an admin refund and a dispute that flags the order.

Related service: Custom software development

Working on something similar?

Describe your system and the outcome you need, and we will suggest the next step.