Galosys.Foundation.Integration.Payment.Abstractions 26.7.31.1

dotnet add package Galosys.Foundation.Integration.Payment.Abstractions --version 26.7.31.1
                    
NuGet\Install-Package Galosys.Foundation.Integration.Payment.Abstractions -Version 26.7.31.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="Galosys.Foundation.Integration.Payment.Abstractions" Version="26.7.31.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Integration.Payment.Abstractions" Version="26.7.31.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Integration.Payment.Abstractions" />
                    
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 Galosys.Foundation.Integration.Payment.Abstractions --version 26.7.31.1
                    
#r "nuget: Galosys.Foundation.Integration.Payment.Abstractions, 26.7.31.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 Galosys.Foundation.Integration.Payment.Abstractions@26.7.31.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=Galosys.Foundation.Integration.Payment.Abstractions&version=26.7.31.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Integration.Payment.Abstractions&version=26.7.31.1
                    
Install as a Cake Tool

Galosys.Foundation.Integration.Payment.Abstractions

成熟度: 🟢 稳定 — 统一支付抽象 + 插件路由,含完整测试覆盖

统一支付抽象模块,通过 IPaymentDispatcher + IPaymentChannel 插件路由实现多支付通道统一管理。代码只需依赖 IPaymentDispatcher,无需关心底层支付通道实现。

功能特性

  • 插件路由PluginRegistry<IPaymentChannel, PaymentRequest> 自动按 Channel 字符串分发
  • 统一 APIIPaymentDispatcher 提供创建/查询/退款/回调/关单 5 个操作
  • 可扩展 — 实现 IPaymentChannel 接口即可接入新支付通道
  • 内置 MockMockPaymentChannel 用于开发和测试环境
  • 完整 DTO — 6 种支付场景(PagePay/FaceToFace/JsApi/H5/Native/App)、5 种订单状态

安装

<PackageReference Include="Galosys.Foundation.Integration.Payment.Abstractions" Version="x.x.x" />

快速开始

1. 注册服务

// 方式一:模块自动发现(推荐)
await Host.CreateDefaultBuilder()
    .UseModularization()
    .Locate()
    .RunAsync();

// 方式二:手动注册
services.AddPayment();
services.AddTransient<IPaymentChannel, AlipayChannel>();
services.AddTransient<IPaymentChannel, WeChatPayChannel>();

2. 创建支付

using Galosys.Foundation.Integration.Payment.Abstractions;

public class OrderService
{
    private readonly IPaymentDispatcher _payment;

    public OrderService(IPaymentDispatcher payment) => _payment = payment;

    // PC 网页支付
    public async Task<PaymentCreateResult> CreatePagePayAsync()
    {
        return await _payment.PayAsync(new PaymentCreateRequest
        {
            Channel = "alipay",          // 路由到 AlipayChannel
            OutTradeNo = "ORD001",
            Amount = 99.9m,
            Subject = "测试订单",
            PaymentType = PaymentType.PagePay,
            NotifyUrl = "https://example.com/notify",
            ReturnUrl = "https://example.com/return"
        });
    }

    // 微信小程序支付
    public async Task<PaymentCreateResult> CreateJsApiAsync()
    {
        return await _payment.PayAsync(new PaymentCreateRequest
        {
            Channel = "wechat",
            OutTradeNo = "ORD002",
            Amount = 199.0m,
            Subject = "小程序订单",
            PaymentType = PaymentType.JsApi,
            OpenId = "用户的OpenId"
        });
    }
}

3. 查询/退款/回调/关单

// 查询订单状态
var result = await _payment.QueryAsync("alipay", "ORD001");

// 退款
var refund = await _payment.RefundAsync(new PaymentRefundRequest
{
    Channel = "alipay",
    OutTradeNo = "ORD001",
    OutRefundNo = "REF001",
    RefundAmount = 50.0m,
    TotalAmount = 99.9m,
    Reason = "部分退款"
});

// 处理支付回调
var notify = await _payment.HandleNotifyAsync("alipay", new PaymentNotifyRequest
{
    RawBody = rawBody,
    Headers = headers
});

// 关闭订单
await _payment.CloseAsync("alipay", "ORD001");

4. 扩展支付通道

using Galosys.Foundation.Integration.Payment.Abstractions;

public class AlipayChannel : IPaymentChannel
{
    public string ChannelName => "alipay";

    public bool Supports(PaymentRequest request)
        => string.Equals(request.Channel, ChannelName, StringComparison.OrdinalIgnoreCase);

    public Task<PaymentCreateResult> CreateAsync(PaymentCreateRequest request)
    {
        // 调用支付宝 SDK
        return Task.FromResult(new PaymentCreateResult("ORD001", payUrl: "https://..."));
    }

    public Task<PaymentQueryResult> QueryAsync(string outTradeNo) => throw new NotImplementedException();
    public Task<PaymentRefundResult> RefundAsync(PaymentRefundRequest request) => throw new NotImplementedException();
    public Task<PaymentNotifyResult> HandleNotifyAsync(PaymentNotifyRequest request) => throw new NotImplementedException();
    public Task CloseAsync(string outTradeNo) => throw new NotImplementedException();
}

// 注册
services.AddTransient<IPaymentChannel, AlipayChannel>();

5. 开发/测试环境使用 Mock

services.AddPayment();
// MockPaymentChannel 已内置,无需额外注册,Channel 传 "mock" 即可

var result = await _payment.PayAsync(new PaymentCreateRequest
{
    Channel = "mock",
    OutTradeNo = "TEST001",
    Amount = 1.0m,
    Subject = "测试"
});

6. 日终对账

using Galosys.Foundation.Integration.Payment.Abstractions;

public class DailyReconciliationJob
{
    private readonly IReconciliationExecutor _executor;

    public DailyReconciliationJob(IReconciliationExecutor executor) => _executor = executor;

    public async Task RunAsync()
    {
        var yesterday = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");

        // 分别对账支付宝和微信
        var alipayResult = await _executor.ExecuteAsync(yesterday, "alipay");
        var wechatResult = await _executor.ExecuteAsync(yesterday, "wechatpay");

        Console.WriteLine($"支付宝差异: {alipayResult.TotalDiffs}");
        Console.WriteLine($"微信差异: {wechatResult.TotalDiffs}");
    }
}

对账规则链自动执行四个阶段:

规则 顺序 说明
ExistsRule 1 双向 EXISTS:渠道有本地无 / 本地有渠道无
AmountRule 2 同一订单号金额比对
RefundRule 3 退款聚合校验
StatusRule 4 状态漂移检查

7. 账单拉取与标准化

// 渠道账单拉取
var rawFile = await channel.PullBillFileAsync(new BillPullRequest(
    "2024-01-20", BillType.Trade));

// 标准化为统一 DTO
var normalizer = new AlipayBillNormalizer();
var bills = await normalizer.NormalizeAsync(rawFile);
// bills[0].TotalAmount, bills[0].TradeStatus, bills[0].Platform...

支付场景(PaymentType)

说明
PagePay PC 网页支付
FaceToFace 当面付(扫码)
JsApi 微信公众号/小程序支付
H5 H5 手机浏览器支付
Native Native 扫码支付
App APP 支付

订单状态(PaymentStatus)

说明
Pending 待支付
Paid 已支付
Closed 已关闭
Refunded 已全额退款
RefundPartial 部分退款

核心类

类名 说明
IPaymentDispatcher 统一支付调度器接口(消费者使用)
IPaymentChannel 支付通道接口(通道实现者使用)
PaymentDispatcher 调度器实现,通过 PluginRegistry 自动路由
MockPaymentChannel 内置 Mock 通道,用于开发/测试
PaymentCreateRequest 创建订单请求
PaymentRefundRequest 退款请求
PaymentNotifyRequest 回调通知请求
PaymentCreateResult 创建结果(PayUrl/QrCode/PrepayId)
PaymentQueryResult 查询结果(Status/Amount/PaidAt)
PaymentNotifyResult 回调处理结果
PaymentRefundResult 退款结果
PaymentType 支付场景枚举
PaymentStatus 订单状态枚举
IReconciliationExecutor 对账编排器接口
IBillNormalizer 账单标准化接口
IReconciliationRule 对账规则接口(内置 4 条规则)
NormalizedBillDto 标准化账单 DTO
BillRawFile 渠道账单原始文件

依赖

  • Galosys.Foundation.CorePluginRegistry<TPlugin, TRequest>IModule
Product Compatible and additional computed target framework versions.
.NET 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 (2)

Showing the top 2 NuGet packages that depend on Galosys.Foundation.Integration.Payment.Abstractions:

Package Downloads
Galosys.Foundation.Wechat

Galosys.Foundation快速开发库

Galosys.Foundation.Alipay

Galosys.Foundation快速开发库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.7.31.1 41 7/31/2026
26.7.30.1 43 7/30/2026
26.7.29.1 76 7/29/2026
26.7.28.1 79 7/28/2026
26.7.26.2 101 7/26/2026
26.7.26.1 97 7/25/2026
26.7.25.1 98 7/25/2026