Tai.Wallet.Recharge.EntityFrameworkCore 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tai.Wallet.Recharge.EntityFrameworkCore --version 0.1.0
                    
NuGet\Install-Package Tai.Wallet.Recharge.EntityFrameworkCore -Version 0.1.0
                    
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="Tai.Wallet.Recharge.EntityFrameworkCore" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tai.Wallet.Recharge.EntityFrameworkCore" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Tai.Wallet.Recharge.EntityFrameworkCore" />
                    
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 Tai.Wallet.Recharge.EntityFrameworkCore --version 0.1.0
                    
#r "nuget: Tai.Wallet.Recharge.EntityFrameworkCore, 0.1.0"
                    
#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 Tai.Wallet.Recharge.EntityFrameworkCore@0.1.0
                    
#: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=Tai.Wallet.Recharge.EntityFrameworkCore&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Tai.Wallet.Recharge.EntityFrameworkCore&version=0.1.0
                    
Install as a Cake Tool

Tai.Wallet.Recharge

可选的钱包充值模块。它组合 Tai.Wallet 和 Tai.Payment:服务端为当前用户生成支付请求,支付成功并确认属于这笔充值后, 给该用户的钱包记一笔 Recharge 流水并增加余额。

Tai.Wallet 核心不引用 Tai.Payment,也不知道本模块存在。只做内部记账或提现的宿主不需要安装本模块和支付模块。 本模块只依赖支付的 Domain 层与网关抽象,不引用微信、支付宝或 Stripe Provider;网关密钥、回调地址和启用的网关仍由宿主按 Tai.Payment 的方式配置,本模块不保存任何凭据。

不包含充值退款、余额付款或前端页面。

自动发布使用模块版本标签和 NuGet Trusted Publishing,配置与操作见发布指南。

构建与验证

需要 .NET 10 SDK;ABP 使用 10.7.0,Microsoft 配套包与 dotnet-ef 使用 10.0.12。在本目录执行:

dotnet tool restore
bash scripts/verify.sh
dotnet run --project samples/Tai.Wallet.Recharge.Sample -- --migrate
dotnet run --project samples/Tai.Wallet.Recharge.Sample --urls http://localhost:5300

verify.sh 执行还原、Release 构建、测试、迁移一致性检查、临时 SQLite 迁移,并把 src 下的项目逐个打包到 artifacts/packages。SQLite 示例迁移不能代替生产数据库验证。

模块结构

包 内容
Tai.Wallet.Recharge.Domain.Shared 充值状态、常量、错误码与中英文本地化
Tai.Wallet.Recharge.Domain WalletRecharge 聚合、WalletRechargeManager、支付完成事件处理器与补账后台作业
Tai.Wallet.Recharge.Application.Contracts / Application IWalletRechargeAppService、DTO 和权限
Tai.Wallet.Recharge.EntityFrameworkCore IWalletRechargeDbContext、模型映射与默认仓储
Tai.Wallet.Recharge.HttpApi api/wallet/recharges 控制器

依赖:Tai.Wallet.Domain 0.1.9、Tai.Payment.Domain 0.1.1 和 Volo.Abp.BackgroundJobs.Abstractions。

宿主接入

宿主模块按需依赖:

[DependsOn(
    typeof(TaiWalletRechargeApplicationModule),
    typeof(TaiWalletRechargeHttpApiModule),
    typeof(TaiWalletRechargeEntityFrameworkCoreModule),
    typeof(TaiWalletEntityFrameworkCoreModule),
    typeof(PaymentHttpApiModule),                    // 网关回调入口
    typeof(PaymentEntityFrameworkCoreModule),
    typeof(PaymentWeChatModule),                     // 按需选择 Provider
    typeof(AbpBackgroundJobsEntityFrameworkCoreModule) // 或宿主已有的后台作业实现
)]

宿主 DbContext 实现 IWalletDbContext、IPaymentDbContext、IWalletRechargeDbContext(以及持久化后台作业时的 IBackgroundJobsDbContext),在 OnModelCreating 调用 ConfigureWallet()、ConfigurePayment()、 ConfigureWalletRecharge()、ConfigureBackgroundJobs(),再用 ReplaceDbContext 接入:

context.Services.AddAbpDbContext<HostDbContext>(o =>
{
    o.ReplaceDbContext<IWalletDbContext>();
    o.ReplaceDbContext<IPaymentDbContext>();
    o.ReplaceDbContext<IWalletRechargeDbContext>();
    o.ReplaceDbContext<IBackgroundJobsDbContext>();
});

默认表为 TaiWalletRecharges,通过 WalletRechargeDbProperties 修改前缀和 Schema。充值记录与钱包流水在同一事务中提交, 因此连接字符串名沿用钱包的 TaiWallet,两者必须位于同一个数据库。示例提供 SQLite 迁移,生产宿主针对自己的 DbContext 生成迁移。

配置 WalletRechargeOptions(示例绑定 WalletRecharge 节):

选项 默认值 说明
Currency CNY 充值币种,必须是钱包的记账币种,且为两位小数的 Tai.Payment 币种
MinAmount / MaxAmount 1 / 100000000 单笔充值金额范围,单位为最小货币单位
ProductName Wallet recharge 服务端生成的支付商品名称

宿主还需要:

  • 使用 UTC 时钟(AbpClockOptions.Kind = DateTimeKind.Utc),与 Tai.Payment 一致。
  • 安装 ABP 后台作业实现。补账作业在支付完成事件中入队;建议使用与支付同库的持久化存储,使作业记录与支付完成一起提交。 未安装实现时只记录警告,需由用户调用刷新或宿主调用 WalletRechargeManager.SettleAsync 补账。
  • 若分布式事件总线使用真实消息代理,配置 ABP Outbox,避免支付已提交但事件丢失。
  • 多实例部署时配置共享的 ABP 分布式锁。

HTTP 接口与权限

请求 权限 说明
POST /api/wallet/recharges Wallet.Recharges.Create 为自己创建充值,请求体只有 requestId 和 amount
GET /api/wallet/recharges/{id} Wallet.Recharges 查询自己的充值状态
POST /api/wallet/recharges/{id}/checkout Wallet.Recharges.Create 用 { "gateway": "WeChat" } 发起支付
POST /api/wallet/recharges/{id}/refresh Wallet.Recharges 向网关查单,已支付则入账

用户与租户取自认证上下文,客户端提交的其他字段会被忽略。他人的充值一律返回 404,管理员权限也不会读写他人的充值。 amount 为最小货币单位的整数,例如 1000 表示 10.00 CNY。不要把 Tai.Payment 的支付建单接口开放给付款人; 本模块在服务端生成支付请求,商品代码固定为 tai-wallet-recharge,幂等键为 tai-wallet-recharge:{充值ID}, 数量 1,单价等于钱包金额除以 100。

状态:WaitingForPayment、PaymentFailed、Paid(已支付、待入账)、Credited。

幂等、事务与补账

  • 同一用户重复提交同一 requestId 返回原充值;金额不同返回 Tai.Wallet:RequestConflict。requestId 按租户和用户隔离。
  • 钱包流水 ID 等于充值 ID,沿用 BalanceManager 的幂等,重复回调、刷新、作业重试最多产生一笔充值流水。
  • 入账前校验支付请求 ID、租户、用户、币种、精确金额和唯一的充值商品;任一不一致返回 Tai.Wallet.Recharge:PaymentMismatch,不入账。支付未完成不入账。
  • 支付完成与钱包入账是两次独立提交。支付完成事件只登记补账作业;入账失败时作业按 ABP 策略重试, 用户刷新或宿主调用 SettleAsync 也会补上同一笔入账,不需要重新付款。
  • 钱包被禁用时拒绝创建和发起支付;若付款后钱包才被禁用,入账失败,重新启用后补账。
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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 121 11/19/2026
1.1.0 189 11/1/2026
1.0.0 137 10/17/2026
0.2.2 112 10/17/2026
0.2.1 118 10/11/2026
0.2.0 110 10/11/2026
0.1.0 114 10/10/2026