mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 06:15:09 +08:00
feat(Goods): 添加 Stripe 信息并优化金额处理
- 在 Goods 类中添加 stripe 属性,包含 Stripe 的 id、product_id 和 price_id - 优化 amount 属性的处理方式,使用命名参数提高代码可读性 - 使用 when 方法条件性地加载 Stripe 信息,提高数据处理灵活性
This commit is contained in:
@@ -25,7 +25,8 @@ use Money\Money;
|
||||
* @property-read int $id
|
||||
* @property-read string $goodsName
|
||||
* @property-read array<string, mixed>|array{} $goodsSpec
|
||||
* @property-read Money $amount
|
||||
* @property-read Money|array{'price': int, 'currency': string} $amount
|
||||
* @property-read array{'id': int, 'product_id': string, 'price_id': string} $stripe
|
||||
*/
|
||||
final class Goods extends JsonResource
|
||||
{
|
||||
@@ -40,7 +41,19 @@ final class Goods extends JsonResource
|
||||
'id' => $this->id,
|
||||
'goodsName' => $this->goodsName,
|
||||
'goodsSpec' => $this->goodsSpec,
|
||||
'amount' => new Money($this->amount['price'], new Currency($this->amount['currency']))
|
||||
'amount' => new Money(
|
||||
amount: $this->amount['price'],
|
||||
currency: new Currency($this->amount['currency']),
|
||||
),
|
||||
'stripe' => $this->when(
|
||||
condition: isset($this->resource->stripeProduct),
|
||||
value: fn()
|
||||
=> [
|
||||
'id' => $this->stripe['id'],
|
||||
'product_id' => $this->stripe['product_id'],
|
||||
'price_id' => $this->stripe['price_id'],
|
||||
],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user