fix dont HMAC request send to montify
This commit is contained in:
@@ -73,8 +73,13 @@ class WalletPaymentController extends Controller
|
|||||||
$withdraw->sts = 3;
|
$withdraw->sts = 3;
|
||||||
$withdraw->save();
|
$withdraw->save();
|
||||||
|
|
||||||
|
\Log::warning('wallet.payment.initiate_failed', [
|
||||||
|
'withdraw_id' => $withdraw->id,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'مشکل در ارتباط با درگاه',
|
'message' => $e->getMessage() ?: 'مشکل در ارتباط با درگاه',
|
||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,18 +84,41 @@ class MontifyPartnerGateway implements WalletPaymentGatewayInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$signer = $this->signer();
|
$signer = $this->signer();
|
||||||
|
$rawBody = $signer->stableStringify($body);
|
||||||
$headers = $signer->signRequest('POST', $path, $body);
|
$headers = $signer->signRequest('POST', $path, $body);
|
||||||
$response = Http::withHeaders($headers)
|
|
||||||
->withBody($signer->stableStringify($body), 'application/json')
|
try {
|
||||||
->acceptJson()
|
// مهم: post($url, []) بدنهٔ withBody را خالی میکند — حتماً send بدون data
|
||||||
->post($this->baseUrl() . $path);
|
$response = Http::withHeaders($headers)
|
||||||
|
->withBody($rawBody, 'application/json')
|
||||||
|
->acceptJson()
|
||||||
|
->timeout(30)
|
||||||
|
->send('POST', $this->baseUrl() . $path);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
report($e);
|
||||||
|
throw new RuntimeException('اتصال به سرور درگاه برقرار نشد');
|
||||||
|
}
|
||||||
|
|
||||||
$data = $response->json();
|
$data = $response->json();
|
||||||
if (!$response->successful() || empty($data['payment_url'])) {
|
if (!$response->successful() || !is_array($data) || empty($data['payment_url'])) {
|
||||||
$message = is_array($data)
|
$errorCode = is_array($data) ? (string) ($data['error'] ?? '') : '';
|
||||||
|
$remoteMessage = is_array($data)
|
||||||
? (string) ($data['message'] ?? $data['error'] ?? 'initiate failed')
|
? (string) ($data['message'] ?? $data['error'] ?? 'initiate failed')
|
||||||
: 'initiate failed';
|
: 'initiate failed';
|
||||||
throw new RuntimeException($message);
|
|
||||||
|
\Log::warning('montify.initiate_failed', [
|
||||||
|
'status' => $response->status(),
|
||||||
|
'error' => $errorCode,
|
||||||
|
'message' => $remoteMessage,
|
||||||
|
'return_url' => $body['return_url'] ?? null,
|
||||||
|
'webhook_url' => $body['webhook_url'] ?? null,
|
||||||
|
'gateway' => $body['gateway'] ?? null,
|
||||||
|
'reference_id' => $body['reference_id'] ?? null,
|
||||||
|
'amount' => $body['amount'] ?? null,
|
||||||
|
'body' => is_array($data) ? $data : $response->body(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new RuntimeException($this->mapInitiateError($errorCode, $remoteMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -106,6 +129,24 @@ class MontifyPartnerGateway implements WalletPaymentGatewayInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function mapInitiateError(string $errorCode, string $fallback): string
|
||||||
|
{
|
||||||
|
return match ($errorCode) {
|
||||||
|
'invalid_signature' => 'امضای درخواست درگاه نامعتبر است (secret یا ساعت سرور را بررسی کنید)',
|
||||||
|
'expired_timestamp' => 'ساعت سرور با درگاه همخوان نیست',
|
||||||
|
'replay_detected' => 'درخواست تکراری شناسایی شد؛ دوباره تلاش کنید',
|
||||||
|
'invalid_return_url' => 'آدرس برگشت (return_url) در whitelist پارتنر Montify ثبت نشده است',
|
||||||
|
'invalid_gateway' => 'نام درگاه داخل Montify نامعتبر است',
|
||||||
|
'amount_too_low' => 'مبلغ کمتر از حد مجاز درگاه است',
|
||||||
|
'duplicate_reference' => 'شناسه پرداخت تکراری است؛ دوباره تلاش کنید',
|
||||||
|
'gateway_not_configured' => 'درگاه انتخابشده در Montify پیکربندی نشده است',
|
||||||
|
'missing_auth_headers' => 'هدرهای احراز هویت به درگاه ارسال نشد',
|
||||||
|
default => $fallback !== '' && $fallback !== 'initiate failed'
|
||||||
|
? $fallback
|
||||||
|
: 'مشکل در ارتباط با درگاه',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public function handleReturn(Request $request): array
|
public function handleReturn(Request $request): array
|
||||||
{
|
{
|
||||||
$query = $request->query();
|
$query = $request->query();
|
||||||
|
|||||||
Reference in New Issue
Block a user