2026-01-24 14:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\pay;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Withdraw;
|
2026-06-04 12:18:53 +03:30
|
|
|
use App\Services\ConfigService;
|
2026-01-24 14:03:11 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
|
|
|
|
use Rooyesh\Wallet\interfaces\WalletInterface;
|
2026-07-19 15:53:05 +03:30
|
|
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
2026-01-24 14:03:11 +00:00
|
|
|
|
|
|
|
|
class paypingController extends Controller
|
|
|
|
|
{
|
2026-06-04 12:18:53 +03:30
|
|
|
private function cfg(): ConfigService
|
|
|
|
|
{
|
|
|
|
|
return app(ConfigService::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function paypingHeaders(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'payping' => $this->cfg()->getString(
|
|
|
|
|
'payping_header_secret',
|
|
|
|
|
(string) config('payment.payping_header_secret', '')
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function paypingStartUrl(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->cfg()->getString(
|
|
|
|
|
'payping_start_url',
|
|
|
|
|
(string) config('payment.payping_start_url', 'https://payping.limangold.ir/payment/start')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function paypingVerifyUrl(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->cfg()->getString(
|
|
|
|
|
'payping_verify_url',
|
|
|
|
|
(string) config('payment.payping_verify_url', 'https://payping.limangold.ir/payment/verify')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** اگر payping_gateway_items پر باشد (با کاما)، مثل گلد علی بین itemها میچرخد */
|
|
|
|
|
private function resolveGatewayItem(): string
|
|
|
|
|
{
|
|
|
|
|
$list = $this->cfg()->getString('payping_gateway_items', '');
|
|
|
|
|
if ($list === '') {
|
2026-07-01 15:47:24 +03:30
|
|
|
return (string) config('payment.payping_gateway_item', 'gp1Q');
|
2026-06-04 12:18:53 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$items = array_values(array_filter(array_map('trim', explode(',', $list))));
|
|
|
|
|
if ($items === []) {
|
|
|
|
|
return 'gp1Q';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$index = (int) cache()->get('payping_gateway_item_index', 0);
|
|
|
|
|
if ($index >= count($items)) {
|
|
|
|
|
$index = 0;
|
|
|
|
|
}
|
|
|
|
|
$item = $items[$index];
|
|
|
|
|
cache()->put('payping_gateway_item_index', $index + 1);
|
|
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
public function startTransation(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$user = auth()->user();
|
|
|
|
|
$finalPriseP = $request->value;
|
2026-06-04 12:18:53 +03:30
|
|
|
if ($user->id == 4) {
|
|
|
|
|
$finalPriseP = 10700;
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
if ($this->cfg()->getBool('payping_round_toman', (bool) config('payment.payping_round_toman', false))) {
|
|
|
|
|
$finalPriseP = (int) (ceil($finalPriseP / 10) * 10);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 15:53:05 +03:30
|
|
|
// شارژ کیف (بدون سفارش): حداقل واریز از تنظیمات
|
|
|
|
|
if (!isset($request->order_id)) {
|
|
|
|
|
$minDeposit = $this->cfg()->getInt('min_deposit', 0);
|
|
|
|
|
if ($minDeposit > 0 && (int) $finalPriseP < $minDeposit) {
|
|
|
|
|
throw new UnprocessableEntityHttpException(
|
|
|
|
|
'حداقل مقدار واریز ' . number_format($minDeposit) . ' ریال است'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
$Withdraw = Withdraw::create([
|
|
|
|
|
'customer_id' => auth('customer')->id(),
|
2026-06-04 12:18:53 +03:30
|
|
|
'cash' => $finalPriseP,
|
|
|
|
|
'note' => 'واریز ریالی',
|
2026-01-24 14:03:11 +00:00
|
|
|
'sts' => 1,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
if (isset($request->order_id)) {
|
|
|
|
|
$Withdraw->order_id = $request->order_id;
|
|
|
|
|
if (isset($request->product_id)) {
|
|
|
|
|
$Withdraw->product_id = $request->product_id;
|
|
|
|
|
}
|
|
|
|
|
$Withdraw->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$payload = [
|
|
|
|
|
'amount' => $finalPriseP / 10,
|
|
|
|
|
'user_name' => $user->name,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
'user' => $user,
|
|
|
|
|
'title' => $this->Config('name_fa'),
|
|
|
|
|
'return_url' => 'https://' . $this->Config('app_url') . '/transactions',
|
|
|
|
|
'server_call_url' => url('/customer/charge_account_verify/' . $Withdraw->id),
|
|
|
|
|
'item' => $this->resolveGatewayItem(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$gatewayName = $this->cfg()->getString('payping_gateway_name', (string) config('payment.payping_gateway_name', ''));
|
|
|
|
|
if ($gatewayName !== '') {
|
|
|
|
|
$payload['gateway'] = $gatewayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$response = Http::withHeaders($this->paypingHeaders())
|
|
|
|
|
->post($this->paypingStartUrl(), $payload)
|
|
|
|
|
->json();
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'مشکل در ارتباط با درگاه',
|
|
|
|
|
'R' => $response ?? $exception,
|
|
|
|
|
], 422);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($response['id']) || empty($response['url'])) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'مشکل در ارتباط با درگاه',
|
|
|
|
|
'R' => $response ?? null,
|
|
|
|
|
], 422);
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$Withdraw->tracked_number = $response['id'];
|
|
|
|
|
$Withdraw->save();
|
2026-06-04 12:18:53 +03:30
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
return $response['url'];
|
|
|
|
|
}
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
public function verifyTransationByID(Request $request, $id)
|
2026-01-24 14:03:11 +00:00
|
|
|
{
|
2026-06-04 12:18:53 +03:30
|
|
|
$expectedSecret = $this->cfg()->getString(
|
|
|
|
|
'payping_header_secret',
|
|
|
|
|
(string) config('payment.payping_header_secret', '')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($request->header('payping') !== $expectedSecret) {
|
2026-01-24 14:03:11 +00:00
|
|
|
return response()->json(['auth needed'], 401);
|
|
|
|
|
}
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
$Withdraw = Withdraw::with('customer')->where('id', $id)->first();
|
2026-01-24 14:03:11 +00:00
|
|
|
$app_url = $this->Config('app_url');
|
|
|
|
|
$User = Customer::where('id', $Withdraw->customer_id)->first();
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
$GTransaction = Http::withHeaders($this->paypingHeaders())
|
|
|
|
|
->post($this->paypingVerifyUrl(), [
|
|
|
|
|
'id' => (string) ($Withdraw->tracked_number ?? $Withdraw->zify_code),
|
|
|
|
|
])
|
|
|
|
|
->json();
|
|
|
|
|
|
|
|
|
|
if (isset($GTransaction['active']) && $GTransaction['active'] == 5) {
|
2026-01-24 14:03:11 +00:00
|
|
|
if ($Withdraw->cash == $GTransaction['amount'] * 10) {
|
|
|
|
|
$Withdraw->zify_code = $Withdraw->tracked_number;
|
2026-06-04 12:18:53 +03:30
|
|
|
$Withdraw->tracked_number = $GTransaction['invoiceNo'];
|
|
|
|
|
$Withdraw->sts = 2;
|
2026-01-24 14:03:11 +00:00
|
|
|
$Withdraw->save();
|
|
|
|
|
|
|
|
|
|
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
|
2026-06-04 12:18:53 +03:30
|
|
|
new TransactionInterface($wallet_interface_fund, [
|
|
|
|
|
'cash' => $GTransaction['amount'] * 10,
|
2026-01-24 14:03:11 +00:00
|
|
|
'expire_at' => now(),
|
|
|
|
|
'withdraw_id' => $Withdraw->id,
|
2026-06-04 12:18:53 +03:30
|
|
|
'active' => true,
|
2026-01-24 14:03:11 +00:00
|
|
|
], 3, false, true);
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
$message = 'کاربر ' . $Withdraw->customer->name . ' با شماره موبایل ' . $Withdraw->customer->mobile
|
|
|
|
|
. ' حساب خود را به مقدار ' . number_format($Withdraw->cash) . ' ریال شارژ کرد. با تشکر، ' . $this->Config('name_fa');
|
|
|
|
|
|
|
|
|
|
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
|
2026-07-18 22:22:01 +03:30
|
|
|
if (self::isSmsNotifEnabled('sms_notif_gateway_charge_admin')) {
|
|
|
|
|
$this->Send($admin->mobile, $message);
|
|
|
|
|
}
|
2026-01-24 14:03:11 +00:00
|
|
|
});
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
return view('showTransactionReport', compact('Withdraw', 'app_url'));
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
return 'مبلغ پرداختی دستکاری شده !';
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
if ($this->cfg()->getBool('payping_strict_failed_withdraw', (bool) config('payment.payping_strict_failed_withdraw', false))) {
|
|
|
|
|
if (!$Withdraw->zify_code) {
|
|
|
|
|
$Withdraw->priority = 51;
|
|
|
|
|
}
|
|
|
|
|
$Withdraw->priority = 111;
|
|
|
|
|
}
|
|
|
|
|
$Withdraw->sts = 3;
|
|
|
|
|
$Withdraw->save();
|
|
|
|
|
|
|
|
|
|
return view('showTransactionReport', compact('Withdraw', 'app_url'));
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
2026-06-04 12:18:53 +03:30
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
public function verifyTransation()
|
|
|
|
|
{
|
|
|
|
|
$Withdraw = Withdraw::with('customer')->where('id', $_GET['clientrefid'])->first();
|
|
|
|
|
$app_url = $this->Config('app_url');
|
|
|
|
|
$User = Customer::where('id', $Withdraw->customer_id)->first();
|
2026-06-04 12:18:53 +03:30
|
|
|
|
|
|
|
|
$verifyResponse = Http::withToken('cf09ee0187335f173c786e7660d778d2dd71ab582d282999f751427f5923d525')
|
|
|
|
|
->post('https://zify.ir/api/order/v2/verify', [
|
|
|
|
|
'order' => (string) $Withdraw->tracked_number,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-24 14:03:11 +00:00
|
|
|
$decodedResponse = json_decode($verifyResponse, true);
|
2026-06-04 12:18:53 +03:30
|
|
|
$verifyMessage = $decodedResponse['message'] ?? null;
|
2026-01-24 14:03:11 +00:00
|
|
|
|
|
|
|
|
if (isset($decodedResponse['data']['refid']) || $verifyMessage == []) {
|
|
|
|
|
if ($Withdraw->cash == $decodedResponse['data']['amount'] * 10) {
|
2026-06-04 12:18:53 +03:30
|
|
|
$Withdraw->zify_code = $Withdraw->tracked_number;
|
|
|
|
|
$Withdraw->tracked_number = $decodedResponse['data']['refid'];
|
|
|
|
|
$Withdraw->sts = 2;
|
2026-01-24 14:03:11 +00:00
|
|
|
$Withdraw->save();
|
|
|
|
|
|
|
|
|
|
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
|
2026-06-04 12:18:53 +03:30
|
|
|
new TransactionInterface($wallet_interface_fund, [
|
|
|
|
|
'cash' => $decodedResponse['data']['amount'] * 10,
|
2026-01-24 14:03:11 +00:00
|
|
|
'expire_at' => now(),
|
|
|
|
|
'withdraw_id' => $_GET['clientrefid'],
|
2026-06-04 12:18:53 +03:30
|
|
|
'active' => true,
|
2026-01-24 14:03:11 +00:00
|
|
|
], 3, false, true);
|
|
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
if ($this->cfg()->getBool('payping_fin_sync_enabled', (bool) config('payment.payping_fin_sync_enabled', false))) {
|
|
|
|
|
$finUrl = $this->cfg()->getString('payping_fin_url', 'https://limangold.ir/kernel/admin/fin');
|
|
|
|
|
$finToken = $this->cfg()->getString('payping_fin_token', '');
|
|
|
|
|
if ($finUrl !== '' && $finToken !== '') {
|
|
|
|
|
Http::withToken($finToken)->post($finUrl, [
|
|
|
|
|
'amount' => $decodedResponse['data']['amount'] * 10,
|
|
|
|
|
'customer_id' => $this->cfg()->getString('payping_fin_customer_id', '23'),
|
|
|
|
|
'date_at' => \Carbon\Carbon::today()->format('Y/m/d'),
|
|
|
|
|
'receive_account_number' => '000',
|
|
|
|
|
'receive_bank' => 'پیپینگ',
|
|
|
|
|
'receive_name' => $this->Config('name_fa'),
|
|
|
|
|
'send_account_number' => '000',
|
|
|
|
|
'send_bank' => ' زیفای کد ' . $Withdraw->zify_code,
|
|
|
|
|
'send_name' => $User->name,
|
|
|
|
|
'track_number' => $decodedResponse['data']['refid'],
|
|
|
|
|
'type' => 1,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-24 14:03:11 +00:00
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
$message = 'کاربر ' . $Withdraw->customer->name . ' با شماره موبایل ' . $Withdraw->customer->mobile
|
|
|
|
|
. ' حساب خود را به مقدار ' . number_format($Withdraw->cash) . ' ریال شارژ کرد. با تشکر، ' . $this->Config('name_fa');
|
2026-01-24 14:03:11 +00:00
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
|
2026-07-18 22:22:01 +03:30
|
|
|
if (self::isSmsNotifEnabled('sms_notif_gateway_charge_admin')) {
|
|
|
|
|
$this->Send($admin->mobile, $message);
|
|
|
|
|
}
|
2026-01-24 14:03:11 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
return view('showTransactionReport', compact('Withdraw', 'app_url'));
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
return 'مبلغ پرداختی دستکاری شده !';
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
$Withdraw->sts = 3;
|
|
|
|
|
$Withdraw->save();
|
2026-01-24 14:03:11 +00:00
|
|
|
|
2026-06-04 12:18:53 +03:30
|
|
|
return view('showTransactionReport', compact('Withdraw', 'app_url'));
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
}
|