Commit 475c89ee by Nilu

S12523603 # Client - Incoming Issues (raised by Client) #Unable to select Yes…

S12523603 # Client - Incoming Issues (raised by Client) #Unable to select Yes for Will this Hiring Team manage own billing?

S12535461 # Client - Incoming Issues (raised by Client) #Inconsistency on page

Handling subscription changes associated with swapping from subscription to PPJ and manage own billing to manage by another hiring team
parent 25a5075e
......@@ -14,7 +14,7 @@
<column name="industry" type="String" nullable="true" length="200"/>
<column name="time_zone" type="String" nullable="true" length="200"/>
<column name="state" type="String" nullable="true" length="200"/>
<column name="country" type="String" nullable="true" length="200"/>
<column name="country" type="String" nullable="false" length="200"/>
<column name="post_code" type="String" nullable="true" length="10"/>
<column name="city" type="String" nullable="true" length="100"/>
<column name="has_client_support" type="Boolean" nullable="true"/>
......
......@@ -14,7 +14,7 @@ CREATE TABLE tl_hiring_team (
industry varchar(200) NULL,
time_zone varchar(200) NULL,
state varchar(200) NULL,
country varchar(200) NULL,
country varchar(200) NOT NULL,
post_code varchar(10) NULL,
city varchar(100) NULL,
has_client_support char(1) NULL,
......
......@@ -15,7 +15,7 @@ CREATE TABLE tl_hiring_team (
industry varchar2(200) NULL,
time_zone varchar2(200) NULL,
state varchar2(200) NULL,
country varchar2(200) NULL,
country varchar2(200) NOT NULL,
post_code varchar2(10) NULL,
city varchar2(100) NULL,
has_client_support char(1) NULL,
......
......@@ -15,7 +15,7 @@ CREATE TABLE tl_hiring_team (
industry varchar(200) NULL,
time_zone varchar(200) NULL,
state varchar(200) NULL,
country varchar(200) NULL,
country varchar(200) NOT NULL,
post_code varchar(10) NULL,
city varchar(100) NULL,
has_client_support char(1) NULL,
......
package performa.form;
import java.util.HashMap;
import java.util.Map;
import oneit.appservices.config.ConfigMgr;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.math.NullArith;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import com.stripe.exception.StripeException;
import com.stripe.model.Card;
import com.stripe.model.Charge;
import java.util.Calendar;
import java.util.Date;
import oneit.logging.LoggingArea;
......@@ -63,22 +59,7 @@ public class MakePaymentFP extends SaveFP
if(hiringTeam.getCardID() != null && hiringTeam.isTrue(hiringTeam.getIsPPJ()))
{
try
{
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", NullArith.intVal(NullArith.multiply(hiringTeam.getPPJAmount(job), 100, 0d)));
chargeParams.put("currency", "aud");
chargeParams.put("description", "Charges of creating job");
chargeParams.put("customer", hiringTeam.getStripeReference());
Charge.create(chargeParams);
}
catch (StripeException e)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while making a payment of company stripe " + company.getStripeReference());
throw new BusinessException("Stripe payment failed, Please contact adminstrator for more info.");
}
StripeUtils.makePayment(hiringTeam, job);
}
if(hiringTeam.getCardID() == null)
......
......@@ -25,10 +25,11 @@ public class SaveCompanyFP extends SaveFP
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{
HttpServletRequest request = submission.getRequest();
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
PaymentPlan paymentPlan = (PaymentPlan) request.getAttribute("PaymentPlan");
HttpServletRequest request = submission.getRequest();
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
PaymentPlan paymentPlan = (PaymentPlan) request.getAttribute("PaymentPlan");
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
if(CollectionUtils.equals(hiringTeam.getIsLogoDeleted(), Boolean.TRUE))
{
......@@ -48,20 +49,38 @@ public class SaveCompanyFP extends SaveFP
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP creating a customer in Stripe : ", hiringTeam );
}
}
if(hiringTeam.getIsPPJ())
else
{
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
if(subscription != null)
if(hiringTeam.getPaymentPlan() != null)
{
StripeUtils.cancelSubscription(subscription);
StripeUtils.cancelSubscription(subscription, true);
hiringTeam.setUsedCredits(0);
hiringTeam.setAvailableCredits(0);
hiringTeam.setMaxCap(0);
hiringTeam.setPaymentPlan(null);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP cancelling a subscription in Stripe since moving to PPJ : ", subscription );
hiringTeam.setHasCap(false);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP cancelling a subscription in Stripe since billing managed by another team: ", subscription );
}
}
if(subscription != null)
{
if(hiringTeam.getIsPPJ())
{
StripeUtils.cancelSubscription(subscription, true);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP cancelling a subscription in Stripe since moving to PPJ : ", subscription );
}
else
{
if(hiringTeam.getPaymentPlan() != null)
{
StripeUtils.cancelSubscription(subscription, false);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP reactivating a subscription (as subscription is not cancelled yet) in Stripe since moving to Subscription from PPJ : ", subscription );
}
}
}
......@@ -75,7 +94,6 @@ public class SaveCompanyFP extends SaveFP
}
// cannot subscribe a user to a plan without card details
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
Subscription updatedSubscription = StripeUtils.updatePlan(hiringTeam, subscription, paymentPlan);
if(updatedSubscription == null)
......@@ -85,7 +103,7 @@ public class SaveCompanyFP extends SaveFP
PaymentPlan currentPlan = hiringTeam.getPaymentPlan();
if(currentPlan != null && currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
if(subscription != null && currentPlan != null && currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
{
boolean hasValidCoupon = hiringTeam.hasValidCouponOn(new Date(subscription.getCurrentPeriodEnd() * 1000));
double currentPlanCost = hiringTeam.getLastPlanAmount() != null ? hiringTeam.getLastPlanAmount() : currentPlan.getAmount();
......
......@@ -42,16 +42,18 @@ public class SaveJobFP extends SaveFP
job.setApplyBy(DateDiff.add(DateDiff.getToday(), Calendar.DATE, 30));
job.setOpenDate(new Date());
if (!billingTeam.canCreateJob())
if (billingTeam.canCreateJob())
{
throw new BusinessException("Please change payment plan settings to open this job");
billingTeam.setUsedCredits(NullArith.add(billingTeam.getUsedCredits(), 1).intValue());
if(billingTeam.getUsedCredits() > billingTeam.getAvailableCredits())
{
StripeUtils.recordUsage(billingTeam);
}
}
billingTeam.setUsedCredits(NullArith.add(billingTeam.getUsedCredits(), 1).intValue());
if(billingTeam.getUsedCredits() > billingTeam.getAvailableCredits())
else if(billingTeam.getIsPPJ())
{
StripeUtils.recordUsage(billingTeam);
StripeUtils.makePayment(hiringTeam, job);
}
LogMgr.log(Job.LOG, LogLevel.PROCESSING1,"Job status changed as Open. ", job );
......@@ -121,9 +123,12 @@ public class SaveJobFP extends SaveFP
if(status != null && status == JobStatus.OPEN)
{
BusinessObjectParser.assertFieldCondition(billingTeam.canCreateJob() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(billingTeam.getCardID() != null , billingTeam, HiringTeam.FIELD_CardID, "mandatoryCardDetails", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(billingTeam.canCreateJob() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
if(!billingTeam.getIsPPJ())
{
BusinessObjectParser.assertFieldCondition(billingTeam.canCreateJob() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
}
}
super.validate(process, submission, exceptions, params);
......
......@@ -599,7 +599,7 @@ public abstract class BaseHiringTeam extends BaseBusinessClass
metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
metaInfo.put ("dbcol", "country");
metaInfo.put ("defaultValue", "Countries.AU");
metaInfo.put ("mandatory", "false");
metaInfo.put ("mandatory", "true");
metaInfo.put ("name", "Country");
metaInfo.put ("type", "Countries");
......@@ -1736,6 +1736,7 @@ public abstract class BaseHiringTeam extends BaseBusinessClass
oldAndNewIdentical = HELPER_Country.compare (_Country, newCountry);
}
BusinessObjectParser.assertFieldCondition (newCountry != null, this, FIELD_Country, "mandatory");
if (FIELD_Country_Validators.length > 0)
......@@ -7308,7 +7309,7 @@ public abstract class BaseHiringTeam extends BaseBusinessClass
result.add(HELPER_Industry.getAttribObject (getClass (), _Industry, false, FIELD_Industry));
result.add(HELPER_TimeZone.getAttribObject (getClass (), _TimeZone, false, FIELD_TimeZone));
result.add(HELPER_State.getAttribObject (getClass (), _State, false, FIELD_State));
result.add(HELPER_Country.getAttribObject (getClass (), _Country, false, FIELD_Country));
result.add(HELPER_Country.getAttribObject (getClass (), _Country, true, FIELD_Country));
result.add(HELPER_PostCode.getAttribObject (getClass (), _PostCode, false, FIELD_PostCode));
result.add(HELPER_City.getAttribObject (getClass (), _City, false, FIELD_City));
result.add(HELPER_HasClientSupport.getAttribObject (getClass (), _HasClientSupport, false, FIELD_HasClientSupport));
......
......@@ -165,10 +165,10 @@ public class HiringTeam extends BaseHiringTeam
}
public boolean canCreateJob()
{
{
if(getManageOwnBilling())
{
return getAvailableCredits() > getUsedCredits() || !getHasCap() || (getHasCap() && getMaxCap() > getUsedCredits());
return getPaymentPlan() != null && (getAvailableCredits() > getUsedCredits() || !getHasCap() || (getHasCap() && getMaxCap() > getUsedCredits()));
}
return getBilledByTeam().canCreateJob();
......@@ -218,7 +218,7 @@ public class HiringTeam extends BaseHiringTeam
public Double getPPJAmount(Job job)
{
double amount = job != null ? (job.getAssessmentType() == AssessmentType.COMPREHENSIVE ? PaymentPlan.PER_PER_JOB_AMOUNT : PaymentPlan.PER_PER_JOB_EXPRESS) : PaymentPlan.PER_PER_JOB_AMOUNT;
double amount = job != null ? (job.getAssessmentType() == AssessmentType.COMPREHENSIVE ? PaymentPlan.PAY_PER_JOB_AMOUNT : PaymentPlan.PAY_PER_JOB_EXPRESS) : PaymentPlan.PAY_PER_JOB_AMOUNT;
return amount * (getCoupon() != null ? (100 - getCoupon().getPercentageOff()) * 0.01 : 1);
}
......
......@@ -6,8 +6,8 @@ import oneit.utils.math.NullArith;
public class PaymentPlan extends BasePaymentPlan
{
private static final long serialVersionUID = 0L;
public static final Double PER_PER_JOB_AMOUNT = 385D;
public static final Double PER_PER_JOB_EXPRESS = 285D;
public static final Double PAY_PER_JOB_AMOUNT = 385D;
public static final Double PAY_PER_JOB_EXPRESS = 285D;
// This constructor should not be called
public PaymentPlan ()
......@@ -32,7 +32,7 @@ public class PaymentPlan extends BasePaymentPlan
{
if(getActiveJobCount()!=null)
{
return NullArith.subtract(NullArith.multiply(getActiveJobCount(), PER_PER_JOB_AMOUNT, 0D), getAmount(), 0D);
return NullArith.subtract(NullArith.multiply(getActiveJobCount(), PAY_PER_JOB_AMOUNT, 0D), getAmount(), 0D);
}
return null;
......
......@@ -32,6 +32,7 @@ import oneit.utils.math.NullArith;
import oneit.utils.parsers.FieldException;
import performa.orm.Company;
import performa.orm.HiringTeam;
import performa.orm.Job;
import performa.orm.PaymentPlan;
import spark.utils.IOUtils;
......@@ -335,23 +336,45 @@ public class StripeUtils
}
public static void cancelSubscription(Subscription subscription) throws BusinessException
public static void cancelSubscription(Subscription subscription, boolean cancelSubscription) throws BusinessException
{
try
{
Map<String, Object> params = new HashMap<>();
params.put("cancel_at_period_end", true);
params.put("cancel_at_period_end", cancelSubscription);
subscription.update(params);
}
catch (StripeException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while cancelling subscription in stripe : "+ subscription);
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while updating subscription in stripe : "+ subscription + " to cancel_at_period_end " + cancelSubscription);
throw new BusinessException("Problem with cancelling your subscription. Please contact adminstrator for more info.");
}
}
public static void makePayment(HiringTeam hiringTeam, Job job) throws BusinessException
{
try
{
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", NullArith.intVal(NullArith.multiply(hiringTeam.getPPJAmount(job), 100, 0d)));
chargeParams.put("currency", hiringTeam.getCountry().getCurrency());
chargeParams.put("description", "Charges of creating job");
chargeParams.put("customer", hiringTeam.getStripeReference());
Charge.create(chargeParams);
}
catch (StripeException e)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, e, "Error while making a payment of hiringTeam stripe " + hiringTeam.getStripeReference());
throw new BusinessException("Stripe payment failed, Please contact adminstrator for more info.");
}
}
public static void handleWebhook(HttpServletRequest request, ObjectTransaction objTran) throws FieldException
......@@ -394,6 +417,31 @@ public class StripeUtils
}
}
}
else if (event != null && event.getType().equals("customer.subscription.deleted"))
{
Subscription subscription = (Subscription) event.getData().getObject();
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Customer Subscription Deleted event received from stripe with Subscription : ", subscription);
if(subscription != null)
{
HiringTeam[] hiringTeams = HiringTeam.SearchByAll().andStripeReference(new EqualsFilter<>(subscription.getCustomer())).search(objTran);
if(hiringTeams != null && hiringTeams.length > 0)
{
HiringTeam hiringTeam = hiringTeams[0];
if(hiringTeam.getIsPPJ())
{
hiringTeam.setPaymentPlan(null);
}
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Setting hiring team with reset plan details : ", hiringTeam);
}
}
}
}
catch (IOException ex)
{
......
......@@ -579,6 +579,13 @@ public class Utils
return hiringTeam.pipelineHiringTeam().toCompany().toHiringTeams(filter).uniqueVals().toArray(new HiringTeam[0]);
}
public static HiringTeam[] getHiringTeamsWithOwnBilling(HiringTeam hiringTeam)
{
Filter<HiringTeam> filter = HiringTeam.SearchByAll().andManageOwnBilling(new EqualsFilter<>(Boolean.TRUE));
return hiringTeam.pipelineHiringTeam().toCompany().toHiringTeams(filter).uniqueVals().toArray(new HiringTeam[0]);
}
public static void setupJobFromTemplate(Job job, Job jobTemplate) throws FieldException, StorageException, BusinessException
{
for(CultureCriteria criteria : job.getCultureCriteriasSet())
......
......@@ -32,9 +32,9 @@
Debug.assertion(job != null, "Job is null in admin portal create job");
HiringTeam hiringTeam = job.getHiringTeam();
HiringTeam billlingTeam = hiringTeam.getManageOwnBilling() ? hiringTeam : hiringTeam.getBilledByTeam();
HiringTeam billingTeam = hiringTeam.getManageOwnBilling() ? hiringTeam : hiringTeam.getBilledByTeam();
process.setAttribute("HiringTeam", billlingTeam);
process.setAttribute("HiringTeam", billingTeam);
%>
<oneit:form name="editJob" method="post" enctype="multipart/form-data">
......@@ -45,10 +45,10 @@
<h1 class="page-title">Review Job
<%
if(billlingTeam.getPaymentPlan() != null)
if(billingTeam.getPaymentPlan() != null)
{
Integer activeCount = billlingTeam.getUsedCredits();
Integer totCount = billlingTeam.getAvailableCredits();
Integer activeCount = billingTeam.getUsedCredits();
Integer totCount = billingTeam.getAvailableCredits();
Integer remCount = (totCount - activeCount) > 0 ? (totCount - activeCount) : 0;
%>
<div style="float:right;">
......@@ -349,7 +349,7 @@
.toMap() %>" />
<%
if(billlingTeam.getCardID() == null)
if(billingTeam.getCardID() == null)
{
%>
<oneit:button value="Open this Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
......@@ -361,22 +361,22 @@
.toMap() %>" />
<%
}
else if(billlingTeam.isTrue(billlingTeam.getIsPPJ()))
else if(billingTeam.canCreateJob())
{
%>
<oneit:button value="Open this Job" name="savePayment" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", sharingPage)
<oneit:button value="Open this Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", sharingPage)
.mapEntry("JobStatus", JobStatus.OPEN)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
.toMap() %>" />
<%
}
else if(billlingTeam.canCreateJob())
else if(billingTeam.isTrue(billingTeam.getIsPPJ()))
{
%>
<oneit:button value="Open this Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", sharingPage)
.mapEntry("JobStatus", JobStatus.OPEN)
<oneit:button value="Open this Job" name="savePayment" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", sharingPage)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
.toMap() %>" />
......
......@@ -207,7 +207,7 @@
{
%>
<div class="per-job-amount-past">
was <oneit:toString value="<%= PaymentPlan.PER_PER_JOB_AMOUNT %>" mode="CurrencyDollarsOnly"/> per job
was <oneit:toString value="<%= PaymentPlan.PAY_PER_JOB_AMOUNT %>" mode="CurrencyDollarsOnly"/> per job
</div>
<%
}
......@@ -224,7 +224,7 @@
<div class="manage-plan-row">
<div class="radio">
<label class="plan-selection">
<oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="IsPPJ" value="false"/>
<oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="IsPPJ" value="false" onchange="paymentPlanChanged()"/>
</label>
</div>
<div class="manage-plan-title">
......
......@@ -186,7 +186,7 @@
<div class="col-md-6">
<oneit:recalcClass htmlTag="div" classScript="hiringTeam.getManageOwnBilling() ? 'hide': 'show'" hiringTeam="<%= hiringTeam %>">
<div class="wider-select">
<tagfile:ormsingleasso_select obj="<%= hiringTeam %>" assocName="BilledByTeam" options="<%= Utils.getOtherHiringTeams(hiringTeam) %>"/>
<tagfile:ormsingleasso_select obj="<%= hiringTeam %>" assocName="BilledByTeam" options="<%= Utils.getHiringTeamsWithOwnBilling(hiringTeam) %>"/>
</div>
</oneit:recalcClass>
</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