mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 03:55:07 +08:00
feat(order): 增加订单商品数量参数并优化代码格式
- 在 Order 类中添加 number 字段,用于表示商品数量 - 修改 StripeRpc 和 WechatRpc 类,增加商品数量参数 -优化代码格式,调整缩进和空格
This commit is contained in:
@@ -14,13 +14,13 @@ 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 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 uid
|
||||
* @property-read string payment
|
||||
* @property-read string remark
|
||||
*/
|
||||
class Order extends JsonResource
|
||||
{
|
||||
@@ -48,12 +48,13 @@ class Order extends JsonResource
|
||||
'goodsName' => $this->resource['goodsName'],
|
||||
'amount' => new Money(
|
||||
$this->resource['amount']['amount'],
|
||||
new Currency($this->resource['amount']['currency'])
|
||||
new Currency($this->resource['amount']['currency']),
|
||||
),
|
||||
'state' => OrderStatus::from($this->resource['state']),
|
||||
'uid' => $this->resource['uid'],
|
||||
'payment' => $this->resource['payment'],
|
||||
'remark' => $this->resource['remark'],
|
||||
'number' => $this->resource['number'] ?? 1,
|
||||
// extends
|
||||
// 'spId' => $this->spId,
|
||||
// 'goodsDetail' => GoodsCollection::make([$this->goodsDetail])->resolve(),
|
||||
|
||||
@@ -14,7 +14,6 @@ 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;
|
||||
@@ -22,7 +21,6 @@ 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;
|
||||
@@ -58,11 +56,15 @@ final class StripeRpc
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Money $money
|
||||
* @param string $uid
|
||||
* @param int $goodsId
|
||||
* @param string $goodsName
|
||||
* @param array $goodsDetail
|
||||
* @param Money $money 总金额
|
||||
* @param string $uid
|
||||
* @param int $goodsId
|
||||
* @param string $goodsName
|
||||
* @param array $goodsDetail
|
||||
* @param int $number
|
||||
* @param Languages|null $locale
|
||||
* @param int|null $service
|
||||
*
|
||||
* @return Order
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
@@ -72,6 +74,7 @@ final class StripeRpc
|
||||
int $goodsId,
|
||||
string $goodsName,
|
||||
array $goodsDetail,
|
||||
int $number = 1,
|
||||
?Languages $locale = null,
|
||||
?int $service = null,
|
||||
): Order {
|
||||
@@ -87,15 +90,16 @@ final class StripeRpc
|
||||
[
|
||||
'id' => $goodsId,
|
||||
'goodsName' => $goodsName,
|
||||
]
|
||||
],
|
||||
),
|
||||
'number' => $number,
|
||||
],
|
||||
options: [
|
||||
'headers' => [
|
||||
Header::CONTENT_TYPE => 'application/json',
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale')
|
||||
]
|
||||
]
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale'),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
|
||||
@@ -46,10 +46,12 @@ final class WechatRpc
|
||||
|
||||
/**
|
||||
* @param RequestInterface $request
|
||||
* @param string $type
|
||||
* @param string $goodsName
|
||||
* @param Money $money
|
||||
* @param string $uid
|
||||
* @param string $type
|
||||
* @param string $goodsName
|
||||
* @param Money $money
|
||||
* @param string $uid
|
||||
* @param int $number
|
||||
*
|
||||
* @return array{uri: string, orderNo: string}
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
@@ -58,7 +60,8 @@ final class WechatRpc
|
||||
string $type,
|
||||
string $goodsName,
|
||||
Money $money,
|
||||
string $uid
|
||||
string $uid,
|
||||
int $number = 1,
|
||||
): array {
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
@@ -76,7 +79,8 @@ final class WechatRpc
|
||||
'goods_detail' => [
|
||||
'goods_name' => $goodsName,
|
||||
],
|
||||
]
|
||||
'number' => $number,
|
||||
],
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
|
||||
Reference in New Issue
Block a user