Commit 276a7b5e by Nilu

Apply coupon if there is an existing subscription, bug : coupon was only getting…

Apply coupon if there is an existing subscription, bug : coupon was only getting updated when a plan upgrade or downgrade happens, it should be updated to an existing plan as well for future billing
parent 48ee863d
......@@ -19,7 +19,6 @@ import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.DateDiff;
import performa.orm.HiringTeam;
import performa.orm.PaymentPlan;
import performa.orm.StripeCoupon;
import performa.orm.types.CouponDuration;
import performa.utils.StripeUtils;
......@@ -49,6 +48,8 @@ public class ApplyCouponFP extends SaveFP
if(coupon != null && coupon.getValid())
{
StripeUtils.applyCoupon(hiringTeam);
StripeCoupon stripeCoupon = null;
if(stripeCoupons != null && stripeCoupons.length > 0)
......
......@@ -265,6 +265,32 @@ public class StripeUtils
}
public static void applyCoupon(HiringTeam hiringTeam) throws BusinessException
{
try
{
Subscription subscription = retrieveSubscription(hiringTeam.getStripeSubscription());
if(subscription != null)
{
Map<String, Object> params = new HashMap<>();
params.put("coupon", hiringTeam.getCouponCode());
subscription.update(params);
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, "Updating subscription : ", subscription, " with coupon : ", hiringTeam.getCouponCode());
}
}
catch (FieldException | StripeException ex)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ex, "Error while applying coupon in stripe for hiring team: "+ hiringTeam);
throw new BusinessException("Problem with applying coupon. Please contact adminstrator for more info.");
}
}
public static void chargeUpgradePlanDifference(HiringTeam hiringTeam, double costDifference) throws BusinessException
{
try
......
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