eClass - Learning Management System

eClass - Learning Management System v6.7

No permission to download

glowboxstudio

New member
Nov 4, 2020
10
2
3
Code:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\RefundCourse;
use App\Currency;
use Auth;
use PayPal\Api\Amount;
use PayPal\Api\Refund;
use PayPal\Api\Sale;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;
use Cartalyst\Stripe\Laravel\Facades\Stripe;
use PaytmWallet;
use Razorpay\Api\Api;
use App\RefundPolicy;
use App\Order;

class RefundController extends Controller
{
    public function __construct()
    {
        /** PayPal api context **/
        $paypal_conf = \Config::get('paypal');
        $this->_api_context = new ApiContext(new OAuthTokenCredential(
            $paypal_conf['client_id'],
            $paypal_conf['secret'])
        );
        $this->_api_context->setConfig($paypal_conf['settings']);
    }

    public function index()
    {
        $refunds = RefundCourse::get();
        return view('admin.refund_order.show', compact('refunds'));
    }

    public function edit($id)
    {
        $refunds = RefundCourse::where('id', $id)->first();
        return view('admin.refund_order.view', compact('refunds'));
    }

    public function update(Request $request, $id)
    {

        $refnd = RefundCourse::where('id', $id)->first();

        if(Auth::check())
        {

            if(Auth::user()->role == "admin")
            {

                if($refnd->status == 0)
                {

                    if(isset($refnd))
                    {

                        if($refnd->payment_method == 'PayPal')
                        {

                            return $this->refundwithPaypal($request, $refnd);

                        }
                        elseif($refnd->payment_method == 'Stripe')
                        {

                            return $this->refundwithStripe($request, $refnd);

                        }
                        elseif($refnd->payment_method == 'Paystack')
                        {

                            return $this->refundwithPaystack($request, $refnd);

                        }
                        elseif($refnd->payment_method == 'Instamojo')
                        {

                            return $this->refundwithInstamojo($request, $refnd);

                        }
                        elseif($refnd->payment_method == 'PayTM')
                        {

                            return $this->refundwithPaytm($request, $refnd);

                        }elseif($refnd->payment_method == 'RazorPay')
                        {

                            return $this->refundwithRazorPay($request, $refnd);

                        }
                        elseif($refnd->payment_method == 'BankTransfer')
                        {

                            return $this->refundwithBank($request, $refnd);

                        }

                      
                    }
                    else
                    {
                        return back()->with('delete', trans('flash.RefundNotFound'));
                    }
                }
                else
                {
                    return back()->with('delete', trans('flash.RefundAlready'));
                }
            }
            else
            {
                return back()->with('delete', trans('flash.UnauthorizedAction'));
            }
        }
        else
        {
            return back()->with('delete', trans('flash.UnauthorizedAction'));
        }

    }


