SAAS-973: Airtime Billing page - Add support for August promotion plans
Backend side pretty much done
This commit is contained in:
parent
4d9fb27554
commit
4ed87de183
3 changed files with 103 additions and 29 deletions
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
define("AIRTIME_PRO_FREE_TRIAL_PLAN_ID", 34);
|
||||||
|
|
||||||
class Billing
|
class Billing
|
||||||
{
|
{
|
||||||
public static function getAPICredentials()
|
public static function getAPICredentials()
|
||||||
|
@ -55,7 +57,6 @@ class Billing
|
||||||
|
|
||||||
//Blacklist all free plans
|
//Blacklist all free plans
|
||||||
foreach ($products as $k => $p) {
|
foreach ($products as $k => $p) {
|
||||||
Logging::info($p);
|
|
||||||
if ($p["paytype"] === "free")
|
if ($p["paytype"] === "free")
|
||||||
{
|
{
|
||||||
unset($products[$k]);
|
unset($products[$k]);
|
||||||
|
@ -326,4 +327,46 @@ class Billing
|
||||||
$result = Billing::makeRequest($credentials["url"], $query_string);
|
$result = Billing::makeRequest($credentials["url"], $query_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isClientEligibleForPromo($newProductId, $newProductBillingCycle)
|
||||||
|
{
|
||||||
|
$currentPaidPlanProductIds = array(
|
||||||
|
"25",
|
||||||
|
"26",
|
||||||
|
"27",
|
||||||
|
"28"
|
||||||
|
);
|
||||||
|
|
||||||
|
$currentPlanProduct = self::getClientCurrentAirtimeProduct();
|
||||||
|
$currentPlanProductId = $currentPlanProduct["pid"];
|
||||||
|
$currentPlanBillingCycle = strtolower($currentPlanProduct["billingcycle"]);
|
||||||
|
|
||||||
|
// if client is on trial plan, YES
|
||||||
|
if ($currentPlanProductId == AIRTIME_PRO_FREE_TRIAL_PLAN_ID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if client is currently on monthly or old plan AND (upgrading OR upgrading/downgrading to annual plan), YES
|
||||||
|
if ($currentPlanBillingCycle == "monthly" || $currentPlanBillingCycle == "free account") {
|
||||||
|
// is the client changing billing cycle to annual?
|
||||||
|
if ($newProductBillingCycle == "annually") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the client staying on monthly and upgrading?
|
||||||
|
// This won't hold true if the client is on an old plan because the old
|
||||||
|
// plan ids are higher than the current plan ids.
|
||||||
|
if ($newProductBillingCycle == "monthly" && $newProductId > $currentPlanProductId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the client staying on monthly and upgrading from an old plan?
|
||||||
|
if ($newProductBillingCycle == "monthly" && !in_array($currentPlanProductId, $currentPaidPlanProductIds)
|
||||||
|
&& in_array($newProductId, $currentPaidPlanProductIds)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,12 @@ class BillingController extends Zend_Controller_Action {
|
||||||
throw new Exception("Must POST data to promoEligibilityCheckAction.");
|
throw new Exception("Must POST data to promoEligibilityCheckAction.");
|
||||||
}
|
}
|
||||||
$data = $request->getPost();
|
$data = $request->getPost();
|
||||||
Logging::info($data);
|
|
||||||
|
$eligible = Billing::isClientEligibleForPromo(
|
||||||
|
$data["newproductid"], $data["newproductbillingcycle"]);
|
||||||
|
|
||||||
//Set the return JSON value
|
//Set the return JSON value
|
||||||
$this->_helper->json(array("result"=>"ok"));
|
$this->_helper->json(array("result"=>$eligible));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upgradeAction()
|
public function upgradeAction()
|
||||||
|
@ -46,13 +48,31 @@ class BillingController extends Zend_Controller_Action {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$form = new Application_Form_BillingUpgradeDowngrade();
|
$form = new Application_Form_BillingUpgradeDowngrade();
|
||||||
if ($request->isPost()) {
|
if ($request->isPost()) {
|
||||||
|
// for testing
|
||||||
$doUpgrade = false;
|
$doUpgrade = false;
|
||||||
|
|
||||||
$formData = $request->getPost();
|
$formData = $request->getPost();
|
||||||
Logging::info($formData);
|
|
||||||
if ($doUpgrade && $form->isValid($formData)) {
|
if ($doUpgrade && $form->isValid($formData)) {
|
||||||
|
// for testing
|
||||||
Logging::info("---upgrading----");
|
Logging::info("---upgrading----");
|
||||||
|
|
||||||
|
// Maps current paid plans to the promo plan ids
|
||||||
|
// TODO: update these to the correct values
|
||||||
|
$promoPlanIdMap = array(
|
||||||
|
"25" => "50", //hobbyist
|
||||||
|
"26" => "51", //starter
|
||||||
|
"27" => "52", //plus
|
||||||
|
"28" => "53" //premium
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if client is eligible for promo and update the new product id if so
|
||||||
|
$eligibleForPromo = Billing::isClientEligibleForPromo(
|
||||||
|
$formData["newproductid"], $formData["newproductbillingcycle"]);
|
||||||
|
if ($eligibleForPromo) {
|
||||||
|
$formData["newproductid"] = $promoPlanIdMap[$formData["newproductid"]];
|
||||||
|
}
|
||||||
|
|
||||||
$credentials = Billing::getAPICredentials();
|
$credentials = Billing::getAPICredentials();
|
||||||
|
|
||||||
//Check if VAT should be applied or not to this invoice.
|
//Check if VAT should be applied or not to this invoice.
|
||||||
|
@ -124,8 +144,7 @@ class BillingController extends Zend_Controller_Action {
|
||||||
|
|
||||||
//If there were no changes to the plan or billing cycle, we just redirect you to the
|
//If there were no changes to the plan or billing cycle, we just redirect you to the
|
||||||
//invoices screen and show a message.
|
//invoices screen and show a message.
|
||||||
if (!$placeAnUpgradeOrder)
|
if (!$placeAnUpgradeOrder) {
|
||||||
{
|
|
||||||
$this->_redirect('billing/invoices?planupdated');
|
$this->_redirect('billing/invoices?planupdated');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,14 +122,23 @@ function configureByCountry(countryCode)
|
||||||
|
|
||||||
function promoEligibilityCheck()
|
function promoEligibilityCheck()
|
||||||
{
|
{
|
||||||
var newproductid = $("input[type='radio'][name='newproductid']:checked");
|
var newproductid = $("input[type='radio'][name='newproductid']:checked").val();
|
||||||
var newproductbillingcycle = $("input[type='radio'][name='newproductbillingcycle']:checked");
|
|
||||||
console.log(newproductid.val());
|
// newproductid can be undefined if the client is currently on an old plan
|
||||||
console.log(newproductbillingcycle.val());
|
// and they just change the billing cycle value without selecting a new plan type.
|
||||||
|
// In this case, let's not check if they are eligible for the promo because
|
||||||
|
// they won't be able to upgrade without selecting a new plan first.
|
||||||
|
if (newproductid === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var newproductbillingcycle = $("input[type='radio'][name='newproductbillingcycle']:checked").val();
|
||||||
|
|
||||||
$.post("/billing/promo-eligibility-check", {"newproductid": newproductid,
|
$.post("/billing/promo-eligibility-check", {"newproductid": newproductid,
|
||||||
"newproductbillingcycle": newproductbillingcycle})
|
"newproductbillingcycle": newproductbillingcycle})
|
||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
console.log(data);
|
if (data.result == true) {
|
||||||
|
$("#promo-plan-eligible").show();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +298,9 @@ echo($currentProduct["name"]);
|
||||||
<div id="billingcycle_disclaimer">
|
<div id="billingcycle_disclaimer">
|
||||||
Save 15% on annual plans (Hobbyist plan excluded).
|
Save 15% on annual plans (Hobbyist plan excluded).
|
||||||
</div>
|
</div>
|
||||||
|
<div id="promo-plan-eligible" style="display:none;">
|
||||||
|
Congratulations, you are eligible for our Awesome Promotional Plan!
|
||||||
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
<div id="subtotal_box">
|
<div id="subtotal_box">
|
||||||
<b>Subtotal:</b><br>
|
<b>Subtotal:</b><br>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue