openpay/ (+3 crates)
op-bnpl/ Affirm + Klarna + Afterpay/Clearpay rails. Full lifecycle
typestate (Initiated→Approved→Captured→Settled→Refunded).
Per-provider sandbox+production base URLs, regions (NA/EU/OC
for Klarna; US/AuNz/Gb/Ca/Eu for Afterpay). HMAC-SHA256
webhook verification with constant-time compare. 61 tests.
op-batch/ NACHA ACH (94-char records, PPD/CCD/WEB/TEL/CTX, R01-R99
return codes, Same-Day ACH cutoffs); SEPA pain.001.001.09
(CT) + pain.008.001.08 (DD) with SCT-Inst flagging; Fedwire
MT103/MT202/CHIPS + pacs.008.001.12 / pacs.009.001.10 +
UETR; Bacs Standard 18. Per-rail cutoff scheduler. Exception
taxonomy unified across rails. 51 tests.
op-screening/ OFAC SDN + EU consolidated + UN consolidated + HMT UK
consolidated + Australia DFAT + Canada SEMA + Japan MOF.
Levenshtein + Jaro-Winkler + Soundex + Metaphone + token
Jaccard scoring. Unicode NFKD normalisation + Cyrillic /
Arabic transliteration. Ed25519-signed BLAKE3-chained
audit log. BSA helpers: CTR + SAR pattern detection
(structuring, round-dollar, rapid-in-out). 43 tests.
smart-byte/smart-byte-rs/ (+3 crates)
smart-byte-bbs/ BBS+ signatures (IETF draft-irtf-cfrg-bbs-signatures-08).
BLS12-381 keys, signatures, disclosure proofs with
cryptographic unlinkability. bbs-2023 Data Integrity
cryptosuite. AnonCreds-shaped link secrets +
predicate proofs. SecretKey zeroize-on-drop. 49 tests.
smart-byte-didcomm/ DIDComm v2 messaging per DIF spec. Pack-encrypted
(ECDH-1PU + ECDH-ES via X25519), pack-signed (JWS),
pack-plaintext. Aries protocols: issue-credential v3,
present-proof v3, basic-message, trust-ping, discover-
features, out-of-band, coordinate-mediation, message-
pickup. Mediator role with pluggable storage. 23 tests.
smart-byte-mdl/ ISO/IEC 18013-5 mobile driver's licence + 18013-7
online presentment. mDoc + MSO with salted-hash
selective disclosure (per item; SHA-256 digest tree).
org.iso.18013.5.1 namespace + AAMVA add-on. ES256
device-auth + issuer-auth. QR-code device-engagement
scaffolding. 28 tests.
eoc/eoc-rs/ (+3 crates)
eoc-local/ Local-inference backends behind one NeuralBackend:
llama.cpp (GGUF, Q4/Q5/Q6/Q8/F16/F32 quantisation),
MLX (Apple Silicon, feature-gated), MLC-LLM (TVM, feature-
gated marker), ONNX Runtime. GGUF file-format reader.
HuggingFace tokenizers. Greedy / top-k / top-p / temperature /
Mirostat samplers. Model registry scanning ~/.eoc/models/.
Joule attribution via eoc-meter. 39 tests.
eoc-rerank/ BM25 sparse + HNSW dense + RRF + min-max hybrid fusion.
Cohere v3.5 + Voyage v2 + bge-reranker v2-m3 + ms-marco
MiniLM + ColBERT v2 rerankers. Two-stage pipeline:
retrieve top-K hybrid → cross-encoder rerank → top-N.
KV-stage recovery shim into the cascade. 31 tests.
eoc-eval/ 15 canonical eval harnesses: MMLU, MMLU-Pro, GPQA,
HumanEval (pass@1 with python3 sandbox), BBH, IFEval (25
verifiable constraints), AlpacaEval, AGIEval, HellaSwag,
ARC (Easy + Challenge), TruthfulQA (MC1+MC2), BoolQ,
GSM8K, MATH (boxed-answer equivalence), Winogrande. Real
questions in BuiltinSamples. EvalRunner emits joules-per-
correct alongside accuracy. 49 tests.
Quality:
- cargo check across all three workspaces: clean
- cargo clippy --all-targets -- -D warnings on every new crate: clean
- 374 new tests, all passing
- #![forbid(unsafe_code)] across every new crate
- No unwrap/expect outside #[cfg(test)]
Rust 1.95.0 edition 2024 (inherited via root rust-toolchain.toml).
133 lines
4.9 KiB
Rust
133 lines
4.9 KiB
Rust
//! The generic [`BnplAcquirer`] trait + initiate/authorize/capture/refund
|
|
//! value types.
|
|
//!
|
|
//! Modelled like `op-rails-card::CardAcquirer` but with the BNPL-specific
|
|
//! intermediate states: between `initiate` (session creation) and `capture`
|
|
//! sits `authorize` (the consumer-token verification step).
|
|
|
|
use async_trait::async_trait;
|
|
use chrono::{DateTime, Utc};
|
|
use op_core::Money;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::error::Result;
|
|
use crate::intent::BnplIntent;
|
|
use crate::lifecycle::{BnplProvider, InstalmentPlan};
|
|
|
|
/// What the provider returns after `initiate`.
|
|
///
|
|
/// The merchant-side flow up to this point:
|
|
///
|
|
/// 1. Merchant calls `initiate(&intent)`.
|
|
/// 2. Provider returns an [`InitiatedSession`] with a `provider_ref`
|
|
/// (Affirm `checkout_token`, Klarna `session_id`, Afterpay `token`)
|
|
/// and a `redirect_url` (or client-token for embedded flows).
|
|
/// 3. Merchant redirects browser to `redirect_url`.
|
|
/// 4. Consumer accepts; browser returns to merchant with a
|
|
/// `consumer_token` (Affirm checkout_token, Klarna authorization_token,
|
|
/// Afterpay orderToken in the query string).
|
|
/// 5. Merchant calls `authorize(&session, &consumer_token)`.
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct InitiatedSession {
|
|
/// Which provider issued this session.
|
|
pub provider: BnplProvider,
|
|
/// Opaque provider-issued session/checkout id. The merchant carries
|
|
/// this across the redirect-to-consumer boundary.
|
|
pub provider_ref: String,
|
|
/// URL to redirect the consumer to. For embedded widgets (Klarna
|
|
/// JS SDK, Afterpay Express), the SDK consumes this internally.
|
|
pub redirect_url: Option<String>,
|
|
/// Provider-issued client token for embedded flows (Klarna).
|
|
/// `None` for redirect-based flows.
|
|
pub client_token: Option<String>,
|
|
/// When the session expires. After this, `authorize` will fail.
|
|
pub expires_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
/// What the provider returns after `authorize`.
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct AuthorizedCheckout {
|
|
/// Which provider.
|
|
pub provider: BnplProvider,
|
|
/// Opaque provider-issued id (Affirm `charge_id`, Klarna `order_id`,
|
|
/// Afterpay `id`).
|
|
pub provider_ref: String,
|
|
/// Amount the provider locked in. May be less than requested for
|
|
/// partial-approval flows (Klarna and Affirm both occasionally
|
|
/// offer a smaller line of credit than the cart total).
|
|
pub authorized_amount: Money,
|
|
/// Instalment plan the consumer accepted.
|
|
pub plan: InstalmentPlan,
|
|
}
|
|
|
|
/// What the provider returns after `capture`.
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct CapturedCheckout {
|
|
/// Which provider.
|
|
pub provider: BnplProvider,
|
|
/// Opaque provider-issued id. Same value as `AuthorizedCheckout`
|
|
/// for Affirm/Klarna; Afterpay may issue a separate `paymentId`
|
|
/// at capture time.
|
|
pub provider_ref: String,
|
|
/// Amount captured.
|
|
pub amount: Money,
|
|
/// Provider's settlement-batch reference, if known at capture time.
|
|
pub settlement_ref: Option<String>,
|
|
}
|
|
|
|
/// What the provider returns after `refund`.
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct RefundedCheckout {
|
|
/// Which provider.
|
|
pub provider: BnplProvider,
|
|
/// Provider-issued id of the original charge.
|
|
pub provider_ref: String,
|
|
/// Provider-issued refund id.
|
|
pub refund_ref: String,
|
|
/// Amount refunded.
|
|
pub amount: Money,
|
|
}
|
|
|
|
/// The generic BNPL acquirer interface.
|
|
///
|
|
/// Implemented by [`crate::AffirmAcquirer`], [`crate::KlarnaAcquirer`],
|
|
/// and [`crate::AfterpayAcquirer`]. The orchestrator holds a
|
|
/// `Box<dyn BnplAcquirer>` and routes by inspecting the intent's
|
|
/// shipping country + currency + amount band.
|
|
#[async_trait]
|
|
pub trait BnplAcquirer: Send + Sync {
|
|
/// Which provider this driver speaks to.
|
|
fn provider(&self) -> BnplProvider;
|
|
|
|
/// Create a session / checkout token. Step 1 of 4.
|
|
async fn initiate(&self, intent: &BnplIntent) -> Result<InitiatedSession>;
|
|
|
|
/// Verify the consumer-completion token and lock in funds. Step 3
|
|
/// of 4. The `consumer_token` is whatever the provider redirects
|
|
/// back to the merchant with (query-string parameter / postMessage
|
|
/// payload / JS SDK callback value).
|
|
async fn authorize(
|
|
&self,
|
|
session: &InitiatedSession,
|
|
consumer_token: &str,
|
|
) -> Result<AuthorizedCheckout>;
|
|
|
|
/// Capture funds. Step 4 of 4. `amount = None` means full
|
|
/// authorized amount; `Some(_)` means partial.
|
|
async fn capture(
|
|
&self,
|
|
auth: &AuthorizedCheckout,
|
|
amount: Option<Money>,
|
|
) -> Result<CapturedCheckout>;
|
|
|
|
/// Refund part or all of a captured checkout.
|
|
async fn refund(
|
|
&self,
|
|
captured: &CapturedCheckout,
|
|
amount: Money,
|
|
) -> Result<RefundedCheckout>;
|
|
|
|
/// Void a pre-capture authorization. Releases the provider-side
|
|
/// reservation; consumer is not charged.
|
|
async fn void(&self, auth: &AuthorizedCheckout) -> Result<()>;
|
|
}
|