    public function refundwithPaypal($request, $refnd)
    {
        $refundrequest = RefundCourse::find($refnd->id);


        $currency = Currency::first();

        $amt = new Amount();
        $amt->setTotal($refundrequest->total_amount)->setCurrency($currency->currency);

        $saleId = $refundrequest->order->sale_id;
        $refund = new Refund();
        $refund->setAmount($amt);
        $sale = new Sale();                       
        $sale->setId($saleId);
      

        try
        {
            $refundedSale = $sale->refund($refund, $this->_api_context);

            RefundCourse::where('id', $refnd->id)
                    ->update([
                'status' => 1,
                'order_refund_id' => $refundrequest->id,
                'refund_transaction_id' => $refundedSale->id,
                'txn_fee' => $refundedSale->refund_from_transaction_fee['value'],
                'refunded_amt' => $refundedSale->total_refunded_amount['value'],
                'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

            ]);

            Order::where('id', $refundrequest->order_id)
                ->update([
                'refunded' => 1,

            ]);
          

            return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));

        }
        catch (\Exception $ex) {

            return $ex->getData();

        }

    }

    public function refundwithStripe($request, $refnd)
    {

        $refundrequest = RefundCourse::find($refnd->id);

        $stripe = new Stripe();

        $stripe = Stripe::make(env('STRIPE_SECRET'));

        $charge_id = $refnd->order->transaction_id;
        $amount = $refnd->total_amount;
      

        try
        {
            $striperefund = $stripe->refunds()
                ->create($charge_id, $amount, [
                    'metadata' => [
                        'reason' => $refnd->reason,
                    ],
                ]);

            RefundCourse::where('id', $refnd->id)
                    ->update([
                'status' => 1,
                'order_refund_id' => $refundrequest->id,
                'refund_transaction_id' => $striperefund['id'],
                'txn_fee' => null,
                'refunded_amt' => $order_refund->amount,
                'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

            ]);

            Order::where('id', $refundrequest->order_id)
                ->update([
                'refunded' => 1,

            ]);

            return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));

        }
        catch(\Exception $e)
        {
            $error = $e->getMessage();

            return redirect('refundorder')->with('delete', $error);
        }

        return redirect('refundorder')->with('delete', trans('flash.RefundError'));

    }

    public function refundwithPaystack($request, $refnd)
    {

        $refundrequest = RefundCourse::find($refnd->id);

        $url = "https://api.paystack.co/refund";

        $fields = [
            'amount' => $refundrequest->amount,
            'transaction' => $refundrequest->order->transaction_id,
            'customer_note' => $refundrequest->reason,
        ];

        $fields_string = http_build_query($fields);
        //open connection
        $ch = curl_init();
        $secret_key = env('PAYSTACK_SECRET_KEY');
        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Authorization: Bearer $secret_key",
            "Cache-Control: no-cache",
        ));

        //So that curl_exec returns the contents of the cURL; rather than echoing it
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        //execute post
        $result = curl_exec($ch);
        $result = json_decode($result, true);

        if ($result['status'] == false) {

            return redirect('refundorder')->with('delete', $result['message']);

        } else {

            RefundCourse::where('id', $refnd->id)
                    ->update([
                'status' => 1,
                'order_refund_id' => $refundrequest->id,
                'refund_transaction_id' => $result['data']['transaction']['id'],
                'txn_fee' => null,
                'refunded_amt' => $result['data']['transaction']['amount'] / 100,
                'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

            ]);


            Order::where('id', $refundrequest->order_id)
                ->update([
                'refunded' => 1,

            ]);

            return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));

        }
      
    }

    public function refundwithInstamojo($request, $refnd)
    {
        $refundrequest = RefundCourse::find($refnd->id);

        $refundrequest->order->transaction_id;

        try {

            $ch = curl_init();
            $api_key = env('IM_API_KEY');
            $auth_token = env('IM_AUTH_TOKEN');
            curl_setopt($ch, CURLOPT_URL, env('IM_REFUND_URL'));
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER,

                array("X-Api-Key:$api_key",
                    "X-Auth-Token:$auth_token"));

            $payload = array(
                'transaction_id' => 'RFD_IM_' . str_random(10),
                'payment_id' => $refundrequest->order->transaction_id,
                'type' => 'QFL',
                'refund_amount' => round($refundrequest->amount, 2),
                'body' => $refundrequest->reason,
            );

            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
            $response = curl_exec($ch);
            curl_close($ch);

            $result = json_decode($response, true);

            if (isset($result['refund'])) {


                RefundCourse::where('id', $refnd->id)
                    ->update([
                    'status' => 1,
                    'order_refund_id' => $refundrequest->id,
                    'refund_transaction_id' => $result['refund']['id'],
                    'txn_fee' => null,
                    'refunded_amt' => $result['refund']['refund_amount'],
                    'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

                ]);

                Order::where('id', $refundrequest->order_id)
                ->update([
                    'refunded' => 1,

                ]);

                return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));

              

            } else {
                return redirect('refundorder')->with('delete', 'Return already completed');
            }

        } catch (\Exception $e) {
            $error = $e->getMessage();

            return redirect('refundorder')->with('delete', $error);
        }
      
    }

    public function refundwithPaytm($request, $refnd)
    {

        $refundrequest = RefundCourse::find($refnd->id);

        $refund = PaytmWallet::with('refund');

        $refund->prepare([
            'order' => $refundrequest->order->order_id,
            'reference' => 'refund' . $refundrequest->order->order_id,
            'amount' => $refundrequest->total_amount,
            'transaction' => $refundrequest->order->transaction_id,
        ]);

        $refund->initiate();
        $response = $refund->response();

        if($refund->isSuccessful()) {


            RefundCourse::where('id', $refnd->id)
                ->update([
                'status' => 1,
                'order_refund_id' => $refundrequest->id,
                'refund_transaction_id' => $response['REFUNDID'],
                'txn_fee' => null,
                'refunded_amt' => $response['REFUNDAMOUNT'],
                'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

            ]);

            Order::where('id', $refundrequest->order_id)
                ->update([
                'refunded' => 1,

            ]);

            return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));
          

        }
        elseif($refund->isFailed()) {

            if($response['STATUS'] == 'TXN_FAILURE') {

                $status = 0;

                return redirect('refundorder')->with('delete', trans('flash.RefundError'));

            }

            return redirect('refundorder')->with('delete', trans('flash.RefundError'));

        }

        return redirect('refundorder')->with('delete', trans('flash.RefundError'));

      
    }

    public function refundwithRazorPay($request, $refnd)
    {

        $refundrequest = RefundCourse::find($refnd->id);

        try {
            $api = new Api(env('RAZORPAY_KEY'), env('RAZORPAY_SECRET'));
            $refund = $api->payment->fetch($refundrequest->order->transaction_id);
            $result = $refund->refund(array('amount' => round($refundrequest->amount * 100, 2)));


            RefundCourse::where('id', $refnd->id)
                ->update([
                'status' => 1,
                'order_refund_id' => $refundrequest->id,
                'refund_transaction_id' => $result->id,
                'txn_fee' => null,
                'refunded_amt' => $result->amount / 100,
                'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

            ]);

            Order::where('id', $refundrequest->order_id)
                ->update([
                'refunded' => 1,

            ]);

            return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));

          

        } catch (\Exception $e) {
            $error = $e->getMessage();

            return redirect('refundorder')->with('delete', $error);
        }
      
    }

    public function refundwithBank($request, $refnd)
    {

        $refundrequest = RefundCourse::find($refnd->id);

        RefundCourse::where('id', $refnd->id)
            ->update([
            'status' => 1,
            'order_refund_id' => $refundrequest->id,
            'refund_transaction_id' => str_random(32),
            'txn_fee' => null,
            'refunded_amt' => $refundrequest->total_amount,
            'updated_at'  => \Carbon\Carbon::now()->toDateTimeString(),

        ]);

      

        Order::where('id', $refundrequest->order_id)
                ->update([
            'refunded' => 1,

        ]);

        return redirect('refundorder')->with('success', trans('flash.RefundSuccessful'));
      
    }
}

