fix(core): harden settlement and wallet integration
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
namespace App\Services\Wallet;
|
||||
|
||||
use App\Models\Player;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use App\Services\Integration\PartnerSiteConfig;
|
||||
use App\Support\Integration\WalletApiRequestGuard;
|
||||
use App\Services\Integration\PartnerSiteConfigResolver;
|
||||
use App\Support\Integration\WalletApiUrlSanitizer;
|
||||
|
||||
/**
|
||||
* 通过 HTTP 调用主站钱包 API(路径见 config lottery.main_site.wallet_*_path)。
|
||||
@@ -15,6 +15,7 @@ final class HttpMainSiteWalletGateway implements MainSiteWalletGateway
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PartnerSiteConfigResolver $partnerSiteConfigResolver,
|
||||
private readonly WalletApiRequestGuard $walletApiRequestGuard,
|
||||
) {}
|
||||
|
||||
public function debitMainForLotteryDeposit(
|
||||
@@ -77,7 +78,7 @@ final class HttpMainSiteWalletGateway implements MainSiteWalletGateway
|
||||
string $currencyCode,
|
||||
int $amountMinor,
|
||||
string $idempotentKey,
|
||||
\App\Services\Integration\PartnerSiteConfig $config,
|
||||
PartnerSiteConfig $config,
|
||||
): MainSiteWalletResult {
|
||||
if (! $config->hasWalletApi()) {
|
||||
$requestSnapshot = [
|
||||
@@ -108,8 +109,11 @@ final class HttpMainSiteWalletGateway implements MainSiteWalletGateway
|
||||
);
|
||||
}
|
||||
|
||||
$base = WalletApiUrlSanitizer::normalizeAndValidate($config->walletApiUrl);
|
||||
if ($base === null) {
|
||||
$endpoint = $this->walletApiRequestGuard->guard(
|
||||
$config->walletApiUrl,
|
||||
$config->walletTimeoutSeconds,
|
||||
);
|
||||
if ($endpoint === null) {
|
||||
return MainSiteWalletResult::failure(
|
||||
'wallet_api_url_invalid',
|
||||
['reason' => 'invalid_base_url'],
|
||||
@@ -142,12 +146,11 @@ final class HttpMainSiteWalletGateway implements MainSiteWalletGateway
|
||||
],
|
||||
]);
|
||||
|
||||
$url = $base.'/'.ltrim($path, '/');
|
||||
$timeout = $config->walletTimeoutSeconds;
|
||||
$url = $endpoint->baseUrl.'/'.ltrim($path, '/');
|
||||
$apiKey = $config->walletApiKey;
|
||||
|
||||
if (app()->environment(['production'])
|
||||
&& $config->source === \App\Services\Integration\PartnerSiteConfig::SOURCE_LEGACY_ENV
|
||||
&& $config->source === PartnerSiteConfig::SOURCE_LEGACY_ENV
|
||||
&& (! is_string($apiKey) || trim($apiKey) === '')
|
||||
) {
|
||||
return MainSiteWalletResult::failure(
|
||||
@@ -164,8 +167,7 @@ final class HttpMainSiteWalletGateway implements MainSiteWalletGateway
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders($headers)
|
||||
->timeout($timeout)
|
||||
$response = $endpoint->request($headers)
|
||||
->acceptJson()
|
||||
->asJson()
|
||||
->post($url, $requestBody);
|
||||
|
||||
Reference in New Issue
Block a user