fix some for weebhok url and return url on montify
This commit is contained in:
@@ -94,6 +94,62 @@ class WalletPaymentController extends Controller
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* وریفای برگشت مرورگر از فرانت — امضا و شارژ سمت سرور؛ بدون افشای secret.
|
||||
* Body یا query: status, reference_id, session_id, amount, track_number, timestamp, signature
|
||||
*/
|
||||
public function verifyReturn(Request $request)
|
||||
{
|
||||
$gateway = $this->payments->resolve();
|
||||
if (!$gateway) {
|
||||
throw new UnprocessableEntityHttpException('پرداخت آنلاین فعال نیست');
|
||||
}
|
||||
|
||||
$payload = array_filter([
|
||||
'status' => $request->input('status'),
|
||||
'reference_id' => $request->input('reference_id'),
|
||||
'session_id' => $request->input('session_id'),
|
||||
'amount' => $request->input('amount'),
|
||||
'track_number' => $request->input('track_number'),
|
||||
'timestamp' => $request->input('timestamp'),
|
||||
'signature' => $request->input('signature'),
|
||||
], static fn ($v) => $v !== null && $v !== '');
|
||||
|
||||
$synthetic = Request::create('/', 'GET', $payload);
|
||||
$result = $gateway->handleReturn($synthetic);
|
||||
|
||||
if (!($result['ok'] ?? false)) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $result['message'] ?? 'خطا در تأیید پرداخت',
|
||||
], (int) ($result['http_status'] ?? 400));
|
||||
}
|
||||
|
||||
/** @var Withdraw|null $withdraw */
|
||||
$withdraw = $result['withdraw'] ?? null;
|
||||
if (!$withdraw) {
|
||||
return response()->json(['ok' => false, 'message' => 'سفارش یافت نشد'], 404);
|
||||
}
|
||||
|
||||
$customerId = (int) auth('customer')->id();
|
||||
if ((int) $withdraw->customer_id !== $customerId) {
|
||||
return response()->json(['ok' => false, 'message' => 'دسترسی غیرمجاز'], 403);
|
||||
}
|
||||
|
||||
$sts = (int) $withdraw->sts;
|
||||
$paid = $sts === 2;
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'paid' => $paid,
|
||||
'status' => $paid ? 'success' : ((string) ($payload['status'] ?? '') === 'success' ? 'pending' : 'failed'),
|
||||
'amount' => (int) $withdraw->cash,
|
||||
'reference_id' => 'WD-' . $withdraw->id,
|
||||
'withdraw_id' => $withdraw->id,
|
||||
'track_number' => $withdraw->tracked_number,
|
||||
]);
|
||||
}
|
||||
|
||||
public function returnFromGateway(Request $request, string $provider)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -48,7 +48,15 @@ class MontifyPartnerGateway implements WalletPaymentGatewayInterface
|
||||
return $fromSettings;
|
||||
}
|
||||
|
||||
return url('/customer/wallet/payment/return/' . $this->key());
|
||||
// پیشفرض: صفحه فرانت برای نمایش نتیجه + verify سمت سرور
|
||||
$site = $this->config->resolvePublicSiteUrl(request());
|
||||
if ($site === '') {
|
||||
$appUrl = rtrim((string) config('app.url'), '/');
|
||||
// اگر APP_URL با /server تمام شود، دامنه فرانت همان host بدون /server است
|
||||
$site = preg_replace('#/server$#', '', $appUrl) ?: $appUrl;
|
||||
}
|
||||
|
||||
return rtrim($site, '/') . '/wallet/payment-result';
|
||||
}
|
||||
|
||||
public function webhookUrl(): string
|
||||
|
||||
Reference in New Issue
Block a user