CustomerPackageController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Utility\PayfastUtility;
  4. use Illuminate\Http\Request;
  5. use App\Models\CustomerPackage;
  6. use App\Models\CustomerPackageTranslation;
  7. use App\Models\CustomerPackagePayment;
  8. use Auth;
  9. use Session;
  10. use App\Models\User;
  11. use App\Http\Controllers\PublicSslCommerzPaymentController;
  12. use App\Http\Controllers\InstamojoController;
  13. use App\Http\Controllers\RazorpayController;
  14. use App\Http\Controllers\VoguePayController;
  15. use App\Utility\PayhereUtility;
  16. class CustomerPackageController extends Controller
  17. {
  18. /**
  19. * Display a listing of the resource.
  20. *
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function index()
  24. {
  25. $customer_packages = CustomerPackage::all();
  26. return view('backend.customer.customer_packages.index', compact('customer_packages'));
  27. }
  28. /**
  29. * Show the form for creating a new resource.
  30. *
  31. * @return \Illuminate\Http\Response
  32. */
  33. public function create()
  34. {
  35. return view('backend.customer.customer_packages.create');
  36. }
  37. /**
  38. * Store a newly created resource in storage.
  39. *
  40. * @param \Illuminate\Http\Request $request
  41. * @return \Illuminate\Http\Response
  42. */
  43. public function store(Request $request)
  44. {
  45. $customer_package = new CustomerPackage;
  46. $customer_package->name = $request->name;
  47. $customer_package->amount = $request->amount;
  48. $customer_package->product_upload = $request->product_upload;
  49. $customer_package->logo = $request->logo;
  50. $customer_package->save();
  51. $customer_package_translation = CustomerPackageTranslation::firstOrNew(['lang' => env('DEFAULT_LANGUAGE'), 'customer_package_id' => $customer_package->id]);
  52. $customer_package_translation->name = $request->name;
  53. $customer_package_translation->save();
  54. flash(translate('Package has been inserted successfully'))->success();
  55. return redirect()->route('customer_packages.index');
  56. }
  57. /**
  58. * Display the specified resource.
  59. *
  60. * @param int $id
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function show($id)
  64. {
  65. //
  66. }
  67. /**
  68. * Show the form for editing the specified resource.
  69. *
  70. * @param int $id
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function edit(Request $request, $id)
  74. {
  75. $lang = $request->lang;
  76. $customer_package = CustomerPackage::findOrFail($id);
  77. return view('backend.customer.customer_packages.edit', compact('customer_package', 'lang'));
  78. }
  79. /**
  80. * Update the specified resource in storage.
  81. *
  82. * @param \Illuminate\Http\Request $request
  83. * @param int $id
  84. * @return \Illuminate\Http\Response
  85. */
  86. public function update(Request $request, $id)
  87. {
  88. $customer_package = CustomerPackage::findOrFail($id);
  89. if ($request->lang == env("DEFAULT_LANGUAGE")) {
  90. $customer_package->name = $request->name;
  91. }
  92. $customer_package->amount = $request->amount;
  93. $customer_package->product_upload = $request->product_upload;
  94. $customer_package->logo = $request->logo;
  95. $customer_package->save();
  96. $customer_package_translation = CustomerPackageTranslation::firstOrNew(['lang' => $request->lang, 'customer_package_id' => $customer_package->id]);
  97. $customer_package_translation->name = $request->name;
  98. $customer_package_translation->save();
  99. flash(translate('Package has been updated successfully'))->success();
  100. return back();
  101. }
  102. /**
  103. * Remove the specified resource from storage.
  104. *
  105. * @param int $id
  106. * @return \Illuminate\Http\Response
  107. */
  108. public function destroy($id)
  109. {
  110. $customer_package = CustomerPackage::findOrFail($id);
  111. foreach ($customer_package->customer_package_translations as $key => $customer_package_translation) {
  112. $customer_package_translation->delete();
  113. }
  114. CustomerPackage::destroy($id);
  115. flash(translate('Package has been deleted successfully'))->success();
  116. return redirect()->route('customer_packages.index');
  117. }
  118. public function purchase_package(Request $request)
  119. {
  120. $data['customer_package_id'] = $request->customer_package_id;
  121. $data['payment_method'] = $request->payment_option;
  122. $request->session()->put('payment_type', 'customer_package_payment');
  123. $request->session()->put('payment_data', $data);
  124. $customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
  125. if ($customer_package->amount == 0) {
  126. $user = User::findOrFail(Auth::user()->id);
  127. if ($user->customer_package_id != $customer_package->id) {
  128. return $this->purchase_payment_done(Session::get('payment_data'), null);
  129. } else {
  130. flash(translate('You can not purchase this package anymore.'))->warning();
  131. return back();
  132. }
  133. }
  134. $decorator = __NAMESPACE__ . '\\Payment\\' . str_replace(' ', '', ucwords(str_replace('_', ' ', $request->payment_option))) . "Controller";
  135. if (class_exists($decorator)) {
  136. return (new $decorator)->pay($request);
  137. }
  138. }
  139. public function purchase_payment_done($payment_data, $payment)
  140. {
  141. $user = User::findOrFail(Auth::user()->id);
  142. $user->customer_package_id = $payment_data['customer_package_id'];
  143. $customer_package = CustomerPackage::findOrFail($payment_data['customer_package_id']);
  144. $user->remaining_uploads += $customer_package->product_upload;
  145. $user->save();
  146. flash(translate('Package purchasing successful'))->success();
  147. return redirect()->route('dashboard');
  148. }
  149. public function purchase_package_offline(Request $request)
  150. {
  151. $customer_package = new CustomerPackagePayment;
  152. $customer_package->user_id = Auth::user()->id;
  153. $customer_package->customer_package_id = $request->package_id;
  154. $customer_package->payment_method = $request->payment_option;
  155. $customer_package->payment_details = $request->trx_id;
  156. $customer_package->approval = 0;
  157. $customer_package->offline_payment = 1;
  158. $customer_package->reciept = ($request->photo == null) ? '' : $request->photo;
  159. $customer_package->save();
  160. flash(translate('Offline payment has been done. Please wait for response.'))->success();
  161. return redirect()->route('customer_products.index');
  162. }
  163. }