Skip to main content

epay_sdk/
lib.rs

1//! EPay (易支付) SDK for Rust.
2//!
3//! The protocol core is transport-free. Use [`ProtocolContext`] for signed
4//! forms and callback verification, and [`Client`] when making async EPay API
5//! requests. The optional `axum` feature adds strict extractors without
6//! enabling reqwest.
7//!
8//! ```no_run
9//! use epay_sdk::{FormPaymentRequest, Money, PayType, ProtocolContext};
10//!
11//! # fn demo() -> epay_sdk::Result<()> {
12//! let epay = ProtocolContext::builder(1001, "merchant-key", "https://pay.example.com")
13//!     .notify_url("https://shop.example.com/notify")
14//!     .return_url("https://shop.example.com/return")
15//!     .build()?;
16//! let html = epay.build_form_payment(
17//!     &FormPaymentRequest::new("ORDER001", "VIP会员", Money::from_yuan_str("9.90")?)
18//!         .pay_type(PayType::Alipay),
19//! )?;
20//! # let _ = html;
21//! # Ok(())
22//! # }
23//! ```
24//!
25//! # Feature flags
26//!
27//! | Feature | Default | Effect |
28//! |---|---|---|
29//! | `reqwest-rustls` | yes | built-in transport with rustls |
30//! | `reqwest-native-tls` | no | built-in transport with native TLS |
31//! | `axum` | no | Axum 0.8 extractors ([`axum`]) |
32//! | `blocking` | no | [`blocking::Client`] for non-async programs |
33//! | `tracing` | no | `tracing` spans/events for every gateway call (replaces `log` output) |
34//! | `test-util` | no | [`test_util`]: [`MockTransport`], [`test_util::NotifyFixture`] |
35
36#![cfg_attr(docsrs, feature(doc_cfg))]
37#![deny(missing_debug_implementations)]
38#![warn(missing_docs)]
39
40#[macro_use]
41mod observe;
42
43#[cfg(feature = "blocking")]
44#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
45pub mod blocking;
46pub mod client;
47pub mod config;
48pub mod endpoint;
49pub mod error;
50pub mod limits;
51pub mod merchant;
52pub mod money;
53pub mod notify;
54pub mod order;
55pub mod params;
56pub mod payment;
57pub mod protocol;
58pub mod refund;
59pub mod signer;
60#[cfg(any(test, feature = "test-util"))]
61#[cfg_attr(docsrs, doc(cfg(feature = "test-util")))]
62pub mod test_util;
63pub mod transport;
64pub mod types;
65
66mod integrations;
67mod secret;
68mod serde_util;
69mod validation;
70
71pub use client::{CallOptions, Client, ClientBuilder};
72pub use config::{Config, HttpConfig, RetryPolicy};
73pub use endpoint::Endpoint;
74pub use error::{Error, ErrorKind, Result, TransportErrorKind};
75pub use merchant::{MerchantInfo, Settlement, SettlementListResponse};
76pub use money::Money;
77pub use notify::{
78    NotifyData, NotifyLimits, NotifySource, RawNotifyEntry, RawNotifyParams, SuccessfulNotify,
79    parse_notify_params, parse_raw_notify_params, parse_raw_notify_params_with_limits,
80};
81pub use order::{OrderDetail, OrderListResponse, OrderQueryRequest, generate_out_trade_no};
82pub use params::Params;
83pub use payment::{
84    FormPaymentRequest, PaymentDestination, PaymentRequest, PaymentResponse, PreparedForm,
85};
86pub use protocol::{ProtocolContext, ProtocolContextBuilder};
87pub use refund::{RefundRequest, RefundResponse};
88pub use signer::Signer;
89pub use transport::{Transport, TransportOptions};
90pub use types::{Device, NOTIFY_FAIL, NOTIFY_SUCCESS, OrderStatus, PayType, TradeStatus};
91pub use url::Url;
92
93#[cfg(any(test, feature = "test-util"))]
94#[cfg_attr(docsrs, doc(cfg(feature = "test-util")))]
95pub use transport::{MockTransport, RecordedRequest};
96
97#[cfg(feature = "axum")]
98#[cfg_attr(docsrs, doc(cfg(feature = "axum")))]
99pub use integrations::axum;
100
101/// Compile the README examples as doctests (`cargo test --all-features`).
102#[cfg(all(doctest, feature = "axum", feature = "test-util"))]
103#[doc = include_str!("../README.md")]
104mod readme_doctests {}
105
106/// Compile the guide examples as doctests (`cargo test --all-features`).
107#[cfg(all(doctest, feature = "axum", feature = "test-util"))]
108#[doc = include_str!("../docs/GUIDE.md")]
109mod guide_doctests {}
110
111/// Commonly used protocol and client types.
112pub mod prelude {
113    pub use crate::{
114        Client, Error, FormPaymentRequest, Money, NOTIFY_FAIL, NOTIFY_SUCCESS, NotifyData,
115        OrderDetail, OrderQueryRequest, PayType, PaymentRequest, PaymentResponse, ProtocolContext,
116        RefundRequest, Result, SuccessfulNotify,
117    };
118
119    #[cfg(feature = "axum")]
120    pub use crate::axum::{NotifyAck, ParsedNotify, VerifiedNotify, VerifiedReturn};
121}