mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 03:35:06 +08:00
feat(OrderRpc): 增加站点和环境参数并优化请求头
- 在 OrderRpc 类中添加了站点 (site) 和环境 (env) 参数 - 优化了请求头,包括接受语言、服务提供商 ID、站点和环境 - 更新了 composer.json 中的依赖版本
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"composer/composer": ">=2.5.8",
|
||||
"composer/composer": ">=2.7.7",
|
||||
"hyperf/config": "~3.1.0",
|
||||
"hyperf/constants": "3.1.*",
|
||||
"hyperf/contract": "~3.1.0",
|
||||
|
||||
1965
composer.lock
generated
1965
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -11,20 +11,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Pay\Sdk;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\Context\Context;
|
||||
use Lmc\HttpConstants\Header;
|
||||
use Singularity\HDK\Core\Enumerations\Sp\ServiceProviderConfiguration;
|
||||
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
|
||||
final class OrderRpc implements ServiceProviderConfiguration
|
||||
{
|
||||
use WebhooksNotificationHandler;
|
||||
|
||||
@@ -38,10 +39,21 @@ final class OrderRpc
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string|null $serviceProvider
|
||||
* @param Languages|null $locale
|
||||
* @param string|null $site
|
||||
* @param string|null $env
|
||||
* @return Order
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function create(
|
||||
array $data,
|
||||
?string $serviceProvider = null,
|
||||
?Languages $locale = null,
|
||||
?string $site = null,
|
||||
?string $env = null,
|
||||
): Order {
|
||||
$data['method'] = 'stripe.checkout';
|
||||
$response = $this->requestService->requestPost(
|
||||
@@ -50,8 +62,16 @@ final class OrderRpc
|
||||
options: [
|
||||
'headers' => [
|
||||
Header::CONTENT_TYPE => 'application/json',
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale'),
|
||||
'X-SP-ID' => $serviceProvider ?? config('app_name'),
|
||||
Header::ACCEPT_LANGUAGE => $locale?->value ?? config('translation.locale', Languages::EN),
|
||||
'X-SP-ID' => $serviceProvider ?? Context::get('sp') ?? config('app_name'),
|
||||
'X-SITE' => match (strtoupper(trim($site ?? config('site', self::NA)))) {
|
||||
'CN' => self::CN,
|
||||
default => self::NA,
|
||||
},
|
||||
'X-ENV' => match (strtolower(trim($env ?? config('app_env', self::DEVELOPMENT)))) {
|
||||
'prod', 'production' => self::PRODUCTION,
|
||||
default => self::DEVELOPMENT
|
||||
},
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user