Expand description
rustlavel-payment: payment gateways behind one trait.
An application takes money through a gateway — a company that presents a virtual account number, a QR code or an e-wallet screen to the customer, collects the payment, and tells the application by webhook. Every gateway does the same five things and describes them differently, so this crate holds the description and a driver holds the difference.
§What crosses the trait
Money— an amount in minor units and a currency. An integer, never a float: money that is rounded is money that goes missing.Channel— how the customer pays: a bank’s virtual account, QRIS, an e-wallet, or a retail counter. The Indonesian set, because that is where the first driver lives; the enum is not closed.Charge— a request for payment and its state, with what the customer needs to pay it (a VA number, a QR string, a deeplink).Transfer— money out, to a bank account or an e-wallet.WebhookEvent— what a gateway says happened, after its signature has been checked.
§The receiver, and why it deduplicates on disk
A gateway retries a webhook until it is acknowledged, and a network that
drops the acknowledgement delivers the same payment twice. Receiver
verifies the signature (each driver knows its own scheme), records the
event by the gateway’s id, and hands a duplicate straight back as already
handled. That record must survive a restart: a duplicate that arrives after
a deploy is still a duplicate, and crediting it twice is a refund
conversation. So the log is a trait with a table-backed implementation
behind the db feature, and the in-memory one is for tests.
§No driver is invented
FakeGateway is the only driver here today. A driver for a real gateway
is written against that gateway’s published specification, not from what
its competitors do — an adapter written from guesses is code that looks
finished and fails on the first real callback.
Re-exports§
pub use channel::Bank;pub use channel::Channel;pub use channel::Retail;pub use channel::Wallet;pub use charge::Charge;pub use charge::ChargeRequest;pub use charge::ChargeStatus;pub use charge::Customer;pub use charge::Instructions;pub use fake::FakeGateway;pub use gateway::Gateway;pub use gateway::GatewayFuture;pub use money::Money;pub use receiver::Handled;pub use receiver::Receiver;pub use transfer::Account;pub use transfer::Transfer;pub use transfer::TransferRequest;pub use transfer::TransferStatus;pub use webhook::EventKind;pub use webhook::MemoryWebhookLog;pub use webhook::WebhookEvent;pub use webhook::WebhookLog;
Modules§
- channel
- How the customer pays.
- charge
- A request for payment, and its state.
- fake
- A gateway that keeps everything in memory and never talks to anybody.
- gateway
- The trait a driver implements.
- money
- An amount of money.
- receiver
- The endpoint a gateway calls.
- signature
- Checking that a webhook came from the gateway.
- transfer
- Money out: to a bank account or an e-wallet.
- webhook
- What a gateway says happened, and the record that stops it being heard twice.
Enums§
- Error
- Every failure the framework itself can produce.
Type Aliases§
- Result
- The framework-wide result type.