Fix 401 error on sign request on verify
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user