180 lines
8.7 KiB
PHP
180 lines
8.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\pay;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Customer;
|
|
use App\Models\User;
|
|
use App\Models\Withdraw;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Rooyesh\Wallet\interfaces\TransactionInterface;
|
|
use Rooyesh\Wallet\interfaces\WalletInterface;
|
|
|
|
class paypingController extends Controller
|
|
{
|
|
public function startTransation(Request $request)
|
|
{
|
|
$user = auth()->user();
|
|
$finalPriseP = $request->value;
|
|
if ($user->id ==4){
|
|
$finalPriseP =10700;
|
|
}
|
|
$Withdraw = Withdraw::create([
|
|
'customer_id' => auth('customer')->id(),
|
|
"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);
|
|
}
|
|
|
|
$Withdraw->tracked_number = $response['id'];
|
|
$Withdraw->save();
|
|
return $response['url'];
|
|
return response()->json(["res"=>$response], 422);
|
|
}
|
|
public function verifyTransationByID(Request $request ,$id)
|
|
{
|
|
if ($request->header('payping') !== '@XOKcNveJ$wpqYy%rdpb78oBh31Aos*bIdQemiUeeq9e9G!oey23SMXp40Ew2fodjx9J5buKNW0M4@nYMr1PR6d0KtuqhLQlx*K$') {
|
|
return response()->json(['auth needed'], 401);
|
|
}
|
|
$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) {
|
|
if ($Withdraw->cash == $GTransaction['amount'] * 10) {
|
|
$Withdraw->zify_code = $Withdraw->tracked_number;
|
|
$Withdraw->tracked_number = $GTransaction['invoiceNo'];//ok
|
|
$Withdraw->sts = 2;//ok
|
|
$Withdraw->save();
|
|
|
|
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
|
|
$transaction = new TransactionInterface($wallet_interface_fund, $_inp = [
|
|
"cash" => $GTransaction['amount'] * 10,
|
|
'expire_at' => now(),
|
|
'withdraw_id' => $Withdraw->id,
|
|
'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) {
|
|
$this->Send($admin->mobile, $message);
|
|
});
|
|
return view('showTransactionReport', compact('Withdraw','app_url'));
|
|
return redirect('https://app.gholaktala.ir/transactions');
|
|
}
|
|
return "مبلغ پرداختی دستکاری شده !";
|
|
} else {
|
|
$Withdraw->tracked_number;
|
|
$Withdraw->sts = 3;//no
|
|
$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);
|
|
$decodedResponse = json_decode($verifyResponse, true);
|
|
$verifyMessage = $decodedResponse['message'];
|
|
// return $decodedResponse['data'];
|
|
|
|
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->save();
|
|
|
|
$wallet_interface_fund = new WalletInterface($User->id, $User->type);
|
|
$transaction = new TransactionInterface($wallet_interface_fund, $_inp = [
|
|
"cash" => $decodedResponse['data']['amount'] * 10,
|
|
'expire_at' => now(),
|
|
'withdraw_id' => $_GET['clientrefid'],
|
|
'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
|
|
|
|
// Constructing the SMS message
|
|
$message = "کاربر $userName با شماره موبایل $userMobile حساب خود را به مقدار " . number_format($chargedAmount) . " ریال شارژ کرد. با تشکر، $companyName";
|
|
|
|
// Getting admin mobile numbers and sending the SMS
|
|
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 "مبلغ پرداختی دستکاری شده !";
|
|
} else {
|
|
|
|
$Withdraw->tracked_number;
|
|
$Withdraw->sts = 3;//no
|
|
$Withdraw->save();
|
|
return view('showTransactionReport', compact('Withdraw','app_url'));
|
|
}
|
|
|
|
|
|
}
|
|
}
|