Commit bef1eb82 by Nilu

adding stripe plan setup from backend (supporting multiple currencies)

parent 60014793
<?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">it_does_not_matter</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="" type="Double" nullable="true"/>
<column name="" type="Double" nullable="true"/>
<column name="" type="String" nullable="true" length="200"/>
<column name="" type="Long" length="11" nullable="true"/>
</NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="it_does_not_matter" indexName="idx_it_does_not_matter_" isUnique="false"><column name=""/></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.DefineTableOperation">
<tableName factory="String">it_does_not_matter</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="" type="CLOB" nullable="true"/>
<column name="" type="CLOB" nullable="true"/>
<column name="" type="Long" nullable="true"/>
</NODE>
</NODE></OBJECTS>
\ No newline at end of file
-- DROP TABLE it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
numeric(20,5) NULL,
numeric(20,5) NULL,
varchar(200) NULL,
numeric(12) NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT PK_it_does_not_matter PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_it_does_not_matter_
ON it_does_not_matter ();
-- DROP TABLE it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id int NOT NULL ,
object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL
,
text NULL,
text NULL,
numeric(12) NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT PK_it_does_not_matter PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
-- DROP TABLE it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
number(20,5) NULL,
number(20,5) NULL,
varchar2(200) NULL,
number(12) NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT PK_it_does_not_matter PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_it_does_not_matter_
ON it_does_not_matter ();
-- DROP TABLE it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id number(12) NOT NULL ,
object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL
,
clob NULL,
clob NULL,
number(12) NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT PK_it_does_not_matter PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
-- @AutoRun
-- drop table it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
numeric(20,5) NULL,
numeric(20,5) NULL,
varchar(200) NULL,
numeric(12) NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT pk_it_does_not_matter PRIMARY KEY
(
object_id
) ;
CREATE INDEX idx_it_does_not_matter_
ON it_does_not_matter ();
-- @AutoRun
-- drop table it_does_not_matter;
CREATE TABLE it_does_not_matter (
object_id numeric(12) NOT NULL ,
object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL
,
text NULL,
text NULL,
numeric(12) NULL
);
ALTER TABLE it_does_not_matter ADD
CONSTRAINT pk_it_does_not_matter PRIMARY KEY
(
object_id
) ;
\ No newline at end of file
package performa.form;
import com.stripe.Stripe;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.servlets.forms.RedisplayResult;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessFormProcessor;
import oneit.servlets.process.ORMProcessState;
import oneit.utils.BusinessException;
import performa.orm.CurrencyPlanNPO;
import performa.orm.HiringTeam;
import performa.orm.StripePlanNPO;
import performa.utils.StripeUtils;
public class CreatePlanFP extends ORMProcessFormProcessor
{
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{
StripePlanNPO plan = (StripePlanNPO) process.getAttribute("StripePlanNPO");
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1, "Inside CreatePlanFP for creating plan : ", plan);
Stripe.apiKey = StripeUtils.STRIPE_KEY;
for(CurrencyPlanNPO currencyPlan : plan.getCurrencyPlansSet())
{
StripeUtils.createPlan(plan, currencyPlan);
}
process.setAttribute("StripePlanNPO", null);
return RedisplayResult.getInstance();
}
}
\ No newline at end of file
package performa.orm;
import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.utils.*;
import oneit.servlets.orm.*;
import performa.orm.types.*;
public class CurrencyPlanNPO extends BaseCurrencyPlanNPO
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public CurrencyPlanNPO ()
{
// 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="CurrencyPlanNPO" package="performa.orm" superclass="NonPersistentBO">
<IMPORT value="oneit.servlets.orm.*"/>
<IMPORT value="performa.orm.types.*"/>
<TABLE name="it_does_not_matter" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="Amount" type="Double" SubType="Currency" Formatter="Currency" />
<ATTRIB name="PerJobAmount" type="Double" SubType="Currency" Formatter="Currency" />
<ATTRIB name="CurrencyType" type="CurrencyType" attribHelper="EnumeratedAttributeHelper"/>
<SINGLEREFERENCE name="Plan" type="StripePlanNPO" backreferenceName="CurrencyPlans"/>
</TABLE>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
package performa.orm;
public class StripePlanNPO extends BaseStripePlanNPO
{
private static final long serialVersionUID = 0L;
// This constructor should not be called
public StripePlanNPO ()
{
// Do not add any code to this, always put it in initialiseNewObject
}
}
\ No newline at end of file
<?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="StripePlanNPO" package="performa.orm" superclass="NonPersistentBO">
<IMPORT value="oneit.servlets.orm.*"/>
<MULTIPLEREFERENCE name="CurrencyPlans" type="CurrencyPlanNPO" backreferenceName="Plan" />
<TABLE name="it_does_not_matter" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="ProductID" type="String" />
<ATTRIB name="PlanName" type="String" />
<ATTRIB name="ActiveJobs" type="Integer" />
</TABLE>
</BUSINESSCLASS>
</ROOT>
\ No newline at end of file
...@@ -31,9 +31,12 @@ import oneit.utils.DateDiff; ...@@ -31,9 +31,12 @@ import oneit.utils.DateDiff;
import oneit.utils.math.NullArith; import oneit.utils.math.NullArith;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
import performa.orm.Company; import performa.orm.Company;
import performa.orm.CurrencyPlanNPO;
import performa.orm.HiringTeam; import performa.orm.HiringTeam;
import performa.orm.Job; import performa.orm.Job;
import performa.orm.PaymentPlan; import performa.orm.PaymentPlan;
import performa.orm.StripePlanNPO;
import performa.orm.types.CurrencyType;
import spark.utils.IOUtils; import spark.utils.IOUtils;
...@@ -49,6 +52,47 @@ public class StripeUtils ...@@ -49,6 +52,47 @@ public class StripeUtils
Stripe.apiKey = STRIPE_KEY; Stripe.apiKey = STRIPE_KEY;
} }
public static void createPlan(StripePlanNPO stripePlan, CurrencyPlanNPO currencyPlan) throws FieldException, BusinessException
{
try
{
Map<String, Object> overagePlanParams = new HashMap<>();
overagePlanParams.put("amount", NullArith.intVal(NullArith.multiply(currencyPlan.getPerJobAmount(), 100, 0d)));
overagePlanParams.put("interval", "month");
overagePlanParams.put("usage_type", "metered");
overagePlanParams.put("product", stripePlan.getProductID());
overagePlanParams.put("currency", currencyPlan.getCurrencyType().getName());
overagePlanParams.put("nickname", stripePlan.getPlanName() + " Overage");
Plan overagePlan = Plan.create(overagePlanParams);
Map<String, Object> planParams = new HashMap<>();
planParams.put("amount", NullArith.intVal(NullArith.multiply(currencyPlan.getAmount(), 100, 0d)));
planParams.put("interval", "month");
planParams.put("product", stripePlan.getProductID());
planParams.put("currency", currencyPlan.getCurrencyType().getName());
planParams.put("nickname", stripePlan.getPlanName());
Map<String, Object> planMetadata = new HashMap<>();
planMetadata.put("ActiveJobs", stripePlan.getActiveJobs());
planMetadata.put("LinkedPlan", overagePlan.getId());
planParams.put("metadata", planMetadata);
Plan plan = Plan.create(planParams);
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Create plan in stripe : ", plan + " overage plan: " + overagePlan);
}
catch (StripeException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating a plan in stripe");
throw new BusinessException("Problem with creating plan : " + ex.getMessage());
}
}
public static void createCustomer(HiringTeam hiringTeam) throws FieldException public static void createCustomer(HiringTeam hiringTeam) throws FieldException
{ {
......
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
<FORM name="*.testAnalysis" factory="Participant" class="performa.form.TestAnalysisFP"/> <FORM name="*.testAnalysis" factory="Participant" class="performa.form.TestAnalysisFP"/>
</NODE> </NODE>
<NODE name="setupPlans_jsp" factory="Participant">
<INHERITS factory="Named" nodename="CoreORMAdmin"/>
<FORM name="*.createPlan" factory="Participant" class="performa.form.CreatePlanFP"/>
</NODE>
<NODE name="createArticle_jsp::TL" factory="Participant"> <NODE name="createArticle_jsp::TL" factory="Participant">
<FORM name="*.assume" factory="Participant" class="performa.form.AssumeHTAdminFP"> <FORM name="*.assume" factory="Participant" class="performa.form.AssumeHTAdminFP">
<NODE name="loginFP" factory="Named" nodename="CMSLoginFP"/> <NODE name="loginFP" factory="Named" nodename="CMSLoginFP"/>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<!-- <TOPMENU name="MENU.TEST_ANALYSIS" desc="Test Analysis" sortOrder="100" factory="Participant" class="oneit.servlets.jsp.ui.DefaultUICustomiser$Element" <!-- <TOPMENU name="MENU.TEST_ANALYSIS" desc="Test Analysis" sortOrder="100" factory="Participant" class="oneit.servlets.jsp.ui.DefaultUICustomiser$Element"
link="/extensions/performa/testAnalysis.jsp"/> --> link="/extensions/performa/testAnalysis.jsp"/> -->
<!--<CHILD name="Performa.Customers" desc="Customers" sortOrder="10" toplevel="ADMIN" priv="admin" link="/extensions/performa/customers.jsp" factory="Participant" class="oneit.servlets.jsp.ui.DefaultUICustomiser$Element" />--> <CHILD name="Performa.SetupPlans" desc="Setup Plans" sortOrder="10" toplevel="ADMIN" priv="admin" link="/extensions/performa/setupPlans.jsp" factory="Participant" class="oneit.servlets.jsp.ui.DefaultUICustomiser$Element" />
</NODE> </NODE>
......
<%@ page extends="oneit.servlets.jsp.FormJSP"%>
<%@ include file="/setuprequest.jsp"%>
<%@ include file="inc/stdimports.jsp"%>
<%@ include file="/editor/stdimports.jsp"%>
<%@ page import="oneit.servlets.jsp.ormtable.*" %>
<%! protected String getName (ServletConfig config) { return "setupPlans_jsp"; } %>
<%
ORMProcessState process = (ORMProcessState) ProcessDecorator.getDefaultProcess(request);
ObjectTransaction objTran = process.getTransaction ();
StripePlanNPO plan = (StripePlanNPO) process.getAttribute("StripePlanNPO");
if(plan == null)
{
plan = StripePlanNPO.createStripePlanNPO(objTran);
process.setAttribute("StripePlanNPO", plan);
%><%@include file="/saferedirect.jsp"%><%
}
ORMTableCellStyle commonCellStyle = new ORMTableCellStyle("nofilter nosort");
BaseBusinessClassFactory currencyPlanFactory = new BaseBusinessClassFactory(CurrencyPlanNPO.REFERENCE_CurrencyPlanNPO, objTran)
.onInitSetSingleAssoc("Plan", plan );
request.setAttribute("oneit.pageFormDetails", CollectionUtils.mapEntry("name", "SetupPlan").mapEntry("enctype", "multipart/form-data").toMap());
request.setAttribute("oneit.pageHeaderTitle", "Setup Stripe Plans");
%>
<%@include file="/editor/header.jsp"%>
<oneit:layout_total widths="<%= new double[] {1, 4, 6} %>" skin="bootstrap">
<oneit:skin tagName="layout_row">
<oneit:layout_label width="1"><oneit:ormlabel obj="<%= plan %>" field="ProductID" /></oneit:layout_label>
<oneit:layout_field width="1">
<oneit:ormInput obj="<%= plan %>" attributeName="ProductID" type="text" class="form-control" required="required"/>
</oneit:layout_field>
</oneit:skin>
<oneit:skin tagName="layout_row">
<oneit:layout_label width="1"><oneit:ormlabel obj="<%= plan %>" field="PlanName" /></oneit:layout_label>
<oneit:layout_field width="1">
<oneit:ormInput obj="<%= plan %>" attributeName="PlanName" type="text" class="form-control" required="required"/>
</oneit:layout_field>
</oneit:skin>
<oneit:skin tagName="layout_row">
<oneit:layout_label width="1"><oneit:ormlabel obj="<%= plan %>" field="ActiveJobs" /></oneit:layout_label>
<oneit:layout_field width="1">
<oneit:ormInput obj="<%= plan %>" attributeName="ActiveJobs" type="text" class="form-control" required="required"/>
</oneit:layout_field>
</oneit:skin>
<oneit:skin tagName="layout_row">
<oneit:layout_field width="2">
<oneit:ormtable class="ormtable cougartable" tableId="currency-plan-list"
rowObjFactory="<%= currencyPlanFactory %>"
rowObjects="<%= plan.getCurrencyPlansSet() %>"
customiser="<%= new TableCustomiser() %>">
<oneit:ormcol expression="CurrencyType" width="3" mode="ormEnum" cellStyle="<%= commonCellStyle %>"/>
<oneit:ormcol expression="PerJobAmount" width="4" mode="text" cellStyle="<%= commonCellStyle %>"/>
<oneit:ormcol expression="Amount" width="4" mode="text" cellStyle="<%= commonCellStyle %>"/>
<oneit:ormcol expression="" width="0.1" mode="jsp" cellStyle="<%= commonCellStyle %>"
jspName="/extensions/standard/ormtable/deleteORMRowButton.jsp" />
</oneit:ormtable>
<input type="button" value="Add" onclick="ormtable_addRow('currency-plan-list');" style="float: right" class="btn btn-default"/>
</oneit:layout_field>
</oneit:skin>
<oneit:skin tagName="layout_row">
<oneit:layout_field width="1">
<oneit:button value="Create Plan" name="createPlan" cssClass="btn btn-primary" requestAttribs='<%= CollectionUtils.EMPTY_MAP %>'/>
</oneit:layout_field>
</oneit:skin>
</oneit:layout_total>
<%@include file="/editor/footer.jsp"%>
\ 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