You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Http\Controllers;
use App\Models\Transaction; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\AllowedFilter; use App\Http\Resources\TransactionResource;
class CreditController extends Controller { public function payments(Request $request, int $business) { \permit('isBusinessOwner');
$query = Transaction::where('business_id', $business);
$builder = QueryBuilder::for($query) ->allowedSorts([ 'amount', 'succeeded', 'created_at', ]) ->allowedFilters([ AllowedFilter::exact('user_id'), AllowedFilter::exact('succeeded'), ]);
return TransactionResource::collection( $builder->paginate($request->per_page) ); }
public function pay(Request $request, int $business) { \permit('isBusinessOwner');
return Transaction::create([ 'user_id'=> Auth::id(), 'business_id'=> $business, 'amount'=> $request->amount, ]); }
public function redirection($transaction) { $transaction = Transaction::findOrFail($transaction); if ($transaction->isWentToPaymentGateway()) { throw new \Exception("Siktir baba ye bar ghablan rafti."); }
return $transaction->prepare()->redirect(); }
public function callback(Request $request) { $transaction = Transaction::findByAuthority($request->get('Authority'))->verify(); if (!$transaction->hasBeenAppliedToWallet() && $transaction->succeeded) { $transaction->business->increment("wallet", $transaction->amount); $transaction->amountWasAppliedToWallet();
return true; }
throw new \Exception("تراکنش تایید نشد"); } }
|