|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
+use App\Events\PaymentEvent;
|
|
use App\Events\UserUpdateCreditsEvent;
|
|
use App\Events\UserUpdateCreditsEvent;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\PartnerDiscount;
|
|
use App\Models\PartnerDiscount;
|
|
@@ -71,29 +72,12 @@ class PaymentController extends Controller
|
|
* @param ShopProduct $shopProduct
|
|
* @param ShopProduct $shopProduct
|
|
* @return RedirectResponse
|
|
* @return RedirectResponse
|
|
*/
|
|
*/
|
|
- public function FreePay(ShopProduct $shopProduct)
|
|
|
|
|
|
+ public function handleFreeProduct(ShopProduct $shopProduct)
|
|
{
|
|
{
|
|
- //check if the product is really free or the discount is 100%
|
|
|
|
- if ($shopProduct->getTotalPrice() > 0) return redirect()->route('home')->with('error', __('An error ocured. Please try again.'));
|
|
|
|
-
|
|
|
|
- //give product
|
|
|
|
/** @var User $user */
|
|
/** @var User $user */
|
|
$user = Auth::user();
|
|
$user = Auth::user();
|
|
|
|
|
|
- //not updating server limit
|
|
|
|
-
|
|
|
|
- //update User with bought item
|
|
|
|
- if ($shopProduct->type == "Credits") {
|
|
|
|
- $user->increment('credits', $shopProduct->quantity);
|
|
|
|
- } elseif ($shopProduct->type == "Server slots") {
|
|
|
|
- $user->increment('server_limit', $shopProduct->quantity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //skipped the referral commission, because the user did not pay anything.
|
|
|
|
-
|
|
|
|
- //not giving client role
|
|
|
|
-
|
|
|
|
- //store payment
|
|
|
|
|
|
+ //create a payment
|
|
$payment = Payment::create([
|
|
$payment = Payment::create([
|
|
'user_id' => $user->id,
|
|
'user_id' => $user->id,
|
|
'payment_id' => uniqid(),
|
|
'payment_id' => uniqid(),
|
|
@@ -110,6 +94,7 @@ class PaymentController extends Controller
|
|
]);
|
|
]);
|
|
|
|
|
|
event(new UserUpdateCreditsEvent($user));
|
|
event(new UserUpdateCreditsEvent($user));
|
|
|
|
+ event(new PaymentEvent($user, $payment, $shopProduct));
|
|
|
|
|
|
//not sending an invoice
|
|
//not sending an invoice
|
|
|
|
|
|
@@ -122,6 +107,12 @@ class PaymentController extends Controller
|
|
$product = ShopProduct::find($request->product_id);
|
|
$product = ShopProduct::find($request->product_id);
|
|
$paymentGateway = $request->payment_method;
|
|
$paymentGateway = $request->payment_method;
|
|
|
|
|
|
|
|
+ // on free products, we don't need to use a payment gateway
|
|
|
|
+ $realPrice = $product->price - ($product->price * PartnerDiscount::getDiscount() / 100);
|
|
|
|
+ if ($realPrice <= 0) {
|
|
|
|
+ return $this->handleFreeProduct($product);
|
|
|
|
+ }
|
|
|
|
+
|
|
return redirect()->route('payment.' . $paymentGateway . 'Pay', ['shopProduct' => $product->id]);
|
|
return redirect()->route('payment.' . $paymentGateway . 'Pay', ['shopProduct' => $product->id]);
|
|
}
|
|
}
|
|
|
|
|