Bitzsoft.Integrations.Payment 1.0.1

dotnet add package Bitzsoft.Integrations.Payment --version 1.0.1
                    
NuGet\Install-Package Bitzsoft.Integrations.Payment -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.Payment" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Payment" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Bitzsoft.Integrations.Payment" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.Payment --version 1.0.1
                    
#r "nuget: Bitzsoft.Integrations.Payment, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.Payment@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.Payment&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Bitzsoft.Integrations.Payment&version=1.0.1
                    
Install as a Cake Tool

Bitzsoft.Integrations.Payment

支付抽象层 — 统一下单、查单、关单、退款与回调验签。屏蔽支付宝、微信、Stripe、PayPal、银联等供应商差异,提供一致的支付全流程 API。

功能特性

  • 统一供应商接口 IPaymentProvider:5 个异步方法覆盖下单、查单、关单、退款与回调验签
  • 泛型结果包装 PaymentResult<T>:统一携带 IsSuccess / Data / ErrorCode / ErrorMessage,无数据操作使用非泛型 PaymentResult
  • 统一供应商编码常量 PaymentProviderCodealipay / 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 供应商编码(如 alipaywechatpaystripepaypalunionpay
CreateOrderAsync Task<PaymentResult<PaymentOrderResult>> 创建支付订单,按场景返回支付链接 / 二维码 / 预支付标识
QueryStatusAsync Task<PaymentResult<PaymentStatusResult>> 按商户订单号查询支付状态
CloseOrderAsync Task<PaymentResult> 关闭订单
RefundAsync Task<PaymentResult<RefundResult>> 申请退款(支持全额 / 部分退款)
VerifyCallbackAsync Task<PaymentResult<CallbackVerificationResult>> 验证支付回调签名并解析回调内容

核心模型

关键字段 说明
PaymentOrderRequest OutTradeNoSubjectTotalAmountCurrencySceneNotifyUrlReturnUrlOpenIdAuthCodeExtra 支付下单请求(金额单位:分)
PaymentOrderResult OutTradeNoPayUrlQrCodePrepayIdRawResponse 下单结果
PaymentStatusResult OutTradeNoTradeNoStatusPaidAmountPaidAt 支付状态查询结果
RefundRequest OutTradeNoRefundNoRefundAmountTotalAmountReason 退款请求
RefundResult RefundNoStatusRefundAmountRefundedAt 退款结果
CallbackPayload BodyHeadersQueryString 回调请求载荷
CallbackVerificationResult OutTradeNoTradeNoPaidAmountPaidAtStatusRawData 回调验签结果
PaymentResult<T> IsSuccessDataErrorCodeErrorMessage 带数据的通用结果包装
PaymentResult IsSuccessErrorCodeErrorMessage 无数据结果(仅成功 / 失败)
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.Payment
支付宝 Bitzsoft.Integrations.Payment.Alipay
微信支付 Bitzsoft.Integrations.Payment.WeChatPay
Stripe Bitzsoft.Integrations.Payment.Stripe
PayPal Bitzsoft.Integrations.Payment.PayPal
银联 Bitzsoft.Integrations.Payment.UnionPay
聚合包 Bitzsoft.Integrations.Payment.All
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 121 8/3/2026
1.0.0 124 8/2/2026
1.0.0-alpha.10 63 7/26/2026
1.0.0-alpha.9 400 7/12/2026