Compare commits

...

25 Commits

Author SHA1 Message Date
ch4o5
456294c1a4 chore(release): 1.0.0-alpha.9 2023-09-26 04:00:52 +00:00
李东云
a6898bb1a0 feat(stripe): 创建 session 接口增加了语言选项 2023-09-26 12:00:39 +08:00
ch4o5
999f3633a5 chore(release): 1.0.0-alpha.8 2023-09-22 10:23:09 +00:00
李东云
6431fc010f fix(order): 修复类型错误的问题 2023-09-22 18:22:59 +08:00
ch4o5
cb0b3a3548 chore(release): 1.0.0-alpha.7 2023-09-22 09:41:40 +00:00
李东云
b8ebebde3c perf(callback): 增加了共用的通知业务系统的方法 2023-09-22 17:41:32 +08:00
ch4o5
1dba3b84a4 chore(release): 1.0.0-alpha.6 2023-09-22 08:15:10 +00:00
李东云
6cecc96c5f build(composer): 兼容 hyperf 的 RequestInterface 2023-09-22 16:15:01 +08:00
ch4o5
448569583c chore(release): 1.0.0-alpha.5 2023-09-22 07:43:53 +00:00
李东云
99af043376 feat(stripe): 增加 callback 对请求的转化 2023-09-22 15:42:22 +08:00
李东云
90dde97bc9 build(composer): 增加 hyperf/contract 包,更新依赖 2023-09-22 15:39:42 +08:00
ch4o5
f7e1386c78 chore(release): 1.0.0-alpha.4 2023-09-20 08:43:10 +00:00
李东云
a6b33ed0ab docs(resource): 更新了资源的字段注释 2023-09-20 16:43:00 +08:00
ch4o5
a532e21f02 chore(release): 1.0.0-alpha.3 2023-09-20 08:32:15 +00:00
李东云
64dd159f9c feat(stripe): 实现了 stripe 获取配置信息的服务方法 2023-09-20 16:30:54 +08:00
ch4o5
a50216f2fc chore(release): 1.0.0-alpha.2 2023-09-19 10:25:16 +00:00
李东云
ff86edf89b feat(stripe): 实现了 stripe 创建订单的服务方法 2023-09-19 18:25:00 +08:00
李东云
eb9c9557c5 feat(pest): 支持了依赖注入 2023-09-19 18:22:47 +08:00
李东云
4b5e1740bc perf: 使用更先进的 hdk 方法创建 http 请求 2023-09-19 17:44:45 +08:00
李东云
7401c97860 build(script): 版本最低为 8.1 2023-09-19 17:26:12 +08:00
李东云
22bb6a4ed2 build(composer): 更新依赖 2023-09-19 17:25:44 +08:00
李东云
98dbe19a5a feat(enum): 增加订单相关的枚举类型 2023-09-19 17:16:13 +08:00
ch4o5
bda7e57f39 chore(release): 1.0.0-alpha.1 2023-07-25 09:06:06 +00:00
李东云
8381195df4 build(release): 增加预发布版本的 flag 2023-07-25 17:05:57 +08:00
李东云
9052dc2d43 fix(goods): 修复类型错误的问题 2023-07-25 17:04:41 +08:00
20 changed files with 4349 additions and 558 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
composer.phar
vendor/
.idea/
.phpunit.result.cache
.phpunit.result.cache
runtime/

View File

