PaymentLink.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Helpers\CommonMethods;
  4. use App\Models\Outlets;
  5. use App\Models\PaymentLinks;
  6. use Carbon\Carbon;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Str;
  9. class PaymentLink extends Controller
  10. {
  11. //
  12. public function payment_links(){
  13. $resto_id = CommonMethods::getRestuarantID();
  14. $payment_links = PaymentLinks::whereNull('deleted_at')->where('resto_id',$resto_id)->orderBy('created_at','DESC')->paginate(50);
  15. return view('payment-links.index',['payment_links'=>$payment_links]);
  16. }
  17. public function save_payment_links(Request $request){
  18. $id = $request->id;
  19. $resto_id = CommonMethods::getRestuarantID();
  20. if(empty($id)){
  21. $payment_link = new PaymentLinks();
  22. $payment_link->resto_id = $resto_id;
  23. $payment_link->unique_id = "PL-".$resto_id.'-'.rand(1000000,9999999);
  24. $payment_link->status = 'active';
  25. }
  26. else
  27. $payment_link = PaymentLinks::find($id);
  28. $payment_link->number_of_uses = $request->number_of_uses;
  29. $payment_link->amount = $request->amount;
  30. $payment_link->outlet_id = $request->outlet_id;
  31. $payment_link->purpose_payment = $request->purpose_payment;
  32. $payment_link->payment_message = $request->payment_message;
  33. $payment_link->save();
  34. $id = $payment_link->id;
  35. if($id > 0){
  36. echo json_encode(array('type'=>'success','message'=>'Payment Link saved!.','id'=>$payment_link->unique_id));
  37. exit;
  38. }else{
  39. echo json_encode(array('type'=>'error','message'=>'Payment Link is saved!.'));
  40. exit;
  41. }
  42. }
  43. public function delete_payment_link($id){
  44. $payment_link = PaymentLinks::find($id);
  45. $payment_link->deleted_at = Carbon::now()->format('Y-m-d H:i:s');
  46. $payment_link->save();
  47. }
  48. public function new_payment(){
  49. $resto_id = CommonMethods::getRestuarantID();
  50. $outlets = Outlets::whereNull('deleted_at')->where('active',1)->where('resto_id',$resto_id)->get();
  51. return view('payment-links.payment-links-form',['outlets'=>$outlets]);
  52. }
  53. public function view_payment($unique_id){
  54. $payment_link = PaymentLinks::withCount('payments')->where('unique_id',$unique_id)->first();
  55. return view('payment-links.payment-links-view',['payment_link'=>$payment_link]);
  56. }
  57. }