Replace this code with app/Http/Controllers/RefundController.php Then no error will be there.

Please do check and inform me the same.

Done, worked like a charm
thanks ChintanBhat
 
  • Love
Reactions: ChintanBhat

ChintanBhat

Well-known member
Null Master
Trusted Uploader
Nov 18, 2020
1,124
1,130
120
39
Universe

White Devil

Well-known member
Trusted Seller
Trusted Uploader
Jan 6, 2019
3,107
6,072
120
world
babiato.tech

ChintanBhat

Well-known member
Null Master
Trusted Uploader
Nov 18, 2020
1,124
1,130
120
39
Universe
1606920658361.png
Anyone know how to solve this problem
Replace this code in app/Http/Middleware/MaintananceMode.php
Code:
<?php

namespace App\Http\Middleware;

use Closure;
use Auth;
use App\ComingSoon;

class MaintananceMode
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $ip = $request->ip();

        $comingsoon = ComingSoon::first();


        $ip_address = array();

        
        if(is_array($comingsoon['allowed_ip']) || is_object($comingsoon['allowed_ip']))
        {
            foreach($comingsoon->allowed_ip as $b)
            {
                array_push($ip_address, $b);
            }
        }

        $ip_address = array_values(array_filter($ip_address));

        $ip_address = array_flatten($ip_address);
            




        if(isset($ip_address) && in_array($ip, $ip_address))
        {
            return $next($request);
        }
        else
        {
            if(Auth::check() && Auth::user()->role == 'admin'){

                return $next($request);
                
            }
            else{

                if($comingsoon['enable'] == 1){

                    return redirect()->route('comingsoon.show');
                }
                else{

                    return $next($request);

                }

            }
        }


        return $next($request);
                
            
        
        
    }
}

