Commit d87409e8 by Nilu

Added new url for sign up of EAP users. Once sign up, a customer will get…

Added new url for sign up of EAP users. Once sign up, a customer will get created in stripe and the customer will be subscribed to default plan and coupon
parent f6ac0fdc
......@@ -17,6 +17,8 @@
<column name="verification_key" type="String" nullable="true" length="10"/>
<column name="is_account_verified" type="Boolean" nullable="true"/>
<column name="is_email_changed" type="Boolean" nullable="true"/>
<column name="stripe_reference" type="String" nullable="true" length="100"/>
<column name="stripe_subscription" type="String" nullable="true" length="100"/>
<column name="user_id" type="Long" length="11" nullable="true"/>
<column name="company_id" type="Long" length="11" nullable="true"/>
</NODE>
......
......@@ -16,6 +16,8 @@ CREATE TABLE oneit_sec_user_extension (
verification_key varchar(10) NULL,
is_account_verified char(1) NULL,
is_email_changed char(1) NULL,
stripe_reference varchar(100) NULL,
stripe_subscription varchar(100) NULL,
user_id numeric(12) NULL,
company_id numeric(12) NULL
);
......
......@@ -17,6 +17,8 @@ CREATE TABLE oneit_sec_user_extension (
verification_key varchar2(10) NULL,
is_account_verified char(1) NULL,
is_email_changed char(1) NULL,
stripe_reference varchar2(100) NULL,
stripe_subscription varchar2(100) NULL,
user_id number(12) NULL,
company_id number(12) NULL
);
......
......@@ -17,6 +17,8 @@ CREATE TABLE oneit_sec_user_extension (
verification_key varchar(10) NULL,
is_account_verified char(1) NULL,
is_email_changed char(1) NULL,
stripe_reference varchar(100) NULL,
stripe_subscription varchar(100) NULL,
user_id numeric(12) NULL,
company_id numeric(12) NULL
);
......
package performa.form;
import com.stripe.Stripe;
import com.stripe.exception.APIConnectionException;
import com.stripe.exception.APIException;
import com.stripe.exception.AuthenticationException;
import com.stripe.exception.CardException;
import com.stripe.exception.InvalidRequestException;
import com.stripe.model.Customer;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.appservices.config.ConfigMgr;
import oneit.business.content.Article;
import oneit.components.ParticipantInitialisationContext;
import oneit.email.ConfigurableArticleTemplateEmailer;
......@@ -20,6 +29,7 @@ import oneit.utils.*;
import performa.intercom.utils.IntercomUtils;
import performa.orm.*;
import performa.orm.types.RoleType;
import performa.utils.StripeUtils;
import performa.utils.Utils;
import performa.utils.WebUtils;
......@@ -99,7 +109,18 @@ public class SendCompanyUserInvitesFP extends SaveFP
if(companyUser == company.getAddedByUser())
{
companyUser.setRole(RoleType.ADMIN);
// Create customer in Stripe and subscribe for plan 0001 and coupon EAP. Only for 0.0.4.1 release
// Need to handle properly when plan and billing screens are added
StripeUtils.createCustomer(companyUser);
LogMgr.log(LOG, LogLevel.PROCESSING1,"Created customer in Stripe, customer reference ", companyUser.getStripeReference());
StripeUtils.subscribeCustomer(companyUser);
LogMgr.log(LOG, LogLevel.PROCESSING1,"Subscribed customer to default plan in Stripe, subscription reference ", companyUser.getStripeSubscription());
//process user invitations
for(CompanyUser cUser : company.getUsersSet())
{
......
......@@ -21,6 +21,8 @@
<ATTRIB name="VerificationKey" type="String" dbcol="verification_key" length="10"/>
<ATTRIB name="IsAccountVerified" type="Boolean" dbcol="is_account_verified" defaultValue="Boolean.FALSE"/>
<ATTRIB name="IsEmailChanged" type="Boolean" dbcol="is_email_changed" defaultValue="Boolean.FALSE"/>
<ATTRIB name="StripeReference" type="String" dbcol="stripe_reference" length="100"/>
<ATTRIB name="StripeSubscription" type="String" dbcol="stripe_subscription" length="100"/>
<SINGLEREFERENCE name="User" type="SecUser" dbcol="user_id" backreferenceName="Extensions" inSuper='TRUE'/>
<SINGLEREFERENCE name="Company" type="Company" dbcol="company_id" backreferenceName="Users"/>
......
package performa.utils;
import com.stripe.Stripe;
import com.stripe.exception.APIConnectionException;
import com.stripe.exception.APIException;
import com.stripe.exception.AuthenticationException;
import com.stripe.exception.CardException;
import com.stripe.exception.InvalidRequestException;
import com.stripe.model.Customer;
import com.stripe.model.Plan;
import com.stripe.model.Subscription;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
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.utils.DateDiff;
import oneit.utils.parsers.FieldException;
import performa.orm.CompanyUser;
public class StripeUtils
{
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_PLAN_ID = ConfigMgr.getKeyfileString("stripe.plan.id","0001");
public static final String STRIPE_COUPON_ID = ConfigMgr.getKeyfileString("stripe.coupon.id","EAP");
static
{
Stripe.apiKey = STRIPE_KEY;
}
public static void createCustomer(CompanyUser companyUser) throws FieldException
{
try
{
SecUser secUser = companyUser.getUser();
Map<String, Object> customerParams = new HashMap<>();
customerParams.put("description", companyUser.getCompany());
customerParams.put("email", secUser.getEmail());
Customer customer = Customer.create(customerParams);
companyUser.setStripeReference(customer.getId());
}
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating a customer in stripe");
}
}
public static void subscribeCustomer(CompanyUser companyUser) throws FieldException
{
try
{
Plan plan = Plan.retrieve(STRIPE_PLAN_ID);
Date today = new Date();
Date trialExpiry = DateDiff.add(today, Calendar.DATE, plan.getTrialPeriodDays());
Map<String, Object> item = new HashMap<>();
item.put("plan", STRIPE_PLAN_ID);
Map<String, Object> items = new HashMap<>();
items.put("0", item);
Map<String, Object> params = new HashMap<>();
params.put("items", items);
params.put("coupon", STRIPE_COUPON_ID);
params.put("customer", companyUser.getStripeReference());
params.put("trial_end", trialExpiry.getTime() / 1000L);
Subscription subscription = Subscription.create(params);
companyUser.setStripeSubscription(subscription.getId());
}
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while creating subscrition in stripe");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.RedefineTableOperation">
<tableName factory="String">oneit_sec_user_extension</tableName>
<column name="stripe_reference" type="String" nullable="true" length="100"/>
<column name="stripe_subscription" type="String" nullable="true" length="100"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment