Commit daaf829c by Nilu

fix pay as you go issues when opening jobs

parent 72ae2747
package performa.form;
import com.stripe.Stripe;
import java.util.HashMap;
import java.util.Map;
import oneit.appservices.config.ConfigMgr;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.StringUtils;
import oneit.utils.math.NullArith;
import oneit.utils.parsers.FieldException;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Card;
import com.stripe.model.Charge;
import java.util.Calendar;
import java.util.Date;
import oneit.logging.LoggingArea;
import oneit.security.SecUser;
import oneit.utils.DateDiff;
import performa.intercom.utils.IntercomUtils;
import performa.orm.Company;
import performa.orm.CompanyUser;
import performa.orm.Job;
import performa.orm.types.AssessmentType;
import performa.orm.types.JobStatus;
import performa.utils.StripeUtils;
......@@ -36,80 +41,85 @@ public class MakePaymentFP extends SaveFP
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map p) throws BusinessException, StorageException
{
HttpServletRequest request = submission.getRequest();
LogMgr.log(LOG, LogLevel.PROCESSING1,"In MakePaymentFP : " );
HttpServletRequest request = submission.getRequest();
Boolean ppj = request.getAttribute("PPJ") != null ? (Boolean) request.getAttribute("PPJ") : Boolean.FALSE;
Boolean editCard = request.getAttribute("EditCard") != null ? (Boolean) request.getAttribute("EditCard") : Boolean.FALSE;
Boolean replaceCard = request.getAttribute("ReplaceCard") != null ? (Boolean) request.getAttribute("ReplaceCard") : Boolean.FALSE;
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
Job job = (Job) process.getAttribute("Job");
Stripe.apiKey = STRIPE_KEY;
String token = request.getParameter("stripe-token-id");
LogMgr.log(LOG, LogLevel.PROCESSING1,"In MakePaymentFP from customer to open job: " + company.getStripeReference());
if(editCard)
{
UpdateCardFP.updateCardDetails(process, submission);
}
if(StringUtils.subBlanks(token) == null)
if(replaceCard)
{
throw new BusinessException("Updating card details failed, Please contact adminstrator for more info.");
ReplaceCardFP.replaceCardDetails(process, submission);
}
try
if(company.getCardID() != null && ppj)
{
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Card card = StripeUtils.updateCardDetails(companyUser.getCompany(), token);
Company company = companyUser.getCompany();
try
{
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", NullArith.intVal(NullArith.multiply(job.getAssessmentType() == AssessmentType.COMPREHENSIVE ? 499.0 : 399.0, 100, 0d)));
chargeParams.put("currency", "aud");
chargeParams.put("description", "Charges of creating job");
chargeParams.put("customer", company.getStripeReference());
Charge.create(chargeParams);
}
catch (StripeException e)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while making a payment of company stripe " + company.getStripeReference());
throw new BusinessException("Stripe payment was failed, Please contact adminstrator for more info.");
}
}
if(company.getCardID() == null)
{
Card card = StripeUtils.retrieveCard(company);
company.setNameOnCard(card.getName());
company.setCardPostCode(card.getAddressZip());
company.setCardID(card.getId());
// cannot subscribe to a plan without card details
StripeUtils.updatePlan(company);
}
catch(StorageException | FieldException e)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while making payment");
}
return super.processForm(process, submission, p);
}
private void performStripePayment(SubmissionDetails submission) throws FieldException, BusinessException
{
HttpServletRequest request = submission.getRequest();
String token = request.getParameter("stripe-token-id");
if(StringUtils.subBlanks(token) == null)
if(!ppj && company.getPaymentPlan() != null)
{
throw new BusinessException("Stripe payment was failed, Please contact adminstrator for more info.");
// cannot subscribe to a plan without card details
StripeUtils.updatePlan(company);
}
Stripe.apiKey = STRIPE_KEY;
// Charge the Customer instead of the card:
Map<String, Object> chargeParams = new HashMap<>();
chargeParams.put("amount", NullArith.intVal(NullArith.multiply(100d, 100, 0d)));
chargeParams.put("currency", "aud");
chargeParams.put("description", "Charges of creating job");
chargeParams.put("source", token);
Charge charge;
try
{
charge = Charge.create(chargeParams);
}
catch (StripeException e)
job.setApplyBy(DateDiff.add(DateDiff.getToday(), Calendar.DATE, 30));
job.setOpenDate(new Date());
job.setJobStatus(JobStatus.OPEN);
job.setLastEdited(new Date());
if(job.getShortenedURL() == null)
{
throw new BusinessException("Stripe payment failure. Reason :: " + e.getMessage());
job.createShortenedURL();
}
if(charge.getFailureCode() != null)
// restarting process as custom attributes needs to be updated to intercom
completeProcessRestartAndRestoreAttribs(process, request);
secUser = SecUser.getTXUser(process.getTransaction());
companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
// Update company in intercom
if(companyUser.getCompany() != null)
{
String errorMsg = "Stripe payment failure Code :: " + charge.getFailureCode() + ", Message :: " + charge.getFailureMessage();
if(charge.getFraudDetails() != null)
{
errorMsg += ", Fraud Details :: " + charge.getFraudDetails();
}
throw new BusinessException(errorMsg);
IntercomUtils.updateCompany(companyUser.getCompany());
}
return super.processForm(process, submission, p);
}
}
\ No newline at end of file
package performa.form;
import com.stripe.Stripe;
import com.stripe.model.Card;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.appservices.config.ConfigMgr;
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 oneit.utils.StringUtils;
import oneit.utils.parsers.FieldException;
import performa.orm.Company;
import performa.orm.CompanyUser;
import performa.utils.StripeUtils;
public class ReplaceCardFP extends SaveFP
{
public static final String STRIPE_KEY = ConfigMgr.getKeyfileString("stripe.key","");
public static final String STRIPE_PUB_KEY = ConfigMgr.getKeyfileString("stripe.pubkey","");
private static final LoggingArea LOG = LoggingArea.createLoggingArea("ReplaceCardFP");
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map p) throws BusinessException, StorageException
{
LogMgr.log(LOG, LogLevel.PROCESSING1,"In ReplaceCardFP to replace card details");
replaceCardDetails(process, submission);
return super.processForm(process, submission, p);
}
public static void replaceCardDetails(ORMProcessState process, SubmissionDetails submission) throws BusinessException
{
HttpServletRequest request = submission.getRequest();
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
{
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Card card = StripeUtils.updateCardDetails(companyUser.getCompany(), token);
Company company = companyUser.getCompany();
LogMgr.log(LOG, LogLevel.PROCESSING1,"In ReplaceCardFP replacing card details of company: " + company );
company.setNameOnCard(card.getName());
company.setCardPostCode(card.getAddressZip());
company.setCardID(card.getId());
// cannot subscribe to a plan without card details
if(company.getPaymentPlan() != null)
{
StripeUtils.updatePlan(company);
}
}
catch(StorageException | FieldException e)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while replacing stripe card details");
}
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.parsers.FieldException;
import performa.orm.Company;
import performa.orm.CompanyUser;
import performa.utils.StripeUtils;
......@@ -35,6 +36,14 @@ public class UpdateCardFP extends SaveFP
Stripe.apiKey = StripeUtils.STRIPE_KEY;
updateCardDetails(process, submission);
return super.processForm(process, submission, p);
}
public static void updateCardDetails(ORMProcessState process, SubmissionDetails submission) throws FieldException
{
try
{
HttpServletRequest request = submission.getRequest();
......@@ -43,35 +52,40 @@ public class UpdateCardFP extends SaveFP
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
Card card = StripeUtils.retrieveCard(company);
LogMgr.log(LOG, LogLevel.PROCESSING1,"In UpdateCardFP updating card details of user : ", company, " card : " , card );
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));
}
if(name != null && !name.isEmpty())
{
updateParams.put("name", name);
company.setNameOnCard(name);
}
updateParams.put("name", name);
updateParams.put("address_zip", addressZip);
if(addressZip != null && !addressZip.isEmpty())
{
updateParams.put("address_zip", addressZip);
company.setCardPostCode(addressZip);
}
Card updatedCard = card.update(updateParams);
company.setNameOnCard(name);
company.setCardPostCode(addressZip);
LogMgr.log(LOG, LogLevel.PROCESSING1,"Updated card details of user : ", company, " updated card : " , updatedCard );
}
catch (AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException e)
{
LogMgr.log(LOG, LogLevel.PROCESSING1, e, "Error while updating card details of user");
}
return super.processForm(process, submission, p);
}
}
\ No newline at end of file
......@@ -67,6 +67,8 @@ public abstract class BaseCompany extends BaseBusinessClass
public static final String FIELD_IsLogoDeleted = "IsLogoDeleted";
public static final String FIELD_CompletedProfile = "CompletedProfile";
public static final String FIELD_PaymentJobCount = "PaymentJobCount";
public static final String FIELD_StripeLast4 = "StripeLast4";
public static final String FIELD_StripeBrand = "StripeBrand";
public static final String SINGLEREFERENCE_AddedByUser = "AddedByUser";
public static final String SINGLEREFERENCE_PaymentPlan = "PaymentPlan";
public static final String MULTIPLEREFERENCE_Users = "Users";
......@@ -102,6 +104,8 @@ public abstract class BaseCompany extends BaseBusinessClass
private static final DefaultAttributeHelper<Company> HELPER_IsLogoDeleted = DefaultAttributeHelper.INSTANCE;
private static final DefaultAttributeHelper<Company> HELPER_CompletedProfile = DefaultAttributeHelper.INSTANCE;
private static final DefaultAttributeHelper<Company> HELPER_PaymentJobCount = DefaultAttributeHelper.INSTANCE;
private static final DefaultAttributeHelper<Company> HELPER_StripeLast4 = DefaultAttributeHelper.INSTANCE;
private static final DefaultAttributeHelper<Company> HELPER_StripeBrand = DefaultAttributeHelper.INSTANCE;
// Private attributes corresponding to business object data
......@@ -128,6 +132,8 @@ public abstract class BaseCompany extends BaseBusinessClass
private Boolean _IsLogoDeleted;
private Boolean _CompletedProfile;
private Integer _PaymentJobCount;
private String _StripeLast4;
private String _StripeBrand;
// Private attributes corresponding to single references
......@@ -151,6 +157,8 @@ public abstract class BaseCompany extends BaseBusinessClass
private static final AttributeValidator[] FIELD_IsLogoDeleted_Validators;
private static final AttributeValidator[] FIELD_CompletedProfile_Validators;
private static final AttributeValidator[] FIELD_PaymentJobCount_Validators;
private static final AttributeValidator[] FIELD_StripeLast4_Validators;
private static final AttributeValidator[] FIELD_StripeBrand_Validators;
private static final AttributeValidator[] FIELD_CompanyName_Validators;
private static final AttributeValidator[] FIELD_CompanyLogo_Validators;
private static final AttributeValidator[] FIELD_HiringTeamType_Validators;
......@@ -193,6 +201,8 @@ public abstract class BaseCompany extends BaseBusinessClass
FIELD_IsLogoDeleted_Validators = (AttributeValidator[])setupAttribMetaData_IsLogoDeleted(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_CompletedProfile_Validators = (AttributeValidator[])setupAttribMetaData_CompletedProfile(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_PaymentJobCount_Validators = (AttributeValidator[])setupAttribMetaData_PaymentJobCount(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_StripeLast4_Validators = (AttributeValidator[])setupAttribMetaData_StripeLast4(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_StripeBrand_Validators = (AttributeValidator[])setupAttribMetaData_StripeBrand(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_CompanyName_Validators = (AttributeValidator[])setupAttribMetaData_CompanyName(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_CompanyLogo_Validators = (AttributeValidator[])setupAttribMetaData_CompanyLogo(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_HiringTeamType_Validators = (AttributeValidator[])setupAttribMetaData_HiringTeamType(validatorMapping).toArray (new AttributeValidator[0]);
......@@ -405,6 +415,40 @@ public abstract class BaseCompany extends BaseBusinessClass
}
// Meta Info setup
private static List setupAttribMetaData_StripeLast4(Map validatorMapping)
{
Map metaInfo = new HashMap ();
metaInfo.put ("name", "StripeLast4");
metaInfo.put ("type", "String");
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.StripeLast4:", metaInfo);
ATTRIBUTES_METADATA_Company.put (FIELD_StripeLast4, Collections.unmodifiableMap (metaInfo));
List validators = BaseBusinessClass.getAttribValidators(Company.class, "StripeLast4", metaInfo, validatorMapping);
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for Company.StripeLast4:", validators);
return validators;
}
// Meta Info setup
private static List setupAttribMetaData_StripeBrand(Map validatorMapping)
{
Map metaInfo = new HashMap ();
metaInfo.put ("name", "StripeBrand");
metaInfo.put ("type", "String");
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.StripeBrand:", metaInfo);
ATTRIBUTES_METADATA_Company.put (FIELD_StripeBrand, Collections.unmodifiableMap (metaInfo));
List validators = BaseBusinessClass.getAttribValidators(Company.class, "StripeBrand", metaInfo, validatorMapping);
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for Company.StripeBrand:", validators);
return validators;
}
// Meta Info setup
private static List setupAttribMetaData_CompanyName(Map validatorMapping)
{
Map metaInfo = new HashMap ();
......@@ -772,6 +816,8 @@ public abstract class BaseCompany extends BaseBusinessClass
_IsLogoDeleted = (Boolean)(Boolean.FALSE);
_CompletedProfile = (Boolean)(Boolean.FALSE);
_PaymentJobCount = (Integer)(HELPER_PaymentJobCount.initialise (_PaymentJobCount));
_StripeLast4 = (String)(HELPER_StripeLast4.initialise (_StripeLast4));
_StripeBrand = (String)(HELPER_StripeBrand.initialise (_StripeBrand));
}
......@@ -3059,6 +3105,202 @@ public abstract class BaseCompany extends BaseBusinessClass
}
}
/**
* Get the attribute StripeLast4
*/
public String getStripeLast4 ()
{
assertValid();
String valToReturn = _StripeLast4;
for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
{
valToReturn = bhd.getStripeLast4 ((Company)this, valToReturn);
}
return valToReturn;
}
/**
* Called prior to the attribute changing. Subclasses need not call super. If a field exception
* is thrown, the attribute change will fail. The new value is different to the old value.
*/
protected void preStripeLast4Change (String newStripeLast4) throws FieldException
{
}
/**
* Called after the attribute changes.
* If a field exception is thrown, the value is still changed, however it
* may lead to the TX being rolled back
*/
protected void postStripeLast4Change () throws FieldException
{
}
public FieldWriteability getWriteability_StripeLast4 ()
{
return getFieldWritabilityUtil (FieldWriteability.TRUE);
}
/**
* Set the attribute StripeLast4. Checks to ensure a new value
* has been supplied. If so, marks the field as altered and sets the attribute.
*/
public void setStripeLast4 (String newStripeLast4) throws FieldException
{
boolean oldAndNewIdentical = HELPER_StripeLast4.compare (_StripeLast4, newStripeLast4);
try
{
for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
{
newStripeLast4 = bhd.setStripeLast4 ((Company)this, newStripeLast4);
oldAndNewIdentical = HELPER_StripeLast4.compare (_StripeLast4, newStripeLast4);
}
if (FIELD_StripeLast4_Validators.length > 0)
{
Object newStripeLast4Obj = HELPER_StripeLast4.toObject (newStripeLast4);
if (newStripeLast4Obj != null)
{
int loopMax = FIELD_StripeLast4_Validators.length;
Map metadata = (Map)ATTRIBUTES_METADATA_Company.get (FIELD_StripeLast4);
for (int v = 0 ; v < loopMax ; ++v)
{
FIELD_StripeLast4_Validators[v].checkAttribute (this, FIELD_StripeLast4, metadata, newStripeLast4Obj);
}
}
}
}
catch (FieldException e)
{
if (!oldAndNewIdentical)
{
e.setWouldModify ();
}
throw e;
}
if (!oldAndNewIdentical)
{
assertValid();
Debug.assertion (getWriteability_StripeLast4 () != FieldWriteability.FALSE, "Field StripeLast4 is not writeable");
preStripeLast4Change (newStripeLast4);
markFieldChange (FIELD_StripeLast4);
_StripeLast4 = newStripeLast4;
postFieldChange (FIELD_StripeLast4);
postStripeLast4Change ();
}
}
/**
* Get the attribute StripeBrand
*/
public String getStripeBrand ()
{
assertValid();
String valToReturn = _StripeBrand;
for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
{
valToReturn = bhd.getStripeBrand ((Company)this, valToReturn);
}
return valToReturn;
}
/**
* Called prior to the attribute changing. Subclasses need not call super. If a field exception
* is thrown, the attribute change will fail. The new value is different to the old value.
*/
protected void preStripeBrandChange (String newStripeBrand) throws FieldException
{
}
/**
* Called after the attribute changes.
* If a field exception is thrown, the value is still changed, however it
* may lead to the TX being rolled back
*/
protected void postStripeBrandChange () throws FieldException
{
}
public FieldWriteability getWriteability_StripeBrand ()
{
return getFieldWritabilityUtil (FieldWriteability.TRUE);
}
/**
* Set the attribute StripeBrand. Checks to ensure a new value
* has been supplied. If so, marks the field as altered and sets the attribute.
*/
public void setStripeBrand (String newStripeBrand) throws FieldException
{
boolean oldAndNewIdentical = HELPER_StripeBrand.compare (_StripeBrand, newStripeBrand);
try
{
for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
{
newStripeBrand = bhd.setStripeBrand ((Company)this, newStripeBrand);
oldAndNewIdentical = HELPER_StripeBrand.compare (_StripeBrand, newStripeBrand);
}
if (FIELD_StripeBrand_Validators.length > 0)
{
Object newStripeBrandObj = HELPER_StripeBrand.toObject (newStripeBrand);
if (newStripeBrandObj != null)
{
int loopMax = FIELD_StripeBrand_Validators.length;
Map metadata = (Map)ATTRIBUTES_METADATA_Company.get (FIELD_StripeBrand);
for (int v = 0 ; v < loopMax ; ++v)
{
FIELD_StripeBrand_Validators[v].checkAttribute (this, FIELD_StripeBrand, metadata, newStripeBrandObj);
}
}
}
}
catch (FieldException e)
{
if (!oldAndNewIdentical)
{
e.setWouldModify ();
}
throw e;
}
if (!oldAndNewIdentical)
{
assertValid();
Debug.assertion (getWriteability_StripeBrand () != FieldWriteability.FALSE, "Field StripeBrand is not writeable");
preStripeBrandChange (newStripeBrand);
markFieldChange (FIELD_StripeBrand);
_StripeBrand = newStripeBrand;
postFieldChange (FIELD_StripeBrand);
postStripeBrandChange ();
}
}
/**
......@@ -4037,6 +4279,8 @@ public abstract class BaseCompany extends BaseBusinessClass
_IsLogoDeleted = sourceCompany._IsLogoDeleted;
_CompletedProfile = sourceCompany._CompletedProfile;
_PaymentJobCount = sourceCompany._PaymentJobCount;
_StripeLast4 = sourceCompany._StripeLast4;
_StripeBrand = sourceCompany._StripeBrand;
}
}
......@@ -4118,6 +4362,8 @@ public abstract class BaseCompany extends BaseBusinessClass
_IsLogoDeleted = (Boolean)(HELPER_IsLogoDeleted.readExternal (_IsLogoDeleted, vals.get(FIELD_IsLogoDeleted))); //
_CompletedProfile = (Boolean)(HELPER_CompletedProfile.readExternal (_CompletedProfile, vals.get(FIELD_CompletedProfile))); //
_PaymentJobCount = (Integer)(HELPER_PaymentJobCount.readExternal (_PaymentJobCount, vals.get(FIELD_PaymentJobCount))); //
_StripeLast4 = (String)(HELPER_StripeLast4.readExternal (_StripeLast4, vals.get(FIELD_StripeLast4))); //
_StripeBrand = (String)(HELPER_StripeBrand.readExternal (_StripeBrand, vals.get(FIELD_StripeBrand))); //
_AddedByUser.readExternalData(vals.get(SINGLEREFERENCE_AddedByUser));
_PaymentPlan.readExternalData(vals.get(SINGLEREFERENCE_PaymentPlan));
_Users.readExternalData(vals.get(MULTIPLEREFERENCE_Users));
......@@ -4156,6 +4402,8 @@ public abstract class BaseCompany extends BaseBusinessClass
vals.put (FIELD_IsLogoDeleted, HELPER_IsLogoDeleted.writeExternal (_IsLogoDeleted));
vals.put (FIELD_CompletedProfile, HELPER_CompletedProfile.writeExternal (_CompletedProfile));
vals.put (FIELD_PaymentJobCount, HELPER_PaymentJobCount.writeExternal (_PaymentJobCount));
vals.put (FIELD_StripeLast4, HELPER_StripeLast4.writeExternal (_StripeLast4));
vals.put (FIELD_StripeBrand, HELPER_StripeBrand.writeExternal (_StripeBrand));
vals.put (SINGLEREFERENCE_AddedByUser, _AddedByUser.writeExternalData());
vals.put (SINGLEREFERENCE_PaymentPlan, _PaymentPlan.writeExternalData());
vals.put (MULTIPLEREFERENCE_Users, _Users.writeExternalData());
......@@ -4262,6 +4510,8 @@ public abstract class BaseCompany extends BaseBusinessClass
visitor.visitField(this, FIELD_IsLogoDeleted, HELPER_IsLogoDeleted.toObject(getIsLogoDeleted()));
visitor.visitField(this, FIELD_CompletedProfile, HELPER_CompletedProfile.toObject(getCompletedProfile()));
visitor.visitField(this, FIELD_PaymentJobCount, HELPER_PaymentJobCount.toObject(getPaymentJobCount()));
visitor.visitField(this, FIELD_StripeLast4, HELPER_StripeLast4.toObject(getStripeLast4()));
visitor.visitField(this, FIELD_StripeBrand, HELPER_StripeBrand.toObject(getStripeBrand()));
}
......@@ -4677,6 +4927,14 @@ public abstract class BaseCompany extends BaseBusinessClass
{
return HELPER_PaymentJobCount.toObject (getPaymentJobCount ());
}
else if (attribName.equals (FIELD_StripeLast4))
{
return HELPER_StripeLast4.toObject (getStripeLast4 ());
}
else if (attribName.equals (FIELD_StripeBrand))
{
return HELPER_StripeBrand.toObject (getStripeBrand ());
}
else
{
return super.getAttribute (attribName);
......@@ -4782,6 +5040,14 @@ public abstract class BaseCompany extends BaseBusinessClass
{
return HELPER_PaymentJobCount;
}
else if (attribName.equals (FIELD_StripeLast4))
{
return HELPER_StripeLast4;
}
else if (attribName.equals (FIELD_StripeBrand))
{
return HELPER_StripeBrand;
}
else
{
return super.getAttributeHelper (attribName);
......@@ -4887,6 +5153,14 @@ public abstract class BaseCompany extends BaseBusinessClass
{
setPaymentJobCount ((Integer)(HELPER_PaymentJobCount.fromObject (_PaymentJobCount, attribValue)));
}
else if (attribName.equals (FIELD_StripeLast4))
{
setStripeLast4 ((String)(HELPER_StripeLast4.fromObject (_StripeLast4, attribValue)));
}
else if (attribName.equals (FIELD_StripeBrand))
{
setStripeBrand ((String)(HELPER_StripeBrand.fromObject (_StripeBrand, attribValue)));
}
else
{
super.setAttribute (attribName, attribValue);
......@@ -5015,6 +5289,14 @@ public abstract class BaseCompany extends BaseBusinessClass
{
return getWriteability_PaymentJobCount ();
}
else if (fieldName.equals (FIELD_StripeLast4))
{
return getWriteability_StripeLast4 ();
}
else if (fieldName.equals (FIELD_StripeBrand))
{
return getWriteability_StripeBrand ();
}
else
{
return super.getWriteable (fieldName);
......@@ -5140,6 +5422,16 @@ public abstract class BaseCompany extends BaseBusinessClass
fields.add (FIELD_PaymentJobCount);
}
if (getWriteability_StripeLast4 () != FieldWriteability.TRUE)
{
fields.add (FIELD_StripeLast4);
}
if (getWriteability_StripeBrand () != FieldWriteability.TRUE)
{
fields.add (FIELD_StripeBrand);
}
super.putUnwriteable (fields);
}
......@@ -5172,6 +5464,8 @@ public abstract class BaseCompany extends BaseBusinessClass
result.add(HELPER_IsLogoDeleted.getAttribObject (getClass (), _IsLogoDeleted, false, FIELD_IsLogoDeleted));
result.add(HELPER_CompletedProfile.getAttribObject (getClass (), _CompletedProfile, false, FIELD_CompletedProfile));
result.add(HELPER_PaymentJobCount.getAttribObject (getClass (), _PaymentJobCount, false, FIELD_PaymentJobCount));
result.add(HELPER_StripeLast4.getAttribObject (getClass (), _StripeLast4, false, FIELD_StripeLast4));
result.add(HELPER_StripeBrand.getAttribObject (getClass (), _StripeBrand, false, FIELD_StripeBrand));
return result;
}
......@@ -5654,6 +5948,42 @@ public abstract class BaseCompany extends BaseBusinessClass
return newPaymentJobCount;
}
/**
* Get the attribute StripeLast4
*/
public String getStripeLast4 (Company obj, String original)
{
return original;
}
/**
* Change the value set for attribute StripeLast4.
* May modify the field beforehand
* Occurs before validation.
*/
public String setStripeLast4 (Company obj, String newStripeLast4) throws FieldException
{
return newStripeLast4;
}
/**
* Get the attribute StripeBrand
*/
public String getStripeBrand (Company obj, String original)
{
return original;
}
/**
* Change the value set for attribute StripeBrand.
* May modify the field beforehand
* Occurs before validation.
*/
public String setStripeBrand (Company obj, String newStripeBrand) throws FieldException
{
return newStripeBrand;
}
}
......@@ -5742,6 +6072,14 @@ public abstract class BaseCompany extends BaseBusinessClass
{
return toPaymentJobCount ();
}
if (name.equals ("StripeLast4"))
{
return toStripeLast4 ();
}
if (name.equals ("StripeBrand"))
{
return toStripeBrand ();
}
if (name.equals ("CompanyName"))
{
return toCompanyName ();
......@@ -5834,6 +6172,10 @@ public abstract class BaseCompany extends BaseBusinessClass
public PipeLine<From, Integer> toPaymentJobCount () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_PaymentJobCount)); }
public PipeLine<From, String> toStripeLast4 () { return pipe(new ORMAttributePipe<Me, String>(FIELD_StripeLast4)); }
public PipeLine<From, String> toStripeBrand () { return pipe(new ORMAttributePipe<Me, String>(FIELD_StripeBrand)); }
public PipeLine<From, String> toCompanyName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_CompanyName)); }
public PipeLine<From, BinaryContent> toCompanyLogo () { return pipe(new ORMAttributePipe<Me, BinaryContent>(FIELD_CompanyLogo)); }
......@@ -5930,6 +6272,16 @@ public abstract class BaseCompany extends BaseBusinessClass
return true;
}
if(CollectionUtils.equals(attribName, "StripeLast4"))
{
return true;
}
if(CollectionUtils.equals(attribName, "StripeBrand"))
{
return true;
}
return super.isTransientAttrib(attribName);
}
......
package performa.orm;
import com.stripe.model.Card;
import java.util.Collection;
import java.util.Collections;
import oneit.logging.LoggingArea;
import oneit.objstore.BaseBusinessClass;
import oneit.objstore.ObjectStatus;
import oneit.objstore.ValidationContext;
import oneit.objstore.rdbms.filters.EqualsFilter;
......@@ -156,17 +153,28 @@ public class Company extends BaseCompany
return getPaymentPlan() != null && getPaymentPlan().getActiveJobCount() > openJobs.length;
}
public Card getCard() throws FieldException
{
return StripeUtils.retrieveCard(this);
}
public String getCardNumber(Card card) throws FieldException
public String getCardNumber() throws FieldException
{
return card != null ? "xxxx-xxxx-xxxx-" + card.getLast4() : "";
if(getStripeLast4() == null)
{
Card card = StripeUtils.retrieveCard(this);
if(card != null)
{
setStripeLast4(card.getLast4());
setStripeBrand(card.getBrand());
return "xxxx-xxxx-xxxx-" + getStripeLast4();
}
else
{
return "";
}
}
return "xxxx-xxxx-xxxx-" + getStripeLast4();
}
......
......@@ -18,6 +18,8 @@
<TRANSIENT name="IsLogoDeleted" type="Boolean" defaultValue="Boolean.FALSE"/>
<TRANSIENT name="CompletedProfile" type="Boolean" defaultValue="Boolean.FALSE"/>
<TRANSIENT name="PaymentJobCount" type="Integer"/>
<TRANSIENT name="StripeLast4" type="String" />
<TRANSIENT name="StripeBrand" type="String" />
<TABLE name="tl_company" tablePrefix="object">
......
......@@ -56,6 +56,7 @@
<FORM name="*.savePayment" factory="Participant" class="performa.form.MakePaymentFP"/>
<FORM name="*.managePlans" factory="Participant" class="performa.form.ManagePlansFP"/>
<FORM name="*.updateCard" factory="Participant" class="performa.form.UpdateCardFP"/>
<FORM name="*.replaceCard" factory="Participant" class="performa.form.ReplaceCardFP"/>
</NODE>
<NODE name="job_assessment_criteria_add_jsp" factory="Participant">
......
......@@ -88,7 +88,7 @@
</div>
</div>
</div>
<oneit:button value="Pay" name="savePayment" cssClass="hide" id="payNow"
<oneit:button value="Pay" name="replaceCard" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
</oneit:form>
......
......@@ -8,10 +8,10 @@
SecUser loggedInUser = SecUser.getTXUser(transaction);
CompanyUser companyUser = loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
String nextPage = WebUtils.getSamePageInRenderMode(request, "CardPayment");
String nextPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&fromJob=true";
Job job = (Job) process.getAttribute("Job");
Boolean ppj = (Boolean) process.getAttribute("PPJ");
String jobsPage = WebUtils.getSamePageInRenderMode(request, "Page");
%>
<oneit:form name="makePayment" method="post" enctype="multipart/form-data">
......@@ -68,34 +68,15 @@
.toMap() %>" />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 btn-right">
<oneit:button value="Pay and Open Job" name="updateCard" cssClass="btn btn-primary large-btn btn-green"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
<oneit:button value="Pay and Open Job" name="savePayment" cssClass="btn btn-primary large-btn btn-green"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("Company", company)
.toMap() %>" />
.mapEntry("PPJ", ppj)
.toMap() %>'/>
</div>
</div>
</div>
</div>
</oneit:form>
<oneit:form name="editJob" 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>
</oneit:dynIncluded>
\ No newline at end of file
......@@ -8,16 +8,17 @@
SecUser loggedInUser = SecUser.getTXUser(transaction);
CompanyUser companyUser = loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
String nextPage = WebUtils.getSamePageInRenderMode(request, "CardPayment");
String nextPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&fromJob=true";
Job job = (Job) process.getAttribute("Job");
String jobsPage = WebUtils.getSamePageInRenderMode(request, "Page");
Boolean ppj = (Boolean) process.getAttribute("PPJ");
%>
<oneit:form name="makePayment" method="post" enctype="multipart/form-data">
<script type="text/javascript">
$(document).ready(function()
{
recalcFunction = setupRecalc ($("form"), {'recalcOnError':true});
recalcFunction = setupRecalc ($("makePayment"), {'recalcOnError':true});
});
</script>
......@@ -69,7 +70,6 @@
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 btn-right">
<oneit:button value="Pay and Open Job" name="updateCard" cssClass="btn btn-primary large-btn btn-green"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("Company", company)
.toMap() %>" />
</div>
</div>
......@@ -80,20 +80,29 @@
<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" />
<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="savePayment" cssClass="hide" id="payNow"
<oneit:button value="Pay" name="savePayment" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
.mapEntry("EditCard", Boolean.TRUE)
.mapEntry("PPJ", ppj)
.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/performaStripe.js"/>
<oneit:script src="/scripts/updateCardStripe.js"/>
</oneit:script>
</oneit:dynIncluded>
\ No newline at end of file
......@@ -61,9 +61,8 @@
<%
if(isEdit)
{
Card card = company.getCard();
%>
<input type="text" name="cardNumber" value="<%= company.getCardNumber(card) %>" class="form-control" readonly>
<input type="text" name="cardNumber" value="<%= company.getCardNumber() %>" class="form-control" readonly>
<%
}
else
......
......@@ -10,7 +10,9 @@
boolean isEdit = (boolean) getData(request, "IsEdit");
String replaceCardPage = WebUtils.getSamePageInRenderMode(request, "ReplaceCard");
String editCardPage = WebUtils.getSamePageInRenderMode(request, "EditCard");
Card card = company.getCard();
String cardNumber = company.getCardNumber();
Job job = (Job) process.getAttribute("Job");
Boolean ppj = (Boolean) process.getAttribute("PPJ");
%>
<oneit:dynIncluded>
<div class="form-group row">
......@@ -18,12 +20,14 @@
<label>Card on file</label>
</div>
<div class="col-lg-5 col-md-5 col-sm-5" style="margin-top: -20px;">
<img src="<%= card.getBrand() == "MasterCard" ? "images/master.svg" : "images/visa.svg" %>" style="width:60px;"/>
<label><%= company.getCardNumber(card) %></label>
<img src="<%= company.getStripeBrand().equals("MasterCard") ? "images/master.svg" : "images/visa.svg" %>" style="width:60px;"/>
<label><%= cardNumber %></label>
</div>
<div class="col-lg-2 col-md-2 col-sm-2">
<oneit:button value=" " name="gotoPage" skin="link" cssClass="<%= "edit-card-link " + (isEdit ? "" : "deselected-link")%>"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", editCardPage)
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job)
.mapEntry("PPJ", ppj).toMap())
.toMap() %>">
Edit Card
</oneit:button>
......@@ -31,6 +35,8 @@
<div class="col-lg-2 col-md-2 col-sm-2">
<oneit:button value=" " name="gotoPage" skin="link" cssClass="<%= "edit-card-link " + (isReplace ? "" : "deselected-link")%>"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", replaceCardPage)
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job)
.mapEntry("PPJ", ppj).toMap())
.toMap() %>">
Replace Card
</oneit:button>
......
......@@ -107,7 +107,8 @@
<div class="a-label-row text-center">
<oneit:recalcClass htmlTag="span" classScript="company.getPaymentPlanAmount()!=null ? 'select-plan enabled': 'select-plan disabled'" company="<%= company %>">
<oneit:button value="Select Plan" name="saveJob" cssClass="btn btn-primary largeBtn btn-green save-btn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", paymentPage)
.mapEntry("PPJ", Boolean.TRUE)
.mapEntry ("fromPage", fromPage)
.mapEntry("JobStatus", JobStatus.OPEN)
.mapEntry ("restartProcess", Boolean.TRUE)
......@@ -135,6 +136,7 @@
</div>
</div>
<div class="form-page-area payment-optio-sep">
<div class="a-label-row">
<div class="col-md-3 col-sm-3 col-xs-3">
......@@ -142,14 +144,17 @@
<div class="col-md-3 col-sm-3 col-xs-3">
<div class="annual-plan">Pay Per Job</div>
<div class="">
<span class="pay-only-job-amt">$499.00</span>
<span class="pay-only-job-amt">
<oneit:toString value="<%= job.getAssessmentType() == AssessmentType.COMPREHENSIVE ? 499.0 : 399.0%>" mode="Currency"/>
</span>
<span class="pay-only-job-txt">&ensp;&ensp;Open for 30 Days</span>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
<oneit:button value="Pay for this job only" name="gotoPage" cssClass="btn pay-only-job-btn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", paymentPage)
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job).toMap())
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job)
.mapEntry("PPJ", Boolean.TRUE).toMap())
.toMap() %>" />
</div>
</div>
......
......@@ -81,7 +81,7 @@
</div>
</div>
</div>
<oneit:button value="Pay" name="savePayment" cssClass="hide" id="payNow"
<oneit:button value="Pay" name="replaceCard" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
</oneit:form>
......
......@@ -8,15 +8,16 @@
SecUser loggedInUser = SecUser.getTXUser(transaction);
CompanyUser companyUser = loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
String nextPage = WebUtils.getSamePageInRenderMode(request, "CardPayment");
String nextPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&fromJob=true";
Job job = (Job) process.getAttribute("Job");
String jobsPage = WebUtils.getSamePageInRenderMode(request, "Page");
Boolean ppj = (Boolean) process.getAttribute("PPJ");
%>
<oneit:form name="makePayment" method="post" enctype="multipart/form-data">
<script type="text/javascript">
$(document).ready(function()
{
recalcFunction = setupRecalc ($("form"), {'recalcOnError':true});
recalcFunction = setupRecalc ($("makePayment"), {'recalcOnError':true});
});
</script>
......@@ -66,7 +67,7 @@
.toMap() %>" />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 btn-right">
<oneit:button value="Pay and Open Job" name="updateCard" cssClass="btn btn-primary large-btn btn-green"
<oneit:button value="Pay and Open Job" name="savePayment" cssClass="btn btn-primary large-btn btn-green"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("Company", company)
.toMap() %>" />
......@@ -85,7 +86,10 @@
</div>
<oneit:button value="Pay" name="savePayment" cssClass="hide" id="payNow"
requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
.toMap() %>'/>
.mapEntry("Company", company)
.mapEntry("ReplaceCard", Boolean.TRUE)
.mapEntry("PPJ", ppj)
.toMap() %>'/>
</oneit:form>
<script src="https://js.stripe.com/v3/"></script>
<script>
......
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