Commit 2472b185 by Nilu

cancelling subscription at the end of period if moved to ppj. show cap value…

cancelling subscription at  the end of period if moved to ppj. show cap value only if toggle is selected to set cap
parent 72e359bf
......@@ -49,16 +49,31 @@ public class SaveCompanyFP extends SaveFP
}
}
if(CollectionUtils.equals(isPayment, Boolean.TRUE))
if(hiringTeam.getIsPPJ())
{
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
if(subscription != null)
{
StripeUtils.cancelSubscription(subscription);
hiringTeam.setPaymentPlan(null);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP cancelling a subscription in Stripe since moving to PPJ : ", subscription );
}
}
if(CollectionUtils.equals(isPayment, Boolean.TRUE))
{
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan());
if(hiringTeam.getCardID() == null)
{
throw new BusinessException("Please enter billing details before selecting a payment plan");
}
// cannot subscribe a user to a plan without card details
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
Subscription updatedSubscription = StripeUtils.updatePlan(hiringTeam, subscription, paymentPlan);
......@@ -67,36 +82,40 @@ public class SaveCompanyFP extends SaveFP
{
throw new BusinessException("Problem with changing your plan. Please contact adminstrator for more info.");
}
PaymentPlan currentPlan = hiringTeam.getPaymentPlan();
if(currentPlan != null && currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
{
double discountPercentage = 0d;
if(subscription.getDiscount() != null && subscription.getDiscount().getCoupon() != null && subscription.getDiscount().getCoupon().getPercentOff() != null)
{
discountPercentage = subscription.getDiscount().getCoupon().getPercentOff().doubleValue();
}
boolean hasValidCoupon = hiringTeam.hasValidCouponOn(new Date(subscription.getCurrentPeriodEnd() * 1000));
double currentPlanCost = discountPercentage > 0 ? currentPlan.getAmount() * discountPercentage * 0.01 : currentPlan.getAmount();
double newPlanCost = hasValidCoupon ? paymentPlan.getAmount() * hiringTeam.getCoupon().getPercentageOff() * 0.01 : paymentPlan.getAmount();
double costDiff = newPlanCost - currentPlanCost;
StripeUtils.chargeUpgradePlanDifference(hiringTeam, costDiff);
}
if(currentPlan == null || currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
{
hiringTeam.setAvailableCredits(paymentPlan.getActiveJobCount());
}
hiringTeam.setPaymentPlan(paymentPlan);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Stripe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
}
//
if(!hiringTeam.isTrue(hiringTeam.getHasCap()))
{
hiringTeam.setMaxCap(null);
}
// // Update company in intercom
// IntercomUtils.updateCompany(company);
......
......@@ -287,7 +287,7 @@ public class StripeUtils
}
public static void recordUsage(HiringTeam hiringTeam)
public static void recordUsage(HiringTeam hiringTeam) throws BusinessException
{
try
{
......@@ -305,7 +305,28 @@ public class StripeUtils
}
catch (StripeException ex)
{
Logger.getLogger(StripeUtils.class.getName()).log(Level.SEVERE, null, ex);
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while recoding usage in stripe for hiring team: "+ hiringTeam);
throw new BusinessException("Problem with opening your job. Please contact adminstrator for more info.");
}
}
public static void cancelSubscription(Subscription subscription) throws BusinessException
{
try
{
Map<String, Object> params = new HashMap<>();
params.put("cancel_at_period_end", true);
subscription.update(params);
}
catch (StripeException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while cancelling subscription in stripe : "+ subscription);
throw new BusinessException("Problem with cancelling your subscription. Please contact adminstrator for more info.");
}
}
......
......@@ -185,7 +185,7 @@ System.out.println(subscription);
<div class="manage-plan-row">
<div class="radio">
<label>
<oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="IsPPJ" value="false" onchange="paymentPlanChanged()"/>
<oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="IsPPJ" value="false"/>
</label>
</div>
<div class="manage-plan-title">
......@@ -359,36 +359,35 @@ System.out.println(subscription);
<%
}
%>
<div class="additional-jobs-over">
<span class="blue-alert">
Additional jobs over plan allowance are billed at the Cost Per Job for the subscription level
</span>
<span>
Would you like to set a maximum limit on the total jobs able to be posted
</span>
</div>
<div class="set-a-cap-option">
<div >
<span> No, leave it open</span>
<label class="switch">
<oneit:recalcClass htmlTag="span" classScript="hiringTeam.isTrue(hiringTeam.getHasCap()) ? 'checkbox checked': 'checkbox unchecked'" hiringTeam="<%= hiringTeam %>">
<oneit:ormInput obj="<%= hiringTeam %>" attributeName="HasCap" type="checkbox"/>
</oneit:recalcClass>
<div class="slider round"></div>
</label>
<span>yes, set a cap</span>
<div class="additional-jobs-over">
<span class="blue-alert">
Additional jobs over plan allowance are billed at the Cost Per Job for the subscription level
</span>
<span>
Would you like to set a maximum limit on the total jobs able to be posted
</span>
</div>
</div>
<div class="setmax">
<div>
<oneit:ormInput obj="<%= hiringTeam %>" type="text" attributeName="MaxCap" cssClass="form-control" />
<oneit:button value="Set Max" name="saveCompany" cssClass="btn btn-primary"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>" />
<div class="set-a-cap-option">
<div >
<span> No, leave it open</span>
<label class="switch">
<oneit:recalcClass htmlTag="span" classScript="hiringTeam.isTrue(hiringTeam.getHasCap()) ? 'checkbox checked': 'checkbox unchecked'" hiringTeam="<%= hiringTeam %>">
<oneit:ormInput obj="<%= hiringTeam %>" attributeName="HasCap" type="checkbox"/>
</oneit:recalcClass>
<div class="slider round"></div>
</label>
<span>yes, set a cap</span>
</div>
</div>
</div>
<div class="setmax">
<oneit:recalcClass htmlTag="div" classScript="hiringTeam.isTrue(hiringTeam.getHasCap()) ? 'show': 'hide'" hiringTeam="<%= hiringTeam %>">
<oneit:ormInput obj="<%= hiringTeam %>" type="text" attributeName="MaxCap" cssClass="form-control" />
<oneit:button value="Set Max" name="saveCompany" cssClass="btn btn-primary"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>" />
</oneit:recalcClass>
</div>
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment