Compare commits

...

15 Commits

Author SHA1 Message Date
李东云
b521e7c9e0 chore(release): 1.2.4 2025-08-21 18:18:31 +08:00
李东云
2276885ac1 refactor(transaction): 修改交易项中的价格字段名称
- 将 Item 类中的 'price' 字段重命名为 'unit_price'
- 更新 CallbackDomainSvc 中的回调函数,使用新的 'unit_price' 字段
2025-08-21 18:18:27 +08:00
李东云
8d2d3c8ba5 chore(release): 1.2.3 2025-08-20 20:00:51 +08:00
李东云
86939ea421 refactor(transaction): 重构交易信息构建方式
- 将 payType 和 type 字段的值存储为它们的 value 属性
-将 status 字段的值存储为它的 name 属性
2025-08-20 20:00:46 +08:00
李东云
960e3f1877 chore(release): 1.2.2 2025-08-20 19:36:33 +08:00
李东云
2ea5227185 fix(transaction): 修复回调服务中的商品价格字段
- 将 Item 类中的 price 字段从 $item['unit_price'] 修改为 $item['price']
- 确保回调服务正确使用商品的价格信息
2025-08-20 19:36:26 +08:00
李东云
c7f94bb396 chore(release): 1.2.1 2025-08-20 14:40:36 +08:00
李东云
9d61106e2e feat(TransactionRecord): 添加 TransactionRecord 类的 getter 方法
- 为 TransactionRecord 类添加了多个 getter 方法,以获取私有属性的值
- 新增的方法包括 getOrderNo、getUid、getPayType、getAction、getStatus、getSource、getItems、getTransactions、getRefunds、getExternal、getExternalId、getCreatedAt、getOccurredAt 和 getLastRefundedAt
- 这些方法提供了对交易记录各个字段的访问能力,便于在域内和其他对象进行交互
2025-08-20 14:40:20 +08:00
李东云
c3a256cb3d build(deps): 更新多个依赖至最新版本
- 更新 ergebnis/http-method 从 2.5.0 到 2.6.0
- 更新 react/promise 从 v2.11.0 到 v3.2.0
- 更新 singularity/hdk-core 从 1.0.0-beta.14 到1.0.1
- 更新多个 symfony/polyfill 包至最新版本
2025-08-20 14:40:04 +08:00
李东云
245f13b26d chore(release): 1.2.0 2025-08-20 13:50:37 +08:00
李东云
fc5cf453ae test: 更新 LuxPay 回调测试用例
移除了 LuxPayCallbackTest 中冗余的 only() 方法调用,简化了测试用例的编写。
2025-08-20 13:50:05 +08:00
李东云
8f71cbeb65 feat(transaction): 添加交易相关实体和回调服务
- 新增 CardTransaction、PointTransaction、Item、Transaction 和 TransactionRecord 类
- 实现 CallbackDomainSvc 类的 callback 方法,用于处理回调请求
- 添加 LuxPayCallbackTest 测试类,验证回调解析功能
2025-08-20 13:48:44 +08:00
李东云
9517b5bd62 chore(release): 1.1.0 2025-08-18 20:00:54 +08:00
李东云
c8ee3bb23b feat(pay): 新增消费命令和通用订单 DTO
- 添加 ConsumeCmd 类用于消费操作
- 重构 RechargeCmd 类,使其返回自身以便链式调用
- 将 RechargeDto 重命名为 OrderDto,作为通用订单数据传输对象
- 更新 OrderRepoInterface 接口,使用新的命令和 DTO 类
- 修改 AccountBalanceRepo、OrderRepo 和 ProductRepo,移除不必要的选项参数
- 新增 CreateConsumptionOrderTest 测试用例
- 更新 CreateRechargeOrderTest 测试用例以使用新的命令和 DTO 类
2025-08-18 19:58:42 +08:00
李东云
80dc1a3706 feat(pay): 添加充值功能
- 新增 RechargeCmd 类用于处理充值命令
- 新增 RechargeDto 类用于表示充值交易数据
- 新增 OrderAction、OrderStatus 和 PayType 枚举类
- 新增 OrderRepoInterface接口和 OrderRepo 实现类,用于处理订单相关操作
- 更新 ConfigProvider,添加新依赖项
- 新增 CreateRechargeOrderTest 测试用例
2025-08-18 19:12:07 +08:00
26 changed files with 953 additions and 77 deletions

