Commit a99e0eea by Nilu

manage plan upgrades

parent 97062fca
......@@ -36,7 +36,7 @@ public class PullStripeDataBatch extends ORMBatch
LogMgr.log (PULL_STRIPE_DATA_BATCH, LogLevel.PROCESSING1, "RUNNING Pull Stripe Data Batch");
Stripe.apiKey = StripeUtils.STRIPE_KEY;
Map<String, Object> planParams = new HashMap<>();
planParams.put("active", true);
......@@ -51,7 +51,6 @@ public class PullStripeDataBatch extends ORMBatch
for (Plan plan : plansList)
{
System.out.println("pllan :: " + plan);
Filter<PaymentPlan> filter = PaymentPlan.SearchByAll().andStripeReference(new EqualsFilter<>(plan.getId()));
List<PaymentPlan> activePlans = (List<PaymentPlan>) CollectionFilter.filter(Arrays.asList(paymentPlans) , filter);
......
......@@ -54,13 +54,15 @@ public class SaveCompanyFP extends SaveFP
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan());
if(hiringTeam.getCompany().getCardID() != null )
if(hiringTeam.getCompany().getCardID() == null)
{
// cannot subscribe a user to a plan without card details
StripeUtils.updatePlan(hiringTeam);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Strpe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
throw new BusinessException("Please enter billing details before selecting a payment plan");
}
// cannot subscribe a user to a plan without card details
StripeUtils.updatePlan(hiringTeam);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Strpe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
}
//
// // Update company in intercom
......@@ -77,13 +79,7 @@ public class SaveCompanyFP extends SaveFP
// Company company = process.getAttribute("Company") != null ? (Company) process.getAttribute("Company") : (Company) request.getAttribute("Company");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
//to select payment plan when job open
// if(CollectionUtils.equals(isPayment, Boolean.TRUE) && company.getPaymentJobCount()!=null)
// {
// BusinessObjectParser.assertFieldCondition(company.getSelectedPaymentPlan()!= null, company , Company.SINGLEREFERENCE_PaymentPlan, "mandatory", exceptions, true, request);
// }
//
if(hiringTeam != null && !hiringTeam.getManageOwnBilling())
{
BusinessObjectParser.assertFieldCondition(hiringTeam.getBillingTeam() != null, hiringTeam , HiringTeam.SINGLEREFERENCE_BillingTeam, "mandatory", exceptions, true, request);
......
......@@ -50,4 +50,9 @@ public class HiringTeam extends BaseHiringTeam
return CompanyUserHiringTeamLink.pipesCompanyUserHiringTeamLink(getUsersSet()).toCompanyUser(filter).uniqueVals();
}
public boolean isPPJ()
{
return isTrue(getIsPPJ());
}
}
\ No newline at end of file
package performa.orm;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.objstore.rdbms.filters.IsNotNullFilter;
import oneit.utils.math.NullArith;
......
......@@ -9,6 +9,7 @@ import com.stripe.model.Event;
import com.stripe.model.Invoice;
import com.stripe.model.Plan;
import com.stripe.model.Subscription;
import com.stripe.model.UsageRecord;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
......@@ -16,6 +17,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import oneit.appservices.config.ConfigMgr;
import oneit.logging.LogLevel;
......@@ -132,6 +135,23 @@ public class StripeUtils
return null;
}
public static Subscription retrieveSubscription(String subscriptionRef) throws FieldException
{
try
{
// Subscription subscription = Subscription.retrieve(subscriptionRef);
// new Date(subscription.getCurrentPeriodEnd() * 1000)
// new Date(subscription.getCurrentPeriodStart()* 1000)
return Subscription.retrieve(subscriptionRef);
}
catch (StripeException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while retrieving a subscription in stripe");
}
return null;
}
public static List<Invoice> retrieveInvoices(Company company) throws FieldException
{
......@@ -239,6 +259,29 @@ public class StripeUtils
}
public static void recordUsage(HiringTeam hiringTeam)
{
try
{
Map<String, Object> params = new HashMap<>();
Date now = new Date();
String subscription = hiringTeam.getManageOwnBilling() ? hiringTeam.getStripeSubscription() : hiringTeam.getBillingTeam().getStripeSubscription();
params.put("quantity", 1);
params.put("timestamp", now.getTime() / 1000L);
params.put("subscription_item", subscription);
params.put("action", "increment");
UsageRecord.create(params, null);
}
catch (StripeException ex)
{
Logger.getLogger(StripeUtils.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void handleWebhook(HttpServletRequest request, ObjectTransaction objTran) throws FieldException
{
try
......
<%@ page import="performa.orm.*, performa.orm.types.*, performa.form.*, performa.utils.*, performa.search.*"%>
<%@ page import="performa.intercom.utils.*, performa.intercom.resources.User, com.stripe.model.*"%>
<%@ page import="oneit.objstore.rdbms.filters.*, oneit.security.jsp.SecUserToNameTransform, oneit.servlets.utils.*, oneit.utils.image.*, oneit.objstore.utils.ObjstoreUtils "%>
<%@ page import="oneit.utils.text.FormatUtils"%>
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