fix pargar bugs 2
This commit is contained in:
@@ -756,4 +756,102 @@ class ConfigService
|
||||
{
|
||||
return $this->accountingProvider() === self::ACCOUNTING_PARGAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hostname for WebOTP SMS (@domain #code) and other public links.
|
||||
* Only from the current HTTP request — no settings, no .env.
|
||||
*/
|
||||
public function resolvePublicHost(?\Illuminate\Http\Request $request = null): string
|
||||
{
|
||||
foreach ($this->publicHostCandidates($request) as $host) {
|
||||
if ($this->isUsableHost($host)) {
|
||||
return $this->normalizeHost($host);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/** Full user-facing site URL, e.g. https://example.ir */
|
||||
public function resolvePublicSiteUrl(?\Illuminate\Http\Request $request = null): string
|
||||
{
|
||||
if ($request !== null) {
|
||||
$origin = rtrim(trim((string) $request->getSchemeAndHttpHost()), '/');
|
||||
$host = $this->parseHostFromUrl($origin);
|
||||
if ($this->isUsableHost($host)) {
|
||||
return $origin;
|
||||
}
|
||||
}
|
||||
|
||||
if (! app()->runningInConsole() && request()) {
|
||||
$origin = rtrim(trim((string) request()->getSchemeAndHttpHost()), '/');
|
||||
$host = $this->parseHostFromUrl($origin);
|
||||
if ($this->isUsableHost($host)) {
|
||||
return $origin;
|
||||
}
|
||||
}
|
||||
|
||||
$host = $this->resolvePublicHost($request);
|
||||
if ($host !== '') {
|
||||
return 'https://' . $host;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/** @deprecated Use resolvePublicHost() — kept for backward compatibility */
|
||||
public function resolveHostForOtp(string $urlSettingKey = 'app_url', ?\Illuminate\Http\Request $request = null): string
|
||||
{
|
||||
return $this->resolvePublicHost($request);
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function publicHostCandidates(?\Illuminate\Http\Request $request): array
|
||||
{
|
||||
$candidates = [];
|
||||
|
||||
if ($request !== null) {
|
||||
$candidates[] = trim((string) $request->getHost());
|
||||
}
|
||||
|
||||
if (! app()->runningInConsole() && request()) {
|
||||
$candidates[] = trim((string) request()->getHost());
|
||||
}
|
||||
|
||||
return $candidates;
|
||||
}
|
||||
|
||||
private function isUsableHost(string $host): bool
|
||||
{
|
||||
$host = strtolower(trim($host));
|
||||
|
||||
return $host !== ''
|
||||
&& ! in_array($host, ['localhost', '127.0.0.1', '0.0.0.0'], true);
|
||||
}
|
||||
|
||||
private function parseHostFromUrl(string $url): string
|
||||
{
|
||||
$url = trim($url);
|
||||
if ($url === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (! preg_match('#^https?://#i', $url)) {
|
||||
$url = 'https://' . ltrim($url, '/');
|
||||
}
|
||||
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if (! is_string($host) || $host === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->normalizeHost($host);
|
||||
}
|
||||
|
||||
private function normalizeHost(string $host): string
|
||||
{
|
||||
$host = strtolower(trim($host));
|
||||
|
||||
return str_starts_with($host, 'www.') ? substr($host, 4) : $host;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,13 @@ class PargarInboundWalletService
|
||||
*/
|
||||
public function applyLatestMandeDifference(Customer $customer): array
|
||||
{
|
||||
if ($this->hasPendingOutboundWalletSync((int) $customer->id)) {
|
||||
return [
|
||||
'applied' => false,
|
||||
'message' => 'سند ارسالی از پنل به پرگار هنوز تأیید نشده — برای جلوگیری از برگشت شارژ، ماندهٔ پرگار اعمال نشد',
|
||||
];
|
||||
}
|
||||
|
||||
$log = PargarSyncLog::query()
|
||||
->where('customer_id', $customer->id)
|
||||
->where('type', PargarSyncService::TYPE_MANDE)
|
||||
@@ -393,6 +400,15 @@ class PargarInboundWalletService
|
||||
]);
|
||||
}
|
||||
|
||||
private function hasPendingOutboundWalletSync(int $customerId): bool
|
||||
{
|
||||
return PargarSyncLog::query()
|
||||
->where('customer_id', $customerId)
|
||||
->whereIn('type', [PargarSyncService::TYPE_WALLET_CASH, PargarSyncService::TYPE_WALLET_GOLD])
|
||||
->where('sync_status', PargarSyncService::STATUS_PENDING)
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function parseNumber(mixed $value): float
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
|
||||
@@ -38,36 +38,7 @@ class PriceStreamService
|
||||
|
||||
public function resolveHost(?Request $request = null): string
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
|
||||
$appUrl = trim($config->getString('app_url', ''));
|
||||
if ($appUrl !== '') {
|
||||
$host = parse_url($appUrl, PHP_URL_HOST);
|
||||
if (is_string($host) && $host !== '') {
|
||||
return $this->normalizeHost($host);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request !== null) {
|
||||
$requestHost = trim((string) $request->getHost());
|
||||
if ($requestHost !== '') {
|
||||
return $this->normalizeHost($requestHost);
|
||||
}
|
||||
}
|
||||
|
||||
if (! app()->runningInConsole() && request()) {
|
||||
$requestHost = trim((string) request()->getHost());
|
||||
if ($requestHost !== '') {
|
||||
return $this->normalizeHost($requestHost);
|
||||
}
|
||||
}
|
||||
|
||||
$nameEn = trim((string) $config->getString('name_en', ''));
|
||||
if ($nameEn !== '') {
|
||||
return $this->normalizeHost($nameEn);
|
||||
}
|
||||
|
||||
return '';
|
||||
return app(ConfigService::class)->resolvePublicHost($request);
|
||||
}
|
||||
|
||||
public function currentSeq(): int
|
||||
@@ -219,11 +190,4 @@ class PriceStreamService
|
||||
|
||||
return md5(json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
private function normalizeHost(string $host): string
|
||||
{
|
||||
$host = strtolower(trim($host));
|
||||
|
||||
return strpos($host, 'www.') === 0 ? substr($host, 4) : $host;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class ReferralGiftService
|
||||
$giftForInviter = (float) $config->get('gift_for_referrer', 0);
|
||||
$giftForInvited = (float) $config->get('gift_for_referral', 0);
|
||||
$companyName = $config->getString('name_fa');
|
||||
$companyUrl = $config->getString('app_url');
|
||||
$companyUrl = $config->resolvePublicSiteUrl(request());
|
||||
|
||||
if ($referrer && $referrerGiftAllowed && $giftForInviter > 0 && !$this->referrerGiftAlreadyGiven($customer, $referrer)) {
|
||||
$this->giveReferrerGift($customer, $referrer, $giftForInviter, $companyName, $companyUrl, $config);
|
||||
|
||||
@@ -74,7 +74,7 @@ class WebsocketBroadcastService
|
||||
}
|
||||
|
||||
$body = array_merge($payload, ['trigger' => $trigger]);
|
||||
$host = $this->resolveHost();
|
||||
$host = app(ConfigService::class)->resolvePublicHost();
|
||||
if ($host !== '') {
|
||||
$body['host'] = $host;
|
||||
}
|
||||
@@ -103,31 +103,4 @@ class WebsocketBroadcastService
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveHost(): string
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
|
||||
$appUrl = trim($config->getString('app_url', ''));
|
||||
if ($appUrl !== '') {
|
||||
$host = parse_url($appUrl, PHP_URL_HOST);
|
||||
if (is_string($host) && $host !== '') {
|
||||
return $host;
|
||||
}
|
||||
}
|
||||
|
||||
if (! app()->runningInConsole() && request()) {
|
||||
$requestHost = trim((string) request()->getHost());
|
||||
if ($requestHost !== '') {
|
||||
return $requestHost;
|
||||
}
|
||||
}
|
||||
|
||||
$nameEn = trim((string) $config->getString('name_en', ''));
|
||||
if ($nameEn !== '') {
|
||||
return $nameEn;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user