ok
Direktori : /home2/selectio/www/bharath/a1tex.in/app/Http/Controllers/ |
Current File : /home2/selectio/www/bharath/a1tex.in/app/Http/Controllers/StripePaymentController.php |
<?php namespace App\Http\Controllers; use App\CPU\CartManager; use App\CPU\Helpers; use App\CPU\OrderManager; use App\Model\BusinessSetting; use App\Model\Currency; use App\Model\Order; use App\Model\Product; use Brian2694\Toastr\Facades\Toastr; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use PHPUnit\Exception; use Stripe\Charge; use Stripe\Stripe; class StripePaymentController extends Controller { public function payment_process_3d() { $currency_model = Helpers::get_business_settings('currency_model'); if ($currency_model == 'multi_currency') { $currency_code = 'USD'; } else { $default = BusinessSetting::where(['type' => 'system_default_currency'])->first()->value; $currency_code = Currency::find($default)->code; } $discount = session()->has('coupon_discount') ? session('coupon_discount') : 0; $value = CartManager::cart_grand_total() - $discount; $tran = OrderManager::gen_unique_id(); session()->put('transaction_ref', $tran); $config = \App\CPU\Helpers::get_business_settings('stripe'); Stripe::setApiKey($config['api_key']); header('Content-Type: application/json'); $YOUR_DOMAIN = url('/'); $products = []; foreach (CartManager::get_cart() as $detail) { array_push($products, [ 'name' => $detail->product['name'], 'image' => 'def.png' ]); } $checkout_session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['card'], 'line_items' => [[ 'price_data' => [ 'currency' => $currency_code, 'unit_amount' => round($value, 2) * 100, 'product_data' => [ 'name' => BusinessSetting::where(['type' => 'company_name'])->first()->value, 'images' => [asset('storage/app/public/company') . '/' . Helpers::get_business_settings('company_web_logo')], ], ], 'quantity' => 1, ]], 'mode' => 'payment', 'success_url' => $YOUR_DOMAIN . '/pay-stripe/success', 'cancel_url' => url()->previous(), ]); return response()->json(['id' => $checkout_session->id]); } public function success() { $unique_id = OrderManager::gen_unique_id(); $order_ids = []; foreach (CartManager::get_cart_group_ids() as $group_id) { $data = [ 'payment_method' => 'stripe', 'order_status' => 'confirmed', 'payment_status' => 'paid', 'transaction_ref' => session('transaction_ref'), 'order_group_id' => $unique_id, 'cart_group_id' => $group_id ]; $order_id = OrderManager::generate_order($data); array_push($order_ids, $order_id); } CartManager::cart_clean(); if (auth('customer')->check()) { Toastr::success('Payment success.'); return view('web-views.checkout-complete'); } return response()->json(['message' => 'Payment succeeded'], 200); } public function fail() { if (auth('customer')->check()) { Toastr::error('Payment failed.'); return redirect('/account-order'); } return response()->json(['message' => 'Payment failed'], 403); } }