pub struct MemoryPayProvider { /* private fields */ }Expand description
内存支付提供商 — 用于测试和开发环境
不实际调用支付平台 API,而是将支付/退款记录暂存到内存,供测试断言使用。
§线程安全
通过 Arc<Mutex<...>> 保护内部状态,支持并发访问。
§用法
ⓘ
use sz_rust_core::pay::{MemoryPayProvider, PayOrder, PayProvider};
let provider = MemoryPayProvider::new();
let order = PayOrder::new()
.out_trade_no("202401010001")
.total_amount(8800)
.subject("鲜视达商品");
let result = provider.pay(order).unwrap();
assert_eq!(result.out_trade_no, "202401010001");
assert_eq!(provider.orders().len(), 1);Implementations§
Source§impl MemoryPayProvider
impl MemoryPayProvider
Sourcepub fn new() -> MemoryPayProvider
pub fn new() -> MemoryPayProvider
创建新的内存支付提供商
Sourcepub fn refunds(&self) -> Vec<RefundOrder>
pub fn refunds(&self) -> Vec<RefundOrder>
获取所有已发起的退款记录(快照)
Sourcepub fn set_query_result(&self, result: PayResult)
pub fn set_query_result(&self, result: PayResult)
预置查询结果(query 调用将返回此结果)
设置后,PayProvider::query 将直接返回此结果,不再查找已发起订单。
传 None 清除预置,恢复正常查找逻辑。
Trait Implementations§
Source§impl Debug for MemoryPayProvider
impl Debug for MemoryPayProvider
Source§impl Default for MemoryPayProvider
impl Default for MemoryPayProvider
Source§fn default() -> MemoryPayProvider
fn default() -> MemoryPayProvider
Returns the “default value” for a type. Read more
Source§impl PayProvider for MemoryPayProvider
impl PayProvider for MemoryPayProvider
Source§fn query(&self, out_trade_no: &str) -> Result<PayResult, PayError>
fn query(&self, out_trade_no: &str) -> Result<PayResult, PayError>
查询订单(对齐
Pay::alipay()->find()) Read moreSource§fn close(&self, out_trade_no: &str) -> Result<(), PayError>
fn close(&self, out_trade_no: &str) -> Result<(), PayError>
关闭订单(对齐
Pay::alipay()->close()) Read moreAuto Trait Implementations§
impl !RefUnwindSafe for MemoryPayProvider
impl !UnwindSafe for MemoryPayProvider
impl Freeze for MemoryPayProvider
impl Send for MemoryPayProvider
impl Sync for MemoryPayProvider
impl Unpin for MemoryPayProvider
impl UnsafeUnpin for MemoryPayProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.