And change this code in app/ComingSoon.php
Code:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class ComingSoon extends Model
{
    use HasTranslations;
    
    public $translatable = ['heading', 'text_one', 'text_two', 'text_three', 'text_four', 'btn_text'];

    /**
     * Convert the model instance to an array.
     *
     * @return array
     */
    public function toArray()
    {
      $attributes = parent::toArray();
      
      foreach ($this->getTranslatableAttributes() as $name) {
          $attributes[$name] = $this->getTranslation($name, app()->getLocale());
      }
      
      return $attributes;
    }

    protected $table = 'coming_soons'; 

    protected $fillable = [ 'bg_image', 'heading', 'count_one', 'count_two', 'count_three', 'count_four', 'text_one', 'text_two', 'text_three', 'text_four', 'btn_text', 'allowed_ip', 'enable' ];

    protected $casts = [
        'allowed_ip' => 'array'
    ];
}
 
  • Like
Reactions: SamDam

iflexure

Member
Jan 22, 2020
58
7
8
Replace this code in app/Http/Middleware/MaintananceMode.php
Code:
<?php

namespace App\Http\Middleware;

use Closure;
use Auth;
use App\ComingSoon;

class MaintananceMode
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $ip = $request->ip();

        $comingsoon = ComingSoon::first();


        $ip_address = array();

       
        if(is_array($comingsoon['allowed_ip']) || is_object($comingsoon['allowed_ip']))
        {
            foreach($comingsoon->allowed_ip as $b)
            {
                array_push($ip_address, $b);
            }
        }

        $ip_address = array_values(array_filter($ip_address));

        $ip_address = array_flatten($ip_address);
           




        if(isset($ip_address) && in_array($ip, $ip_address))
        {
            return $next($request);
        }
        else
        {
            if(Auth::check() && Auth::user()->role == 'admin'){

                return $next($request);
               
            }
            else{

                if($comingsoon['enable'] == 1){

                    return redirect()->route('comingsoon.show');
                }
                else{

                    return $next($request);

                }

            }
        }


        return $next($request);
               
           
       
       
    }
}

And change this code in app/ComingSoon.php
Code:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class ComingSoon extends Model
{
    use HasTranslations;
   
    public $translatable = ['heading', 'text_one', 'text_two', 'text_three', 'text_four', 'btn_text'];

    /**
     * Convert the model instance to an array.
     *
     * @return array
     */
    public function toArray()
    {
      $attributes = parent::toArray();
     
      foreach ($this->getTranslatableAttributes() as $name) {
          $attributes[$name] = $this->getTranslation($name, app()->getLocale());
      }
     
      return $attributes;
    }

    protected $table = 'coming_soons';

    protected $fillable = [ 'bg_image', 'heading', 'count_one', 'count_two', 'count_three', 'count_four', 'text_one', 'text_two', 'text_three', 'text_four', 'btn_text', 'allowed_ip', 'enable' ];

    protected $casts = [
        'allowed_ip' => 'array'
    ];
}
thanx
 

tcspune

New member
Jul 20, 2020
17
3
3

NullMaster

Well-known member
Null Master
Trusted Uploader
Jul 25, 2018
12,058
22,063
120
  • Like
Reactions: xacall and phpCore

xacall

Active member
May 15, 2019
146
30
28
Is there a way to have every country, every state and every city in the world without having to add it one by one? My system is for online classes and I don't need to restrict by cities! Please help me. Thanks
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu