finishing up of Partner checkout
support for 100% discount
This commit is contained in:
parent
b6e45c443c
commit
ed5a968d11
3 changed files with 189 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -75,30 +75,33 @@
|
|||
<div class="row">
|
||||
<!-- accepted payments column -->
|
||||
<div class="col-6">
|
||||
<p class="lead">{{ __('Payment Methods') }}:</p>
|
||||
@if($total!=0)
|
||||
<p class="lead">{{ __('Payment Methods') }}:</p>
|
||||
|
||||
<div>
|
||||
@if (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') || config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET'))
|
||||
<label class="text-center " for="paypal">
|
||||
<img class="mb-3" height="50"
|
||||
src="{{ url('/images/paypal_logo.png') }}"></br>
|
||||
|
||||
<input x-model="paymentMethod" type="radio" id="paypal" value="paypal"
|
||||
name="payment_method">
|
||||
</input>
|
||||
</label>
|
||||
@endif
|
||||
@if (config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:SECRET'))
|
||||
<label class="ml-5 text-center " for="stripe">
|
||||
<img class="mb-3" height="50"
|
||||
src="{{ url('/images/stripe_logo.png') }}" /></br>
|
||||
<input x-model="paymentMethod" type="radio" id="stripe" value="stripe"
|
||||
name="payment_method">
|
||||
</input>
|
||||
</label>
|
||||
@endif
|
||||
</div>
|
||||
<div>
|
||||
@if (config('SETTINGS::PAYMENTS:PAYPAL:SECRET') || config('SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET'))
|
||||
<label class="text-center " for="paypal">
|
||||
<img class="mb-3" height="50"
|
||||
src="{{ url('/images/paypal_logo.png') }}"></br>
|
||||
|
||||
<input x-model="paymentMethod" type="radio" id="paypal" value="paypal"
|
||||
name="payment_method">
|
||||
</input>
|
||||
</label>
|
||||
@endif
|
||||
@if (config('SETTINGS::PAYMENTS:STRIPE:TEST_SECRET') || config('SETTINGS::PAYMENTS:STRIPE:SECRET'))
|
||||
<label class="ml-5 text-center " for="stripe">
|
||||
<img class="mb-3" height="50"
|
||||
src="{{ url('/images/stripe_logo.png') }}" /></br>
|
||||
<input x-model="paymentMethod" type="radio" id="stripe" value="stripe"
|
||||
name="payment_method">
|
||||
</input>
|
||||
</label>
|
||||
@endif
|
||||
</div>
|
||||
@else
|
||||
<p class="lead" style="text-align: center">{{ __('This product is free for you') }}.</p>
|
||||
@endif
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
<div class="col-6">
|
||||
|
@ -155,7 +158,7 @@
|
|||
return {
|
||||
//loading
|
||||
paymentMethod: '',
|
||||
paymentRoute: '',
|
||||
paymentRoute: ({{ $total }} == 0)?('{{ route('payment.FreePay', $product->id) }}'):'',
|
||||
setPaymentRoute(provider) {
|
||||
switch (provider) {
|
||||
case 'paypal':
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Reference in a new issue