Galosys.Foundation.Payment 26.5.20.1

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

Galosys.Foundation.Payment

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

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

功能特性

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

安装

<PackageReference Include="Galosys.Foundation.Payment" 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.Payment;

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.Payment;

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 = "测试"
});

支付场景(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 订单状态枚举

依赖

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

Package Downloads
Galosys.Foundation.AlipayEasySDK

Galosys.Foundation快速开发库

Galosys.Foundation.Wechat

Galosys.Foundation快速开发库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.5.20.1 156 5/20/2026
26.5.19.1 154 5/19/2026
26.5.18.1 148 5/18/2026
26.5.15.1 155 5/15/2026
26.5.12.3 147 5/12/2026
26.5.12.2 147 5/12/2026
26.4.27.1-rc1 145 4/26/2026
26.4.25.1-rc1 137 4/25/2026
26.4.22.2-rc7 144 4/22/2026
26.4.22.2-rc6 141 4/22/2026
26.4.22.2-rc4 147 4/22/2026
26.4.22.2-rc3 90 4/22/2026
26.4.19.1-rc1 99 4/19/2026