Bitzsoft.Integrations.Payment
1.0.0
See the version list below for details.
dotnet add package Bitzsoft.Integrations.Payment --version 1.0.0
NuGet\Install-Package Bitzsoft.Integrations.Payment -Version 1.0.0
<PackageReference Include="Bitzsoft.Integrations.Payment" Version="1.0.0" />
<PackageVersion Include="Bitzsoft.Integrations.Payment" Version="1.0.0" />
<PackageReference Include="Bitzsoft.Integrations.Payment" />
paket add Bitzsoft.Integrations.Payment --version 1.0.0
#r "nuget: Bitzsoft.Integrations.Payment, 1.0.0"
#:package Bitzsoft.Integrations.Payment@1.0.0
#addin nuget:?package=Bitzsoft.Integrations.Payment&version=1.0.0
#tool nuget:?package=Bitzsoft.Integrations.Payment&version=1.0.0
Bitzsoft.Integrations.Payment
支付抽象层 — 统一下单、查单、关单、退款与回调验签。屏蔽支付宝、微信、Stripe、PayPal、银联等供应商差异,提供一致的支付全流程 API。
功能特性
- 统一供应商接口
IPaymentProvider:5 个异步方法覆盖下单、查单、关单、退款与回调验签 - 泛型结果包装
PaymentResult<T>:统一携带IsSuccess/Data/ErrorCode/ErrorMessage,无数据操作使用非泛型PaymentResult - 统一供应商编码常量
PaymentProviderCode:alipay/wechatpay/stripe/paypal/unionpay - 配置抽象
IPaymentConfigProvider<TOptions>:解耦配置来源,支持 IOptions / 数据库 / 配置中心 - 统一异常
PaymentException:封装供应商名称、错误码与原始错误消息 - 多场景支持:
PaymentScene覆盖 App / Web / H5 / 扫码支付
安装
dotnet add package Bitzsoft.Integrations.Payment
<PackageReference Include="Bitzsoft.Integrations.Payment" Version="1.0.0" />
接口
IPaymentProvider
统一的支付供应商接口。
| 方法 | 返回类型 | 说明 |
|---|---|---|
Code |
string |
供应商编码(如 alipay、wechatpay、stripe、paypal、unionpay) |
CreateOrderAsync |
Task<PaymentResult<PaymentOrderResult>> |
创建支付订单,按场景返回支付链接 / 二维码 / 预支付标识 |
QueryStatusAsync |
Task<PaymentResult<PaymentStatusResult>> |
按商户订单号查询支付状态 |
CloseOrderAsync |
Task<PaymentResult> |
关闭订单 |
RefundAsync |
Task<PaymentResult<RefundResult>> |
申请退款(支持全额 / 部分退款) |
VerifyCallbackAsync |
Task<PaymentResult<CallbackVerificationResult>> |
验证支付回调签名并解析回调内容 |
核心模型
| 类 | 关键字段 | 说明 |
|---|---|---|
PaymentOrderRequest |
OutTradeNo、Subject、TotalAmount、Currency、Scene、NotifyUrl、ReturnUrl、OpenId、AuthCode、Extra |
支付下单请求(金额单位:分) |
PaymentOrderResult |
OutTradeNo、PayUrl、QrCode、PrepayId、RawResponse |
下单结果 |
PaymentStatusResult |
OutTradeNo、TradeNo、Status、PaidAmount、PaidAt |
支付状态查询结果 |
RefundRequest |
OutTradeNo、RefundNo、RefundAmount、TotalAmount、Reason |
退款请求 |
RefundResult |
RefundNo、Status、RefundAmount、RefundedAt |
退款结果 |
CallbackPayload |
Body、Headers、QueryString |
回调请求载荷 |
CallbackVerificationResult |
OutTradeNo、TradeNo、PaidAmount、PaidAt、Status、RawData |
回调验签结果 |
PaymentResult<T> |
IsSuccess、Data、ErrorCode、ErrorMessage |
带数据的通用结果包装 |
PaymentResult |
IsSuccess、ErrorCode、ErrorMessage |
无数据结果(仅成功 / 失败) |
PaymentException |
— | 统一异常(继承 IntegrationException,构造函数接收 providerName / errorCode / providerMessage) |
枚举
| 枚举 | 说明 |
|---|---|
PaymentScene |
支付场景:App / Web / H5 / Code |
PaymentStatus |
支付状态:Pending / Success / Closed / Refunded / Failed |
RefundStatus |
退款状态:Pending / Success / Failed / Abnormal |
供应商编码常量
PaymentProviderCode 静态类提供以下常量:
| 常量 | 值 | 供应商 |
|---|---|---|
Alipay |
alipay |
支付宝 |
WeChatPay |
wechatpay |
微信支付 |
Stripe |
stripe |
Stripe |
PayPal |
paypal |
PayPal |
UnionPay |
unionpay |
银联 |
使用示例
抽象层本身只定义接口与模型,具体实现由各供应商包提供。以下示例假设已注册某个供应商实现:
public class OrderService(IPaymentProvider payment)
{
public async Task<string> CreatePaymentAsync(string outTradeNo, long amountCents, string subject)
{
var result = await payment.CreateOrderAsync(new PaymentOrderRequest
{
OutTradeNo = outTradeNo,
Subject = subject,
TotalAmount = amountCents,
Currency = "CNY",
Scene = PaymentScene.Web
});
if (!result.IsSuccess)
{
throw new PaymentException(payment.Code, result.ErrorCode, result.ErrorMessage);
}
return result.Data!.PayUrl!;
}
public async Task<bool> IsPaidAsync(string outTradeNo)
{
var result = await payment.QueryStatusAsync(outTradeNo);
return result.IsSuccess && result.Data!.Status == PaymentStatus.Success;
}
}
多供应商解析
同一应用注册多个供应商时,通过 IIntegrationProviderResolver<IPaymentProvider> 按供应商编码解析:
var resolver = serviceProvider.GetRequiredService<IIntegrationProviderResolver<IPaymentProvider>>();
var alipay = resolver.GetRequired(PaymentProviderCode.Alipay);
var result = await alipay.CreateOrderAsync(request);
依赖
- Bitzsoft.Integrations.Core:公共基座(
IntegrationException、IIntegrationProviderResolver<T>)
相关包
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.0)
- Bitzsoft.Integrations.Core (>= 1.0.0)
-
net5.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.0)
- Bitzsoft.Integrations.Core (>= 1.0.0)
-
net8.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.0)
- Bitzsoft.Integrations.Core (>= 1.0.0)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Bitzsoft.Integrations.Payment:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.Payment.All
支付聚合包 — 包含支付宝 / 微信支付 / Stripe / PayPal / 银联 全部实现 |
|
|
Bitzsoft.Integrations.Payment.WeChatPay
微信支付实现 — 支持 APP / Native 扫码 / H5 / 付款码 / 退款 / 回调验签(APIv3) |
|
|
Bitzsoft.Integrations.Payment.Stripe
Stripe 支付实现 — 支持 Checkout Session 下单 / 退款 / Webhook 回调验签 |
|
|
Bitzsoft.Integrations.Payment.Alipay
支付宝支付实现 — 支持 APP / 电脑网页 / 手机网站 / 扫码当面付 / 退款 / 回调验签 |
|
|
Bitzsoft.Integrations.Payment.PayPal
PayPal 支付实现 — OAuth2 Client Credentials 令牌缓存 + Orders REST API v2,支持下单 / 查询 / 关单 / 退款 / Webhook 回调验签 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 139 | 8/3/2026 |
| 1.0.0 | 144 | 8/2/2026 |
| 1.0.0-alpha.10 | 63 | 7/26/2026 |
| 1.0.0-alpha.9 | 400 | 7/12/2026 |