merge goldali with abshode_khanegi branch

This commit is contained in:
2026-06-04 12:18:53 +03:30
parent aea3cbbc6e
commit a9815fa717
28 changed files with 1359 additions and 379 deletions
+189 -102
View File
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Models\Customer;
use App\Models\User;
use App\Models\Withdraw;
use App\Services\ConfigService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Rooyesh\Wallet\interfaces\TransactionInterface;
@@ -13,167 +14,253 @@ use Rooyesh\Wallet\interfaces\WalletInterface;
class paypingController extends Controller
{
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 === '') {
return $this->cfg()->getString('payping_gateway_item', (string) config('payment.payping_gateway_item', 'gp1Q'));
}
$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;
}
public function startTransation(Request $request)
{
$user = auth()->user();
$finalPriseP = $request->value;
if ($user->id ==4){
$finalPriseP =10700;
if ($user->id == 4) {
$finalPriseP = 10700;
}
if ($this->cfg()->getBool('payping_round_toman', (bool) config('payment.payping_round_toman', false))) {
$finalPriseP = (int) (ceil($finalPriseP / 10) * 10);
}
$Withdraw = Withdraw::create([
'customer_id' => auth('customer')->id(),
"cash" => $finalPriseP,
"note" => "واریز ریالی",
'cash' => $finalPriseP,
'note' => 'واریز ریالی',
'sts' => 1,
]);
try {
$response = Http::withHeaders([
'payping' => '@XOKcNveJ$wpqYy%rdpb78oBh31Aos*bIdQemiUeeq9e9G!oey23SMXp40Ew2fodjx9J5buKNW0M4@nYMr1PR6d0KtuqhLQlx*K$', // Custom header with 'payping' value
])->post("https://payping.limangold.ir/payment/start", [
"amount" => $finalPriseP/10, // Payment amount
"user_name" => $user->name, // User name
"user_id" => $user->id, // User ID
"user" => $user, // User ID
"title" => $this->Config('name_fa'), // Title of the payment
"return_url" => "https://".$this->Config('app_url')."/transactions", // Callback URL
"server_call_url" => url("/customer/charge_account_verify/".$Withdraw->id), // Callback URL
"item" => "gp1Q", // Item identifier
])->json();
}catch (\Exception $exception){
return response()->json(["message"=>"مشکل در ارتباط با درگاه","R"=>$response??$exception,], 422);
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);
}
$Withdraw->tracked_number = $response['id'];
$Withdraw->save();
return $response['url'];
return response()->json(["res"=>$response], 422);
}
public function verifyTransationByID(Request $request ,$id)
public function verifyTransationByID(Request $request, $id)
{
if ($request->header('payping') !== '@XOKcNveJ$wpqYy%rdpb78oBh31Aos*bIdQemiUeeq9e9G!oey23SMXp40Ew2fodjx9J5buKNW0M4@nYMr1PR6d0KtuqhLQlx*K$') {
$expectedSecret = $this->cfg()->getString(
'payping_header_secret',
(string) config('payment.payping_header_secret', '')
);
if ($request->header('payping') !== $expectedSecret) {
return response()->json(['auth needed'], 401);
}
$Withdraw = Withdraw::with('customer')->where('id',$id)->first();
$Withdraw = Withdraw::with('customer')->where('id', $id)->first();
$app_url = $this->Config('app_url');
$User = Customer::where('id', $Withdraw->customer_id)->first();
$GTransaction = Http::withHeaders([
'payping' => '@XOKcNveJ$wpqYy%rdpb78oBh31Aos*bIdQemiUeeq9e9G!oey23SMXp40Ew2fodjx9J5buKNW0M4@nYMr1PR6d0KtuqhLQlx*K$', // Custom header with 'payping' value
])->post("https://payping.limangold.ir/payment/verify", [
"id" => "$Withdraw->tracked_number",
])->json();
if (isset( $GTransaction['active']) and $GTransaction['active'] == 5) {
$GTransaction = Http::withHeaders($this->paypingHeaders())
->post($this->paypingVerifyUrl(), [
'id' => (string) ($Withdraw->tracked_number ?? $Withdraw->zify_code),
])
->json();
if (isset($GTransaction['active']) && $GTransaction['active'] == 5) {
if ($Withdraw->cash == $GTransaction['amount'] * 10) {
$Withdraw->zify_code = $Withdraw->tracked_number;
$Withdraw->tracked_number = $GTransaction['invoiceNo'];//ok
$Withdraw->sts = 2;//ok
$Withdraw->tracked_number = $GTransaction['invoiceNo'];
$Withdraw->sts = 2;
$Withdraw->save();
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
$transaction = new TransactionInterface($wallet_interface_fund, $_inp = [
"cash" => $GTransaction['amount'] * 10,
new TransactionInterface($wallet_interface_fund, [
'cash' => $GTransaction['amount'] * 10,
'expire_at' => now(),
'withdraw_id' => $Withdraw->id,
'active' => true
'active' => true,
], 3, false, true);
//----------sms
$userMobile = $Withdraw->customer->mobile; // User's mobile number
$userName = $Withdraw->customer->name; // User's name
$chargedAmount = $Withdraw->cash; // Charged amount
$companyName = $this->Config('name_fa'); // Company name from configuration
$message = "کاربر $userName با شماره موبایل $userMobile حساب خود را به مقدار " . number_format($chargedAmount) . " ریال شارژ کرد. با تشکر، $companyName";
User::where('send_sms', 1)->get()->each(function($admin) use ($message) {
$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) {
$this->Send($admin->mobile, $message);
});
return view('showTransactionReport', compact('Withdraw','app_url'));
return redirect('https://app.gholaktala.ir/transactions');
return view('showTransactionReport', compact('Withdraw', 'app_url'));
}
return "مبلغ پرداختی دستکاری شده !";
} else {
$Withdraw->tracked_number;
$Withdraw->sts = 3;//no
$Withdraw->save();
return view('showTransactionReport', compact('Withdraw','app_url'));
return 'مبلغ پرداختی دستکاری شده !';
}
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'));
}
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();
$url = 'https://zify.ir/api/order/v2/verify';
$payload = [
"order" => "$Withdraw->tracked_number",
];
$verifyResponse = Http::withToken("cf09ee0187335f173c786e7660d778d2dd71ab582d282999f751427f5923d525")
->post($url, $payload);
$verifyResponse = Http::withToken('cf09ee0187335f173c786e7660d778d2dd71ab582d282999f751427f5923d525')
->post('https://zify.ir/api/order/v2/verify', [
'order' => (string) $Withdraw->tracked_number,
]);
$decodedResponse = json_decode($verifyResponse, true);
$verifyMessage = $decodedResponse['message'];
// return $decodedResponse['data'];
$verifyMessage = $decodedResponse['message'] ?? null;
if (isset($decodedResponse['data']['refid']) || $verifyMessage == []) {
if ($Withdraw->cash == $decodedResponse['data']['amount'] * 10) {
$Withdraw->zify_code = $Withdraw->tracked_number;//ok
$Withdraw->tracked_number = $decodedResponse['data']['refid'];//ok
$Withdraw->sts = 2;//ok
$Withdraw->zify_code = $Withdraw->tracked_number;
$Withdraw->tracked_number = $decodedResponse['data']['refid'];
$Withdraw->sts = 2;
$Withdraw->save();
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
$transaction = new TransactionInterface($wallet_interface_fund, $_inp = [
"cash" => $decodedResponse['data']['amount'] * 10,
new TransactionInterface($wallet_interface_fund, [
'cash' => $decodedResponse['data']['amount'] * 10,
'expire_at' => now(),
'withdraw_id' => $_GET['clientrefid'],
'active' => true
'active' => true,
], 3, false, true);
$User = Customer::where('id', $Withdraw->customer_id)->first();
$url = 'https://limangold.ir/kernel/admin/fin';
$payload = [
"amount" => $decodedResponse['data']['amount'] * 10,
"customer_id" => "23",
"date_at" => \Carbon\Carbon::today()->format('Y/m/d'),
"receive_account_number" => "000",
"receive_bank" => "پیپینگ",
"receive_name" => "لیمان گلد",
"send_account_number" => "000",
"send_bank" => " زیفای کد $Withdraw->zify_code",
"send_name" => $User->name,
"track_number" => $decodedResponse['data']['refid'],
"type" => 1,
];
$verifyResponse = Http::withToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbGltYW5nb2xkLmlyXC9rZXJuZWxcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNzI3NTMwNjA0LCJleHAiOjE3MzAxMjI2MDQsIm5iZiI6MTcyNzUzMDYwNCwianRpIjoiYXBINmlPZXlGTE9oTUhRdyIsInN1YiI6MiwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.IrO6icD-EXjgZ3mYyeEAP4aqG7q35yJTCU_hQhEDGwk")
->post($url, $payload);
//----------sms
// User information
$userMobile = $Withdraw->customer->mobile; // User's mobile number
$userName = $Withdraw->customer->name; // User's name
$chargedAmount = $Withdraw->cash; // Charged amount
// Company name
$companyName = $this->Config('name_fa'); // Company name from configuration
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,
]);
}
}
// Constructing the SMS message
$message = "کاربر $userName با شماره موبایل $userMobile حساب خود را به مقدار " . number_format($chargedAmount) . " ریال شارژ کرد. با تشکر، $companyName";
$message = 'کاربر ' . $Withdraw->customer->name . ' با شماره موبایل ' . $Withdraw->customer->mobile
. ' حساب خود را به مقدار ' . number_format($Withdraw->cash) . ' ریال شارژ کرد. با تشکر، ' . $this->Config('name_fa');
// Getting admin mobile numbers and sending the SMS
User::where('send_sms', 1)->get()->each(function($admin) use ($message) {
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
$this->Send($admin->mobile, $message);
});
return view('showTransactionReport', compact('Withdraw','app_url'));
return redirect('https://app.gholaktala.ir/transactions');
return view('showTransactionReport', compact('Withdraw', 'app_url'));
}
return "مبلغ پرداختی دستکاری شده !";
} else {
$Withdraw->tracked_number;
$Withdraw->sts = 3;//no
$Withdraw->save();
return view('showTransactionReport', compact('Withdraw','app_url'));
return 'مبلغ پرداختی دستکاری شده !';
}
$Withdraw->sts = 3;
$Withdraw->save();
return view('showTransactionReport', compact('Withdraw', 'app_url'));
}
}