Viewing file: ManageTaxiOrderPaymentController.php (4.83 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers;
use App\Models\TaxiOrder; use App\Models\Utility; use Illuminate\Http\Request; use Omnipay\Omnipay; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB;
class ManageTaxiOrderPaymentController extends Controller { public function payment_success(Request $request) {
DB::beginTransaction();
try {
if (!$request->order_id || !$request->thx_id) { if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Invalid Taxi Order')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Invalid Taxi Order')); } }
$order = TaxiOrder::where('id', $request->order_id)->where('payment_status', 'unpaid')->first();
if (!$order) { if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Invalid Taxi Order')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Invalid Taxi Order')); } }
$company_payment_setting = Utility::getCompanyPaymentSetting($order->company_id);
if (!isset($company_payment_setting['is_paypal_enabled']) && $company_payment_setting['is_paypal_enabled'] != 'on' && !isset($company_payment_setting['paypal_client_id']) || !isset($company_payment_setting['paypal_secret_key'])) { if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Invalid Taxi Order')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Invalid Taxi Order')); } }
$paypal_client_id = $company_payment_setting['paypal_client_id']; $paypal_client_secret = $company_payment_setting['paypal_secret_key'];
$mode = isset($company_payment_setting['paypal_mode']) && $company_payment_setting['paypal_mode'] && $company_payment_setting['paypal_mode'] == 'live' ? 'false' : 'true'; $gateway = Omnipay::create('PayPal_Rest'); $gateway->setClientId($paypal_client_id); $gateway->setSecret($paypal_client_secret); $gateway->setTestMode($mode);
$decodedTrxId = Crypt::decryptString($request->thx_id);
if ($request->paymentId && $request->PayerID) { $transaction = $gateway->completePurchase(array( 'payer_id' => $request->PayerID, 'transactionReference' => $request->paymentId, ));
$response = $transaction->send();
if (!$response->isSuccessful()) { if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Invalid Taxi Order')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Invalid Taxi Order')); } }
if ($decodedTrxId == $order->trx_id) { $order->payment_status = 'paid'; $order->trx_id = $request->paymentId; $order->save(); }
DB::commit();
if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('success', __('Taxi Order Successfully Created')); }else{ return redirect()->route('taxi-order.index')->with('success', __('Taxi Order Successfully Created')); } } else { if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Invalid Taxi Order')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Invalid Taxi Order')); } }
} catch (\Exception $ex) { DB::rollBack();
if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Invalid Taxi Order')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Invalid Taxi Order')); } } }
public function payment_cancel() { if( \Auth::user()->type=='customer'){ return redirect()->route('customer.order.request')->with('error', __('Taxi Order Payment Has Been Cancelled.')); }else{ return redirect()->route('taxi-order.index')->with('error', __('Taxi Order Payment Has Been Cancelled.')); } } }
|