mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-09-28 09:13:05 -04:00
Subscription Module - Paypal confirmation pop and some changes
This commit is contained in:
@@ -9,6 +9,7 @@ use Modules\Subscription\Rules\PhoneFormat;
|
||||
use Brian2694\Toastr\Facades\Toastr;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Subscription\Entities\AmazeSubscription;
|
||||
use Modules\Subscription\Entities\SubscriptionSetting;
|
||||
use Modules\PaymentGateway\Http\Controllers\StripeController;
|
||||
@@ -43,6 +44,7 @@ use Modules\Shipping\Entities\ShippingMethod;
|
||||
use Modules\Subscription\Entities\SubscriptionPlan;
|
||||
use Modules\Subscription\Entities\SubscriptionPlanPrice;
|
||||
use Modules\Subscription\Entities\SubscriptionPlanPricePaypal;
|
||||
use Modules\Subscription\Entities\SubscriptionCoupon;
|
||||
use Modules\WTIJobBoard\Entities\JobRequest;
|
||||
use Modules\Subscription\Services\PaypalPaymentService;
|
||||
|
||||
@@ -266,7 +268,7 @@ class SubscriptionController extends Controller
|
||||
$response = $this->paypalPayment->showSubscription($request->subscription_id);
|
||||
if(isset($response->status)){
|
||||
if($response->status == 'APPROVED'){
|
||||
$this->sendSubscriptionPendingApproval($subscription->user, ($subscription->user->company != null ? $user->company->storefront : ''));
|
||||
$this->sendSubscriptionPendingApproval($subscription->user, ($subscription->user->company != null ?$subscription->user->company->storefront : ''));
|
||||
} else if($response->status == 'APPROVAL_PENDING'){
|
||||
$subscription->delete();
|
||||
}
|
||||
@@ -847,18 +849,20 @@ class SubscriptionController extends Controller
|
||||
|
||||
} else {
|
||||
|
||||
if($active_subscription && ($planPrice->subscription_plan_id == $active_subscription->planPrice->subscription_plan_id || $planPrice->payment == 'upfront')){
|
||||
if($active_subscription->payment_method == 'stripe'){
|
||||
$response = $this->stripePayment->subscriptions->retrieve($active_subscription->txn_id, []);
|
||||
$trial_end = $response['current_period_end'];
|
||||
} else if($active_subscription->payment_method == 'paypal' && $active_subscription->expired_at != null){
|
||||
$trial_end = $active_subscription->expired_at->timestamp;
|
||||
}
|
||||
if($active_subscription && $active_subscription->planPrice->payment =='monthly'){
|
||||
if($request->has('renew_now') && !$request->renew_now){
|
||||
if($active_subscription->payment_method == 'stripe'){
|
||||
$response = $this->stripePayment->subscriptions->retrieve($active_subscription->txn_id, []);
|
||||
$trial_end = $response['current_period_end'];
|
||||
} else if($active_subscription->payment_method == 'paypal' && $active_subscription->expired_at != null){
|
||||
$trial_end = $active_subscription->expired_at->timestamp;
|
||||
}
|
||||
|
||||
if(isset($trial_end)){
|
||||
$startDate = Carbon::createFromTimestamp($trial_end);
|
||||
$endDate = Carbon::now();
|
||||
$trial_days = $startDate->diffInDays($endDate);
|
||||
if(isset($trial_end)){
|
||||
$startDate = Carbon::createFromTimestamp($trial_end);
|
||||
$endDate = Carbon::now();
|
||||
$trial_days = $startDate->diffInDays($endDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,7 +895,8 @@ class SubscriptionController extends Controller
|
||||
|
||||
$data['custom_id'] = json_encode([
|
||||
'user_id' => auth()->user()->id,
|
||||
'coupon_id' => $coupon_id
|
||||
'coupon_id' => $coupon_id,
|
||||
'renew_now' => false
|
||||
]);
|
||||
|
||||
//lets create new plan price with discount
|
||||
@@ -910,12 +915,68 @@ class SubscriptionController extends Controller
|
||||
'message' => 'Something went wrong, please try again later.'
|
||||
], 404);
|
||||
}
|
||||
} else if($request->has('renew_now') && $request->renew_now && $request->has('prorate_discount') && $request->prorate_discount){
|
||||
|
||||
$prorate_discount = $request->prorate_discount;
|
||||
$coupon_id = Str::random(8);
|
||||
|
||||
$coupon = new SubscriptionCoupon();
|
||||
$coupon->fill([
|
||||
'subscription_plan_price_id' => $planPrice->id,
|
||||
'stripe_coupon_id' => $coupon_id,
|
||||
'name' => 'Prorated Discount',
|
||||
'code' => $coupon_id,
|
||||
'type' => 'Amount',
|
||||
'applied_to' => 'subscription',
|
||||
'payment_mode' => 'Monthly',
|
||||
'discount' => $prorate_discount,
|
||||
'duration' => 'Once',
|
||||
'max_redemptions' => 1,
|
||||
'active' => 1
|
||||
]);
|
||||
$coupon->save();
|
||||
|
||||
|
||||
$price_monthly = $planPrice->price / $planPrice->custom_interval;
|
||||
if ($coupon->type == 'Amount') {
|
||||
$discounted_price_monthly = number_format($price_monthly - $coupon->discount,2);
|
||||
$discounted_price_all = number_format($planPrice->price - $coupon->discount,2);
|
||||
|
||||
} else {
|
||||
$discounted_price_monthly = number_format($price_monthly - (($coupon->discount / 100) * $price_monthly),2);
|
||||
$discounted_price_all = number_format($planPrice->price - (($coupon->discount / 100) * $planPrice->price),2);
|
||||
}
|
||||
|
||||
$data['custom_id'] = json_encode([
|
||||
'user_id' => auth()->user()->id,
|
||||
'coupon_id' => $coupon_id,
|
||||
'renew_now' => true
|
||||
]);
|
||||
|
||||
//lets create new plan price with discount
|
||||
$response = $this->paypalPayment->createProductPriceWithDiscount($planPrice,$coupon->duration,$discounted_price_monthly,$discounted_price_all,$payment_details);
|
||||
if(isset($response->id)){
|
||||
|
||||
$data['plan_id'] = $response->id;
|
||||
|
||||
$paypalPlanPrice = new SubscriptionPlanPricePaypal;
|
||||
$paypalPlanPrice->user_id = auth()->user()->id;
|
||||
$paypalPlanPrice->subscription_plan_price_id = $planPrice->id;
|
||||
$paypalPlanPrice->paypal_price_id = $response->id;
|
||||
$paypalPlanPrice->save();
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => 'Something went wrong, please try again later.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
$data['plan_id'] = $planPrice->paypal_price_id;
|
||||
$data['custom_id'] = json_encode([
|
||||
'user_id' => auth()->user()->id
|
||||
'user_id' => auth()->user()->id,
|
||||
'renew_now' => false
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user