Commit 2f2126fd by Nilu

coupons, payment plans

parent b4215bac
...@@ -29,10 +29,12 @@ ...@@ -29,10 +29,12 @@
<column name="is_ppj" type="Boolean" nullable="true"/> <column name="is_ppj" type="Boolean" nullable="true"/>
<column name="has_cap" type="Boolean" nullable="true"/> <column name="has_cap" type="Boolean" nullable="true"/>
<column name="max_cap" type="Long" nullable="true"/> <column name="max_cap" type="Long" nullable="true"/>
<column name="coupon_expiry_date" type="Date" nullable="true"/>
<column name="company_id" type="Long" length="11" nullable="false"/> <column name="company_id" type="Long" length="11" nullable="false"/>
<column name="billing_team_id" type="Long" length="11" nullable="true"/> <column name="billing_team_id" type="Long" length="11" nullable="true"/>
<column name="added_by_user_id" type="Long" length="11" nullable="false"/> <column name="added_by_user_id" type="Long" length="11" nullable="false"/>
<column name="payment_plan_id" type="Long" length="11" nullable="true"/> <column name="payment_plan_id" type="Long" length="11" nullable="true"/>
<column name="coupon_id" type="Long" length="11" nullable="true"/>
</NODE> </NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_hiring_team" indexName="idx_tl_hiring_team_company_id" isUnique="false"><column name="company_id"/></NODE> <NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_hiring_team" indexName="idx_tl_hiring_team_company_id" isUnique="false"><column name="company_id"/></NODE>
......
...@@ -9,8 +9,12 @@ ...@@ -9,8 +9,12 @@
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/> <column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/> <column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="coupon_code" type="String" nullable="false" length="100"/> <column name="coupon_code" type="String" nullable="false" length="100"/>
<column name="percentage_off" type="Long" nullable="true"/> <column name="percentage_off" type="Double" nullable="true"/>
<column name="duration_in_months" type="Long" nullable="true"/> <column name="duration_in_months" type="Long" nullable="true"/>
<column name="coupon_duration" type="String" nullable="true" length="200"/>
<column name="redeem_by" type="Date" nullable="true"/>
<column name="max_redemptions" type="Long" nullable="true"/>
<column name="times_redeemed" type="Long" nullable="true"/>
</NODE> </NODE>
</NODE></OBJECTS> </NODE></OBJECTS>
\ No newline at end of file
-- DROP TABLE tl_coupon;
CREATE TABLE tl_coupon (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
coupon_code varchar(100) NOT NULL,
percentage_off numeric(12) NULL,
duration_in_months numeric(12) NULL
);
ALTER TABLE tl_coupon ADD
CONSTRAINT PK_tl_coupon PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
...@@ -29,10 +29,12 @@ CREATE TABLE tl_hiring_team ( ...@@ -29,10 +29,12 @@ CREATE TABLE tl_hiring_team (
is_ppj char(1) NULL, is_ppj char(1) NULL,
has_cap char(1) NULL, has_cap char(1) NULL,
max_cap numeric(12) NULL, max_cap numeric(12) NULL,
coupon_expiry_date datetime NULL,
company_id numeric(12) NOT NULL, company_id numeric(12) NOT NULL,
billing_team_id numeric(12) NULL, billing_team_id numeric(12) NULL,
added_by_user_id numeric(12) NOT NULL, added_by_user_id numeric(12) NOT NULL,
payment_plan_id numeric(12) NULL payment_plan_id numeric(12) NULL,
coupon_id numeric(12) NULL
); );
......
...@@ -9,8 +9,12 @@ CREATE TABLE tl_coupon ( ...@@ -9,8 +9,12 @@ CREATE TABLE tl_coupon (
object_created_date datetime DEFAULT getdate() NOT NULL object_created_date datetime DEFAULT getdate() NOT NULL
, ,
coupon_code varchar(100) NOT NULL, coupon_code varchar(100) NOT NULL,
percentage_off numeric(12) NULL, percentage_off numeric(20,5) NULL,
duration_in_months numeric(12) NULL duration_in_months numeric(12) NULL,
coupon_duration varchar(200) NULL,
redeem_by datetime NULL,
max_redemptions numeric(12) NULL,
times_redeemed numeric(12) NULL
); );
......
-- DROP TABLE tl_coupon;
CREATE TABLE tl_coupon (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
coupon_code varchar2(100) NOT NULL,
percentage_off number(12) NULL,
duration_in_months number(12) NULL
);
ALTER TABLE tl_coupon ADD
CONSTRAINT PK_tl_coupon PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
...@@ -30,10 +30,12 @@ CREATE TABLE tl_hiring_team ( ...@@ -30,10 +30,12 @@ CREATE TABLE tl_hiring_team (
is_ppj char(1) NULL, is_ppj char(1) NULL,
has_cap char(1) NULL, has_cap char(1) NULL,
max_cap number(12) NULL, max_cap number(12) NULL,
coupon_expiry_date date NULL,
company_id number(12) NOT NULL, company_id number(12) NOT NULL,
billing_team_id number(12) NULL, billing_team_id number(12) NULL,
added_by_user_id number(12) NOT NULL, added_by_user_id number(12) NOT NULL,
payment_plan_id number(12) NULL payment_plan_id number(12) NULL,
coupon_id number(12) NULL
); );
......
...@@ -10,8 +10,12 @@ CREATE TABLE tl_coupon ( ...@@ -10,8 +10,12 @@ CREATE TABLE tl_coupon (
object_created_date date DEFAULT SYSDATE NOT NULL object_created_date date DEFAULT SYSDATE NOT NULL
, ,
coupon_code varchar2(100) NOT NULL, coupon_code varchar2(100) NOT NULL,
percentage_off number(12) NULL, percentage_off number(20,5) NULL,
duration_in_months number(12) NULL duration_in_months number(12) NULL,
coupon_duration varchar2(200) NULL,
redeem_by date NULL,
max_redemptions number(12) NULL,
times_redeemed number(12) NULL
); );
......
-- @AutoRun
-- drop table tl_coupon;
CREATE TABLE tl_coupon (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
coupon_code varchar(100) NOT NULL,
percentage_off numeric(12) NULL,
duration_in_months numeric(12) NULL
);
ALTER TABLE tl_coupon ADD
CONSTRAINT pk_tl_coupon PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
...@@ -30,10 +30,12 @@ CREATE TABLE tl_hiring_team ( ...@@ -30,10 +30,12 @@ CREATE TABLE tl_hiring_team (
is_ppj char(1) NULL, is_ppj char(1) NULL,
has_cap char(1) NULL, has_cap char(1) NULL,
max_cap numeric(12) NULL, max_cap numeric(12) NULL,
coupon_expiry_date timestamp NULL,
company_id numeric(12) NOT NULL, company_id numeric(12) NOT NULL,
billing_team_id numeric(12) NULL, billing_team_id numeric(12) NULL,
added_by_user_id numeric(12) NOT NULL, added_by_user_id numeric(12) NOT NULL,
payment_plan_id numeric(12) NULL payment_plan_id numeric(12) NULL,
coupon_id numeric(12) NULL
); );
......
...@@ -10,8 +10,12 @@ CREATE TABLE tl_coupon ( ...@@ -10,8 +10,12 @@ CREATE TABLE tl_coupon (
object_created_date timestamp DEFAULT NOW() NOT NULL object_created_date timestamp DEFAULT NOW() NOT NULL
, ,
coupon_code varchar(100) NOT NULL, coupon_code varchar(100) NOT NULL,
percentage_off numeric(12) NULL, percentage_off numeric(20,5) NULL,
duration_in_months numeric(12) NULL duration_in_months numeric(12) NULL,
coupon_duration varchar(200) NULL,
redeem_by timestamp NULL,
max_redemptions numeric(12) NULL,
times_redeemed numeric(12) NULL
); );
......
package performa.form; package performa.form;
import com.stripe.model.Coupon; import com.stripe.model.Coupon;
import java.util.Calendar;
import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel; import oneit.logging.LogLevel;
import oneit.logging.LogMgr; import oneit.logging.LogMgr;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException; import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.servlets.forms.RedisplayResult; import oneit.servlets.forms.RedisplayResult;
import oneit.servlets.forms.SubmissionDetails; import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult; import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessFormProcessor;
import oneit.servlets.process.ORMProcessState; import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.ProcessRedirectResult;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException; import oneit.utils.BusinessException;
import oneit.utils.DateDiff;
import performa.orm.HiringTeam; import performa.orm.HiringTeam;
import performa.orm.PaymentPlan;
import performa.orm.StripeCoupon; import performa.orm.StripeCoupon;
import performa.orm.types.CouponDuration;
import performa.utils.StripeUtils; import performa.utils.StripeUtils;
public class ApplyCouponFP extends ORMProcessFormProcessor public class ApplyCouponFP extends SaveFP
{ {
@Override @Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{ {
HttpServletRequest request = submission.getRequest(); HttpServletRequest request = submission.getRequest();
HiringTeam hiringTeam = (HiringTeam) request.getAttribute("HiringTeam"); ObjectTransaction objTran = process.getTransaction();
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1, "Inside ApplyCouponFP for ", hiringTeam ); LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1, "Inside ApplyCouponFP for ", hiringTeam );
Coupon coupon = StripeUtils.retrieveCoupon(hiringTeam.getCouponCode()); if(hiringTeam.getCoupon() != null && hiringTeam.getCoupon().getCouponCode().equals(hiringTeam.getCouponCode()))
{
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1, "Inside ApplyCouponFP for ", hiringTeam , " already has a coupon added with coupon code: ", hiringTeam.getCouponCode());
return RedisplayResult.getInstance();
}
Coupon coupon = StripeUtils.retrieveCoupon(hiringTeam.getCouponCode());
StripeCoupon[] stripeCoupons = StripeCoupon.SearchByAll()
.andCouponCode(new EqualsFilter<>(hiringTeam.getCouponCode()))
.search(objTran);
if(coupon.getValid()) if(coupon != null && coupon.getValid())
{ {
StripeCoupon stripeCoupon = StripeCoupon.createStripeCoupon(process.getTransaction()); StripeCoupon stripeCoupon = null;
stripeCoupon.setCouponCode(coupon.getId()); if(stripeCoupons != null && stripeCoupons.length > 0)
// stripeCoupon.setDurationInMonths(coupon.getDurationInMonths()); {
// stripeCoupon.setPercentageOff(coupon.getPercentOff()); stripeCoupon = stripeCoupons[0];
LogMgr.log (HiringTeam.LOG, LogLevel.PROCESSING1, "Using an already created coupon : " , stripeCoupon);
}
else
{
stripeCoupon = StripeCoupon.createStripeCoupon(objTran);
stripeCoupon.setCouponCode(coupon.getId());
stripeCoupon.setDurationInMonths(coupon.getDurationInMonths() != null ? coupon.getDurationInMonths().intValue() : 0);
stripeCoupon.setPercentageOff(coupon.getPercentOff() != null ? coupon.getPercentOff().doubleValue() : 0d);
stripeCoupon.setCouponDuration(CouponDuration.forName(coupon.getDuration().toUpperCase()));
stripeCoupon.setMaxRedemptions(coupon.getMaxRedemptions() != null ? coupon.getMaxRedemptions().intValue() : 0);
stripeCoupon.setTimesRedeemed(coupon.getTimesRedeemed() != null ? coupon.getTimesRedeemed().intValue() : 0);
if(coupon.getRedeemBy() != null)
{
stripeCoupon.setRedeemBy(new Date(coupon.getRedeemBy() * 1000));
}
LogMgr.log (HiringTeam.LOG, LogLevel.PROCESSING1, "Creating a new coupon for coupon code: ", hiringTeam.getCouponCode());
}
if(stripeCoupon.getCouponDuration() == CouponDuration.REPEATING)
{
hiringTeam.setCouponExpiryDate(DateDiff.add(new Date(), Calendar.MONTH, stripeCoupon.getDurationInMonths()));
}
hiringTeam.setCoupon(stripeCoupon);
}
else
{
return new ProcessRedirectResult((String) request.getAttribute("nextPage"), new String[]{ "invalidcoupon", "true"});
} }
System.out.println("coupon : " + coupon);
return RedisplayResult.getInstance(); return super.processForm(process, submission, params);
} }
} }
\ No newline at end of file
package performa.form; package performa.form;
import com.stripe.model.Subscription;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel; import oneit.logging.LogLevel;
...@@ -24,13 +25,10 @@ public class SaveCompanyFP extends SaveFP ...@@ -24,13 +25,10 @@ public class SaveCompanyFP extends SaveFP
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{ {
HttpServletRequest request = submission.getRequest(); HttpServletRequest request = submission.getRequest();
// Company company = process.getAttribute("Company") != null ? (Company) process.getAttribute("Company") : (Company) request.getAttribute("Company");
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam"); HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment"); Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
PaymentPlan paymentPlan = (PaymentPlan) request.getAttribute("PaymentPlan"); PaymentPlan paymentPlan = (PaymentPlan) request.getAttribute("PaymentPlan");
// LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP saving company : ", company );
if(CollectionUtils.equals(hiringTeam.getIsLogoDeleted(), Boolean.TRUE)) if(CollectionUtils.equals(hiringTeam.getIsLogoDeleted(), Boolean.TRUE))
{ {
hiringTeam.setHiringTeamLogo(null); hiringTeam.setHiringTeamLogo(null);
...@@ -45,12 +43,13 @@ public class SaveCompanyFP extends SaveFP ...@@ -45,12 +43,13 @@ public class SaveCompanyFP extends SaveFP
if(hiringTeam.getStripeReference() == null) if(hiringTeam.getStripeReference() == null)
{ {
StripeUtils.createCustomer(hiringTeam); StripeUtils.createCustomer(hiringTeam);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP creating a customer in Stripe : ", hiringTeam );
} }
} }
if(CollectionUtils.equals(isPayment, Boolean.TRUE)) if(CollectionUtils.equals(isPayment, Boolean.TRUE))
{ {
hiringTeam.setPaymentPlan(paymentPlan);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan()); LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan());
...@@ -60,9 +59,16 @@ public class SaveCompanyFP extends SaveFP ...@@ -60,9 +59,16 @@ public class SaveCompanyFP extends SaveFP
} }
// cannot subscribe a user to a plan without card details // cannot subscribe a user to a plan without card details
StripeUtils.updatePlan(hiringTeam); Subscription updatedSubscription = StripeUtils.updatePlan(hiringTeam);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Strpe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription()); if(updatedSubscription == null)
{
throw new BusinessException("Problem with changing your plan. Please contact admin.");
}
hiringTeam.setPaymentPlan(paymentPlan);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Stripe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
} }
// //
// // Update company in intercom // // Update company in intercom
...@@ -76,8 +82,6 @@ public class SaveCompanyFP extends SaveFP ...@@ -76,8 +82,6 @@ public class SaveCompanyFP extends SaveFP
public void validate(ORMProcessState process, SubmissionDetails submission, MultiException exceptions, Map params) throws StorageException public void validate(ORMProcessState process, SubmissionDetails submission, MultiException exceptions, Map params) throws StorageException
{ {
HttpServletRequest request = submission.getRequest(); HttpServletRequest request = submission.getRequest();
// Company company = process.getAttribute("Company") != null ? (Company) process.getAttribute("Company") : (Company) request.getAttribute("Company");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam"); HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
if(hiringTeam != null && !hiringTeam.getManageOwnBilling()) if(hiringTeam != null && !hiringTeam.getManageOwnBilling())
......
package performa.orm; package performa.orm;
import com.stripe.model.Card; import com.stripe.model.Card;
import com.stripe.model.Coupon;
import java.util.Date;
import java.util.Set; import java.util.Set;
import oneit.logging.LoggingArea; import oneit.logging.LoggingArea;
import oneit.objstore.ValidationContext; import oneit.objstore.ValidationContext;
import oneit.objstore.rdbms.filters.EqualsFilter; import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.utils.DateDiff;
import oneit.utils.StringUtils; import oneit.utils.StringUtils;
import oneit.utils.filter.Filter; import oneit.utils.filter.Filter;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
...@@ -106,4 +109,28 @@ public class HiringTeam extends BaseHiringTeam ...@@ -106,4 +109,28 @@ public class HiringTeam extends BaseHiringTeam
{ {
return super.getUsedCredits() != null ? super.getUsedCredits() : 0; return super.getUsedCredits() != null ? super.getUsedCredits() : 0;
} }
public boolean hasValidCoupon() throws FieldException
{
return hasValidCouponOn(DateDiff.getToday());
}
public boolean hasValidCouponOn(Date date) throws FieldException
{
if(getCoupon() != null)
{
Coupon coupon = StripeUtils.retrieveCoupon(getCoupon().getCouponCode());
if(coupon.getValid() && (getCouponExpiryDate() == null || date.before(getCouponExpiryDate())))
{
return true;
}
}
setCoupon(null);
setCouponExpiryDate(null);
return false;
}
} }
\ No newline at end of file
...@@ -39,11 +39,13 @@ ...@@ -39,11 +39,13 @@
<ATTRIB name="IsPPJ" type="Boolean" dbcol="is_ppj" defaultValue="Boolean.TRUE"/> <ATTRIB name="IsPPJ" type="Boolean" dbcol="is_ppj" defaultValue="Boolean.TRUE"/>
<ATTRIB name="HasCap" type="Boolean" dbcol="has_cap" defaultValue="Boolean.FALSE"/> <ATTRIB name="HasCap" type="Boolean" dbcol="has_cap" defaultValue="Boolean.FALSE"/>
<ATTRIB name="MaxCap" type="Integer" dbcol="max_cap" /> <ATTRIB name="MaxCap" type="Integer" dbcol="max_cap" />
<ATTRIB name="CouponExpiryDate" type="Date" dbcol="coupon_expiry_date" />
<SINGLEREFERENCE name="Company" type="Company" dbcol="company_id" mandatory="true" backreferenceName="HiringTeams" /> <SINGLEREFERENCE name="Company" type="Company" dbcol="company_id" mandatory="true" backreferenceName="HiringTeams" />
<SINGLEREFERENCE name="BillingTeam" type="HiringTeam" dbcol="billing_team_id" mandatory="false" /> <SINGLEREFERENCE name="BillingTeam" type="HiringTeam" dbcol="billing_team_id" mandatory="false" />
<SINGLEREFERENCE name="AddedByUser" type="CompanyUser" dbcol="added_by_user_id" mandatory="true" /> <SINGLEREFERENCE name="AddedByUser" type="CompanyUser" dbcol="added_by_user_id" mandatory="true" />
<SINGLEREFERENCE name="PaymentPlan" type="PaymentPlan" dbcol="payment_plan_id" mandatory="false" /> <SINGLEREFERENCE name="PaymentPlan" type="PaymentPlan" dbcol="payment_plan_id" mandatory="false" />
<SINGLEREFERENCE name="Coupon" type="StripeCoupon" dbcol="coupon_id" mandatory="false" />
</TABLE> </TABLE>
......
...@@ -36,4 +36,20 @@ public class PaymentPlan extends BasePaymentPlan ...@@ -36,4 +36,20 @@ public class PaymentPlan extends BasePaymentPlan
return null; return null;
} }
public Double getAmountPerJob(HiringTeam hiringTeam)
{
if(getActiveJobCount() != null)
{
return (getAmount() / getActiveJobCount()) * (hiringTeam.getCoupon() != null ? (100 - hiringTeam.getCoupon().getPercentageOff()) * 0.01 : 1);
}
return getAmount();
}
public Double getTotalAmount(HiringTeam hiringTeam)
{
return getAmount() * (hiringTeam.getCoupon() != null ? (100 - hiringTeam.getCoupon().getPercentageOff()) * 0.01 : 1);
}
} }
\ No newline at end of file
...@@ -8,10 +8,14 @@ ...@@ -8,10 +8,14 @@
<TABLE name="tl_coupon" tablePrefix="object"> <TABLE name="tl_coupon" tablePrefix="object">
<ATTRIB name="CouponCode" type="String" dbcol="coupon_code" mandatory="true" length="100" /> <ATTRIB name="CouponCode" type="String" dbcol="coupon_code" mandatory="true" length="100" />
<ATTRIB name="PercentageOff" type="Integer" dbcol="percentage_off" /> <ATTRIB name="PercentageOff" type="Double" dbcol="percentage_off" />
<ATTRIB name="DurationInMonths" type="Integer" dbcol="duration_in_months" /> <ATTRIB name="DurationInMonths" type="Integer" dbcol="duration_in_months" />
<ATTRIB name="CouponDuration" type="CouponDuration" dbcol="coupon_duration" attribHelper="EnumeratedAttributeHelper" />
<ATTRIB name="RedeemBy" type="Date" dbcol="redeem_by" />
<ATTRIB name="MaxRedemptions" type="Integer" dbcol="max_redemptions" />
<ATTRIB name="TimesRedeemed" type="Integer" dbcol="times_redeemed" />
</TABLE> </TABLE>
<SEARCH type="All" paramFilter="tl_coupon.object_id is not null" > <SEARCH type="All" paramFilter="tl_coupon.object_id is not null" >
......
package performa.orm.types;
import java.util.*;
import oneit.utils.*;
/**
* This class was generated using constGen.bat.
* DO NOT MODIFY THIS CODE.
* Edit the associated .xml file, and regenerate this file
* constGen (directory) (file minus extension)
* e.g. constGen C:\...\sql FieldType
*/
public class CouponDuration extends AbstractEnumerated
{
public static final EnumeratedFactory FACTORY_CouponDuration = new CouponDurationFactory();
public static final CouponDuration FORVER = new CouponDuration ("FORVER", "FORVER", "Forever", false);
public static final CouponDuration ONCE = new CouponDuration ("ONCE", "ONCE", "Once", false);
public static final CouponDuration REPEATING = new CouponDuration ("REPEATING", "REPEATING", "Repeating", false);
private static final CouponDuration[] allCouponDurations =
new CouponDuration[] { FORVER,ONCE,REPEATING};
private static CouponDuration[] getAllCouponDurations ()
{
return allCouponDurations;
}
private CouponDuration (String name, String value, String description, boolean disabled)
{
super (name, value, description, disabled);
}
public static final Comparator COMPARE_BY_POSITION = new CompareEnumByPosition (allCouponDurations);
static
{
defineAdditionalData ();
}
public boolean isEqual (CouponDuration other)
{
return this.name.equals (other.name);
}
public Enumeration getAllInstances ()
{
return CouponDuration.getAll ();
}
private Object readResolve() throws java.io.ObjectStreamException
{
return CouponDuration.forName (this.name);
}
public EnumeratedFactory getFactory ()
{
return FACTORY_CouponDuration;
}
public static CouponDuration forName (String name)
{
if (name == null) { return null; }
CouponDuration[] all = getAllCouponDurations();
int enumIndex = AbstractEnumerated.getIndexForName (all, name);
return all[enumIndex];
}
public static CouponDuration forValue (String value)
{
if (value == null) { return null; }
CouponDuration[] all = getAllCouponDurations();
int enumIndex = AbstractEnumerated.getIndexForValue (getAllCouponDurations (), value);
return all[enumIndex];
}
public static java.util.Enumeration getAll ()
{
return AbstractEnumerated.getAll (getAllCouponDurations());
}
public static CouponDuration[] getCouponDurationArray ()
{
return (CouponDuration[])getAllCouponDurations().clone ();
}
public static void defineAdditionalData ()
{
}
static class CouponDurationFactory implements EnumeratedFactory
{
public AbstractEnumerated getForName (String name)
{
return CouponDuration.forName (name);
}
public AbstractEnumerated getForValue (String name)
{
return CouponDuration.forValue (name);
}
public Enumeration getAll ()
{
return CouponDuration.getAll ();
}
}
public Map getAdditionalAttributes ()
{
Map attribs = new HashMap ();
return attribs;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CONSTANT package="performa.orm.types" name="CouponDuration">
<VALUE name="FORVER" description="Forever" />
<VALUE name="ONCE" description="Once" />
<VALUE name="REPEATING" description="Repeating" />
</CONSTANT>
</ROOT>
\ No newline at end of file
...@@ -30,7 +30,6 @@ import oneit.security.SecUser; ...@@ -30,7 +30,6 @@ import oneit.security.SecUser;
import oneit.utils.DateDiff; import oneit.utils.DateDiff;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
import performa.orm.Company; import performa.orm.Company;
import performa.orm.CompanyUser;
import performa.orm.HiringTeam; import performa.orm.HiringTeam;
import performa.orm.PaymentPlan; import performa.orm.PaymentPlan;
import spark.utils.IOUtils; import spark.utils.IOUtils;
...@@ -129,7 +128,7 @@ public class StripeUtils ...@@ -129,7 +128,7 @@ public class StripeUtils
} }
catch (StripeException ex) catch (StripeException ex)
{ {
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while updating a customer in stripe"); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while retrieving coupon in stripe coupon code: " + couponCode);
} }
return null; return null;
...@@ -139,9 +138,6 @@ public class StripeUtils ...@@ -139,9 +138,6 @@ public class StripeUtils
{ {
try try
{ {
// Subscription subscription = Subscription.retrieve(subscriptionRef);
// new Date(subscription.getCurrentPeriodEnd() * 1000)
// new Date(subscription.getCurrentPeriodStart()* 1000)
return Subscription.retrieve(subscriptionRef); return Subscription.retrieve(subscriptionRef);
} }
catch (StripeException ex) catch (StripeException ex)
...@@ -208,7 +204,7 @@ public class StripeUtils ...@@ -208,7 +204,7 @@ public class StripeUtils
} }
public static void updatePlan(HiringTeam hiringTeam) throws FieldException public static Subscription updatePlan(HiringTeam hiringTeam) throws FieldException
{ {
try try
{ {
...@@ -221,10 +217,9 @@ public class StripeUtils ...@@ -221,10 +217,9 @@ public class StripeUtils
if(hiringTeam.getStripeSubscription() != null) if(hiringTeam.getStripeSubscription() != null)
{ {
subscription = Subscription.retrieve(hiringTeam.getStripeSubscription()); subscription = Subscription.retrieve(hiringTeam.getStripeSubscription());
String subID = subscription.getSubscriptionItems().getData().get(0).getId();
itemA.put("id", subID); itemA.put("id", subscription.getSubscriptionItems().getData().get(0).getId());
itemB.put("id", subID); itemB.put("id", subscription.getSubscriptionItems().getData().get(1).getId());
} }
itemA.put("plan", paymentPlan.getStripeReference()); itemA.put("plan", paymentPlan.getStripeReference());
...@@ -236,7 +231,13 @@ public class StripeUtils ...@@ -236,7 +231,13 @@ public class StripeUtils
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("items", items); params.put("items", items);
params.put("prorate", false);
if(hiringTeam.getCoupon() != null)
{
params.put("coupon", hiringTeam.getCoupon().getCouponCode());
}
if(subscription != null) if(subscription != null)
{ {
subscription.update(params); subscription.update(params);
...@@ -251,11 +252,15 @@ public class StripeUtils ...@@ -251,11 +252,15 @@ public class StripeUtils
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Subscribing customer in stripe : ", subscription); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Subscribing customer in stripe : ", subscription);
hiringTeam.setStripeSubscription(subscription.getId()); hiringTeam.setStripeSubscription(subscription.getId());
return subscription;
} }
catch (StripeException ex) catch (StripeException ex)
{ {
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating subscrition in stripe"); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating subscrition in stripe");
} }
return null;
} }
......
...@@ -5807,8 +5807,8 @@ label, label .label-title span { ...@@ -5807,8 +5807,8 @@ label, label .label-title span {
margin-bottom:26px; margin-bottom:26px;
} }
.choose-plan-headings div {display: inline-block ; min-width: 125px;} .choose-plan-headings div {display: inline-block ; min-width: 125px;}
.choose-plan-headings .jobs-per-month {margin-right: 45px; } .choose-plan-headings .jobs-per-month {margin-right: 65px; }
.choose-plan-headings .cost-per-job {margin-right: 12px; } .choose-plan-headings .cost-per-job {margin-right: 50px; }
.choose-plan-headings {color: #8E97A0; font-size: 11px;margin-bottom: 10px;} .choose-plan-headings {color: #8E97A0; font-size: 11px;margin-bottom: 10px;}
...@@ -5863,7 +5863,7 @@ label, label .label-title span { ...@@ -5863,7 +5863,7 @@ label, label .label-title span {
display: block; display: block;
} }
.choose-plan-item div.jobs { .choose-plan-item div.jobs {
min-width: 140px; min-width: 170px;
} }
.choose-plan-item.active div.jobs { .choose-plan-item.active div.jobs {
color: #03A0E7; color: #03A0E7;
...@@ -5872,9 +5872,9 @@ label, label .label-title span { ...@@ -5872,9 +5872,9 @@ label, label .label-title span {
min-width: 140px; min-width: 140px;
} }
.choose-plan-item div.cost { .choose-plan-item div.cost {
min-width: 140px; min-width: 170px;
} }
.coupon-applied .choose-plan-item div.cost , .coupon-applied .choose-plan-item div.fee { .coupon-applied .choose-plan-item div.cost.discounted , .coupon-applied .choose-plan-item div.fee.discounted{
color: #67B413; color: #67B413;
} }
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.RedefineTableOperation">
<tableName factory="String">tl_hiring_team</tableName>
<column name="coupon_id" type="Long" length="11" nullable="true"/>
<column name="coupon_expiry_date" type="Date" nullable="true"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun --> <!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au"><NODE name="Script" factory="Vector"> <OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation"> <NODE name="DDL" factory="Participant" class="oneit.sql.transfer.DefineTableOperation">
<tableName factory="String">tl_coupon</tableName> <tableName factory="String">tl_coupon</tableName>
<column name="object_id" type="Long" nullable="false" length="11"/> <column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/> <column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/> <column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="coupon_code" type="String" nullable="false" length="100"/> <column name="coupon_code" type="String" nullable="false" length="100"/>
<column name="percentage_off" type="Long" nullable="true"/> <column name="percentage_off" type="Double" nullable="true"/>
<column name="duration_in_months" type="Long" nullable="true"/> <column name="duration_in_months" type="Long" nullable="true"/>
</NODE> <column name="coupon_duration" type="String" nullable="true" length="200"/>
<column name="redeem_by" type="Date" nullable="true"/>
<column name="max_redemptions" type="Long" nullable="true"/>
<column name="times_redeemed" type="Long" nullable="true"/>
</NODE>
</NODE></OBJECTS> </NODE>
\ No newline at end of file </OBJECTS>
\ No newline at end of file
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