SAAS-973: Airtime Billing page - Add support for August promotion plans

Un-hardcode product ids
This commit is contained in:
drigato 2015-07-30 09:39:50 -04:00
parent 4ed87de183
commit d9e2ba0ed3
2 changed files with 91 additions and 25 deletions

View file

@ -32,10 +32,10 @@ class Billing
{
//Making this static to cache the products during a single HTTP request.
//This saves us roundtrips to WHMCS if getProducts() is called multiple times.
static $result = array();
if (!empty($result))
static $products = array();
if (!empty($products))
{
return $result["products"]["product"];
return $products;
}
$credentials = self::getAPICredentials();
@ -56,8 +56,9 @@ class Billing
$products = $result["products"]["product"];
//Blacklist all free plans
//Hide the promo plans - we will tell the user if they are eligible for a promo plan
foreach ($products as $k => $p) {
if ($p["paytype"] === "free")
if ($p["paytype"] === "free" || strpos($p["name"], "Awesome August 2015") !== false)
{
unset($products[$k]);
}
@ -327,14 +328,91 @@ class Billing
$result = Billing::makeRequest($credentials["url"], $query_string);
}
/**
* Returns an array of the current Airtime Pro plan IDs.
* This excludes any old, free, promotional, or custom plans.
*/
public static function getCurrentPaidProductIds()
{
$products = self::getProducts();
$productIds = array();
foreach ($products as $k => $p) {
array_push($productIds, $p["pid"]);
}
return $productIds;
}
/**
* Returns an array of the Awesome August 2015 Promotional plans
*/
public static function getAwesomeAugustPromoProducts()
{
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getproducts";
$postfields["responsetype"] = "json";
//gid is the Airtime product group id on whmcs
$postfields["gid"] = "15";
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($credentials["url"], $query_string);
$promoProducts = $result["products"]["product"];
foreach ($promoProducts as $k => $p) {
if (strpos($p["name"], "Awesome August 2015") === false) {
unset($promoProducts[$k]);
}
}
return $promoProducts;
}
/**
* Returns the eligible promo plan ID that corresponds to the regular paid plan.
*
* i.e. if the client wants to upgrade to the Plus plan this function returns the
* plan id of the Awesome August 2015 Plus plan.
*/
public static function getEligibleAwesomeAugustPromoPlanId($productName)
{
$promoPlans = self::getAwesomeAugustPromoProducts();
$promoPlanId = "";
foreach($promoPlans as $k => $p) {
if (strpos($p["name"], $productName) !== false) {
$promoPlanId = $p["pid"];
break;
}
}
return $promoPlanId;
}
public static function getProductName($productId)
{
$products = self::getProducts();
$productName = "";
foreach($products as $k => $p) {
if ($p["pid"] == $productId) {
$productName = $p["name"];
break;
}
}
return $productName;
}
public static function isClientEligibleForPromo($newProductId, $newProductBillingCycle)
{
$currentPaidPlanProductIds = array(
"25",
"26",
"27",
"28"
);
// use this to check if client is upgrading from an old plan
$currentPaidPlanProductIds = self::getCurrentPaidProductIds();
$currentPlanProduct = self::getClientCurrentAirtimeProduct();
$currentPlanProductId = $currentPlanProduct["pid"];