diff --git a/app/Http/Controllers/Admin/PaymentController.php b/app/Http/Controllers/Admin/PaymentController.php index 30f03085..e21e121d 100644 --- a/app/Http/Controllers/Admin/PaymentController.php +++ b/app/Http/Controllers/Admin/PaymentController.php @@ -68,6 +68,58 @@ class PaymentController extends Controller ]); } + /** + * @param Request $request + * @param ShopProduct $shopProduct + * @return RedirectResponse + */ + public function FreePay(Request $request, ShopProduct $shopProduct) + { + //dd($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 */ + $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 + $payment = Payment::create([ + 'user_id' => $user->id, + 'payment_id' => uniqid(), + 'payment_method' => 'free', + 'type' => $shopProduct->type, + 'status' => 'paid', + 'amount' => $shopProduct->quantity, + 'price' => $shopProduct->price - ($shopProduct->price*PartnerDiscount::getDiscount()/100), + 'tax_value' => $shopProduct->getTaxValue(), + 'tax_percent' => $shopProduct->getTaxPercent(), + 'total_price' => $shopProduct->getTotalPrice(), + 'currency_code' => $shopProduct->currency_code, + 'shop_item_product_id' => $shopProduct->id, + ]); + + event(new UserUpdateCreditsEvent($user)); + + //not sending an invoice + + //redirect back to home + return redirect()->route('home')->with('success', __('Your credit balance has been increased!')); + } + /** * @param Request $request * @param ShopProduct $shopProduct @@ -75,6 +127,7 @@ class PaymentController extends Controller */ public function PaypalPay(Request $request, ShopProduct $shopProduct) { + if(!$this->checkAmount($shopProduct->getTotalPrice(), strtoupper($shopProduct->currency_code), "paypal")) return redirect()->route('home')->with('error', __('The product you chose can´t be purchased with this payment method. The total amount is too small. Please buy a bigger amount or try a different payment method.')); $request = new OrdersCreateRequest(); $request->prefer('return=representation'); $request->body = [ @@ -284,6 +337,7 @@ class PaymentController extends Controller */ public function StripePay(Request $request, ShopProduct $shopProduct) { + if(!$this->checkAmount($shopProduct->getTotalPrice(), strtoupper($shopProduct->currency_code), "stripe")) return redirect()->route('home')->with('error', __('The product you chose can´t be purchased with this payment method. The total amount is too small. Please buy a bigger amount or try a different payment method.')); $stripeClient = $this->getStripeClient(); @@ -664,6 +718,114 @@ class PaymentController extends Controller $user->notify(new InvoiceNotification($invoice, $user, $payment)); } + public function checkAmount($amount, $currencyCode, $payment_method) + { + $minimums = [ + "USD" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "AED" => [ + "paypal" => 0, + "stripe" => 2 + ], + "AUD" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "BGN" => [ + "paypal" => 0, + "stripe" => 1 + ], + "BRL" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "CAD" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "CHF" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "CZK" => [ + "paypal" => 0, + "stripe" => 15 + ], + "DKK" => [ + "paypal" => 0, + "stripe" => 2.5 + ], + "EUR" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "GBP" => [ + "paypal" => 0, + "stripe" => 0.3 + ], + "HKD" => [ + "paypal" => 0, + "stripe" => 4 + ], + "HRK" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "HUF" => [ + "paypal" => 0, + "stripe" => 175 + ], + "INR" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "JPY" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "MXN" => [ + "paypal" => 0, + "stripe" => 10 + ], + "MYR" => [ + "paypal" => 0, + "stripe" => 2 + ], + "NOK" => [ + "paypal" => 0, + "stripe" => 3 + ], + "NZD" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "PLN" => [ + "paypal" => 0, + "stripe" => 2 + ], + "RON" => [ + "paypal" => 0, + "stripe" => 2 + ], + "SEK" => [ + "paypal" => 0, + "stripe" => 3 + ], + "SGD" => [ + "paypal" => 0, + "stripe" => 0.5 + ], + "THB" => [ + "paypal" => 0, + "stripe" => 10 + ] + ]; + return $amount >= $minimums[$currencyCode][$payment_method]; + } + + /** * @return JsonResponse|mixed * @throws Exception diff --git a/resources/views/store/checkout.blade.php b/resources/views/store/checkout.blade.php index dbbe6cb3..2e0556ca 100644 --- a/resources/views/store/checkout.blade.php +++ b/resources/views/store/checkout.blade.php @@ -75,30 +75,33 @@
-

{{ __('Payment Methods') }}:

+ @if($total!=0) +

{{ __('Payment Methods') }}:

-
- @if (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') || config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET')) - - @endif - @if (config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:SECRET')) - - @endif -
+
+ @if (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') || config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET')) + + @endif + @if (config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:SECRET')) + + @endif +
+ @else +

{{ __('This product is free for you') }}.

+ @endif
@@ -155,7 +158,7 @@ return { //loading paymentMethod: '', - paymentRoute: '', + paymentRoute: ({{ $total }} == 0)?('{{ route('payment.FreePay', $product->id) }}'):'', setPaymentRoute(provider) { switch (provider) { case 'paypal': diff --git a/routes/web.php b/routes/web.php index fc2b75aa..27dd6cc4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -83,6 +83,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () { Route::get('payment/PaypalSuccess', [PaymentController::class, 'PaypalSuccess'])->name('payment.PaypalSuccess'); Route::get('payment/StripePay/{shopProduct}', [PaymentController::class, 'StripePay'])->name('payment.StripePay'); Route::get('payment/StripeSuccess', [PaymentController::class, 'StripeSuccess'])->name('payment.StripeSuccess'); + Route::get('payment/FreePay/{shopProduct}', [PaymentController::class, 'FreePay'])->name('payment.FreePay'); Route::get('payment/Cancel', [PaymentController::class, 'Cancel'])->name('payment.Cancel'); Route::get('users/logbackin', [UserController::class, 'logBackIn'])->name('users.logbackin');