SimulatedPaymentGateway

class SimulatedPaymentGateway(val limit: BigDecimal, down: () -> Boolean = { false }) : PaymentGateway

A gateway for trying the eShop out and for its tests, after the classic eShop's PaymentProcessor, which approves or declines by a setting. Its answer is a function of the amount, so a test chooses the outcome by the order's total: it approves an amount up to limit and declines one above it. Its transaction id is the charge's idempotency key.

While down says so, the gateway is unreachable: a charge fails with a technical error, which the saga retries and then parks the payment for (the failure ledger's end-to-end test).

Constructors

Link copied to clipboard
constructor(limit: BigDecimal, down: () -> Boolean = { false })

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open suspend override fun charge(paymentId: String, amount: BigDecimal, description: String, idempotencyKey: String): GatewayOutcome

Charges amount for the payment paymentId, for what description says (the buyer's statement line). A gateway charges once per idempotencyKey: the saga's execution, the same each time it handles the same commit, so a retried charge is not charged twice.