mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 07:35:09 +08:00
Compare commits
3 Commits
v1.0.0-bet
...
v1.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b669931e78 | ||
|
|
ce1ad9561e | ||
|
|
427b6cd7af |
@@ -1,4 +1,12 @@
|
||||
# 版本更新日志
|
||||
## [1.0.0-beta.3](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2025-07-08)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **order:** 兼容 v2 创建订单 ([ce1ad95](http://124.126.16.154:8888/singularity/hdk-pay/commit/ce1ad9561e0a780f670d766b8d4c841130a18697))
|
||||
* **Order:** 增加订单商品名称和数量字段 ([427b6cd](http://124.126.16.154:8888/singularity/hdk-pay/commit/427b6cd7af1800c4c4d5ba685686c61cc6fbef52))
|
||||
|
||||
## [1.0.0-beta.2](http://124.126.16.154:8888/singularity/hdk-pay/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2024-12-06)
|
||||
|
||||
|
||||
|
||||
@@ -62,5 +62,5 @@
|
||||
"url": "https://mirrors.aliyun.com/composer/"
|
||||
}
|
||||
},
|
||||
"version": "1.0.0-beta.2"
|
||||
"version": "1.0.0-beta.3"
|
||||
}
|
||||
|
||||
@@ -11,9 +11,12 @@ namespace Singularity\HDK\Pay\Enum;
|
||||
|
||||
enum PaymentMethod: string
|
||||
{
|
||||
case Stripe = 'stripe';
|
||||
// case Stripe = 'stripe';
|
||||
// case WechatPay = 'wechat';
|
||||
|
||||
case WechatPay = 'wechat';
|
||||
case StripeCheckout = 'stripe.checkout';
|
||||
case StripeIntent = 'stripe.intent';
|
||||
case WechatNative = 'wechat.native';
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
|
||||
@@ -14,13 +14,15 @@ use Singularity\HDK\Pay\Enum\OrderStatus;
|
||||
* 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
|
||||
* @property-read string $orderNo
|
||||
* @property-read string $transactionId
|
||||
* @property-read string $goodsName
|
||||
* @property-read Money|array{'amount': int, 'currency': string} $amount
|
||||
* @property-read OrderStatus $state
|
||||
* @property-read string $uid
|
||||
* @property-read string $payment
|
||||
* @property-read string $remark
|
||||
* @property-read int $number
|
||||
*/
|
||||
class Order extends JsonResource
|
||||
{
|
||||
@@ -32,11 +34,13 @@ class Order extends JsonResource
|
||||
* @return array{
|
||||
* orderNo: string,
|
||||
* transactionId: string,
|
||||
* goodsName: string,
|
||||
* amount: Money,
|
||||
* state: OrderStatus,
|
||||
* uid: string,
|
||||
* payment: string,
|
||||
* remark: string
|
||||
* remark: string,
|
||||
* number: int
|
||||
* }
|
||||
*/
|
||||
public function toArray(): array
|
||||
|
||||
72
src/Resource/V2/Order.php
Normal file
72
src/Resource/V2/Order.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Singularity\HDK\Pay\Resource\V2;
|
||||
|
||||
use App\Model\ServiceProvider;
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Resource\Json\JsonResource;
|
||||
use Singularity\HDK\Pay\Enum\OrderStatus;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* App\Resource\ Order@LuxPay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/19
|
||||
*
|
||||
* @property string $order_no 订单号
|
||||
* @property OrderStatus $state 订单状态
|
||||
* @property string $transaction_id 订单号
|
||||
* @property string $uid 购买用户的 uid
|
||||
* @property string $method 支付方式
|
||||
* @property string $description 订单描述
|
||||
* @property int $total_amount 金额,单位:分
|
||||
* @property string $currency 币种,三个大写字母
|
||||
* @property array $items 订单详情
|
||||
* @property array $external 额外订单信息
|
||||
* @property string $remark 订单备注
|
||||
* @property array $notification 原始通知
|
||||
* @property array more_details 支付信息
|
||||
*/
|
||||
class Order extends JsonResource
|
||||
{
|
||||
public ?string $wrap = null;
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array{
|
||||
* orderNo: string,
|
||||
* transactionId: string,
|
||||
* amount: array{amount: numeric, currency: string},
|
||||
* state: string,
|
||||
* uid: string,
|
||||
* payment: string,
|
||||
* remark: string
|
||||
* }
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'order_no' => $this->order_no,
|
||||
'state' => $this->state,
|
||||
'transaction_id' => $this->transaction_id,
|
||||
'uid' => $this->uid,
|
||||
'method' => $this->method,
|
||||
'description' => $this->description,
|
||||
'total_amount' => $this->total_amount,
|
||||
'currency' => $this->currency,
|
||||
'items' => $this->items,
|
||||
'external' => $this->external,
|
||||
'remark' => $this->remark,
|
||||
'notification' => $this->notification ?? new StdClass(),
|
||||
'more_details' => $this->more_details,
|
||||
];
|
||||
}
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->resource->{$key} ?? $this->resource[$key];
|
||||
}
|
||||
}
|
||||
63
src/Sdk/OrderRpc.php
Normal file
63
src/Sdk/OrderRpc.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OrderRpc.php@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/7/9
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Pay\Sdk;
|
||||
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Lmc\HttpConstants\Header;
|
||||
use Singularity\HDK\Core\Http\RequestService;
|
||||
use Singularity\HDK\Core\Http\RequestServiceFactory;
|
||||
use Singularity\HDK\Core\I18n\Enum\Languages;
|
||||
use Singularity\HDK\Pay\Resource\V2\Order;
|
||||
use Singularity\HDK\Pay\Trait\WebhooksNotificationHandler;
|
||||
|
||||
use stdClass;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
final class OrderRpc
|
||||
{
|
||||
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 create(
|
||||
array $data,
|
||||
?string $serviceProvider = null,
|
||||
?Languages $locale = null,
|
||||
): Order {
|
||||
$data['method'] = 'stripe.checkout';
|
||||
$response = $this->requestService->requestPost(
|
||||
url: '/rpc/v2/orders',
|
||||
data: $data,
|
||||
options: [
|
||||
'headers' => [
|
||||
Header::CONTENT_TYPE => 'application/json',
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale'),
|
||||
'X-SP-ID' => $serviceProvider ?? config('app_name'),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
$result = Json::decode($content);
|
||||
return new Order($result);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace Singularity\HDK\Pay\Trait;
|
||||
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
use Singularity\HDK\Pay\Resource\V2\Order;
|
||||
|
||||
/**
|
||||
* Singularity\HDK\Pay\Trait\Webhooks@Pay
|
||||
|
||||
Reference in New Issue
Block a user