mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 06:15:09 +08:00
feat(stripe): 实现了 stripe 获取配置信息的服务方法
This commit is contained in:
45
src/Resource/StripeConfiguration.php
Normal file
45
src/Resource/StripeConfiguration.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ use Singularity\HDK\Core\Http\RequestService;
|
||||
use Singularity\HDK\Core\Http\RequestServiceFactory;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
|
||||
use Singularity\HDK\Pay\Resource\StripeConfiguration;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
/**
|
||||
@@ -40,6 +42,15 @@ final class StripeRpc
|
||||
]);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -12,11 +12,12 @@
|
||||
|
||||
use Money\Money;
|
||||
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']);
|
||||
$service = \Hyperf\Support\make(StripeRpc::class, ['baseUrl' => 'http://192.168.2.218:9611']);
|
||||
$order = $service->createSession(
|
||||
money: Money::USD(51),
|
||||
uid: uniqid('NAT_'),
|
||||
@@ -27,3 +28,14 @@ test('能够正常创建 Stripe 订单', function () {
|
||||
);
|
||||
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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user