subscription webhook updated with multiple referral

This commit is contained in:
Hritikkk9
2024-07-11 13:57:10 +05:30
parent 11adc43d6d
commit 613ef95a84

View File

@@ -103,8 +103,24 @@ class StripeWebhookController extends Controller
//update subscription add 30 days trial period to this subscription
$nextPaymentDate = $referralUserSubscriptionData->next_payment_date;
$date = new DateTime($nextPaymentDate);
// we are setting next payment date based on REFERRAL .. IF USER HAS NOT REFERRED YET.. then it will take next_payment_date
//Otherwise IT need to take THE LAST REFERRED DATA
// $userLastReferredDate = ReferralUsers::where('iam_principal_xid',$referralUserId)->last();
$userLastReferredDate = ReferralUsers::where('iam_principal_xid', $referralUserId)
->orderBy('referred_date_time', 'desc')
->first();
if ($userLastReferredDate && $userLastReferredDate->referred_date_time) {
Log::info("trial date added for multiple time");
$date = new DateTime($userLastReferredDate->referred_date_time);
} else {
$date = new DateTime($nextPaymentDate);
}
// $date = new DateTime($nextPaymentDate);
// $date->modify('+30 days');
$newDate = $date->format('Y-m-d H:i:s');
Log::info("new Date = ");
Log::info($newDate);
@@ -215,9 +231,9 @@ class StripeWebhookController extends Controller
Log::info("Creating entry in Referral User table");
ReferralUsers::create([
'iam_principal_xid'=>$referralUserId, //Referral User Xid
'referred_user_xid'=>$userId, // new user Id
'referred_date_time'=>Carbon::now(),
'iam_principal_xid' => $referralUserId, //Referral User Xid
'referred_user_xid' => $userId, // new user Id
'referred_date_time' => Carbon::now(),
]);
Log::info("Created entry in Referral User table");
@@ -226,7 +242,7 @@ class StripeWebhookController extends Controller
$getUserData = IamPrincipal::where('id', $userId)->first();
$title = "Congratulations your subscription is now active";
$message = $getUserData->first_name . " has subscribed for " . $subscriptionProductData->name ;
$message = $getUserData->first_name . " has subscribed for " . $subscriptionProductData->name;
$content_type = "new_subscription";
onesignalhelper::sendNotificationApi($getUserData->one_signal_player_id, $title, $message, $content_type, $image = null, $id = null);