Commit 5e8aad37 by Nilu

Stripe plan retrieval via batch. Subscribe to multiple plans in one…

Stripe plan retrieval via batch. Subscribe to multiple plans in one subscription. Creating accounts in stripe upone adding hiring teams where billing is managed on their own.
parent d8031d35
<?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.DefineTableOperation">
<tableName factory="String">tl_coupon</tableName>
<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_created_date" type="Date" nullable="false" length="22"/>
<column name="coupon_code" type="String" nullable="false" length="100"/>
<column name="percentage_off" type="Long" nullable="true"/>
<column name="duration_in_months" type="Long" nullable="true"/>
</NODE>
</NODE></OBJECTS>
\ No newline at end of file
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
<column name="interval_count" type="Long" nullable="false"/> <column name="interval_count" type="Long" nullable="false"/>
<column name="trial_period_days" type="Long" nullable="true"/> <column name="trial_period_days" type="Long" nullable="true"/>
<column name="active_job_count" type="Long" nullable="true"/> <column name="active_job_count" type="Long" nullable="true"/>
<column name="disabled" type="Boolean" nullable="true"/>
<column name="product_reference" type="String" nullable="true" length="100"/>
<column name="usage_type" type="String" nullable="true" length="200"/>
<column name="linked_plan" type="String" nullable="true" length="100"/>
</NODE> </NODE>
</NODE></OBJECTS> </NODE></OBJECTS>
\ No newline at end of file
<?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.DefineTableOperation">
<tableName factory="String">tl_coupon</tableName>
<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_created_date" type="Date" nullable="false" length="22"/>
<column name="coupon_code" type="String" nullable="false" length="100"/>
<column name="percentage_off" type="Long" nullable="true"/>
<column name="duration_in_months" type="Long" nullable="true"/>
</NODE>
</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
...@@ -16,7 +16,11 @@ CREATE TABLE tl_payment_plan ( ...@@ -16,7 +16,11 @@ CREATE TABLE tl_payment_plan (
interval varchar(200) NOT NULL, interval varchar(200) NOT NULL,
interval_count numeric(12) NOT NULL, interval_count numeric(12) NOT NULL,
trial_period_days numeric(12) NULL, trial_period_days numeric(12) NULL,
active_job_count numeric(12) NULL active_job_count numeric(12) NULL,
disabled char(1) NULL,
product_reference varchar(100) NULL,
usage_type varchar(200) NULL,
linked_plan varchar(100) NULL
); );
......
-- 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
-- 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
...@@ -17,7 +17,11 @@ CREATE TABLE tl_payment_plan ( ...@@ -17,7 +17,11 @@ CREATE TABLE tl_payment_plan (
interval varchar2(200) NOT NULL, interval varchar2(200) NOT NULL,
interval_count number(12) NOT NULL, interval_count number(12) NOT NULL,
trial_period_days number(12) NULL, trial_period_days number(12) NULL,
active_job_count number(12) NULL active_job_count number(12) NULL,
disabled char(1) NULL,
product_reference varchar2(100) NULL,
usage_type varchar2(200) NULL,
linked_plan varchar2(100) 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
-- @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
...@@ -17,7 +17,11 @@ CREATE TABLE tl_payment_plan ( ...@@ -17,7 +17,11 @@ CREATE TABLE tl_payment_plan (
interval varchar(200) NOT NULL, interval varchar(200) NOT NULL,
interval_count numeric(12) NOT NULL, interval_count numeric(12) NOT NULL,
trial_period_days numeric(12) NULL, trial_period_days numeric(12) NULL,
active_job_count numeric(12) NULL active_job_count numeric(12) NULL,
disabled char(1) NULL,
product_reference varchar(100) NULL,
usage_type varchar(200) NULL,
linked_plan varchar(100) 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
package performa.batch; package performa.batch;
import com.stripe.Stripe; import com.stripe.Stripe;
import com.stripe.exception.APIConnectionException; import com.stripe.exception.StripeException;
import com.stripe.exception.APIException;
import com.stripe.exception.AuthenticationException;
import com.stripe.exception.CardException;
import com.stripe.exception.InvalidRequestException;
import com.stripe.model.Plan; import com.stripe.model.Plan;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -17,10 +14,13 @@ import oneit.logging.LoggingArea; ...@@ -17,10 +14,13 @@ import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction; import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException; import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.EqualsFilter; import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.utils.filter.CollectionFilter;
import oneit.utils.filter.Filter;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
import performa.orm.PaymentPlan; import performa.orm.PaymentPlan;
import performa.orm.types.CurrencyType; import performa.orm.types.CurrencyType;
import performa.orm.types.Interval; import performa.orm.types.Interval;
import performa.orm.types.UsageType;
import performa.utils.StripeUtils; import performa.utils.StripeUtils;
...@@ -38,16 +38,28 @@ public class PullStripeDataBatch extends ORMBatch ...@@ -38,16 +38,28 @@ public class PullStripeDataBatch extends ORMBatch
Stripe.apiKey = StripeUtils.STRIPE_KEY; Stripe.apiKey = StripeUtils.STRIPE_KEY;
Map<String, Object> planParams = new HashMap<>(); Map<String, Object> planParams = new HashMap<>();
List<Plan> plansList = Plan.list(planParams).getData();
planParams.put("active", true);
List<Plan> plansList = Plan.list(planParams).getData();
PaymentPlan[] paymentPlans = PaymentPlan.searchAll(ot);
for (PaymentPlan paymentPlan : paymentPlans)
{
paymentPlan.setDisabled(Boolean.TRUE);
}
for (Plan plan : plansList) for (Plan plan : plansList)
{ {
PaymentPlan[] paymentPlans = PaymentPlan.SearchByAll().andStripeReference(new EqualsFilter<>(plan.getId())).search(ot); System.out.println("pllan :: " + plan);
Filter<PaymentPlan> filter = PaymentPlan.SearchByAll().andStripeReference(new EqualsFilter<>(plan.getId()));
List<PaymentPlan> activePlans = (List<PaymentPlan>) CollectionFilter.filter(Arrays.asList(paymentPlans) , filter);
PaymentPlan paymentPlan; PaymentPlan paymentPlan;
if(paymentPlans != null && paymentPlans.length > 0) if(activePlans != null && !activePlans.isEmpty())
{ {
paymentPlan = paymentPlans[0]; paymentPlan = activePlans.get(0);
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, "Updating exiting payment plan: " , paymentPlan, " to match stripe plan: ", plan); LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, "Updating exiting payment plan: " , paymentPlan, " to match stripe plan: ", plan);
} }
else else
...@@ -58,25 +70,34 @@ public class PullStripeDataBatch extends ORMBatch ...@@ -58,25 +70,34 @@ public class PullStripeDataBatch extends ORMBatch
Map<String, String> metadata = plan.getMetadata(); Map<String, String> metadata = plan.getMetadata();
String activeJobs = metadata.get("ActiveJobs"); String activeJobs = metadata.get("ActiveJobs");
String linkedPlan = metadata.get("LinkedPlan");
paymentPlan.setStripeReference(plan.getId()); paymentPlan.setStripeReference(plan.getId());
paymentPlan.setPlanName(plan.getName()); paymentPlan.setPlanName(plan.getNickname());
paymentPlan.setDescription(plan.getStatementDescriptor()); // paymentPlan.setDescription(plan.());
paymentPlan.setCurrencyType(CurrencyType.forName(plan.getCurrency().toUpperCase())); paymentPlan.setCurrencyType(CurrencyType.forName(plan.getCurrency().toUpperCase()));
paymentPlan.setAmount(plan.getAmount().doubleValue() / 100); paymentPlan.setAmount(plan.getAmount().doubleValue() / 100);
paymentPlan.setInterval(Interval.forName(plan.getInterval().toUpperCase())); paymentPlan.setInterval(Interval.forName(plan.getInterval().toUpperCase()));
paymentPlan.setIntervalCount(plan.getIntervalCount()); paymentPlan.setIntervalCount(plan.getIntervalCount().intValue());
paymentPlan.setTrialPeriodDays(plan.getTrialPeriodDays()); paymentPlan.setTrialPeriodDays(plan.getTrialPeriodDays().intValue());
paymentPlan.setDisabled(Boolean.FALSE);
paymentPlan.setProductReference(plan.getProduct());
paymentPlan.setUsageType(UsageType.forName(plan.getUsageType().toUpperCase()));
if(activeJobs != null) if(activeJobs != null)
{ {
paymentPlan.setActiveJobCount(Integer.valueOf(activeJobs)); paymentPlan.setActiveJobCount(Integer.valueOf(activeJobs));
} }
if(linkedPlan != null)
{
paymentPlan.setLinkedPlanReference(linkedPlan);
}
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, "Saving payment plan: " , paymentPlan, " mapped from stripe plan: ", plan); LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, "Saving payment plan: " , paymentPlan, " mapped from stripe plan: ", plan);
} }
} }
catch (AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException | StorageException | FieldException | NumberFormatException ex) catch (StripeException ex)
{ {
LogMgr.log(PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, ex, "Error while pulling plan details from stripe"); LogMgr.log(PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, ex, "Error while pulling plan details from stripe");
......
...@@ -16,6 +16,7 @@ import oneit.utils.BusinessException; ...@@ -16,6 +16,7 @@ import oneit.utils.BusinessException;
import oneit.utils.MultiException; import oneit.utils.MultiException;
import performa.orm.Company; import performa.orm.Company;
import performa.orm.HiringTeam; import performa.orm.HiringTeam;
import performa.utils.StripeUtils;
public class AddHiringTeamFP extends SaveFP public class AddHiringTeamFP extends SaveFP
...@@ -58,6 +59,8 @@ public class AddHiringTeamFP extends SaveFP ...@@ -58,6 +59,8 @@ public class AddHiringTeamFP extends SaveFP
if(hiringTeam.getManageOwnBilling()) if(hiringTeam.getManageOwnBilling())
{ {
hiringTeam.setBillingTeam(null); hiringTeam.setBillingTeam(null);
StripeUtils.createCustomer(hiringTeam);
} }
else else
{ {
......
...@@ -13,6 +13,7 @@ import oneit.servlets.process.ORMProcessFormProcessor; ...@@ -13,6 +13,7 @@ import oneit.servlets.process.ORMProcessFormProcessor;
import oneit.servlets.process.ORMProcessState; import oneit.servlets.process.ORMProcessState;
import oneit.utils.BusinessException; import oneit.utils.BusinessException;
import performa.orm.HiringTeam; import performa.orm.HiringTeam;
import performa.orm.StripeCoupon;
import performa.utils.StripeUtils; import performa.utils.StripeUtils;
...@@ -28,6 +29,15 @@ public class ApplyCouponFP extends ORMProcessFormProcessor ...@@ -28,6 +29,15 @@ public class ApplyCouponFP extends ORMProcessFormProcessor
Coupon coupon = StripeUtils.retrieveCoupon(hiringTeam.getCouponCode()); Coupon coupon = StripeUtils.retrieveCoupon(hiringTeam.getCouponCode());
if(coupon.getValid())
{
StripeCoupon stripeCoupon = StripeCoupon.createStripeCoupon(process.getTransaction());
stripeCoupon.setCouponCode(coupon.getId());
// stripeCoupon.setDurationInMonths(coupon.getDurationInMonths());
// stripeCoupon.setPercentageOff(coupon.getPercentOff());
}
System.out.println("coupon : " + coupon); System.out.println("coupon : " + coupon);
return RedisplayResult.getInstance(); return RedisplayResult.getInstance();
......
...@@ -109,7 +109,7 @@ public class MakePaymentFP extends SaveFP ...@@ -109,7 +109,7 @@ public class MakePaymentFP extends SaveFP
// company.setPlanRenewedOn(DateDiff.getToday()); // company.setPlanRenewedOn(DateDiff.getToday());
// company.setUsedCredits(1); // company.setUsedCredits(1);
StripeUtils.updatePlan(company); // StripeUtils.updatePlan(company);
} }
// restarting process as custom attributes needs to be updated to intercom // restarting process as custom attributes needs to be updated to intercom
......
...@@ -69,7 +69,7 @@ public class ReplaceCardFP extends SaveFP ...@@ -69,7 +69,7 @@ public class ReplaceCardFP extends SaveFP
// cannot subscribe to a plan without card details // cannot subscribe to a plan without card details
if(company.getPaymentPlan() != null) if(company.getPaymentPlan() != null)
{ {
StripeUtils.updatePlan(company); // StripeUtils.updatePlan(company);
} }
} }
catch(StorageException | FieldException e) catch(StorageException | FieldException e)
......
...@@ -13,9 +13,8 @@ import oneit.servlets.process.SaveFP; ...@@ -13,9 +13,8 @@ import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException; import oneit.utils.BusinessException;
import oneit.utils.CollectionUtils; import oneit.utils.CollectionUtils;
import oneit.utils.MultiException; import oneit.utils.MultiException;
import performa.intercom.utils.IntercomUtils;
import performa.orm.Company;
import performa.orm.HiringTeam; import performa.orm.HiringTeam;
import performa.orm.PaymentPlan;
import performa.utils.StripeUtils; import performa.utils.StripeUtils;
...@@ -28,6 +27,7 @@ public class SaveCompanyFP extends SaveFP ...@@ -28,6 +27,7 @@ public class SaveCompanyFP extends SaveFP
// Company company = process.getAttribute("Company") != null ? (Company) process.getAttribute("Company") : (Company) request.getAttribute("Company"); // 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");
// LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP saving company : ", company ); // LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP saving company : ", company );
...@@ -35,28 +35,33 @@ public class SaveCompanyFP extends SaveFP ...@@ -35,28 +35,33 @@ public class SaveCompanyFP extends SaveFP
{ {
hiringTeam.setHiringTeamLogo(null); hiringTeam.setHiringTeamLogo(null);
LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP setting hiring team logo to null of hiring team : ", hiringTeam ); LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP setting hiring team logo to null of hiring team : ", hiringTeam );
} }
if(hiringTeam.getManageOwnBilling()) if(hiringTeam.getManageOwnBilling())
{ {
hiringTeam.setBillingTeam(null); hiringTeam.setBillingTeam(null);
if(hiringTeam.getStripeReference() == null)
{
StripeUtils.createCustomer(hiringTeam);
}
} }
// if(CollectionUtils.equals(isPayment, Boolean.TRUE) && company.getPaymentJobCount()!=null) if(CollectionUtils.equals(isPayment, Boolean.TRUE))
// { {
// company.setPaymentPlan(company.getSelectedPaymentPlan()); hiringTeam.setPaymentPlan(paymentPlan);
//
// LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"Company payment plan updated.", company, company.getPaymentPlan()); LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan());
//
// if(company.getCardID() != null ) if(hiringTeam.getCompany().getCardID() != null )
// { {
// // cannot subscribe a user to a plan without card details // cannot subscribe a user to a plan without card details
// StripeUtils.updatePlan(company); StripeUtils.updatePlan(hiringTeam);
//
// LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"Strpe subscription updated.", company, company.getStripeSubscription()); LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Strpe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
// } }
// } }
// //
// // Update company in intercom // // Update company in intercom
// IntercomUtils.updateCompany(company); // IntercomUtils.updateCompany(company);
......
package performa.form; package performa.form;
import com.stripe.Stripe;
import com.stripe.exception.APIConnectionException;
import com.stripe.exception.APIException;
import com.stripe.exception.AuthenticationException;
import com.stripe.exception.CardException;
import com.stripe.exception.InvalidRequestException;
import com.stripe.model.Customer;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import oneit.appservices.config.ConfigMgr;
import oneit.business.content.Article; import oneit.business.content.Article;
import oneit.components.ParticipantInitialisationContext; import oneit.components.ParticipantInitialisationContext;
import oneit.email.ConfigurableArticleTemplateEmailer; import oneit.email.ConfigurableArticleTemplateEmailer;
...@@ -117,7 +106,7 @@ public class SendCompanyUserInvitesFP extends SaveFP ...@@ -117,7 +106,7 @@ public class SendCompanyUserInvitesFP extends SaveFP
// Create customer in Stripe and subscribe for plan 0001 and coupon EAP. Only for 0.0.4.1 release // Create customer in Stripe and subscribe for plan 0001 and coupon EAP. Only for 0.0.4.1 release
// Need to handle properly when plan and billing screens are added // Need to handle properly when plan and billing screens are added
StripeUtils.createCustomer(companyUser); StripeUtils.createCustomer(companyUser.getDefaultHiringTeam());
LogMgr.log(LOG, LogLevel.PROCESSING1,"Created customer in Stripe, customer reference ", company.getStripeReference()); LogMgr.log(LOG, LogLevel.PROCESSING1,"Created customer in Stripe, customer reference ", company.getStripeReference());
// StripeUtils.subscribeCustomer(company); // StripeUtils.subscribeCustomer(company);
......
package performa.form; package performa.form;
import com.stripe.Stripe; import com.stripe.Stripe;
import com.stripe.exception.APIConnectionException;
import com.stripe.exception.APIException;
import com.stripe.exception.AuthenticationException; import com.stripe.exception.AuthenticationException;
import com.stripe.exception.CardException; import com.stripe.exception.CardException;
import com.stripe.exception.InvalidRequestException; import com.stripe.exception.InvalidRequestException;
import com.stripe.exception.StripeException;
import com.stripe.model.Card; import com.stripe.model.Card;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -83,7 +82,7 @@ public class UpdateCardFP extends SaveFP ...@@ -83,7 +82,7 @@ public class UpdateCardFP extends SaveFP
LogMgr.log(LOG, LogLevel.PROCESSING1,"Updated card details of user : ", company, " updated card : " , updatedCard ); LogMgr.log(LOG, LogLevel.PROCESSING1,"Updated card details of user : ", company, " updated card : " , updatedCard );
} }
catch (AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException e) catch (StripeException e)
{ {
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while updating card details of user"); LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while updating card details of user");
} }
......
package performa.orm; package performa.orm;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.objstore.rdbms.filters.IsNotNullFilter;
import oneit.utils.math.NullArith; import oneit.utils.math.NullArith;
......
...@@ -17,7 +17,11 @@ ...@@ -17,7 +17,11 @@
<ATTRIB name="IntervalCount" type="Integer" dbcol="interval_count" mandatory="true"/> <ATTRIB name="IntervalCount" type="Integer" dbcol="interval_count" mandatory="true"/>
<ATTRIB name="TrialPeriodDays" type="Integer" dbcol="trial_period_days" /> <ATTRIB name="TrialPeriodDays" type="Integer" dbcol="trial_period_days" />
<ATTRIB name="ActiveJobCount" type="Integer" dbcol="active_job_count" /> <ATTRIB name="ActiveJobCount" type="Integer" dbcol="active_job_count" />
<ATTRIB name="Disabled" type="Boolean" dbcol="disabled" />
<ATTRIB name="ProductReference" type="String" dbcol="product_reference" length="100" />
<ATTRIB name="UsageType" type="UsageType" dbcol="usage_type" attribHelper="EnumeratedAttributeHelper" />
<ATTRIB name="LinkedPlanReference" type="String" dbcol="linked_plan" length="100" />
</TABLE> </TABLE>
<SEARCH type="All" paramFilter="tl_payment_plan.object_id is not null" orderBy="tl_payment_plan.object_id" /> <SEARCH type="All" paramFilter="tl_payment_plan.object_id is not null" orderBy="tl_payment_plan.object_id" />
......
package performa.orm;
import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.utils.*;
import performa.orm.types.*;
public class StripeCoupon extends BaseStripeCoupon
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public StripeCoupon ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://www.oneit.com.au/schemas/5.2/BusinessObject.xsd'>
<BUSINESSCLASS name="StripeCoupon" package="performa.orm">
<IMPORT value="performa.orm.types.*"/>
<TABLE name="tl_coupon" tablePrefix="object">
<ATTRIB name="CouponCode" type="String" dbcol="coupon_code" mandatory="true" length="100" />
<ATTRIB name="PercentageOff" type="Integer" dbcol="percentage_off" />
<ATTRIB name="DurationInMonths" type="Integer" dbcol="duration_in_months" />
</TABLE>
<SEARCH type="All" paramFilter="tl_coupon.object_id is not null" >
</SEARCH>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
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 UsageType extends AbstractEnumerated
{
public static final EnumeratedFactory FACTORY_UsageType = new UsageTypeFactory();
public static final UsageType METERED = new UsageType ("METERED", "METERED", "Metered", false);
public static final UsageType LICENSED = new UsageType ("LICENSED", "LICENSED", "Licensed", false);
private static final UsageType[] allUsageTypes =
new UsageType[] { METERED,LICENSED};
private static UsageType[] getAllUsageTypes ()
{
return allUsageTypes;
}
private UsageType (String name, String value, String description, boolean disabled)
{
super (name, value, description, disabled);
}
public static final Comparator COMPARE_BY_POSITION = new CompareEnumByPosition (allUsageTypes);
static
{
defineAdditionalData ();
}
public boolean isEqual (UsageType other)
{
return this.name.equals (other.name);
}
public Enumeration getAllInstances ()
{
return UsageType.getAll ();
}
private Object readResolve() throws java.io.ObjectStreamException
{
return UsageType.forName (this.name);
}
public EnumeratedFactory getFactory ()
{
return FACTORY_UsageType;
}
public static UsageType forName (String name)
{
if (name == null) { return null; }
UsageType[] all = getAllUsageTypes();
int enumIndex = AbstractEnumerated.getIndexForName (all, name);
return all[enumIndex];
}
public static UsageType forValue (String value)
{
if (value == null) { return null; }
UsageType[] all = getAllUsageTypes();
int enumIndex = AbstractEnumerated.getIndexForValue (getAllUsageTypes (), value);
return all[enumIndex];
}
public static java.util.Enumeration getAll ()
{
return AbstractEnumerated.getAll (getAllUsageTypes());
}
public static UsageType[] getUsageTypeArray ()
{
return (UsageType[])getAllUsageTypes().clone ();
}
public static void defineAdditionalData ()
{
}
static class UsageTypeFactory implements EnumeratedFactory
{
public AbstractEnumerated getForName (String name)
{
return UsageType.forName (name);
}
public AbstractEnumerated getForValue (String name)
{
return UsageType.forValue (name);
}
public Enumeration getAll ()
{
return UsageType.getAll ();
}
}
public Map getAdditionalAttributes ()
{
Map attribs = new HashMap ();
return attribs;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CONSTANT package="performa.orm.types" name="UsageType">
<VALUE name="METERED" description="Metered" />
<VALUE name="LICENSED" description="Licensed" />
</CONSTANT>
</ROOT>
\ No newline at end of file
package performa.utils; package performa.utils;
import com.stripe.Stripe; import com.stripe.Stripe;
import com.stripe.exception.APIConnectionException; import com.stripe.exception.StripeException;
import com.stripe.exception.APIException;
import com.stripe.exception.AuthenticationException;
import com.stripe.exception.CardException;
import com.stripe.exception.InvalidRequestException;
import com.stripe.model.Card; import com.stripe.model.Card;
import com.stripe.model.Coupon; import com.stripe.model.Coupon;
import com.stripe.model.Customer; import com.stripe.model.Customer;
...@@ -21,19 +17,18 @@ import java.util.HashMap; ...@@ -21,19 +17,18 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oneit.appservices.config.ConfigMgr; import oneit.appservices.config.ConfigMgr;
import oneit.logging.LogLevel; import oneit.logging.LogLevel;
import oneit.logging.LogMgr; import oneit.logging.LogMgr;
import oneit.logging.LoggingArea; import oneit.logging.LoggingArea;
import oneit.objstore.ObjectTransaction; import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.EqualsFilter; import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.security.SecUser; 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.CompanyUser;
import performa.orm.HiringTeam;
import performa.orm.PaymentPlan; import performa.orm.PaymentPlan;
import spark.utils.IOUtils; import spark.utils.IOUtils;
...@@ -51,27 +46,26 @@ public class StripeUtils ...@@ -51,27 +46,26 @@ public class StripeUtils
} }
public static void createCustomer(CompanyUser companyUser) throws FieldException public static void createCustomer(HiringTeam hiringTeam) throws FieldException
{ {
try try
{ {
Company company = companyUser.getCompany(); SecUser secUser = hiringTeam.getAddedByUser().getUser();
SecUser secUser = companyUser.getUser();
Map<String, Object> customerParams = new HashMap<>(); Map<String, Object> customerParams = new HashMap<>();
customerParams.put("description", company); customerParams.put("description", hiringTeam);
customerParams.put("email", secUser.getEmail()); customerParams.put("email", secUser.getEmail());
Customer customer = Customer.create(customerParams); Customer customer = Customer.create(customerParams);
company.setStripeReference(customer.getId()); hiringTeam.setStripeReference(customer.getId());
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Create customer in stripe : ", customer); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Create customer in stripe : ", customer);
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex) catch (StripeException ex)
{ {
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating a customer in stripe"); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating a customer in stripe");
} }
} }
...@@ -81,7 +75,7 @@ public class StripeUtils ...@@ -81,7 +75,7 @@ public class StripeUtils
{ {
if(company.getStripeReference() == null) if(company.getStripeReference() == null)
{ {
createCustomer(company.getAddedByUser()); createCustomer(company.getAddedByUser().getDefaultHiringTeam());
} }
Customer customer = Customer.retrieve(company.getStripeReference()); Customer customer = Customer.retrieve(company.getStripeReference());
...@@ -99,10 +93,10 @@ public class StripeUtils ...@@ -99,10 +93,10 @@ public class StripeUtils
return card; return card;
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException 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 updating a customer in stripe");
} }
return null; return null;
} }
...@@ -116,7 +110,7 @@ public class StripeUtils ...@@ -116,7 +110,7 @@ public class StripeUtils
return (Card) customer.getSources().retrieve(customer.getDefaultSource()); return (Card) customer.getSources().retrieve(customer.getDefaultSource());
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException 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 updating a customer in stripe");
} }
...@@ -130,7 +124,7 @@ public class StripeUtils ...@@ -130,7 +124,7 @@ public class StripeUtils
{ {
return Coupon.retrieve(couponCode); return Coupon.retrieve(couponCode);
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException 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 updating a customer in stripe");
} }
...@@ -151,7 +145,7 @@ public class StripeUtils ...@@ -151,7 +145,7 @@ public class StripeUtils
return Invoice.list(invoiceParams).getData(); return Invoice.list(invoiceParams).getData();
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex) catch (StripeException ex)
{ {
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while retriving invoices in stripe for subscription: " + company.getStripeSubscription()); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while retriving invoices in stripe for subscription: " + company.getStripeSubscription());
} }
...@@ -167,7 +161,7 @@ public class StripeUtils ...@@ -167,7 +161,7 @@ public class StripeUtils
{ {
Plan plan = Plan.retrieve(STRIPE_PLAN_ID); Plan plan = Plan.retrieve(STRIPE_PLAN_ID);
Date today = new Date(); Date today = new Date();
Date trialExpiry = DateDiff.add(today, Calendar.DATE, plan.getTrialPeriodDays()); Date trialExpiry = DateDiff.add(today, Calendar.DATE, plan.getTrialPeriodDays().intValue());
Map<String, Object> item = new HashMap<>(); Map<String, Object> item = new HashMap<>();
item.put("plan", STRIPE_PLAN_ID); item.put("plan", STRIPE_PLAN_ID);
...@@ -187,33 +181,38 @@ public class StripeUtils ...@@ -187,33 +181,38 @@ public class StripeUtils
company.setStripeSubscription(subscription.getId()); company.setStripeSubscription(subscription.getId());
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException 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");
} }
} }
public static void updatePlan(Company company) throws FieldException public static void updatePlan(HiringTeam hiringTeam) throws FieldException
{ {
try try
{ {
Subscription subscription = null; Subscription subscription = null;
PaymentPlan paymentPlan = company.getPaymentPlan(); PaymentPlan paymentPlan = hiringTeam.getPaymentPlan();
Map<String, Object> item = new HashMap<>(); Map<String, Object> itemA = new HashMap<>();
Map<String, Object> itemB = new HashMap<>();
if(company.getStripeSubscription() != null) if(hiringTeam.getStripeSubscription() != null)
{ {
subscription = Subscription.retrieve(company.getStripeSubscription()); subscription = Subscription.retrieve(hiringTeam.getStripeSubscription());
String subID = subscription.getSubscriptionItems().getData().get(0).getId();
item.put("id", subscription.getSubscriptionItems().getData().get(0).getId());
itemA.put("id", subID);
itemB.put("id", subID);
} }
item.put("plan", paymentPlan.getStripeReference()); itemA.put("plan", paymentPlan.getStripeReference());
itemB.put("plan", paymentPlan.getLinkedPlanReference());
Map<String, Object> items = new HashMap<>(); Map<String, Object> items = new HashMap<>();
items.put("0", item); items.put("0", itemA);
items.put("1", itemB);
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("items", items); params.put("items", items);
...@@ -224,16 +223,16 @@ public class StripeUtils ...@@ -224,16 +223,16 @@ public class StripeUtils
} }
else else
{ {
params.put("customer", company.getStripeReference()); params.put("customer", hiringTeam.getStripeReference());
subscription = Subscription.create(params); subscription = Subscription.create(params);
} }
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Subscribing customer in stripe : ", subscription); LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Subscribing customer in stripe : ", subscription);
company.setStripeSubscription(subscription.getId()); hiringTeam.setStripeSubscription(subscription.getId());
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException 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");
} }
......
<?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_payment_plan</tableName>
<column name="disabled" type="Boolean" nullable="true"/>
<column name="product_reference" type="String" nullable="true" length="100"/>
<column name="usage_type" type="String" nullable="true" length="200"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
<?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_payment_plan</tableName>
<column name="linked_plan" type="String" nullable="true" length="100"/>
</NODE>
</NODE>
</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