Expand description
EPay (易支付) SDK for Rust.
The protocol core is transport-free. Use ProtocolContext for signed
forms and callback verification, and Client when making async EPay API
requests. The optional axum feature adds strict extractors without
enabling reqwest.
use epay_sdk::{FormPaymentRequest, Money, PayType, ProtocolContext};
let epay = ProtocolContext::builder(1001, "merchant-key", "https://pay.example.com")
.notify_url("https://shop.example.com/notify")
.return_url("https://shop.example.com/return")
.build()?;
let html = epay.build_form_payment(
&FormPaymentRequest::new("ORDER001", "VIP会员", Money::from_yuan_str("9.90")?)
.pay_type(PayType::Alipay),
)?;§Feature flags
| Feature | Default | Effect |
|---|---|---|
reqwest-rustls | yes | built-in transport with rustls |
reqwest-native-tls | no | built-in transport with native TLS |
axum | no | Axum 0.8 extractors (axum) |
blocking | no | blocking::Client for non-async programs |
tracing | no | tracing spans/events for every gateway call (replaces log output) |
test-util | no | test_util: MockTransport, test_util::NotifyFixture |
Re-exports§
pub use client::CallOptions;pub use client::Client;pub use client::ClientBuilder;pub use config::Config;pub use config::HttpConfig;pub use config::RetryPolicy;pub use endpoint::Endpoint;pub use error::Error;pub use error::ErrorKind;pub use error::Result;pub use error::TransportErrorKind;pub use merchant::MerchantInfo;pub use merchant::Settlement;pub use merchant::SettlementListResponse;pub use money::Money;pub use notify::NotifyData;pub use notify::NotifyLimits;pub use notify::NotifySource;pub use notify::RawNotifyEntry;pub use notify::RawNotifyParams;pub use notify::SuccessfulNotify;pub use notify::parse_notify_params;pub use notify::parse_raw_notify_params;pub use notify::parse_raw_notify_params_with_limits;pub use order::OrderDetail;pub use order::OrderListResponse;pub use order::OrderQueryRequest;pub use order::generate_out_trade_no;pub use params::Params;pub use payment::FormPaymentRequest;pub use payment::PaymentDestination;pub use payment::PaymentRequest;pub use payment::PaymentResponse;pub use payment::PreparedForm;pub use protocol::ProtocolContext;pub use protocol::ProtocolContextBuilder;pub use refund::RefundRequest;pub use refund::RefundResponse;pub use signer::Signer;pub use transport::Transport;pub use transport::TransportOptions;pub use types::Device;pub use types::NOTIFY_FAIL;pub use types::NOTIFY_SUCCESS;pub use types::OrderStatus;pub use types::PayType;pub use types::TradeStatus;pub use transport::MockTransport;test-utilpub use transport::RecordedRequest;test-util
Modules§
- axum
axum - Axum 0.8 integration for strict EPay callback and return verification.
- blocking
blocking - Blocking wrapper around
crate::Client(featureblocking). - client
- Async HTTP client for
mapi.phpandapi.php. - config
- Validated protocol configuration and HTTP client settings.
- endpoint
- Gateway endpoints addressed by
crate::Client. - error
- Error type, stable numeric codes and log-safe redaction helpers.
- limits
- Size limits applied to outbound requests.
- merchant
- Merchant profile (
act=query) and settlement records (act=settle). - money
- Exact positive CNY amounts.
- notify
- Strict parsing and verification of
notify_url/return_urlcallbacks. - order
- Order queries (
act=order,act=orders) and order-number generation. - params
- Sorted, log-safe parameter map used for signing and encoding.
- payment
- Payment requests for
mapi.php(API) andsubmit.php(form). - prelude
- Commonly used protocol and client types.
- protocol
- Transport-free protocol context: signing, forms and callback verification.
- refund
- Refunds (
POST api.php?act=refund). - signer
- MD5 signing and constant-time verification (彩虹易支付 V1).
- test_
util test-util - Test helpers (feature
test-util): a scriptedMockTransportand aNotifyFixturethat produces correctly signed gateway notifications. - transport
- HTTP transport abstraction, the built-in reqwest transport and a mock.
- types
- Protocol enums and constants.
Structs§
- Url
- A parsed URL record.