finishing up of Partner checkout
support for 100% discount
This commit is contained in:
parent
b6e45c443c
commit
ed5a968d11
|
@ -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 Request $request
|
||||||
* @param ShopProduct $shopProduct
|
* @param ShopProduct $shopProduct
|
||||||
|
@ -75,6 +127,7 @@ class PaymentController extends Controller
|
||||||
*/
|
*/
|
||||||
public function PaypalPay(Request $request, ShopProduct $shopProduct)
|
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 = new OrdersCreateRequest();
|
||||||
$request->prefer('return=representation');
|
$request->prefer('return=representation');
|
||||||
$request->body = [
|
$request->body = [
|
||||||
|
@ -284,6 +337,7 @@ class PaymentController extends Controller
|
||||||
*/
|
*/
|
||||||
public function StripePay(Request $request, ShopProduct $shopProduct)
|
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();
|
$stripeClient = $this->getStripeClient();
|
||||||
|
|
||||||
|
|
||||||
|
@ -664,6 +718,114 @@ class PaymentController extends Controller
|
||||||
$user->notify(new InvoiceNotification($invoice, $user, $payment));
|
$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
|
* @return JsonResponse|mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- accepted payments column -->
|
<!-- accepted payments column -->
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
|
@if($total!=0)
|
||||||
<p class="lead">{{ __('Payment Methods') }}:</p>
|
<p class="lead">{{ __('Payment Methods') }}:</p>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
@ -98,7 +99,9 @@
|
||||||
</label>
|
</label>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@else
|
||||||
|
<p class="lead" style="text-align: center">{{ __('This product is free for you') }}.</p>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<!-- /.col -->
|
<!-- /.col -->
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
|
@ -155,7 +158,7 @@
|
||||||
return {
|
return {
|
||||||
//loading
|
//loading
|
||||||
paymentMethod: '',
|
paymentMethod: '',
|
||||||
paymentRoute: '',
|
paymentRoute: ({{ $total }} == 0)?('{{ route('payment.FreePay', $product->id) }}'):'',
|
||||||
setPaymentRoute(provider) {
|
setPaymentRoute(provider) {
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case 'paypal':
|
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/PaypalSuccess', [PaymentController::class, 'PaypalSuccess'])->name('payment.PaypalSuccess');
|
||||||
Route::get('payment/StripePay/{shopProduct}', [PaymentController::class, 'StripePay'])->name('payment.StripePay');
|
Route::get('payment/StripePay/{shopProduct}', [PaymentController::class, 'StripePay'])->name('payment.StripePay');
|
||||||
Route::get('payment/StripeSuccess', [PaymentController::class, 'StripeSuccess'])->name('payment.StripeSuccess');
|
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('payment/Cancel', [PaymentController::class, 'Cancel'])->name('payment.Cancel');
|
||||||
|
|
||||||
Route::get('users/logbackin', [UserController::class, 'logBackIn'])->name('users.logbackin');
|
Route::get('users/logbackin', [UserController::class, 'logBackIn'])->name('users.logbackin');
|
||||||
|
|
Loading…
Reference in a new issue