Skip to main content

PaymentAdapter

Trait PaymentAdapter 

Source
pub trait PaymentAdapter: Send + Sync {
    // Required methods
    fn authorize(
        &self,
        request: &PaymentAuthorizeRequest,
    ) -> Result<PaymentAuthorization, PaymentError>;
    fn capture(
        &self,
        authorization_id: &str,
        amount_units: u64,
        currency: &str,
        reference: &str,
    ) -> Result<PaymentResult, PaymentError>;
    fn release(
        &self,
        authorization_id: &str,
        reference: &str,
    ) -> Result<PaymentResult, PaymentError>;
    fn refund(
        &self,
        transaction_id: &str,
        amount_units: u64,
        currency: &str,
        reference: &str,
    ) -> Result<PaymentResult, PaymentError>;

    // Provided methods
    fn rail_id(&self) -> &'static str { ... }
    fn rail_mode(&self) -> Option<PaymentRailMode> { ... }
    fn settlement_state(
        &self,
        reference: &str,
        authorization_id: Option<&str>,
    ) -> Result<RailSettlementState, PaymentError> { ... }
}
Expand description

Trait for executing payments against an external rail.

Required Methods§

Source

fn authorize( &self, request: &PaymentAuthorizeRequest, ) -> Result<PaymentAuthorization, PaymentError>

Authorize or prepay up to amount_units before the tool executes.

Implementations must be idempotent by request.reference: repeating the same request returns the same authorization and creates at most one rail-side hold or prepayment.

Source

fn capture( &self, authorization_id: &str, amount_units: u64, currency: &str, reference: &str, ) -> Result<PaymentResult, PaymentError>

Finalize payment for the actual cost after tool execution.

Implementations must be idempotent by (authorization_id, reference).

Source

fn release( &self, authorization_id: &str, reference: &str, ) -> Result<PaymentResult, PaymentError>

Release an unused authorization hold.

Implementations must be idempotent by (authorization_id, reference).

Source

fn refund( &self, transaction_id: &str, amount_units: u64, currency: &str, reference: &str, ) -> Result<PaymentResult, PaymentError>

Refund a previously executed payment.

Provided Methods§

Source

fn rail_id(&self) -> &'static str

Source

fn rail_mode(&self) -> Option<PaymentRailMode>

Source

fn settlement_state( &self, reference: &str, authorization_id: Option<&str>, ) -> Result<RailSettlementState, PaymentError>

Return the side-effect-free rail state for a durable reference.

This query must remain answerable when authorization_id is absent so recovery can close the crash window after authorization but before the rail-assigned identifier reaches the local journal.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§