Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
6
Indexable
Never
<?php

namespace App\Http\Controllers;

use App\Models\User;

use App\Models\Payutraansaction;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Tzsk\Payu\Concerns\Attributes;
use Tzsk\Payu\Concerns\Customer;
use Tzsk\Payu\Concerns\Transaction;

use Tzsk\Payu\Facades\Payu;
use Tzsk\Pay\Models\PayuTransaction;

class PaymentController extends Controller
{
    public function payment(Request $request)
    {
        $request->validate([
            'amount' => 'required|numeric|min:1'
        ]);

        $customer = Customer::make()
            ->firstName(Auth::user()->name)
            ->email(Auth::user()->email);

        $transaction = Transaction::make()
            ->charge($request->amount)
            ->for('Product')
            ->against(User::find(Auth::user()->id))
           
            ->to($customer);
        

        return Payu::initiate($transaction)->redirect(route('payment.status'));
    }

    public function status()
    {
        $transaction = Payu::capture();
        return redirect()->route('dashboard');
        return response()->json("Payment " . $transaction->status);
    }
}