View File

@@ -1,4 +1,57 @@
# 版本更新日志
### [1.2.4](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.2.3...v1.2.4) (2025-08-21)
### ♻️ Code Refactoring | 代码重构
* **transaction:** 修改交易项中的价格字段名称 ([2276885](http://124.126.16.154:8888/singularity/hdk-pay/commit/2276885ac1759a330eb6fb73e1158235edcac941))
### [1.2.3](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.2.2...v1.2.3) (2025-08-20)
### ♻️ Code Refactoring | 代码重构
* **transaction:** 重构交易信息构建方式 ([86939ea](http://124.126.16.154:8888/singularity/hdk-pay/commit/86939ea421d2f14c621da4e3bb86e3ab8d8b7d33))
### [1.2.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.2.1...v1.2.2) (2025-08-20)
### 🐛 Bug Fixes | Bug 修复
* **transaction:** 修复回调服务中的商品价格字段 ([2ea5227](http://124.126.16.154:8888/singularity/hdk-pay/commit/2ea52271852e4e009b044fb9baeb222b3a54c111))
### [1.2.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.2.0...v1.2.1) (2025-08-20)
### 📦‍ Build System | 打包构建
* **deps:** 更新多个依赖至最新版本 ([c3a256c](http://124.126.16.154:8888/singularity/hdk-pay/commit/c3a256cb3d5e41a29a4969442b5a7f27c9000576))
### ✨ Features | 新功能
* **TransactionRecord:** 添加 TransactionRecord 类的 getter 方法 ([9d61106](http://124.126.16.154:8888/singularity/hdk-pay/commit/9d61106e2e8b04559fb34b606fb489a2890c34d5))
## [1.2.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.1.0...v1.2.0) (2025-08-20)
### ✨ Features | 新功能
* **transaction:** 添加交易相关实体和回调服务 ([8f71cbe](http://124.126.16.154:8888/singularity/hdk-pay/commit/8f71cbeb653d0722f231c300c2a1fabe79764580))
### ✅ Tests | 测试
* 更新 LuxPay 回调测试用例 ([fc5cf45](http://124.126.16.154:8888/singularity/hdk-pay/commit/fc5cf453aed133552514e1b60699fe63d2178543))
## [1.1.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0...v1.1.0) (2025-08-18)
### ✨ Features | 新功能
* **pay:** 新增消费命令和通用订单 DTO ([c8ee3bb](http://124.126.16.154:8888/singularity/hdk-pay/commit/c8ee3bb23bf41f39a64ca08db4a005d2893c1554))
* **pay:** 添加充值功能 ([80dc1a3](http://124.126.16.154:8888/singularity/hdk-pay/commit/80dc1a3706fa973f3360c70f1db34d403eb741df))
## [1.0.0](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-beta.5...v1.0.0) (2025-08-18)

View File

@@ -70,5 +70,5 @@
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.0.0"
"version": "1.2.4"
}

133
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1502e30908a8b64e02da6b75783f3598",
"content-hash": "842b9afd4b54f12687b614b3d52a7b77",
"packages": [
{
"name": "carbonphp/carbon-doctrine-types",
@@ -942,16 +942,16 @@
},
{
"name": "ergebnis/http-method",
"version": "2.5.0",
"version": "2.6.0",
"source": {
"type": "git",
"url": "https://github.com/ergebnis/http-method.git",
"reference": "cb034b68d82e21b8a3cd4062426d3c28ced32d2c"
"reference": "e8dd54f942095fdbc5678fac193c4940710a2fba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ergebnis/http-method/zipball/cb034b68d82e21b8a3cd4062426d3c28ced32d2c",
"reference": "cb034b68d82e21b8a3cd4062426d3c28ced32d2c",
"url": "https://api.github.com/repos/ergebnis/http-method/zipball/e8dd54f942095fdbc5678fac193c4940710a2fba",
"reference": "e8dd54f942095fdbc5678fac193c4940710a2fba",
"shasum": "",
"mirrors": [
{
@@ -961,20 +961,27 @@
]
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0"
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.39.0",
"ergebnis/license": "^2.3.0",
"ergebnis/php-cs-fixer-config": "^6.12.0",
"ergebnis/phpunit-slow-test-detector": "^2.4.0",
"phpunit/phpunit": "^10.4.2",
"psalm/plugin-phpunit": "~0.18.4",
"rector/rector": "~0.18.11",
"vimeo/psalm": "^5.16.0"
"ergebnis/composer-normalize": "^2.44.0",
"ergebnis/license": "^2.6.0",
"ergebnis/php-cs-fixer-config": "^6.37.0",
"ergebnis/phpunit-slow-test-detector": "^2.16.1",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^1.12.10",
"phpstan/phpstan-deprecation-rules": "^1.2.1",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.1",
"phpunit/phpunit": "^10.5.26",
"rector/rector": "^1.2.10",
"roave/backward-compatibility-check": "^8.6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.6-dev"
},
"composer-normalize": {
"indent-size": 2,
"indent-style": "space"
@@ -1008,7 +1015,7 @@
"security": "https://github.com/ergebnis/http-method/blob/main/.github/SECURITY.md",
"source": "https://github.com/ergebnis/http-method"
},
"time": "2023-11-28T09:50:06+00:00"
"time": "2024-11-17T21:27:47+00:00"
},
{
"name": "fig/http-message-util",
@@ -5710,16 +5717,16 @@
},
{
"name": "react/promise",
"version": "v2.11.0",
"version": "v3.2.0",
"source": {
"type": "git",
"url": "https://github.com/reactphp/promise.git",
"reference": "1a8460931ea36dc5c76838fec5734d55c88c6831"
"reference": "8a164643313c71354582dc850b42b33fa12a4b63"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/reactphp/promise/zipball/1a8460931ea36dc5c76838fec5734d55c88c6831",
"reference": "1a8460931ea36dc5c76838fec5734d55c88c6831",
"url": "https://api.github.com/repos/reactphp/promise/zipball/8a164643313c71354582dc850b42b33fa12a4b63",
"reference": "8a164643313c71354582dc850b42b33fa12a4b63",
"shasum": "",
"mirrors": [
{
@@ -5729,10 +5736,11 @@
]
},
"require": {
"php": ">=5.4.0"
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
"phpstan/phpstan": "1.10.39 || 1.4.10",
"phpunit/phpunit": "^9.6 || ^7.5"
},
"type": "library",
"autoload": {
@@ -5776,7 +5784,7 @@
],
"support": {
"issues": "https://github.com/reactphp/promise/issues",
"source": "https://github.com/reactphp/promise/tree/v2.11.0"
"source": "https://github.com/reactphp/promise/tree/v3.2.0"
},
"funding": [
{
@@ -5784,7 +5792,7 @@
"type": "open_collective"
}
],
"time": "2023-11-16T16:16:50+00:00"
"time": "2024-05-24T10:39:05+00:00"
},
{
"name": "rector/rector",
@@ -6102,16 +6110,16 @@
},
{
"name": "singularity/hdk-core",
"version": "1.0.0-beta.14",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://nest.doylee.cn/HDK/hdk-core",
"reference": "1.0.0-beta.14"
"reference": "1.0.1"
},
"dist": {
"type": "zip",
"url": "https://nest.doylee.cn/api/packages/HDK/composer/files/singularity%2Fhdk-core/1.0.0-beta.14/singularity-hdk-core.1.0.0-beta.14.zip",
"shasum": "dc0a07b1c83088d3ba2b694de7d11dae9ca8b115"
"url": "https://nest.doylee.cn/api/packages/HDK/composer/files/singularity%2Fhdk-core/1.0.1/singularity-hdk-core.1.0.1.zip",
"shasum": "b61df9f495b193f441b0e92edf7f8cdeb8d1d038"
},
"require": {
"composer/composer": ">=2.0",
@@ -6204,7 +6212,7 @@
}
],
"description": "Common Hyperf Development Kit",
"time": "2025-08-12T15:05:30+08:00"
"time": "2025-08-20T14:10:21+08:00"
},
{
"name": "swow/psr7-plus",
@@ -6662,7 +6670,7 @@
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
@@ -6727,7 +6735,7 @@
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.32.0"
},
"funding": [
{
@@ -6747,7 +6755,7 @@
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
@@ -6811,7 +6819,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.32.0"
},
"funding": [
{
@@ -6831,7 +6839,7 @@
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
@@ -6898,7 +6906,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.32.0"
},
"funding": [
{
@@ -6918,16 +6926,16 @@
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341"
"reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341",
"reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493",
"reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493",
"shasum": "",
"mirrors": [
{
@@ -6937,6 +6945,7 @@
]
},
"require": {
"ext-iconv": "*",
"php": ">=7.2"
},
"provide": {
@@ -6948,8 +6957,8 @@
"type": "library",
"extra": {
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
"url": "https://github.com/symfony/polyfill",
"name": "symfony/polyfill"
}
},
"autoload": {
@@ -6984,7 +6993,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.32.0"
},
"funding": [
{
@@ -7000,11 +7009,11 @@
"type": "tidelift"
}
],
"time": "2024-09-09T11:45:10+00:00"
"time": "2024-12-23T08:48:59+00:00"
},
{
"name": "symfony/polyfill-php73",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
@@ -7066,7 +7075,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-php73/tree/v1.32.0"
},
"funding": [
{
@@ -7086,16 +7095,16 @@
},
{
"name": "symfony/polyfill-php80",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8"
"reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8",
"reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608",
"reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608",
"shasum": "",
"mirrors": [
{
@@ -7152,7 +7161,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-php80/tree/v1.32.0"
},
"funding": [
{
@@ -7168,11 +7177,11 @@
"type": "tidelift"
}
],
"time": "2024-09-09T11:45:10+00:00"
"time": "2025-01-02T08:10:11+00:00"
},
{
"name": "symfony/polyfill-php81",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php81.git",
@@ -7234,7 +7243,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-php81/tree/v1.32.0"
},
"funding": [
{
@@ -7254,7 +7263,7 @@
},
{
"name": "symfony/polyfill-php82",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php82.git",
@@ -7316,7 +7325,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php82/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-php82/tree/v1.32.0"
},
"funding": [
{
@@ -7336,7 +7345,7 @@
},
{
"name": "symfony/polyfill-php83",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php83.git",
@@ -7398,7 +7407,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php83/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-php83/tree/v1.32.0"
},
"funding": [
{
@@ -7418,16 +7427,16 @@
},
{
"name": "symfony/polyfill-php84",
"version": "v1.31.0",
"version": "v1.32.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php84.git",
"reference": "e5493eb51311ab0b1cc2243416613f06ed8f18bd"
"reference": "000df7860439609837bbe28670b0be15783b7fbf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php84/zipball/e5493eb51311ab0b1cc2243416613f06ed8f18bd",
"reference": "e5493eb51311ab0b1cc2243416613f06ed8f18bd",
"url": "https://api.github.com/repos/symfony/polyfill-php84/zipball/000df7860439609837bbe28670b0be15783b7fbf",
"reference": "000df7860439609837bbe28670b0be15783b7fbf",
"shasum": "",
"mirrors": [
{
@@ -7480,7 +7489,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php84/tree/v1.31.0"
"source": "https://github.com/symfony/polyfill-php84/tree/v1.32.0"
},
"funding": [
{
@@ -7496,7 +7505,7 @@
"type": "tidelift"
}
],
"time": "2024-09-09T12:04:04+00:00"
"time": "2025-02-20T12:04:08+00:00"
},
{
"name": "symfony/process",

View File

@@ -0,0 +1,41 @@
<?php
/**
* ConsumeCmd.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Application\Command;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
use Singularity\HDK\Pay\Enum\PaymentMethod;
final class ConsumeCmd
{
public array $items = [];
public function __construct(
public string $uid,
public PayType $type,
public PaymentMethod|PointType $method,
public array $external,
public ?string $externalID = null,
public ?string $remark = null,
) {}
public function addItem(string $name, float $unitPrice, int $quantity = 1): ConsumeCmd
{
$this->items[] = [
'name' => $name,
'quantity' => $quantity,
'unit_price' => $unitPrice,
];
return $this;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* RechargeCmd.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Application\Command;
final class RechargeCmd {
public array $items = [];
public function __construct(public string $uid) {}
public function addItem(int $productId, int $quantity = 1): RechargeCmd
{
$this->items[] = [
'product_id' => $productId,
'quantity' => $quantity,
];
return $this;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* RechargeDto.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Application\Dto\Transaction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderAction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
final readonly class OrderDto
{
public function __construct(
private string $orderNo,
private OrderAction $action,
private PayType $payType,
private OrderStatus $status,
) {}
public function getOrderNo(): string
{
return $this->orderNo;
}
public function getAction(): OrderAction
{
return $this->action;
}
public function getPayType(): PayType
{
return $this->payType;
}
public function getStatus(): OrderStatus
{
return $this->status;
}
}

View File

@@ -9,7 +9,9 @@ use Hyperf\Framework\Logger\StdoutLogger;
use Singularity\HDK\Pay\Domain\Account\Repository\AccountRepoInterface;
use Singularity\HDK\Pay\Domain\Product\Repository\ExchangeRepoInterface;
use Singularity\HDK\Pay\Domain\Product\Repository\RechargeProductRepoInterface;
use Singularity\HDK\Pay\Domain\Transaction\Repository\OrderRepoInterface;
use Singularity\HDK\Pay\Infrastructure\Repository\AccountBalanceRepo;
use Singularity\HDK\Pay\Infrastructure\Repository\OrderRepo;
use Singularity\HDK\Pay\Infrastructure\Repository\ProductRepo;
/**
@@ -28,10 +30,11 @@ class ConfigProvider
'dependencies' => [
StdoutLoggerInterface::class => StdoutLogger::class,
// Repository
// Command
AccountRepoInterface::class => AccountBalanceRepo::class,
ExchangeRepoInterface::class => ProductRepo::class,
RechargeProductRepoInterface::class => ProductRepo::class,
OrderRepoInterface::class => OrderRepo::class,
],
// 合并到 config/autoload/annotations.php 文件
'annotations' => [

View File

@@ -0,0 +1,127 @@
<?php
/**
* TransactionRecord.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Transaction\Aggregate;
use Carbon\Carbon;
use Singularity\HDK\Pay\Domain\AggregateRoot;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Item;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction\CardTransaction;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction\PointTransaction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderAction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
final class TransactionRecord extends AggregateRoot
{
/**
* @param string $orderNo
* @param string $uid
* @param PayType $payType
* @param OrderAction $action
* @param OrderStatus $status
* @param string $source
* @param Item[] $items
* @param array<PointTransaction|CardTransaction> $transactions
* @param array $refunds
* @param array|null $external
* @param string|null $externalId
* @param Carbon|null $createdAt
* @param Carbon|null $occurredAt
* @param Carbon|null $lastRefundedAt
*/
public function __construct(
private readonly string $orderNo,
private readonly string $uid,
private readonly PayType $payType,
private readonly OrderAction $action,
private readonly OrderStatus $status,
private readonly string $source,
private readonly array $items,
private readonly array $transactions,
private readonly array $refunds,
private readonly ?array $external,
private readonly ?string $externalId,
private readonly ?Carbon $createdAt,
private readonly ?Carbon $occurredAt,
private readonly ?Carbon $lastRefundedAt,
) {}
public function getOrderNo(): string
{
return $this->orderNo;
}
public function getUid(): string
{
return $this->uid;
}
public function getPayType(): PayType
{
return $this->payType;
}
public function getAction(): OrderAction
{
return $this->action;
}
public function getStatus(): OrderStatus
{
return $this->status;
}
public function getSource(): string
{
return $this->source;
}
public function getItems(): array
{
return $this->items;
}
public function getTransactions(): array
{
return $this->transactions;
}
public function getRefunds(): array
{
return $this->refunds;
}
public function getExternal(): ?array
{
return $this->external;
}
public function getExternalId(): ?string
{
return $this->externalId;
}
public function getCreatedAt(): ?Carbon
{
return $this->createdAt;
}
public function getOccurredAt(): ?Carbon
{
return $this->occurredAt;
}
public function getLastRefundedAt(): ?Carbon
{
return $this->lastRefundedAt;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Item.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject;
use Swoole\ArrayObject;
final class Item extends ArrayObject
{
public function __construct(
private readonly string $name,
private readonly int $quantity,
private readonly float $price,
) {
parent::__construct([
'name' => $name,
'quantity' => $quantity,
'unit_price' => $price,
]);
}
public function getName(): string
{
return $this->name;
}
public function getQuantity(): int
{
return $this->quantity;
}
public function getPrice(): float
{
return $this->price;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Transaction.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
use Singularity\HDK\Pay\Enum\PaymentMethod;
use Swoole\ArrayObject;
/**
* Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
abstract class Transaction extends ArrayObject
{
public function __construct(
private PayType $payType,
private PaymentMethod|PointType $type,
private float $amount,
private OrderStatus $status,
) {
parent::__construct(
[
'pay_type' => $payType->value,
'type' => $type->value,
'amount' => $amount,
'status' => $status->name,
],
);
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* CardTransaction.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
use Singularity\HDK\Pay\Enum\PaymentMethod;
final class CardTransaction extends Transaction
{
public function __construct(
PaymentMethod $method,
float $amount,
OrderStatus $status,
) {
parent::__construct(
payType: PayType::Card,
type: $method,
amount: $amount,
status: $status,
);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* PointTransaction.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
final class PointTransaction extends Transaction
{
public function __construct(PointType $type, float $amount, OrderStatus $status)
{
parent::__construct(
payType: PayType::Point,
type: $type,
amount: $amount,
status: $status,
);
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* OrderAction.php@LuxDesign
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/7/30
*/
namespace Singularity\HDK\Pay\Domain\Transaction\Enum;
enum OrderAction: string {
case Recharge = 'recharge';
case Consumption = 'consumption';
case Refund = 'refund';
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* OrderStatus.php@LuxDesign
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2024/11/26
*/
namespace Singularity\HDK\Pay\Domain\Transaction\Enum;
enum OrderStatus
{
case created;
case paid;
case completed;
case refunded;
case cancelled;
case failed;
case closed;
public static function tryFrom(mixed $status): OrderStatus
{
$status = strtolower($status);
return match ($status) {
'paid' => self::paid,
'refunded' => self::refunded,
'cancelled' => self::cancelled,
'completed' => self::completed,
'failed' => self::failed,
'closed' => self::closed,
default => self::created,
};
}
public static function all(): array
{
return [
self::created,
self::paid,
self::completed,
self::refunded,
self::cancelled,
self::closed,
];
}
public static function values(): array
{
return array_column(self::all(), 'value');
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* PayType.php@LuxDesign
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/7/25
*/
namespace Singularity\HDK\Pay\Domain\Transaction\Enum;
Enum PayType: string {
case Point = 'point';
case Card = 'card';
case Hybrid = 'hybrid';
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* OrderRepoInterface.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
namespace Singularity\HDK\Pay\Domain\Transaction\Repository;
use Singularity\HDK\Pay\Application\Command\ConsumeCmd;
use Singularity\HDK\Pay\Application\Command\RechargeCmd;
use Singularity\HDK\Pay\Application\Dto\Transaction\OrderDto;
interface OrderRepoInterface
{
public function recharge(RechargeCmd $cmd): OrderDto;
public function consume(ConsumeCmd $cmd): OrderDto;
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* CallbackDomainSvc.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Domain\Transaction\Service;
use Carbon\Carbon;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\TransactionRecord;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Item;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction\CardTransaction;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\ValueObject\Transaction\PointTransaction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderAction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
use Singularity\HDK\Pay\Enum\PaymentMethod;
/**
* Singularity\HDK\Pay\Domain\Transaction\Service\CallbackDomainSvc@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
final class CallbackDomainSvc
{
/**
* @param array $order
* @return TransactionRecord
*/
public function callback(array $order): TransactionRecord
{
$payType = PayType::tryFrom($order['pay_type']);
return new TransactionRecord(
orderNo: $order['order_no'],
uid: $order['uid'],
payType: $payType,
action: OrderAction::tryFrom($order['action']),
status: OrderStatus::tryFrom($order['status']),
source: $order['source'],
items: array_map(
callback: fn(array $item) => new Item(
name: $item['name'],
quantity: $item['quantity'],
price: $item['unit_price'],
),
array: $order['items'],
),
transactions: array_map(
callback: fn(array $transaction)
=> $transaction['pay_type'] === PayType::Card->value
? new CardTransaction(
method: PaymentMethod::tryFrom($transaction['type']),
amount: $transaction['amount'],
status: OrderStatus::tryFrom($transaction['status']),
)
: new PointTransaction(
type: PointType::tryFrom($transaction['type']),
amount: $transaction['amount'],
status: OrderStatus::tryFrom($transaction['status']),
),
array: $order['transactions'],
),
refunds: $order['refunds'],
external: $order['external'],
externalId: $order['external_id'],
createdAt: isset($order['created_at']) ? new Carbon($order['created_at']) : null,
occurredAt: isset($order['occurred_at']) ? new Carbon($order['occurred_at']) : null,
lastRefundedAt: isset($order['last_refunded_at']) ? new Carbon($order['last_refunded_at']) : null,
);
}
}

View File

@@ -30,6 +30,7 @@ abstract class AbstractRepo
$this->requestService = RequestServiceFactory::make([
'base_uri' => $baseUrl ?? config('payment.base_uri'),
RequestOptions::ALLOW_REDIRECTS => true,
'headers' => $this->headerBuilder(),
]);
}
}

View File

@@ -26,9 +26,6 @@ final class AccountBalanceRepo extends AbstractRepo implements AccountRepoInterf
params: [
'type' => join(',', PointType::values()),
],
options: [
'headers' => $this->headerBuilder(),
],
);
$content = $response->getBody()->getContents();
@@ -55,9 +52,6 @@ final class AccountBalanceRepo extends AbstractRepo implements AccountRepoInterf
{
$response = $this->requestService->requestGet(
url: "/rpc/v2/account/$uid/balance/$pointType->value",
options: [
'headers' => $this->headerBuilder(),
],
);
$content = $response->getBody()->getContents();

View File

@@ -0,0 +1,77 @@
<?php
/**
* OrderRepo.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Infrastructure\Repository;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Codec\Json;
use Singularity\HDK\Pay\Application\Command\ConsumeCmd;
use Singularity\HDK\Pay\Application\Command\RechargeCmd;
use Singularity\HDK\Pay\Application\Dto\Transaction\OrderDto;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderAction;
use Singularity\HDK\Pay\Domain\Transaction\Enum\OrderStatus;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
use Singularity\HDK\Pay\Domain\Transaction\Repository\OrderRepoInterface;
final class OrderRepo extends AbstractRepo implements OrderRepoInterface
{
/**
* @param RechargeCmd $cmd
* @return OrderDto
* @throws GuzzleException
*/
public function recharge(RechargeCmd $cmd): OrderDto
{
$response = $this->requestService->requestPost(
url: '/rpc/v2/transaction/orders/recharge',
data: [
'uid' => $cmd->uid,
'items' => $cmd->items,
],
);
$content = $response->getBody()->getContents();
$result = Json::decode($content);
return new OrderDto(
orderNo: $result['order_no'],
action: OrderAction::tryFrom($result['action']),
payType: PayType::tryFrom($result['pay_type']),
status: OrderStatus::tryFrom($result['status']),
);
}
public function consume(ConsumeCmd $cmd): OrderDto
{
$response = $this->requestService->requestPost(
url: '/rpc/v2/transaction/orders/consumption',
data: [
'uid' => $cmd->uid,
'type' => $cmd->type->value,
'method' => $cmd->method->value,
'items' => $cmd->items,
'external' => $cmd->external,
'external_id' => $cmd->externalID ?? '',
'remark' => $cmd->remark,
],
);
$content = $response->getBody()->getContents();
$result = Json::decode($content);
return new OrderDto(
orderNo: $result['order_no'],
action: OrderAction::tryFrom($result['action']),
payType: PayType::tryFrom($result['pay_type']),
status: OrderStatus::tryFrom($result['status']),
);
}
}

View File

@@ -80,9 +80,6 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
$response = $this->requestService->requestGet(
url: '/rpc/v2/products/ema',
params: ['uid' => $uid],
options: [
'headers' => $this->headerBuilder(),
],
);
$content = $response->getBody()->getContents();
@@ -148,9 +145,6 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
{
$response = $this->requestService->requestGet(
url: "/rpc/v2/products/$target->value/exchange-rate/$source->value",
options: [
'headers' => $this->headerBuilder(),
],
);
$content = $response->getBody()->getContents();

View File

@@ -43,4 +43,4 @@ it('should can query EMA products', function () {
->and($products->getRenew())->toBeInstanceOf(ProductItem::class),
)
->and($products->getPlans())->each->toBeInstanceOf(ProductItem::class);
})->only();
});

View File

@@ -0,0 +1,34 @@
<?php
/**
* CreateConsumptionOrderTest.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
use Singularity\HDK\Pay\Application\Command\ConsumeCmd;
use Singularity\HDK\Pay\Application\Dto\Transaction\OrderDto;
use Singularity\HDK\Pay\Domain\Account\Enum\PointType;
use Singularity\HDK\Pay\Domain\Transaction\Enum\PayType;
use Singularity\HDK\Pay\Infrastructure\Repository\OrderRepo;
use function Hyperf\Support\make;
it('should can create consumption order', function () {
$uid = 'cn3321';
$cmd = (new ConsumeCmd(
uid: $uid,
type: PayType::Point,
method: PointType::FtaiAligner,
external: [],
externalID: null,
remark: '',
))->addItem('Design FTAI Aligner', 1, 5);
$repo = make(OrderRepo::class);
$result = $repo->consume($cmd);
expect($result)->toBeInstanceOf(OrderDto::class);
});

View File

@@ -0,0 +1,23 @@
<?php
/**
* CreateRechargeOrderTest.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/18
*/
use Singularity\HDK\Pay\Application\Command\RechargeCmd;
use Singularity\HDK\Pay\Application\Dto\Transaction\OrderDto;
use Singularity\HDK\Pay\Infrastructure\Repository\OrderRepo;
use function Hyperf\Support\make;
it('should can create recharge order', function () {
$cmd = (new RechargeCmd('cn3321'))->addItem(1, 2);
$repo = make(OrderRepo::class);
$result = $repo->recharge($cmd);
expect($result)->toBeInstanceOf(OrderDto::class);
});

View File

@@ -0,0 +1,99 @@
<?php
/**
* LuxPayCallbackTest.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2025/8/20
*/
use Hyperf\Codec\Json;
use Singularity\HDK\Pay\Domain\Transaction\Aggregate\TransactionRecord;
use Singularity\HDK\Pay\Domain\Transaction\Service\CallbackDomainSvc;
use function Hyperf\Support\make;
dataset('cases', [
'recharge' => [
<<<JSON
{
"order_no": "202508191929138659DTB",
"uid": "cn3321",
"pay_type": "card",
"action": "recharge",
"status": "created",
"source": "LuxDesign",
"items": [
{
"name": "Starter Pack",
"unit_price": 399,
"quantity": 1
}
],
"transactions": [
{
"pay_type": "card",
"type": "stripe.checkout",
"amount": 399,
"status": "created"
}
],
"refunds": [],
"external": [],
"external_id": "",
"created_at": "2025-08-20 10:44:46",
"occurred_at": null,
"last_refunded_at": null
}
JSON,
],
'consumption' => [
<<<JSON
{
"order_no": "202508190441101116DTB",
"uid": "cn3321",
"pay_type": "hybrid",
"action": "consumption",
"status": "created",
"source": "LuxDesign",
"items": [
{
"name": "Design - retainer",
"quantity": 1,
"unit_price": 3
}
],
"transactions": [
{
"pay_type": "card",
"type": "stripe.checkout",
"amount": 3,
"status": "created"
},
{
"pay_type": "point",
"type": "lux-point",
"amount": 3.05,
"status": "created"
}
],
"refunds": [],
"external": [],
"external_id": "",
"created_at": "2025-08-20 10:44:46",
"occurred_at": null,
"last_refunded_at": null
}
JSON,
]
]);
it(
'should parse request recharge body to TransactionRecord Entity',
function ($data) {
$data = Json::decode($data);
$entity = make(CallbackDomainSvc::class)->callback($data);
expect($entity)->toBeInstanceOf(TransactionRecord::class);
},
)->with('cases');

View File

@@ -34,6 +34,7 @@ $container = ApplicationContext::setContainer($container);
/** @var Config $config */
$config = make(Config::class, [
[
'app_name' => 'LuxDesign',
'dependencies' => [],
'payment' => [
'base_uri' => env('LUX_PAY_BASE_URI', 'http://test-pay.luxcreo.com'),