@@ -1,4 +1,90 @@
# 版本更新日志
## [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)
### ✨ Features | 新功能
* **stripe:** 实现了 stripe 获取配置信息的服务方法 ([64dd159](http://124.126.16.154:8888/singularity/hdk-pay/commit/64dd159f9c153183d22e51390a8d670e5bfd7385))
## [1.0.0-alpha.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2023-09-19)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([22bb6a4](http://124.126.16.154:8888/singularity/hdk-pay/commit/22bb6a4ed2f8f76ed7960cd3dc116cdbf3370abb))
* **script:** 版本最低为 8.1 ([7401c97](http://124.126.16.154:8888/singularity/hdk-pay/commit/7401c9786011a27e658075036301aef9e9cb9eed))
### ⚡ Performance Improvements | 性能优化
* 使用更先进的 hdk 方法创建 http 请求 ([4b5e174](http://124.126.16.154:8888/singularity/hdk-pay/commit/4b5e1740bca1e83820de207d4d0c8bea0e94a42f))
### ✨ Features | 新功能
* **enum:** 增加订单相关的枚举类型 ([98dbe19](http://124.126.16.154:8888/singularity/hdk-pay/commit/98dbe19a5a5091ae6549c32d91b58f6c94a507c2))
* **pest:** 支持了依赖注入 ([eb9c955](http://124.126.16.154:8888/singularity/hdk-pay/commit/eb9c9557c51cb80531886f1929cfeb0c949054b5))
* **stripe:** 实现了 stripe 创建订单的服务方法 ([ff86edf](http://124.126.16.154:8888/singularity/hdk-pay/commit/ff86edf89b1a7ed459349f4101251bc654cda69c))
## [1.0.0-alpha.1](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-alpha.0...v1.0.0-alpha.1) (2023-07-25)
### 🐛 Bug Fixes | Bug 修复
* **goods:** 修复类型错误的问题 ([9052dc2](http://124.126.16.154:8888/singularity/hdk-pay/commit/9052dc2d4347f806d5c4b1705d163522e719ef31))
### 📦‍ Build System | 打包构建
* **release:** 增加预发布版本的 flag ([8381195](http://124.126.16.154:8888/singularity/hdk-pay/commit/8381195df4f12931802eda17555c481dfcb11f17))
## 1.0.0-alpha.0 (2023-07-25)

View File

@@ -14,19 +14,22 @@
}
},
"require": {
"php": ">=8.0",
"php": ">=8.1",
"composer/composer": ">=2.5.8",
"hyperf/guzzle": "~3.0.0",
"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",
"firebase/php-jwt": "^6.8.0",
"phpunit/phpunit": "^9.6.9"
"phpunit/phpunit": "^9.6.9",
"swoole/ide-helper": "^4.8.13"
},
"minimum-stability": "dev",
"prefer-stable": true,
@@ -57,8 +60,8 @@
},
"packagist": {
"type": "composer",
"url": "https://mirrors.cloud.tencent.com/composer/"
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.0.0-alpha.0"
"version": "1.0.0-alpha.9"
}

4223
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,4 +7,4 @@ docker run \
-w "/srv/www" \
-v "$(pwd)":/srv/www \
-v ~/.ssh:/root/.ssh \
harbor.luxcreo.cn/library/hyperf:8.0-swoole /bin/ash
harbor.luxcreo.cn/library/hyperf:8.1-swoole /bin/ash

View File

@@ -2,4 +2,4 @@
docker run --rm -it \
-v $(pwd):/app -e "GIT_AUTHOR_NAME=ch4o5" -e "EMAIL=dongyun.li@luxcreo.ai" \
detouched/standard-version:latest $1
detouched/standard-version:latest -p=alpha $1

23
src/Enum/CurrencyEnum.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
/**
* Currencies.php@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/5/17
*/
namespace Singularity\HDK\Pay\Enum;
use Money\Currency;
enum CurrencyEnum
{
case CNY;
case USD;
public function getInstance(): Currency
{
return new Currency($this->name);
}
}

54
src/Enum/OrderStatus.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
/**
* OrderStatus.php@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/5/19
*/
declare(strict_types=1);
namespace Singularity\HDK\Pay\Enum;
/**
* App\Enum\OrderStatus@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/5/19
*/
enum OrderStatus: string
{
case Created = "Created";
case Paid = 'Paid';
case Cancelled = 'Cancelled';
case Closed = 'Closed';
/**
* @return string[]
*/
public static function all(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[] = $key->name;
}
return $list;
}
// public static function from(string $value): ?OrderStatus
// {
// var_dump($value, __METHOD__);
// return match ($value) {
// 'Created' => OrderStatus::Created,
// 'Paid' => OrderStatus::Paid,
// 'Cancelled' => OrderStatus::Cancelled,
// 'Closed' => OrderStatus::Closed,
// default => null
// };
// }
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* PaymentMethod.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/19
*/
namespace Singularity\HDK\Pay\Enum;
enum PaymentMethod: string
{
case Stripe = 'stripe';
case WechatPay = 'wechat';
/**
* @return array<string, string>
*/
public static function all(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[$key->name] = $key->value;
}
return $list;
}
/**
* @return string[]
*/
public function values(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[] = $key->value;
}
return $list;
}
/**
* @return string[]
*/
public function keys(): array
{
$list = [];
foreach (self::cases() as $key) {
$list[] = $key->name;
}
return $list;
}
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Singularity\HDK\Pay\Resource;
use Hyperf\Resource\Json\JsonResource;
use Money\Currency;
use Money\Money;
/**
@@ -39,7 +40,7 @@ final class Goods extends JsonResource
'id' => $this->id,
'goodsName' => $this->goodsName,
'goodsSpec' => $this->goodsSpec,
'amount' => new Money($this->amount['price'], $this->amount['currency'])
'amount' => new Money($this->amount['price'], new Currency($this->amount['currency']))
];
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
/**
* GoodsCollection.php@LuxPay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/7/20
*/
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;
}

69
src/Resource/Order.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
namespace Singularity\HDK\Pay\Resource;
use Hyperf\Resource\Json\JsonResource;
use Money\Currency;
use Money\Money;
use Singularity\HDK\Pay\Enum\OrderStatus;
/**
* App\Resource\ Order@LuxPay
*
* @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
{
public ?string $wrap = null;
/**
* Transform the resource into an array.
*
* @return array{
* orderNo: string,
* transactionId: string,
* amount: Money,
* state: OrderStatus,
* uid: string,
* payment: string,
* remark: string
* }
*/
public function toArray(): array
{
return [
// 'id ' => $this->id,
'orderNo' => $this->resource['orderNo'],
'transactionId' => $this->resource['transactionId'],
'goodsName' => $this->resource['goodsName'],
'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'],
'remark' => $this->resource['remark'],
// extends
// 'spId' => $this->spId,
// 'goodsDetail' => GoodsCollection::make([$this->goodsDetail])->resolve(),
// 'goodsDetail' => $this->goodsDetail,
// 'notification' => $this->notification,
];
}
public function __get($key)
{
return $this->resource->{$key} ?? $this->resource[$key];
}
}

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/**
* StripeConfiguration.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/20
*/
namespace Singularity\HDK\Pay\Resource;
use Hyperf\Resource\Json\JsonResource;
/**
* Singularity\HDK\Pay\Resource\StripeConfiguration@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/20
*
* @property-read string $id The unique identifier for this stripe account
* @property-read string $pk The publishable key for this stripe account
*/
final class StripeConfiguration extends JsonResource
{
public ?string $wrap = null;
public function toArray(): array
{
return [
'id' => $this->resource['id'],
'pk' => $this->resource['pk'],
'sk' => $this->when(isset($this->resource['sk']), fn() => $this->resource['sk']),
'webhookSecret' => $this->when(isset($this->webhookSecret), fn() =>$this->resource['webhookSecret']),
'notifyUrl' => $this->when(!empty($this->resource['notifyUrl']), fn() => $this->resource['notifyUrl'])
];
}
public function __get($key): ?string
{
return $this->resource[$key] ?? null;
}
}

View File

@@ -14,25 +14,22 @@ namespace Singularity\HDK\Pay\Sdk;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Hyperf\Codec\Json;
use Hyperf\Di\Annotation\Inject;
use Singularity\HDK\Core\Service\HttpRequestService;
use Singularity\HDK\Core\Http\RequestService;
use Singularity\HDK\Core\Http\RequestServiceFactory;
use Singularity\HDK\Pay\Resource\Goods;
use function Hyperf\Config\config;
final class GoodsRpc
{
public function __construct(private HttpRequestService $requestService, private ?string $baseUri = null)
private RequestService $requestService;
public function __construct(?string $baseUri = null)
{
$this->baseUri ??= config('payment.base_uri');
if (empty($this->baseUri)) {
throw new \InvalidArgumentException('payment.base_uri is required');
}
$this->requestService->setOptions(
[
'base_uri' => $this->baseUri,
RequestOptions::ALLOW_REDIRECTS => true,
]
);
$this->requestService = RequestServiceFactory::make([
'base_uri' => $baseUri ?? config('payment.base_uri'),
RequestOptions::ALLOW_REDIRECTS => true,
]);
}
/**
@@ -44,10 +41,8 @@ final class GoodsRpc
*/
public function find(int $goodsId, array $specifies): Goods
{
$url = $this->baseUri . '/rpc/v1/wechat/qrcode';
$response = $this->requestService->requestGet("/rpc/v1/goods/$goodsId/search", $specifies);
$content = $response->getBody()->getContents();
return Goods::make(Json::decode($content, false));
return Goods::make(Json::decode($content));
}
}

105
src/Sdk/StripeRpc.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
/**
* WechatRpc.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/7/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;
/**
* Singularity\HDK\Pay\Sdk\WechatRpc@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/7/17
*/
final class StripeRpc
{
use WebhooksNotificationHandler;
private RequestService $requestService;
public function __construct(?string $baseUrl = null)
{
$this->requestService = RequestServiceFactory::make([
'base_uri' => $baseUrl ?? config('payment.base_uri'),
RequestOptions::ALLOW_REDIRECTS => true,
]);
}
public function getConfigurations(): StripeConfiguration
{
$resp = $this->requestService->requestGet('/rpc/v1/stripe/configurations');
$content = $resp->getBody()->getContents();
$order = Json::decode($content);
return StripeConfiguration::make($order);
}
/**
* @param Money $money
* @param string $uid
* @param int $goodsId
* @param string $goodsName
* @param array $goodsDetail
* @return Order
* @throws GuzzleException
*/
public function createSession(
Money $money,
string $uid,
int $goodsId,
string $goodsName,
array $goodsDetail,
?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' => (string)$money->getCurrency(),
'uid' => $uid,
'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();
$order = Json::decode($content);
return Order::make($order);
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* WechatRpc.php@Pay
@@ -11,12 +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\Service\HttpRequestService;
use Singularity\HDK\Core\Http\RequestService;
use Singularity\HDK\Core\Http\RequestServiceFactory;
use Singularity\HDK\Pay\Trait\WebhooksNotificationHandler;
use function Hyperf\Config\config;
@@ -29,9 +32,17 @@ use function Hyperf\Config\config;
*/
final class WechatRpc
{
#[Inject]
private HttpRequestService $requestService;
use WebhooksNotificationHandler;
private RequestService $requestService;
public function __construct(?string $baseUrl = null)
{
$this->requestService = RequestServiceFactory::make([
'base_uri' => $baseUrl ?? config('payment.base_uri'),
RequestOptions::ALLOW_REDIRECTS => true,
]);
}
/**
* @param RequestInterface $request
@@ -49,23 +60,24 @@ final class WechatRpc
Money $money,
string $uid
): array {
$url = config('payment.base_uri') . '/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);

View 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());
}
}

View File

@@ -11,26 +11,25 @@ declare(strict_types=1);
*/
use Singularity\HDK\Core\Service\HttpRequestService;
use GuzzleHttp\Exception\GuzzleException;
use Singularity\HDK\Pay\Resource\Goods;
use Singularity\HDK\Pay\Sdk\GoodsRpc;
/** @var GoodsRpc $service */
$service = \Hyperf\Support\make(
GoodsRpc::class,
[
'requestService' => \Hyperf\Support\make(HttpRequestService::class),
'baseUri' => 'http://localhost:9611'
]);
test('根据分类和商品名称获取到对应的 SKU', function () use ($service) {
$goods = $service->find(
1,
[
'lattice' => 'TYPE-0',
'precision' => 'high',
'mode' => 'gradient',
],
);
expect($goods)->toBeInstanceOf(Goods::class);
})->only();
test(
'根据分类和商品名称获取到对应的 SKU',
/**
* @throws GuzzleException
*/
function () {
$service = new GoodsRpc('http://192.168.2.218:9611');
$goods = $service->find(
1,
[
'lattice' => 'TYPE-0',
'precision' => 'high',
'mode' => 'gradient',
],
);
expect($goods)->toBeInstanceOf(Goods::class);
}
);

43
tests/Unit/StripeTest.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
/**
* StripeTest.php@Pay
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/19
*/
/** @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;
test('能够正常创建 Stripe 订单', function () {
/** @var StripeRpc $service */
$service = \Hyperf\Support\make(StripeRpc::class, ['baseUrl' => 'http://192.168.2.218:9611']);
$order = $service->createSession(
money: Money::USD(51),
uid: uniqid('NAT_'),
goodsId: 1,
goodsName: 'HDK-Pay Test',
goodsDetail: [],
locale: Languages::EN,
service: 1
);
expect($order)->toBeInstanceOf(Order::class);
});
test('能够正常获取 Stripe 配置信息', function () {
/** @var StripeRpc $service */
$service = \Hyperf\Support\make(StripeRpc::class, ['baseUrl' => 'http://192.168.2.218:9611']);
$configures = $service->getConfigurations();
expect($configures)
->toBeInstanceOf(StripeConfiguration::class)
->toHaveKeys(['id', 'pk'])
->and($configures->resolve())->toBeArray();
});

View File

@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
@@ -9,8 +10,28 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSource;
use Psr\Container\ContainerInterface;
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
!defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
!defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
Swoole\Runtime::enableCoroutine(true);
require BASE_PATH . '/vendor/autoload.php';
Hyperf\Di\ClassLoader::init();
$container = new Container(new DefinitionSource([]));
if (!$container instanceof ContainerInterface) {
throw new RuntimeException('The dependency injection container is invalid.');
}
$container = ApplicationContext::setContainer($container);