WalletController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Controllers\Payment;
  3. use App\Http\Controllers\CheckoutController;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\CombinedOrder;
  6. use App\Models\CustomerPackage;
  7. use App\Models\SellerPackage;
  8. use Session;
  9. use Auth;
  10. class WalletController extends Controller
  11. {
  12. public function pay(){
  13. if(Session::has('payment_type')){
  14. if(Session::get('payment_type') == 'cart_payment'){
  15. $user = Auth::user();
  16. $combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
  17. if ($user->balance >= $combined_order->grand_total) {
  18. $user->balance -= $combined_order->grand_total;
  19. $user->save();
  20. return (new CheckoutController)->checkout_done($combined_order->id, null);
  21. } else {
  22. flash(translate('Insufficient balance'))->warning();
  23. }
  24. }
  25. elseif (Session::get('payment_type') == 'customer_package_payment') {
  26. $customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
  27. $amount = $customer_package->amount;
  28. }
  29. elseif (Session::get('payment_type') == 'seller_package_payment') {
  30. $seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
  31. $amount = $seller_package->amount;
  32. }
  33. }
  34. }
  35. }