mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 07:35:09 +08:00
Compare commits
19 Commits
v1.0.0-alp
...
v1.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d1b5d2ab7 | ||
|
|
8cb8f7eb9e | ||
|
|
c13fc7e800 | ||
|
|
8d6c0189a0 | ||
|
|
dd690e228e | ||
|
|
46ecc8117c | ||
|
|
456294c1a4 | ||
|
|
a6898bb1a0 | ||
|
|
999f3633a5 | ||
|
|
6431fc010f | ||
|
|
cb0b3a3548 | ||
|
|
b8ebebde3c | ||
|
|
1dba3b84a4 | ||
|
|
6cecc96c5f | ||
|
|
448569583c | ||
|
|
99af043376 | ||
|
|
90dde97bc9 | ||
|
|
f7e1386c78 | ||
|
|
a6b33ed0ab |
28
.gitea/workflows/publish_on_tagged.yml
Normal file
28
.gitea/workflows/publish_on_tagged.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Release development version to registry
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '**.**'
|
||||
|
||||
jobs:
|
||||
Publish on Tagged:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
|
||||
- name: List files in the repository
|
||||
run: |
|
||||
ls ${{ gitea.workspace }}
|
||||
- name: Zip files in the repository
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install zip
|
||||
zip -r dist.zip *
|
||||
- name: Publish to registry
|
||||
run: |
|
||||
curl --user ch4o5:4fd300672472e666014314c1c94c604c634165a9 \
|
||||
--upload-file ./dist.zip \
|
||||
https://nest.doylee.cn/api/packages/HDK/composer?version=${{ gitea.ref_name }}
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
68
CHANGELOG.md
68
CHANGELOG.md
@@ -1,4 +1,72 @@
|
||||
# 版本更新日志
|
||||
## [1.0.0-alpha.12](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.11...v1.0.0-alpha.12) (2023-10-23)
|
||||
|
||||
|
||||
### 👷 Continuous Integration | CI 配置
|
||||
|
||||
* 修复内容为空的问题 ([8cb8f7e](http://124.126.16.154:8888/singularity/hdk-pay/commit/8cb8f7eb9e8d97408a3a71fec75699579b058c09))
|
||||
|
||||
## [1.0.0-alpha.11](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.10...v1.0.0-alpha.11) (2023-10-23)
|
||||
|
||||
|
||||
### 👷 Continuous Integration | CI 配置
|
||||
|
||||
* 迁移到 Gitea Actions ([8d6c018](http://124.126.16.154:8888/singularity/hdk-pay/commit/8d6c0189a0198d5d6e11e90cd8293107f414273c))
|
||||
|
||||
## [1.0.0-alpha.10](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2023-09-26)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 更新依赖 ([46ecc81](http://124.126.16.154:8888/singularity/hdk-pay/commit/46ecc8117ccb463ed498fa82e84bf41d9ebb752b))
|
||||
|
||||
## [1.0.0-alpha.9](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2023-09-26)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **stripe:** 创建 session 接口增加了语言选项 ([a6898bb](http://124.126.16.154:8888/singularity/hdk-pay/commit/a6898bb1a097f3c66d3ef14f375725fdeaed4df5))
|
||||
|
||||
## [1.0.0-alpha.8](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2023-09-22)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **order:** 修复类型错误的问题 ([6431fc0](http://124.126.16.154:8888/singularity/hdk-pay/commit/6431fc010fe3e989773b84506df62d3c8f7ffc81))
|
||||
|
||||
## [1.0.0-alpha.7](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2023-09-22)
|
||||
|
||||
|
||||
### ⚡ Performance Improvements | 性能优化
|
||||
|
||||
* **callback:** 增加了共用的通知业务系统的方法 ([b8ebebd](http://124.126.16.154:8888/singularity/hdk-pay/commit/b8ebebde3c5835bb0abc6e5078517c82341db95f))
|
||||
|
||||
## [1.0.0-alpha.6](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2023-09-22)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 兼容 hyperf 的 RequestInterface ([6cecc96](http://124.126.16.154:8888/singularity/hdk-pay/commit/6cecc96c5ffc223a1a72df6abd1f07d54cb7953d))
|
||||
|
||||
## [1.0.0-alpha.5](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2023-09-22)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 增加 hyperf/contract 包,更新依赖 ([90dde97](http://124.126.16.154:8888/singularity/hdk-pay/commit/90dde97bc90d33917eb2c1a4d09779dd45776d30))
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **stripe:** 增加 callback 对请求的转化 ([99af043](http://124.126.16.154:8888/singularity/hdk-pay/commit/99af043376c4b44412a275d1b778e3e3584f5f96))
|
||||
|
||||
## [1.0.0-alpha.4](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2023-09-20)
|
||||
|
||||
|
||||
### ✏️ Documentation | 文档
|
||||
|
||||
* **resource:** 更新了资源的字段注释 ([a6b33ed](http://124.126.16.154:8888/singularity/hdk-pay/commit/a6b33ed0abed2d23b041407c0a6a58e8405e075c))
|
||||
|
||||
## [1.0.0-alpha.3](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2023-09-20)
|
||||
|
||||
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
"moneyphp/money": "^4.1",
|
||||
"singularity/hdk-core": "^1.0.0",
|
||||
"hyperf/contract": "~3.0.0",
|
||||
"hyperf/constants": "3.0.*",
|
||||
"hyperf/config": "~3.0.0",
|
||||
"hyperf/di": "~3.0.0"
|
||||
"hyperf/di": "~3.0.0",
|
||||
"hyperf/http-server": "3.0.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"cooper/hyperf-pest": "^1.1",
|
||||
@@ -29,12 +31,11 @@
|
||||
"phpunit/phpunit": "^9.6.9",
|
||||
"swoole/ide-helper": "^4.8.13"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"minimum-stability": "alpha",
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true,
|
||||
"secure-http": false,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true
|
||||
}
|
||||
@@ -52,14 +53,14 @@
|
||||
"analyse": "phpstan analyse --memory-limit 300M -l 0 -c phpstan.neon ./app ./config"
|
||||
},
|
||||
"repositories": {
|
||||
"lux-map": {
|
||||
"nest": {
|
||||
"type": "composer",
|
||||
"url": "https://satis.luxcreo.cn/"
|
||||
"url": "https://nest.doylee.cn/api/packages/HDK/composer"
|
||||
},
|
||||
"packagist": {
|
||||
"type": "composer",
|
||||
"url": "https://mirrors.cloud.tencent.com/composer/"
|
||||
"url": "https://mirrors.aliyun.com/composer/"
|
||||
}
|
||||
},
|
||||
"version": "1.0.0-alpha.3"
|
||||
"version": "1.0.0-alpha.12"
|
||||
}
|
||||
|
||||
3885
composer.lock
generated
3885
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,13 @@ namespace Singularity\HDK\Pay\Resource;
|
||||
|
||||
use Hyperf\Resource\Json\ResourceCollection;
|
||||
|
||||
/**
|
||||
* Singularity\HDK\Pay\Resource\ GoodsCollection@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/20
|
||||
*/
|
||||
final class GoodsCollection extends ResourceCollection
|
||||
{
|
||||
public ?string $wrap = null;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Singularity\HDK\Pay\Resource;
|
||||
|
||||
use Hyperf\Resource\Json\JsonResource;
|
||||
use Money\Currency;
|
||||
use Money\Money;
|
||||
use Singularity\HDK\Pay\Enum\OrderStatus;
|
||||
|
||||
@@ -12,6 +13,14 @@ use Singularity\HDK\Pay\Enum\OrderStatus;
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/19
|
||||
*
|
||||
* @property-read string $orderNo
|
||||
* @property-read string transactionId
|
||||
* @property-read Money amount
|
||||
* @property-read OrderStatus state
|
||||
* @property-read string uid
|
||||
* @property-read string payment
|
||||
* @property-read string remark
|
||||
*/
|
||||
class Order extends JsonResource
|
||||
{
|
||||
@@ -23,8 +32,8 @@ class Order extends JsonResource
|
||||
* @return array{
|
||||
* orderNo: string,
|
||||
* transactionId: string,
|
||||
* amount: array{amount: numeric, currency: string},
|
||||
* state: string,
|
||||
* amount: Money,
|
||||
* state: OrderStatus,
|
||||
* uid: string,
|
||||
* payment: string,
|
||||
* remark: string
|
||||
@@ -37,7 +46,10 @@ class Order extends JsonResource
|
||||
'orderNo' => $this->resource['orderNo'],
|
||||
'transactionId' => $this->resource['transactionId'],
|
||||
'goodsName' => $this->resource['goodsName'],
|
||||
'amount' => new Money($this->resource['amount']['amount'], $this->resource['amount']['currency']),
|
||||
'amount' => new Money(
|
||||
$this->resource['amount']['amount'],
|
||||
new Currency($this->resource['amount']['currency'])
|
||||
),
|
||||
'state' => OrderStatus::from($this->resource['state']),
|
||||
'uid' => $this->resource['uid'],
|
||||
'payment' => $this->resource['payment'],
|
||||
|
||||
@@ -14,13 +14,17 @@ namespace Singularity\HDK\Pay\Sdk;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Lmc\HttpConstants\Header;
|
||||
use Money\Money;
|
||||
use Singularity\HDK\Core\Http\RequestService;
|
||||
use Singularity\HDK\Core\Http\RequestServiceFactory;
|
||||
use Singularity\HDK\Core\I18n\Enum\Languages;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
|
||||
use Singularity\HDK\Pay\Resource\StripeConfiguration;
|
||||
|
||||
use Singularity\HDK\Pay\Trait\WebhooksNotificationHandler;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
/**
|
||||
@@ -32,6 +36,8 @@ use function Hyperf\Config\config;
|
||||
*/
|
||||
final class StripeRpc
|
||||
{
|
||||
use WebhooksNotificationHandler;
|
||||
|
||||
private RequestService $requestService;
|
||||
|
||||
public function __construct(?string $baseUrl = null)
|
||||
@@ -66,20 +72,30 @@ final class StripeRpc
|
||||
int $goodsId,
|
||||
string $goodsName,
|
||||
array $goodsDetail,
|
||||
?int $service = null
|
||||
?Languages $locale = null,
|
||||
?int $service = null,
|
||||
): Order {
|
||||
$response = $this->requestService->requestPost(
|
||||
url: '/rpc/v1/stripe/order',
|
||||
data: [
|
||||
'service' => $service ?? config('payment.sp_id'),
|
||||
'amount' => $money->getAmount(),
|
||||
'currency' => $money->getCurrency(),
|
||||
'currency' => (string)$money->getCurrency(),
|
||||
'uid' => $uid,
|
||||
'goodsDetail' => array_replace($goodsDetail, [
|
||||
'id' => $goodsId,
|
||||
'goodsName' => $goodsName,
|
||||
]),
|
||||
'goodsDetail' => array_replace(
|
||||
$goodsDetail,
|
||||
[
|
||||
'id' => $goodsId,
|
||||
'goodsName' => $goodsName,
|
||||
]
|
||||
),
|
||||
],
|
||||
options: [
|
||||
'headers' => [
|
||||
Header::CONTENT_TYPE => 'application/json',
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale')
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* WechatRpc.php@Pay
|
||||
@@ -11,15 +12,14 @@ declare(strict_types=1);
|
||||
namespace Singularity\HDK\Pay\Sdk;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Lmc\HttpConstants\Header;
|
||||
use Money\Money;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
use Singularity\HDK\Core\Http\RequestService;
|
||||
|
||||
use Singularity\HDK\Core\Http\RequestServiceFactory;
|
||||
use Singularity\HDK\Pay\Trait\WebhooksNotificationHandler;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
@@ -32,14 +32,16 @@ use function Hyperf\Config\config;
|
||||
*/
|
||||
final class WechatRpc
|
||||
{
|
||||
private RequestService $requestService;
|
||||
use WebhooksNotificationHandler;
|
||||
|
||||
private string $baseUrl;
|
||||
private RequestService $requestService;
|
||||
|
||||
public function __construct(?string $baseUrl = null)
|
||||
{
|
||||
$this->requestService = RequestServiceFactory::make();
|
||||
$this->baseUrl = $baseUrl ?? config('payment.base_uri');
|
||||
$this->requestService = RequestServiceFactory::make([
|
||||
'base_uri' => $baseUrl ?? config('payment.base_uri'),
|
||||
RequestOptions::ALLOW_REDIRECTS => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,23 +60,24 @@ final class WechatRpc
|
||||
Money $money,
|
||||
string $uid
|
||||
): array {
|
||||
$url = $this->baseUrl . '/rpc/v1/wechat/qrcode';
|
||||
$data = [
|
||||
'service' => config('payment.sp_id'),
|
||||
'amount' => (int)$money->getAmount(),
|
||||
'fileType' => $type,
|
||||
'uid' => $uid,
|
||||
'goods_detail' => [
|
||||
'goods_name' => $goodsName,
|
||||
],
|
||||
];
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
'headers' => [
|
||||
Header::ACCEPT => $request->getHeader(Header::ACCEPT),
|
||||
],
|
||||
])
|
||||
->requestPost($url, $data);
|
||||
->requestPost(
|
||||
url: '/rpc/v1/wechat/qrcode',
|
||||
data: [
|
||||
'service' => config('payment.sp_id'),
|
||||
'amount' => (int)$money->getAmount(),
|
||||
'fileType' => $type,
|
||||
'uid' => $uid,
|
||||
'goods_detail' => [
|
||||
'goods_name' => $goodsName,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
|
||||
28
src/Trait/WebhooksNotificationHandler.php
Normal file
28
src/Trait/WebhooksNotificationHandler.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Webhooks.php@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/22
|
||||
*/
|
||||
|
||||
namespace Singularity\HDK\Pay\Trait;
|
||||
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
|
||||
/**
|
||||
* Singularity\HDK\Pay\Trait\Webhooks@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/22
|
||||
*/
|
||||
trait WebhooksNotificationHandler
|
||||
{
|
||||
public function callback(RequestInterface $request): Order
|
||||
{
|
||||
return Order::make($request->post());
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
/** @var StripeRpc $service */
|
||||
|
||||
use Money\Money;
|
||||
use Singularity\HDK\Core\I18n\Enum\Languages;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
use Singularity\HDK\Pay\Resource\StripeConfiguration;
|
||||
use Singularity\HDK\Pay\Sdk\StripeRpc;
|
||||
@@ -21,9 +22,10 @@ test('能够正常创建 Stripe 订单', function () {
|
||||
$order = $service->createSession(
|
||||
money: Money::USD(51),
|
||||
uid: uniqid('NAT_'),
|
||||
goodsId: 3,
|
||||
goodsId: 1,
|
||||
goodsName: 'HDK-Pay Test',
|
||||
goodsDetail: [],
|
||||
locale: Languages::EN,
|
||||
service: 1
|
||||
);
|
||||
expect($order)->toBeInstanceOf(Order::class);
|
||||
|
||||
Reference in New Issue
Block a user