Fix 401 error on sign request on verify

This commit is contained in:
mahmood
2026-07-27 01:17:08 +03:30
parent afc23165bd
commit cdefe88afe
3 changed files with 71 additions and 12 deletions
@@ -157,10 +157,16 @@ class MontifyPartnerGateway implements WalletPaymentGatewayInterface
public function handleReturn(Request $request): array
{
$query = $request->query();
// query() آبجکت ParameterBag است؛ برای HMAC باید آرایهٔ string باشد
$query = $this->normalizeReturnQuery($request->query()->all());
$signer = $this->signer();
if (!$signer->verifyReturnSignature($query)) {
\Log::warning('montify.return_invalid_signature', [
'keys' => array_keys($query),
'reference_id' => $query['reference_id'] ?? null,
]);
return ['ok' => false, 'withdraw' => null, 'http_status' => 401, 'message' => 'امضای نامعتبر'];
}
@@ -200,6 +206,31 @@ class MontifyPartnerGateway implements WalletPaymentGatewayInterface
];
}
/**
* پارامترهای برگشت Montify باید همگی string باشند (طبق مستند).
*
* @param array<string, mixed> $query
* @return array<string, string>
*/
private function normalizeReturnQuery(array $query): array
{
$normalized = [];
foreach ($query as $key => $value) {
if (!is_string($key) || $key === '') {
continue;
}
if (is_array($value)) {
continue;
}
if ($value === null) {
continue;
}
$normalized[$key] = (string) $value;
}
return $normalized;
}
public function handleWebhook(Request $request): array
{
$body = $request->all();