Commit cced2597 by Nilu

replace card, edit card functionality

parent 8c2fa209
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
<column name="has_client_support" type="Boolean" nullable="true"/> <column name="has_client_support" type="Boolean" nullable="true"/>
<column name="stripe_reference" type="String" nullable="true" length="100"/> <column name="stripe_reference" type="String" nullable="true" length="100"/>
<column name="stripe_subscription" type="String" nullable="true" length="100"/> <column name="stripe_subscription" type="String" nullable="true" length="100"/>
<column name="name_on_card" type="String" nullable="true" length="100"/>
<column name="card_post_code" type="String" nullable="true" length="10"/>
<column name="card_id" type="String" nullable="true" length="100"/>
<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"/>
</NODE> </NODE>
......
...@@ -21,6 +21,9 @@ CREATE TABLE tl_company ( ...@@ -21,6 +21,9 @@ CREATE TABLE tl_company (
has_client_support char(1) NULL, has_client_support char(1) NULL,
stripe_reference varchar(100) NULL, stripe_reference varchar(100) NULL,
stripe_subscription varchar(100) NULL, stripe_subscription varchar(100) NULL,
name_on_card varchar(100) NULL,
card_post_code varchar(10) NULL,
card_id varchar(100) 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
); );
......
...@@ -22,6 +22,9 @@ CREATE TABLE tl_company ( ...@@ -22,6 +22,9 @@ CREATE TABLE tl_company (
has_client_support char(1) NULL, has_client_support char(1) NULL,
stripe_reference varchar2(100) NULL, stripe_reference varchar2(100) NULL,
stripe_subscription varchar2(100) NULL, stripe_subscription varchar2(100) NULL,
name_on_card varchar2(100) NULL,
card_post_code varchar2(10) NULL,
card_id varchar2(100) 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
); );
......
...@@ -22,6 +22,9 @@ CREATE TABLE tl_company ( ...@@ -22,6 +22,9 @@ CREATE TABLE tl_company (
has_client_support char(1) NULL, has_client_support char(1) NULL,
stripe_reference varchar(100) NULL, stripe_reference varchar(100) NULL,
stripe_subscription varchar(100) NULL, stripe_subscription varchar(100) NULL,
name_on_card varchar(100) NULL,
card_post_code varchar(10) NULL,
card_id varchar(100) 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
); );
......
...@@ -15,15 +15,15 @@ import oneit.logging.LogMgr; ...@@ -15,15 +15,15 @@ import oneit.logging.LogMgr;
import oneit.objstore.StorageException; import oneit.objstore.StorageException;
import oneit.servlets.forms.SuccessfulResult; import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState; import oneit.servlets.process.ORMProcessState;
import performa.orm.Job;
import com.stripe.Stripe; import com.stripe.Stripe;
import com.stripe.exception.StripeException; import com.stripe.exception.StripeException;
import com.stripe.model.Card;
import com.stripe.model.Charge; import com.stripe.model.Charge;
import com.stripe.model.Customer; import oneit.logging.LoggingArea;
import com.stripe.model.Subscription; import oneit.security.SecUser;
import java.util.Calendar; import performa.orm.Company;
import java.util.Date; import performa.orm.CompanyUser;
import oneit.utils.DateDiff; import performa.utils.StripeUtils;
public class MakePaymentFP extends SaveFP public class MakePaymentFP extends SaveFP
...@@ -31,48 +31,39 @@ public class MakePaymentFP extends SaveFP ...@@ -31,48 +31,39 @@ public class MakePaymentFP extends SaveFP
public static final String STRIPE_KEY = ConfigMgr.getKeyfileString("stripe.key",""); public static final String STRIPE_KEY = ConfigMgr.getKeyfileString("stripe.key","");
public static final String STRIPE_PUB_KEY = ConfigMgr.getKeyfileString("stripe.pubkey",""); public static final String STRIPE_PUB_KEY = ConfigMgr.getKeyfileString("stripe.pubkey","");
private static final LoggingArea LOG = LoggingArea.createLoggingArea("MakePaymentFP");
@Override @Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map p) throws BusinessException, StorageException public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map p) throws BusinessException, StorageException
{ {
HttpServletRequest request = submission.getRequest(); HttpServletRequest request = submission.getRequest();
LogMgr.log(Job.LOG, LogLevel.PROCESSING1,"In MakePaymentFP : " ); LogMgr.log(LOG, LogLevel.PROCESSING1,"In MakePaymentFP : " );
Stripe.apiKey = STRIPE_KEY; Stripe.apiKey = STRIPE_KEY;
String token = request.getParameter("stripe-token-id");
if(StringUtils.subBlanks(token) == null)
{
throw new BusinessException("Updating card details failed, Please contact adminstrator for more info.");
}
try try
{ {
Customer customer = Customer.retrieve("cus_C8kIeItf64JnHe"); SecUser secUser = SecUser.getTXUser(process.getTransaction());
System.out.println("customer :: " + customer); CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Card card = StripeUtils.updateCardDetails(companyUser.getCompany(), token);
// Map<String, Object> item = new HashMap<>(); Company company = companyUser.getCompany();
// item.put("plan", "0001");
// company.setNameOnCard(card.getName());
// Map<String, Object> items = new HashMap<>(); company.setCardPostCode(card.getAddressZip());
// items.put("0", item); company.setCardID(card.getId());
//
// Map<String, Object> params = new HashMap<>();
// params.put("items", items);
// params.put("coupon", "EAP");
// params.put("customer", "cus_C8kIeItf64JnHe");
//
// Date today = new Date();
// Date trialExpiry = DateDiff.add(today, Calendar.DATE, 30);
//
// params.put("trial_end", trialExpiry.getTime() / 1000L);
//
// Subscription subscription = Subscription.create(params);
//
// System.out.println("subscription : " + subscription);
} }
catch(Exception e) catch(StorageException | FieldException e)
{ {
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while making payment");
System.out.println("error occured : " + e);
} }
// performStripePayment(submission);
return super.processForm(process, submission, p); return super.processForm(process, submission, p);
} }
...@@ -91,12 +82,13 @@ public class MakePaymentFP extends SaveFP ...@@ -91,12 +82,13 @@ public class MakePaymentFP extends SaveFP
Stripe.apiKey = STRIPE_KEY; Stripe.apiKey = STRIPE_KEY;
// Charge the Customer instead of the card: // Charge the Customer instead of the card:
Map<String, Object> chargeParams = new HashMap<String, Object>(); Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", NullArith.intVal(NullArith.multiply(100d, 100, 0d))); chargeParams.put("amount", NullArith.intVal(NullArith.multiply(100d, 100, 0d)));
chargeParams.put("currency", "aud"); chargeParams.put("currency", "aud");
chargeParams.put("description", "Charges of creating job"); chargeParams.put("description", "Charges of creating job");
chargeParams.put("source", token); chargeParams.put("source", token);
Charge charge; Charge charge;
try try
{ {
charge = Charge.create(chargeParams); charge = Charge.create(chargeParams);
...@@ -114,10 +106,7 @@ public class MakePaymentFP extends SaveFP ...@@ -114,10 +106,7 @@ public class MakePaymentFP extends SaveFP
errorMsg += ", Fraud Details :: " + charge.getFraudDetails(); errorMsg += ", Fraud Details :: " + charge.getFraudDetails();
} }
throw new BusinessException(errorMsg); throw new BusinessException(errorMsg);
} }
System.out.println("stripe response : " + charge.toJson());
} }
} }
\ No newline at end of file
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.Card;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.objstore.StorageException;
import oneit.security.SecUser;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import performa.orm.Company;
import performa.orm.CompanyUser;
import performa.utils.StripeUtils;
public class UpdateCardFP extends SaveFP
{
private static final LoggingArea LOG = LoggingArea.createLoggingArea("UpdateCardFP");
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map p) throws BusinessException, StorageException
{
LogMgr.log(LOG, LogLevel.PROCESSING1,"In UpdateCardFP : " );
Stripe.apiKey = StripeUtils.STRIPE_KEY;
try
{
HttpServletRequest request = submission.getRequest();
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
Card card = StripeUtils.retrieveCard(company);
Map<String, Object> updateParams = new HashMap<>();
String expiryDate = request.getParameter("expiry-date");
String name = request.getParameter("holder-name");
String addressZip = request.getParameter("address-zip");
if(expiryDate != null && !expiryDate.isEmpty() && expiryDate.length() == 7)
{
updateParams.put("exp_month", expiryDate.substring(0, 2));
updateParams.put("exp_year", expiryDate.substring(5, 7));
}
updateParams.put("name", name);
updateParams.put("address_zip", addressZip);
card.update(updateParams);
company.setNameOnCard(name);
company.setCardPostCode(addressZip);
}
catch (AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException e)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while making payment");
}
return super.processForm(process, submission, p);
}
}
\ No newline at end of file
package performa.orm; package performa.orm;
import com.stripe.model.Card;
import oneit.logging.LoggingArea; import oneit.logging.LoggingArea;
import oneit.objstore.ObjectStatus; import oneit.objstore.ObjectStatus;
import oneit.objstore.ValidationContext; import oneit.objstore.ValidationContext;
...@@ -10,6 +11,7 @@ import oneit.utils.CollectionUtils; ...@@ -10,6 +11,7 @@ import oneit.utils.CollectionUtils;
import oneit.utils.StringUtils; import oneit.utils.StringUtils;
import oneit.utils.math.NullArith; import oneit.utils.math.NullArith;
import oneit.utils.parsers.FieldException; import oneit.utils.parsers.FieldException;
import performa.utils.StripeUtils;
public class Company extends BaseCompany public class Company extends BaseCompany
...@@ -133,4 +135,20 @@ public class Company extends BaseCompany ...@@ -133,4 +135,20 @@ public class Company extends BaseCompany
return null; return null;
} }
public String getCardNumber() throws FieldException
{
Card card = StripeUtils.retrieveCard(this);
return card != null ? "xxxx-xxxx-xxxx-" + card.getLast4() : "";
}
public String getExpiry () throws FieldException
{
Card card = StripeUtils.retrieveCard(this);
return card != null ? String.format("%02d", card.getExpMonth()) + " / " + (card.getExpYear() % 100) : "";
}
} }
\ No newline at end of file
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
<ATTRIB name="HasClientSupport" type="Boolean" dbcol="has_client_support" mandatory="false" defaultValue="Boolean.FALSE"/> <ATTRIB name="HasClientSupport" type="Boolean" dbcol="has_client_support" mandatory="false" defaultValue="Boolean.FALSE"/>
<ATTRIB name="StripeReference" type="String" dbcol="stripe_reference" length="100"/> <ATTRIB name="StripeReference" type="String" dbcol="stripe_reference" length="100"/>
<ATTRIB name="StripeSubscription" type="String" dbcol="stripe_subscription" length="100"/> <ATTRIB name="StripeSubscription" type="String" dbcol="stripe_subscription" length="100"/>
<ATTRIB name="NameOnCard" type="String" dbcol="name_on_card" length="100"/>
<ATTRIB name="CardPostCode" type="String" dbcol="card_post_code" length="10"/>
<ATTRIB name="CardID" type="String" dbcol="card_id" length="100"/>
<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"/>
......
...@@ -6,12 +6,16 @@ import com.stripe.exception.APIException; ...@@ -6,12 +6,16 @@ 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.model.Card;
import com.stripe.model.Customer; import com.stripe.model.Customer;
import com.stripe.model.ExternalAccount;
import com.stripe.model.ExternalAccountCollection;
import com.stripe.model.Plan; import com.stripe.model.Plan;
import com.stripe.model.Subscription; import com.stripe.model.Subscription;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import oneit.appservices.config.ConfigMgr; import oneit.appservices.config.ConfigMgr;
import oneit.logging.LogLevel; import oneit.logging.LogLevel;
...@@ -61,7 +65,7 @@ public class StripeUtils ...@@ -61,7 +65,7 @@ public class StripeUtils
} }
public static void updateCardDetails(Company company, String token) throws FieldException public static Card updateCardDetails(Company company, String token) throws FieldException
{ {
try try
{ {
...@@ -76,13 +80,34 @@ public class StripeUtils ...@@ -76,13 +80,34 @@ public class StripeUtils
updateParams.put("source", token); updateParams.put("source", token);
customer.update(updateParams); customer = customer.update(updateParams);
return (Card) customer.getSources().retrieve(customer.getDefaultSource());
}
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while updating a customer in stripe");
}
return null;
}
public static Card retrieveCard(Company company) throws FieldException
{
try
{
Customer customer = Customer.retrieve(company.getStripeReference());
return (Card) customer.getSources().retrieve(customer.getDefaultSource());
} }
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex) catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException 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;
} }
......
...@@ -5454,6 +5454,15 @@ label, label .label-title span { ...@@ -5454,6 +5454,15 @@ label, label .label-title span {
font-family: "Usual-Medium"; font-family: "Usual-Medium";
margin-top: 20px; margin-top: 20px;
} }
.edit-card-link
{
text-decoration: underline;
font-size: 13px;
}
.deselected-link{
color: #03a0e7;
}
/*My Company Pages End*/ /*My Company Pages End*/
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
<FORM name="*.processCulture" factory="Participant" class="performa.form.ProcessCultureFP"/> <FORM name="*.processCulture" factory="Participant" class="performa.form.ProcessCultureFP"/>
<FORM name="*.savePayment" factory="Participant" class="performa.form.MakePaymentFP"/> <FORM name="*.savePayment" factory="Participant" class="performa.form.MakePaymentFP"/>
<FORM name="*.managePlans" factory="Participant" class="performa.form.ManagePlansFP"/> <FORM name="*.managePlans" factory="Participant" class="performa.form.ManagePlansFP"/>
<FORM name="*.updateCard" factory="Participant" class="performa.form.UpdateCardFP"/>
</NODE> </NODE>
<NODE name="job_assessment_criteria_add_jsp" factory="Participant"> <NODE name="job_assessment_criteria_add_jsp" factory="Participant">
......
...@@ -77,6 +77,8 @@ ...@@ -77,6 +77,8 @@
<RenderMode name="Page" preIncludeJSP="extensions/adminportal/my_company.jsp"/> <RenderMode name="Page" preIncludeJSP="extensions/adminportal/my_company.jsp"/>
<RenderMode name="ManagePlan" preIncludeJSP="extensions/adminportal/manage_plan.jsp"/> <RenderMode name="ManagePlan" preIncludeJSP="extensions/adminportal/manage_plan.jsp"/>
<RenderMode name="Billing" preIncludeJSP="extensions/adminportal/billing.jsp"/> <RenderMode name="Billing" preIncludeJSP="extensions/adminportal/billing.jsp"/>
<RenderMode name="ReplaceCard" preIncludeJSP="extensions/adminportal/replace_card.jsp"/>
<RenderMode name="EditCard" preIncludeJSP="extensions/adminportal/edit_card.jsp"/>
<RenderMode name="Invoices" preIncludeJSP="extensions/adminportal/invoices.jsp"/> <RenderMode name="Invoices" preIncludeJSP="extensions/adminportal/invoices.jsp"/>
</NODE> </NODE>
</MAP> </MAP>
......
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
Debug.assertion(company != null , "Invalid company in admin portal my company"); Debug.assertion(company != null , "Invalid company in admin portal my company");
String nextPage = WebUtils.getSamePageInRenderMode(request, "Billing"); String nextPage = WebUtils.getSamePageInRenderMode(request, "Billing");
String replaceCardPage = WebUtils.getSamePageInRenderMode(request, "ReplaceCard");
%> %>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() $(document).ready(function()
{ {
recalcFunction = setupRecalc ($("form"), {'recalcOnError':true}); recalcFunction = setupRecalc ($("makePayment"), {'recalcOnError':true});
}); });
</script> </script>
...@@ -42,68 +43,30 @@ ...@@ -42,68 +43,30 @@
<label class="label-20">Billing</label><br/> <label class="label-20">Billing</label><br/>
<span id="card-errors" style="color: #eb1c26; font-size: 15px;"></span> <span id="card-errors" style="color: #eb1c26; font-size: 15px;"></span>
</div> </div>
<%
if(company.getCardID() != null)
{
%>
<oneit:dynInclude page="/extensions/adminportal/inc/existing_card.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"
Company="<%= company %>" IsEdit="<%= false %>" IsReplace="<%= false %>"/>
<%
}
else
{
%>
<div> <div>
<label class="label-14 bold">Add a payment method</label><br/> <label class="label-14 bold">Add a payment method</label><br/>
<label class="label-14">Your card details will be saved for future billing</label> <label class="label-14">Your card details will be saved for future billing</label>
</div> </div>
<div class="grey-area"> <oneit:dynInclude page="/extensions/adminportal/inc/card_details.jsp" data="<%= CollectionUtils.EMPTY_MAP%>" Company="<%= company %>"/>
<div class="form-group"> <%
<label>Card Number</label> }
<div id="card-number" class="form-control"> %>
</div>
</div>
<div class="form-group">
<label>Name on Card</label>
<oneit:ormInput obj="<%= company %>" type="text" attributeName="CompanyName" cssClass="form-control" />
</div>
<div class="form-group row">
<div class="col-md-4">
<label>Expires</label>
<div id="card-expiry" class="form-control">
</div>
</div>
<div class="col-md-4">
<label>CCV</label>
<div id="card-cvc" class="form-control">
</div>
</div>
<div class="col-md-4">
<label>Postal Code</label>
<oneit:ormInput obj="<%= company %>" type="text" attributeName="PostCode" cssClass="form-control" />
</div> </div>
</div> </div>
<div class="form-group">
<oneit:button value="Save Card" name="saveCompany" cssClass="btn btn-primary btn-green large-btn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("Company", company)
.toMap() %>" />
</div>
</div>
</div>
</div>
</div> </div>
</oneit:form> </oneit:form>
<oneit:form name="editCompany" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="form-group hide">
<input type="hidden" name="stripe-token-id" />
</div>
</div>
</div>
<oneit:button value="Pay" name="savePayment" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
</oneit:form>
<script src="https://js.stripe.com/v3/"></script>
<script>
var stripePubKey = '<%= MakePaymentFP.STRIPE_PUB_KEY %>';
</script>
<oneit:script>
<!-- MUST be included after initializing stripePubKey -->
<oneit:script src="/scripts/performaStripe.js"/>
</oneit:script>
</div> </div>
</div> </div>
</div> </div>
......
<%@ page extends="oneit.servlets.jsp.JSPInclude" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>
<oneit:dynIncluded>
<%
SecUser loggedInUser = SecUser.getTXUser(transaction);
CompanyUser companyUser = loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
Debug.assertion(company != null , "Invalid company in admin portal my company");
String nextPage = WebUtils.getSamePageInRenderMode(request, "Billing");
%>
<script type="text/javascript">
$(document).ready(function()
{
recalcFunction = setupRecalc ($("makePayment"), {'recalcOnError':true});
});
</script>
<div class="container-fluid">
<div class="row content">
<div class="main-content-area">
<h1 class="page-title">My Hiring Team</h1>
<div class="my-company-area">
<oneit:form name="makePayment" method="post" enctype="multipart/form-data">
<div style="padding-left: 15px; padding-right: 15px;">
<oneit:dynInclude page="/extensions/applicantportal/inc/multifieldtext.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"/>
</div>
<oneit:dynInclude page="/extensions/adminportal/inc/my_company_tabs.jsp" TabNumber="3" data="<%= CollectionUtils.EMPTY_MAP%>"/>
<div class="company-content-area">
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="company-detail">
<div class="tabpage-title">
<label class="label-20">Billing</label><br/>
<span id="card-errors" style="color: #eb1c26; font-size: 15px;"></span>
</div>
<%
if(company.getCardID() != null)
{
%>
<oneit:dynInclude page="/extensions/adminportal/inc/existing_card.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"
Company="<%= company %>" IsEdit="<%= true %>" IsReplace="<%= false %>"/>
<%
}
%>
</div>
<div>
<div>
<label class="label-14 bold">Edit Card</label><br/>
<label class="label-14">Your card details will be saved for future billing</label>
</div>
<oneit:dynInclude page="/extensions/adminportal/inc/card_details.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"
Company="<%= company %>" IsEdit="<%= true %>" IsReplace="<%= false %>"/>
</div>
</div>
</div>
</oneit:form>
<oneit:form name="editCompany" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="form-group hide">
<input type="hidden" name="expiry-date" />
</div>
<div class="form-group hide">
<input type="hidden" name="holder-name" />
</div>
<div class="form-group hide">
<input type="hidden" name="address-zip" />
</div>
</div>
</div>
<oneit:button value="Pay" name="updateCard" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
</oneit:form>
<script src="https://js.stripe.com/v2/"></script>
<script src="https://js.stripe.com/v3/"></script>
<script>
var stripePubKey = '<%= MakePaymentFP.STRIPE_PUB_KEY %>';
</script>
<oneit:script>
<!-- MUST be included after initializing stripePubKey -->
<oneit:script src="/scripts/updateCardStripe.js"/>
</oneit:script>
</div>
</div>
</div>
</div>
</oneit:dynIncluded>
<%@ page extends="oneit.servlets.jsp.JSPInclude" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>
<%
Company company = (Company) getData(request, "Company");
boolean isReplace = (boolean) getData(request, "IsReplace");
boolean isEdit = (boolean) getData(request, "IsEdit");
String nextPage = WebUtils.getSamePageInRenderMode(request, "Billing");
%>
<oneit:dynIncluded>
<script>
$(document).ready(function() {
$('#cardExpiry').attr("maxlength", 7);
$("#cardExpiry" ).keydown(function(e) {
var val = $(this).val();
if(e.keyCode == 8) {
temp_val = val.substring(0,1);
$(this).val(temp_val);
}
if(!isNaN(val)) {
if(val.length === 3 || val.length === 2)
{
temp_val = val + " / ";
$(this).val(temp_val);
}
else
{
if(val > 1 && val < 10 && val.length === 1) {
temp_val = "0" + val + " / ";
$(this).val(temp_val);
}
else if (val >= 1 && val < 10 && val.length === 2 && e.keyCode != 7) {
temp_val = val + " / ";
$(this).val(temp_val);
}
else if(val > 9 && val.length === 2 && e.keyCode !== 7) {
temp_val = val + " / ";
$(this).val(temp_val);
}
}
}
});
});
</script>
<div class="grey-area">
<div class="form-group">
<label>Card Number</label>
<%
if(isEdit)
{
%>
<input type="text" name="cardNumber" value="<%= company.getCardNumber() %>" class="form-control" readonly>
<%
}
else
{
%>
<div id="card-number" class="form-control" style="padding-top:15px;">
</div>
<%
}
%>
</div>
<div class="form-group">
<label>Name on Card</label>
<oneit:ormInput obj="<%= company %>" type="text" attributeName="NameOnCard" cssClass="form-control" id="NameOnCard" data-stripe="name"/>
</div>
<div class="form-group row">
<div class="col-md-4">
<label>Expires</label>
<%
if(isEdit)
{
%>
<input type="text" id="cardExpiry" class="form-control" placeholder="MM / YY" value="<%= company.getExpiry() %>">
<%
}
else
{
%>
<div id="card-expiry" class="form-control" style="padding-top:15px;">
</div>
<%
}
%>
</div>
<div class="col-md-4">
<label>CCV</label>
<%
if(isEdit)
{
%>
<input type="text" name="ccv" value="" class="form-control" readonly>
<%
}
else
{
%>
<div id="card-cvc" class="form-control" style="padding-top:15px;">
</div>
<%
}
%>
</div>
<div class="col-md-4">
<label>Postal Code</label>
<oneit:ormInput obj="<%= company %>" type="text" attributeName="CardPostCode" cssClass="form-control" id="PostCode" />
</div>
</div>
<div class="form-group">
<oneit:button value="Save Card" name="updateCard" cssClass="btn btn-primary btn-green large-btn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("Company", company)
.toMap() %>" />
</div>
<input type="hidden" name="expiration-date" />
</div>
</oneit:dynIncluded>
<%@ page extends="oneit.servlets.jsp.JSPInclude" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>
<%
Company company = (Company) getData(request, "Company");
boolean isReplace = (boolean) getData(request, "IsReplace");
boolean isEdit = (boolean) getData(request, "IsEdit");
String replaceCardPage = WebUtils.getSamePageInRenderMode(request, "ReplaceCard");
String editCardPage = WebUtils.getSamePageInRenderMode(request, "EditCard");
%>
<oneit:dynIncluded>
<div class="form-group row">
<div class="col-md-3">
<label>Card on file</label>
</div>
<div class="col-md-5">
<label><%= company.getCardNumber() %></label>
</div>
<div class="col-md-2">
<oneit:button value=" " name="gotoPage" skin="link" cssClass="<%= "edit-card-link " + (isEdit ? "" : "deselected-link")%>"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", editCardPage)
.toMap() %>">
Edit Card
</oneit:button>
</div>
<div class="col-md-2">
<oneit:button value=" " name="gotoPage" skin="link" cssClass="<%= "edit-card-link " + (isReplace ? "" : "deselected-link")%>"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", replaceCardPage)
.toMap() %>">
Replace Card
</oneit:button>
</div>
</div>
</oneit:dynIncluded>
<%@ page extends="oneit.servlets.jsp.JSPInclude" %>
<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>
<oneit:dynIncluded>
<%
SecUser loggedInUser = SecUser.getTXUser(transaction);
CompanyUser companyUser = loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
Debug.assertion(company != null , "Invalid company in admin portal my company");
String nextPage = WebUtils.getSamePageInRenderMode(request, "Billing");
%>
<script type="text/javascript">
$(document).ready(function()
{
recalcFunction = setupRecalc ($("makePayment"), {'recalcOnError':true});
});
</script>
<div class="container-fluid">
<div class="row content">
<div class="main-content-area">
<h1 class="page-title">My Hiring Team</h1>
<div class="my-company-area">
<oneit:form name="makePayment" method="post" enctype="multipart/form-data">
<div style="padding-left: 15px; padding-right: 15px;">
<oneit:dynInclude page="/extensions/applicantportal/inc/multifieldtext.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"/>
</div>
<oneit:dynInclude page="/extensions/adminportal/inc/my_company_tabs.jsp" TabNumber="3" data="<%= CollectionUtils.EMPTY_MAP%>"/>
<div class="company-content-area">
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="company-detail">
<div class="tabpage-title">
<label class="label-20">Billing</label><br/>
<span id="card-errors" style="color: #eb1c26; font-size: 15px;"></span>
</div>
<%
if(company.getCardID() != null)
{
%>
<oneit:dynInclude page="/extensions/adminportal/inc/existing_card.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"
Company="<%= company %>" IsEdit="<%= false %>" IsReplace="<%= true %>"/>
<%
}
%>
</div>
<div>
<div>
<label class="label-14 bold">Replace Card</label><br/>
<label class="label-14">Your card details will be saved for future billing</label>
</div>
<oneit:dynInclude page="/extensions/adminportal/inc/card_details.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"
Company="<%= company %>" IsEdit="<%= false %>" IsReplace="<%= true %>"/>
</div>
</div>
</div>
</oneit:form>
<oneit:form name="editCompany" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="form-group hide">
<input type="hidden" name="stripe-token-id" />
</div>
</div>
</div>
<oneit:button value="Pay" name="savePayment" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
</oneit:form>
<script src="https://js.stripe.com/v3/"></script>
<script>
var stripePubKey = '<%= MakePaymentFP.STRIPE_PUB_KEY %>';
</script>
<oneit:script>
<!-- MUST be included after initializing stripePubKey -->
<oneit:script src="/scripts/performaStripe.js"/>
</oneit:script>
</div>
</div>
</div>
</div>
</oneit:dynIncluded>
<?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_company</tableName>
<column name="name_on_card" type="String" nullable="true" length="100"/>
<column name="card_post_code" type="String" nullable="true" length="10"/>
<column name="card_id" type="String" nullable="true" length="100"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
...@@ -12,34 +12,26 @@ var elements = stripe.elements(); ...@@ -12,34 +12,26 @@ var elements = stripe.elements();
var style = { var style = {
base: { base: {
// Add your base input styles here. For example: // Add your base input styles here. For example:
fontSize: '16px', fontSize: '14px',
color: "#32325d", fontFamily: '"Usual-Light"',
color: "#555",
'::placeholder': {
color: '#DBDBDF',
fontSize: '18px',
},
// padding-top: "7px !important",
} }
}; };
var cardNumber = elements.create('cardNumber', {style: style}); var cardNumber = elements.create('cardNumber', {style: style, placeholder: ''});
cardNumber.mount('#card-number'); cardNumber.mount('#card-number');
var cardExpiry = elements.create('cardExpiry', {style: style}); var cardExpiry = elements.create('cardExpiry', {style: style});
cardExpiry.mount('#card-expiry'); cardExpiry.mount('#card-expiry');
var cardCvc = elements.create('cardCvc', {style: style}); var cardCvc = elements.create('cardCvc', {style: style, placeholder: ''});
cardCvc.mount('#card-cvc'); cardCvc.mount('#card-cvc');
// Create an instance of the card Element
//var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>
//card.mount('#card-element');
//card.addEventListener('change', function(event) {
// var displayError = document.getElementById('card-errors');
// if (event.error) {
// displayError.textContent = event.error.message;
// } else {
// displayError.textContent = '';
// }
//});
cardNumber.addEventListener('change', function(event) { cardNumber.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors'); var displayError = document.getElementById('card-errors');
if (event.error) { if (event.error) {
...@@ -71,7 +63,10 @@ var form = document.getElementById('makePayment'); ...@@ -71,7 +63,10 @@ var form = document.getElementById('makePayment');
form.addEventListener('submit', function(event) { form.addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();
stripe.createToken(cardNumber, {name: "Demo Card Name"}).then(function(result) { var nameOnCard = document.getElementById('NameOnCard').value;
var postalCode = document.getElementById('PostCode').value;
stripe.createToken(cardNumber, {name: nameOnCard, address_zip : postalCode}).then(function(result) {
if (result.error) { if (result.error) {
// Inform the customer that there was an error // Inform the customer that there was an error
var errorElement = document.getElementById('card-errors'); var errorElement = document.getElementById('card-errors');
...@@ -80,24 +75,6 @@ form.addEventListener('submit', function(event) { ...@@ -80,24 +75,6 @@ form.addEventListener('submit', function(event) {
// Send the token to your server // Send the token to your server
$('input[name=stripe-token-id]').val(result.token.id); $('input[name=stripe-token-id]').val(result.token.id);
$('#payNow').click(); $('#payNow').click();
// stripeTokenHandler(result.token);
} }
}); });
}); });
\ No newline at end of file
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
// var form = document.getElementById('payment-form');
// var hiddenInput = document.createElement('input');
// hiddenInput.setAttribute('type', 'hidden');
// hiddenInput.setAttribute('name', 'stripeToken');
// hiddenInput.setAttribute('value', token.id);
// form.appendChild(hiddenInput);
alert(token.id);
$('input[name=stripe-token-id]').val(token.id);
// $('div.stripedetails').removeClass('stripedetails');
alert($('input[name=stripe-token-id]').val());
$('#payNow').click();
// Submit the form
// form.submit();
}
\ No newline at end of file
/**
* Reference : https://stripe.com/docs/stripe-js#elements
*/
// Create a Stripe client
var stripe = Stripe(stripePubKey);
var form = document.getElementById('makePayment');
form.addEventListener('submit', function(event) {
event.preventDefault();
var cardExpiry = document.getElementById('cardExpiry').value;
if(cardExpiry.length !== 0 && !Stripe.card.validateExpiry(cardExpiry))
{
var displayError = document.getElementById('card-errors');
displayError.textContent = "Please enter a valid expiry";
}
else
{
$('input[name=expiry-date]').val(document.getElementById('cardExpiry').value);
$('input[name=holder-name]').val(document.getElementById('NameOnCard').value);
$('input[name=address-zip]').val(document.getElementById('PostCode').value);
$('#payNow').click();
}
});
\ 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