Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Http/Controllers/WebhookController.php
Назад
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Repositories\TransactionRepository; use App\Repositories\UserRepository; use App\Repositories\NotificationRepository; use App\Interfaces\TransactionRepositoryInterface; use App\Interfaces\UserRepositoryInterface; use App\Interfaces\NotificationRepositoryInterface; use App\Models\User; use App\Models\Unit; use App\Models\TransactionDetail; use App\Models\Transaction; use App\Models\RentPayment; use App\Models\Wallet; use App\Models\Lease; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; class WebhookController extends Controller { private TransactionRepositoryInterface $transactionInterfaceObj; private UserRepositoryInterface $userInterfaceObj; private NotificationRepository $notificationInterfaceObj; public function __construct(TransactionRepository $transactionRepo, UserRepository $userRepo,NotificationRepository $notiRepo) { $this->transactionInterfaceObj = $transactionRepo; $this->userInterfaceObj = $userRepo; $this->notificationInterfaceObj = $notiRepo; } public function subscriptionAutoChargeSuccess(Request $request){ try { //$request->data->object $payload = json_decode($request->getContent(), true); \Log::info('This is Stripe Subscription Success Object: ',[$payload]); $email = $payload['customer_email']; $user = $this->userInterfaceObj->getUserByKey('email',$email); $transaction_id = $this->transactionInterfaceObj->createTransaction( $user->id ?? 0, null, $payload['amount_paid'], 'paid', 'Monthly Subscription Charges', null, json_encode($payload), null, null, null, 'subscription_charges' ); return response()->json([ 'code' => 200, 'message' => 'subscription Auto Charge Success' ],200); } catch (\Throwable $th) { \Log::info('This is Stripe Subscription Success: ',[$th]); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } public function subscriptionAutoChargeFail(Request $request){ try { //$request->data->object $payload = json_decode($request->getContent(), true); \Log::info('This is Stripe Subscription Fail Object: ',[$payload]); $object = $payload['data']['object']; $user = User::where('stripe_id',$object['customer'])->first(); $email = $user->email; $user = $this->userInterfaceObj->getUserByKey('email',$email); $user->subscription($payload['subscription'])->retryCharge(3); return response()->json([ 'code' => 200, 'message' => 'subscription Auto Charge Fail' ],200); } catch (\Throwable $th) { \Log::info('This is Stripe Subscription Fail: ',[$th]); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } public function subscriptionAutoChargeCancel(Request $request){ try { //$request->data->object $payload = json_decode($request->getContent(), true); \Log::info('This is Stripe Subscription Fail Object: ',[$payload]); if($payload['type'] == "customer.subscription.deleted"){ $object = $payload['data']['object']; $user = User::where('stripe_id',$object['customer'])->first(); $email = $user->email; $user = $this->userInterfaceObj->getUserByKey('email',$email); $user->subscription_status = 'canceled'; $user->save(); return response()->json([ 'code' => 200, 'message' => 'subscription Auto Charge Cancel' ],200); } } catch (\Throwable $th) { \Log::info('This is Stripe Subscription Fail: ',[$th]); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } public function checkoutSessionComplete(Request $request){ try { $payload = json_decode($request->getContent(), true); // $payload = json_decode($request); \Log::info('This is Stripe Bank Complete: ',[$payload]); // $email = $payload->customer_email; // $user = $this->userInterfaceObj->getUserByKey('email',$email); // $user->subscription_status = 'canceled'; // $user->save(); return response()->json([ 'code' => 200, 'message' => 'subscription Auto Charge Cancel' ],200); } catch (\Throwable $th) { \Log::info('This is Stripe Bank Complete Fail: ',[$th]); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } public function checkoutSessionPaymentFailed(Request $request){ try { $payload = json_decode($request->getContent(), true); if($payload['type'] == "charge.failed"){ \Log::info('This is Stripe Bank Payment Async FAILED 200: ',[$payload]); DB::beginTransaction(); $object = $payload['data']['object']; $user = User::where('stripe_id',$object['customer'])->first(); // $transaction_latest = TransactionDetail::whereJsonContains('payload->payment_method', $object['payment_method'])->where('payment_type','monthly_rent')->first(); $payment_method = stripslashes($object['payment_method']); $transaction_latest = TransactionDetail::whereRaw('JSON_VALID(payload)')->whereJsonContains('payload->payment_method', $payment_method)->where('payment_type','monthly_rent')->first(); $unit = Unit::whereId($transaction_latest->unit_id)->first(); // ->get();->where('payment_type','monthly_rent')->first(); $transaction = Transaction::whereId($transaction_latest->transaction_id)->update(['status'=> 'failed']); $title = 'Payment Failed'; $message = 'Payment failed please try again.'; $fl = $this->notificationInterfaceObj->CreateAndSendNotification($user,$title,$message); DB::commit(); } return response()->json([ 'code' => 200, 'message' => 'Bank Payment Failed' ],200); } catch (\Throwable $th) { \Log::info('This is Stripe Bank Payment Async FAILED Error 500: ',[$th]); DB::rollback(); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } public function checkoutSessionPaymentComplete(Request $request){ \Log::info('This is Stripe Bank Payment Async Complete Success CHECK:'); try { $payload = json_decode($request->getContent(), true); if($payload['type'] == "charge.succeeded"){ \Log::info('This is Stripe Bank Payment Async Complete Success 200: ',[$payload]); $object = $payload['data']['object']; $payment_method_details = $payload['data']['object']['payment_method_details']; if($payment_method_details['type'] == "us_bank_account"){ $user = User::where('stripe_id',$object['customer'])->first(); DB::beginTransaction(); // $transaction_latest = TransactionDetail::whereJsonContains('payload->payment_method', $object['payment_method'])->where('payment_type','monthly_rent')->first(); $payment_method = stripslashes($object['payment_method']); $transaction_latest = TransactionDetail::whereRaw('JSON_VALID(payload)')->whereJsonContains('payload->payment_method', $payment_method)->where('payment_type','monthly_rent')->first(); $transaction_details = TransactionDetail::whereRaw('JSON_VALID(payload)')->whereJsonContains('payload->payment_method', $payment_method)->whereIn('payment_type',['monthly_rent','annual_somni_fee','security_deposit'])->get(); // ->get();->where('payment_type','monthly_rent')->first(); \Log::info('Latest Transaction Detail 200: ',[$transaction_latest]); $unit = Unit::whereId($transaction_latest->unit_id)->first(); $landlord = $unit->property->user; $transaction = Transaction::whereId($transaction_latest->transaction_id)->update(['status'=> 'paid']); foreach($transaction_details as $detail){ RentPayment::where('unit_id', $detail->unit_id)->where('month', $detail->payment_month)->where('year', $detail->payment_year)->where('payment_type', $detail->payment_type)->where('status' , 'unpaid')->update(['status' => 'paid', 'amount_paid' => $detail->amount ]); if($detail->payment_type != 'annual_somni_fee'){ Wallet::where('user_id',$landlord->id)->increment('balance', (double)$detail->amount); } } DB::commit(); $title = 'Payment Sent'; $message = 'Payment Has been sent to '.$unit->property->user->name.'.'; $fl = $this->notificationInterfaceObj->CreateAndSendNotification($user,$title,$message); $title = 'Payment Recieved'; $message = 'Payment Has been recieved. Amount of $'.number_format(($object['amount'] / 100),2).' has been deposited in your SOMNI Wallet.'; $fl = $this->notificationInterfaceObj->CreateAndSendNotification($unit->property->user,$title,$message); } //Wallet main paiay reh gae && RentPayment Update } return response()->json([ 'code' => 200, 'message' => 'Bank Payment Completed' ],200); } catch (\Throwable $th) { \Log::info('This is Stripe Bank Payment Async Complete Error 500: ',[$th]); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } public function signatureSigned(Request $request){ try { $payload = json_decode($request->getContent(), true); if($payload['event'] == 'envelope-completed'){ $envelope_id = $payload['data']['envelopeId']; $summary = $payload['data']['envelopeSummary']; $envelopeDocuments = $payload['data']['envelopeSummary']['envelopeDocuments']; $PDFBytes = $envelopeDocuments[0]['PDFBytes']; if($summary['status'] == 'completed'){ $update = Lease::where('envelope_id' , $envelope_id)->update(['status' => 1]); // Status Signed $lease = Lease::where('envelope_id' , $envelope_id)->first(); $userFolder = "user_{$lease->landlord_id}"; if (!Storage::exists($userFolder)) { Storage::makeDirectory($userFolder, 0777, true, true); } $pdfContent = base64_decode($PDFBytes); $pdfSizeKB = strlen($pdfContent) / 1024; //Into KBs $filePath = $userFolder . '/signed_' . basename('/dum/'.$lease->name) . '.pdf'; // Store the PDF file Storage::disk('public')->put($filePath, $pdfContent); $update = Lease::where('envelope_id' , $envelope_id)->update(['document_path' => $filePath]); $update = Lease::where('envelope_id' , $envelope_id)->update(['payload' => $payload]); $update = Lease::where('envelope_id' , $envelope_id)->update(['size' => $pdfSizeKB]); // Status Signed } } return response()->json([ 'code' => 200, 'message' => 'Signing completed' ],200); } catch (\Throwable $th) { \Log::info('This is DocuSign Signature Complete Error 500: ',[$th]); return response()->json([ 'code' => 500, 'message' => $th->getMessage(), ],500); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка