Commit 6ebd772e by Nilu

move stripe reference to company from company user

parent bee8281b
......@@ -19,6 +19,8 @@
<column name="post_code" type="String" nullable="true" length="10"/>
<column name="city" type="String" nullable="true" length="100"/>
<column name="has_client_support" 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="added_by_user_id" type="Long" length="11" nullable="false"/>
</NODE>
......
......@@ -18,8 +18,6 @@
<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>
......
......@@ -19,6 +19,8 @@ CREATE TABLE tl_company (
post_code varchar(10) NULL,
city varchar(100) NULL,
has_client_support char(1) NULL,
stripe_reference varchar(100) NULL,
stripe_subscription varchar(100) NULL,
added_by_user_id numeric(12) NOT NULL
);
......
......@@ -17,8 +17,6 @@ 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
);
......
......@@ -20,6 +20,8 @@ CREATE TABLE tl_company (
post_code varchar2(10) NULL,
city varchar2(100) NULL,
has_client_support char(1) NULL,
stripe_reference varchar2(100) NULL,
stripe_subscription varchar2(100) NULL,
added_by_user_id number(12) NOT NULL
);
......
......@@ -18,8 +18,6 @@ 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
);
......
......@@ -20,6 +20,8 @@ CREATE TABLE tl_company (
post_code varchar(10) NULL,
city varchar(100) NULL,
has_client_support char(1) NULL,
stripe_reference varchar(100) NULL,
stripe_subscription varchar(100) NULL,
added_by_user_id numeric(12) NOT NULL
);
......
......@@ -18,8 +18,6 @@ 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
);
......
......@@ -118,10 +118,10 @@ public class SendCompanyUserInvitesFP extends SaveFP
// 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());
LogMgr.log(LOG, LogLevel.PROCESSING1,"Created customer in Stripe, customer reference ", company.getStripeReference());
StripeUtils.subscribeCustomer(companyUser);
LogMgr.log(LOG, LogLevel.PROCESSING1,"Subscribed customer to default plan in Stripe, subscription reference ", companyUser.getStripeSubscription());
StripeUtils.subscribeCustomer(company);
LogMgr.log(LOG, LogLevel.PROCESSING1,"Subscribed customer to default plan in Stripe, subscription reference ", company.getStripeSubscription());
//process user invitations
......
......@@ -31,6 +31,8 @@
<ATTRIB name="PostCode" type="String" dbcol="post_code" mandatory="false" length="10"/>
<ATTRIB name="City" type="String" dbcol="city" mandatory="false" length="100"/>
<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="StripeSubscription" type="String" dbcol="stripe_subscription" length="100"/>
<SINGLEREFERENCE name="AddedByUser" type="CompanyUser" dbcol="added_by_user_id" mandatory="true"/>
......
......@@ -22,8 +22,6 @@
<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"/>
......
......@@ -21,6 +21,7 @@ import oneit.objstore.StorageException;
import oneit.security.SecUser;
import oneit.utils.DateDiff;
import oneit.utils.parsers.FieldException;
import performa.orm.Company;
import performa.orm.CompanyUser;
......@@ -41,15 +42,16 @@ public class StripeUtils
{
try
{
Company company = companyUser.getCompany();
SecUser secUser = companyUser.getUser();
Map<String, Object> customerParams = new HashMap<>();
customerParams.put("description", companyUser.getCompany());
customerParams.put("description", company);
customerParams.put("email", secUser.getEmail());
Customer customer = Customer.create(customerParams);
companyUser.setStripeReference(customer.getId());
company.setStripeReference(customer.getId());
}
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex)
......@@ -59,7 +61,7 @@ public class StripeUtils
}
public static void subscribeCustomer(CompanyUser companyUser) throws FieldException
public static void subscribeCustomer(Company company) throws FieldException
{
try
{
......@@ -76,12 +78,12 @@ public class StripeUtils
Map<String, Object> params = new HashMap<>();
params.put("items", items);
params.put("coupon", STRIPE_COUPON_ID);
params.put("customer", companyUser.getStripeReference());
params.put("customer", company.getStripeReference());
params.put("trial_end", trialExpiry.getTime() / 1000L);
Subscription subscription = Subscription.create(params);
companyUser.setStripeSubscription(subscription.getId());
company.setStripeSubscription(subscription.getId());
}
catch (StorageException | AuthenticationException | InvalidRequestException | APIConnectionException | CardException | APIException ex)
{
......
<?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="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