Пример #1
0
 public static function validateUsername($username)
 {
     $zapi;
     try {
         $zapi = new zApi();
     } catch (Exception $e) {
         return null;
     }
     //Disallow apostrophes
     if (strpos($username, "'") !== false) {
         return false;
     }
     //Get Account ID with this email
     $accResult = $zapi->zQuery("SELECT Id FROM Account WHERE Name='" . $username . "'");
     foreach ($accResult->result->records as $acc) {
         $_SESSION['accountId'] = $acc->Id;
         return true;
     }
     return false;
 }
Пример #2
0
 public static function buildHierarchy($partnerID, $parentName, $parentId, $acctName, $acctId, $parentHierarchy)
 {
     $zapi;
     try {
         $zapi = new zApi();
     } catch (Exception $e) {
         return false;
     }
     $chldHierarchy = new Summary_Hierarchy();
     //$parentName, $parentID);
     $chldHierarchy->partnerId = $partnerID;
     $chldHierarchy->ParentName = $parentName;
     $chldHierarchy->ParentId = $parentId;
     $chldHierarchy->accountId = $acctId;
     $chldHierarchy->acctName = $acctName;
     $chldHierarchy->sub_Hierarchies = array();
     $hierarchy = $chldHierarchy;
     $acctResult = $zapi->zQuery("Select Id, Name from Account where ParentId = '" . $acctId . "'");
     foreach ($acctResult->result->records as $acc) {
         AccountManager::buildHierarchy($partnerID, $acctName, $acctId, $acc->Name, $acc->Id, $hierarchy);
     }
     if ($parentHierarchy != 'null') {
         array_push($parentHierarchy->sub_Hierarchies, $hierarchy);
     }
     return $hierarchy;
 }
Пример #3
0
 /**
  * Deletes the selected payment method from the logged in user's account
  * @param $pmId ID of payment method to be removed
  */
 public static function removePaymentMethod($pmId)
 {
     $zapi = new zApi();
     $deleteResult = $zapi->zDelete(array($pmId), 'PaymentMethod');
     return $deleteResult;
 }
Пример #4
0
 /**
  * Reads the Product Catalog Data from Zuora and saves it to a JSON cache stored on the server to reduce load times. This method must be called each time the Product Catalog is changed in Zuora to ensure the catalog is not out of date for the user.
  * @return A model containing all necessary information needed to display the products and rate plans in the product catalog
  */
 public static function refreshCache()
 {
     //Initialize Zuora API Instance
     include './config.php';
     $zapi = new zApi();
     // if guided selling filter fields exist, loop through and create string for the query
     $guidedSellingFieldsString = '';
     if (count($guidedSellingFields) > 0) {
         $guidedSellingFieldsString = ',' . implode(",", $guidedSellingFields);
     }
     //For each classification
     $fieldGroups;
     $numGroups;
     if ($showAllProducts) {
         $numGroups = 1;
         $fieldGroups = array('');
     } else {
         $numGroups = count($groupingFieldValues);
         $fieldGroups = $groupingFieldValues;
     }
     $catalog_groups = array();
     foreach ($fieldGroups as $fieldGroup) {
         $catalog_group = new Catalog_Group();
         if ($fieldGroup == 'Base Product') {
             $catalog_group->isBase = true;
         } elseif ($fieldGroup == 'Add-On Product') {
             $catalog_group->isAddon = true;
             // } elseif ($fieldGroup == 'Partner') {
             // 	$catalog_group->isPartner = true;
         } else {
             $catalog_group->isHidden = true;
         }
         $catalog_group->Name = $fieldGroup;
         $catalog_group->products = array();
         date_default_timezone_set('America/Los_Angeles');
         $curDate = date('Y-m-d\\TH:i:s', time());
         //Get All Products
         $productZoql = "select Id,Name,SKU,Description" . $guidedSellingFieldsString . " from Product where EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "'";
         if (!$showAllProducts) {
             $productZoql .= " and " . $groupingField . "='" . $fieldGroup . "'";
         }
         $result = $zapi->zQuery($productZoql);
         $qProducts = array();
         if ($result->result != null) {
             $qProducts = $result->result->records;
         } else {
             addErrors(null, 'No Products found.');
             return;
         }
         //Set up Catalog_Product objects
         foreach ($qProducts as $p) {
             $catalog_product = new Catalog_Product();
             $catalog_product->Id = $p->Id;
             $catalog_product->Name = $p->Name;
             $catalog_product->Description = isset($p->Description) ? $p->Description : "";
             $catalog_product->SKU = $p->SKU;
             // loop through the guided selling fields from config file
             if (count($guidedSellingFields) > 0) {
                 $guidedFieldsArray = array();
                 foreach ($guidedSellingFields as $filterField) {
                     // set the product to have the value of the guided selling field
                     $catalog_product->{$filterField} = isset($p->{$filterField}) ? $p->{$filterField} : "";
                     $guidedSellingValues = array();
                     if ($catalog_product->{$filterField} != "") {
                         $guidedFieldsArray[$filterField] = $catalog_product->{$filterField};
                     }
                 }
                 $catalog_product->filterValues = array();
                 array_push($catalog_product->filterValues, $guidedFieldsArray);
             }
             //Get RatePlans for this Product
             $result = $zapi->zQuery("select Id,Name,Description," . $promoField . " from ProductRatePlan where ProductId='" . $catalog_product->Id . "' and EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "' ");
             $qRatePlans = array();
             $catalog_product->ratePlans = array();
             if ($result->result != null) {
                 $qRatePlans = $result->result->records;
                 if ($qRatePlans != null) {
                     foreach ($qRatePlans as $rp) {
                         $catalog_rateplan = new Catalog_RatePlan();
                         $catalog_rateplan->Id = $rp->Id;
                         $catalog_rateplan->Name = $rp->Name;
                         $catalog_rateplan->productName = $p->Name;
                         $catalog_rateplan->Description = isset($rp->Description) ? $rp->Description : "";
                         $catalog_rateplan->{$promoField} = isset($rp->{$promoField}) ? $rp->{$promoField} : "";
                         //Get Charges for the Rate Plan
                         $result = $zapi->zQuery("select Id,Name,DefaultQuantity,Description,UOM,ChargeModel,ChargeType,BillingPeriod from ProductRatePlanCharge where ProductRatePlanId='" . $catalog_rateplan->Id . "'");
                         $qCharges = array();
                         $catalog_rateplan->charges = array();
                         if ($result->result != null) {
                             $qCharges = $result->result->records;
                             if ($qCharges != null) {
                                 // start of for loop for rate plan charges
                                 foreach ($qCharges as $rpc) {
                                     $catalog_charge = new Catalog_Charge();
                                     $catalog_charge->Id = $rpc->Id;
                                     $catalog_charge->Name = $rpc->Name;
                                     $catalog_charge->Description = isset($rpc->Description) ? $rpc->Description : "";
                                     $catalog_charge->ChargeModel = $rpc->ChargeModel;
                                     $catalog_charge->ChargeType = $rpc->ChargeType;
                                     $catalog_charge->BillingPeriod = $rpc->BillingPeriod;
                                     if ($catalog_charge->ChargeModel == 'Tiered with Overage Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing') {
                                         $catalog_charge->Uom = $rpc->UOM;
                                         $catalog_charge->isTiered = true;
                                     }
                                     if ($catalog_charge->ChargeType != 'Usage' && ($catalog_charge->ChargeModel == 'Per Unit Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing')) {
                                         $catalog_charge->Uom = $rpc->UOM;
                                         $catalog_charge->quantifiable = true;
                                         $catalog_charge->DefaultQuantity = isset($rpc->DefaultQuantity) ? $rpc->DefaultQuantity : "1";
                                     }
                                     // probably need special case for ChargeModel == Overage Pricing to show overage price
                                     //MD New Lines to get detail for the individual charges
                                     $result = $zapi->zQuery("select Id,Price,Currency,Tier,StartingUnit,EndingUnit,PriceFormat from ProductRatePlanChargeTier where ProductRatePlanChargeId='" . $catalog_charge->Id . "'");
                                     $qChargeTiers = array();
                                     $catalog_charge->chargeTiers = array();
                                     if ($result->result != null) {
                                         usort($result->result->records, "Catalog::cmpTiers");
                                         $qChargeTiers = $result->result->records;
                                         if ($qChargeTiers != null) {
                                             foreach ($qChargeTiers as $rpct) {
                                                 $catalog_chargeTier = new Catalog_ChargeTier();
                                                 $catalog_chargeTier->Id = $rpct->Id;
                                                 $catalog_chargeTier->Price = $rpct->Price;
                                                 $catalog_chargeTier->Currency = $rpct->Currency;
                                                 $catalog_chargeTier->myCurrency = $rpct->Currency == $defaultCurrency;
                                                 $catalog_chargeTier->Tier = $rpct->Tier;
                                                 $catalog_chargeTier->StartingUnit = $rpct->StartingUnit;
                                                 $catalog_chargeTier->EndingUnit = $rpct->EndingUnit;
                                                 $catalog_chargeTier->PriceFormat = $rpct->PriceFormat;
                                                 array_push($catalog_charge->chargeTiers, $catalog_chargeTier);
                                             }
                                         }
                                     }
                                     //MD end new lines to get charge detail
                                     array_push($catalog_rateplan->charges, $catalog_charge);
                                 }
                             }
                         }
                         array_push($catalog_product->ratePlans, $catalog_rateplan);
                     }
                     array_push($catalog_group->products, $catalog_product);
                 }
             }
         }
         array_push($catalog_groups, $catalog_group);
     }
     $catalogJson = json_encode($catalog_groups);
     $lastSync = date(NULL);
     //Cache product list
     $myFile = $cachePath;
     $fh = fopen($myFile, 'w') or die("can't open file");
     fwrite($fh, $catalogJson);
     fclose($fh);
     return $catalog_groups;
 }
Пример #5
0
function getAccountID()
{
    $zapi;
    try {
        $zapi = new zApi();
    } catch (Exception $e) {
        return null;
    }
    if (isset($_SESSION['email'])) {
        $accName = $_SESSION['email'];
    } else {
        return '';
    }
    //Get Contact with this email
    $accResult = $zapi->zQuery("SELECT Id FROM Account WHERE Name='" . $accName . "'");
    foreach ($accResult->result->records as $acc) {
        return $acc->Id;
    }
}
Пример #6
0
function test_ChangeDefaultPaymentMethod()
{
    global $EXISTING_CUSTOMER_ACCOUNT_NAME;
    printResultStart(__FUNCTION__);
    $messages = array();
    $pmId;
    $checkPmId;
    try {
        $zapi = new zApi();
        $pres = $zapi->zQuery("SELECT DefaultPaymentMethodId FROM Account WHERE Name='" . $EXISTING_CUSTOMER_ACCOUNT_NAME . "'");
        if (count($pres->result->records) == 0) {
            throw new Exception("ACCOUNT_DOESNT_EXIST");
        }
        $pmId = $pres->result->records[0]->DefaultPaymentMethodId;
        $cpmres = $zapi->zQuery("SELECT Id from PaymentMethod where Name='Check'");
        //Test
        echo "Updating Default Payment Method on Account " . $EXISTING_CUSTOMER_ACCOUNT_NAME . " to 'Check': <br>";
        $changeRes = PaymentManager::changePaymentMethod($EXISTING_CUSTOMER_ACCOUNT_NAME, $pmId);
        print_r_html($changeRes);
        echo "Updating Default Payment Method on Account " . $EXISTING_CUSTOMER_ACCOUNT_NAME . " back to original payment method: <br>";
        $changeRes = PaymentManager::changePaymentMethod($EXISTING_CUSTOMER_ACCOUNT_NAME, $pmId);
        print_r_html($changeRes);
    } catch (Exception $e) {
        array_push($messages, $e->getMessage());
    }
    printResultEnd($messages);
}
Пример #7
0
 public static function getUpgradeDowngradePlans($updownSku)
 {
     //Initialize Zuora API Instance
     include './config.php';
     $zapi = new zApi();
     $_SESSION['myCurrency'] = $defaultCurrency;
     //For each classification
     date_default_timezone_set('America/Los_Angeles');
     $curDate = date('Y-m-d\\TH:i:s', time());
     //Get the Upgrade/Downgrade Product by SKU
     $productZoql = "select Id,Name,SKU,Description from Product where SKU='" . $updownSku . "' or Id='" . $updownSku . "' and EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "'";
     $result = $zapi->zQuery($productZoql);
     if ($result->result != null) {
         $qProduct = $result->result->records[0];
     } else {
         addErrors(null, 'No Products found.');
         return;
     }
     //Set up the Catalog_Product object
     $catalog_product = new Catalog_Product();
     $catalog_product->Id = $qProduct->Id;
     $catalog_product->Name = $qProduct->Name;
     $catalog_product->Description = isset($qProduct->Description) ? $qProduct->Description : "";
     $catalog_product->SKU = $qProduct->SKU;
     //Get RatePlans for this Product
     $result = $zapi->zQuery("select Id,Name,Description from ProductRatePlan where ProductId='" . $catalog_product->Id . "' and EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "' ");
     $qRatePlans = array();
     $catalog_product->ratePlans = array();
     $qRatePlans = $result->result->records;
     if ($qRatePlans != null) {
         foreach ($qRatePlans as $rp) {
             $catalog_rateplan = new Catalog_RatePlan();
             $catalog_rateplan->Id = $rp->Id;
             $catalog_rateplan->Name = $rp->Name;
             $catalog_rateplan->productName = $qProduct->Name;
             $catalog_rateplan->Description = isset($rp->Description) ? $rp->Description : "";
             //Get Charges for the Rate Plan
             $result = $zapi->zQuery("select Id,Name,DefaultQuantity,Description,UOM,ChargeModel,ChargeType,BillingPeriod from ProductRatePlanCharge where ProductRatePlanId='" . $catalog_rateplan->Id . "'");
             $qCharges = array();
             $catalog_rateplan->charges = array();
             $qCharges = $result->result->records;
             if ($qCharges != null) {
                 // start of for loop for rate plan charges
                 foreach ($qCharges as $rpc) {
                     $catalog_charge = new Catalog_Charge();
                     $catalog_charge->Id = $rpc->Id;
                     $catalog_charge->Name = $rpc->Name;
                     $catalog_charge->Description = isset($rpc->Description) ? $rpc->Description : "";
                     $catalog_charge->ChargeModel = $rpc->ChargeModel;
                     $catalog_charge->ChargeType = $rpc->ChargeType;
                     $catalog_charge->BillingPeriod = $rpc->BillingPeriod;
                     if ($catalog_charge->ChargeModel == 'Tiered with Overage Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing') {
                         $catalog_charge->Uom = $rpc->UOM;
                         $catalog_charge->isTiered = true;
                     }
                     if ($catalog_charge->ChargeType != 'Usage' && ($catalog_charge->ChargeModel == 'Per Unit Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing')) {
                         $catalog_charge->Uom = $rpc->UOM;
                         $catalog_charge->quantifiable = true;
                         $catalog_charge->DefaultQuantity = isset($rpc->DefaultQuantity) ? $rpc->DefaultQuantity : "1";
                     }
                     // probably need special case for ChargeModel == Overage Pricing to show overage price
                     //MD New Lines to get detail for the individual charges
                     $result = $zapi->zQuery("select Id,Price,Currency,Tier,StartingUnit,EndingUnit,PriceFormat from ProductRatePlanChargeTier where ProductRatePlanChargeId='" . $catalog_charge->Id . "'");
                     $qChargeTiers = array();
                     $catalog_charge->chargeTiers = array();
                     if ($result->result != null) {
                         usort($result->result->records, "Amender::cmpTiers");
                         $qChargeTiers = $result->result->records;
                         if ($qChargeTiers != null) {
                             foreach ($qChargeTiers as $rpct) {
                                 $catalog_chargeTier = new Catalog_ChargeTier();
                                 $catalog_chargeTier->Id = $rpct->Id;
                                 $catalog_chargeTier->Price = $rpct->Price;
                                 $catalog_chargeTier->Currency = $rpct->Currency;
                                 $catalog_chargeTier->myCurrency = $rpct->Currency == $_SESSION['myCurrency'];
                                 $catalog_chargeTier->Tier = $rpct->Tier;
                                 $catalog_chargeTier->StartingUnit = $rpct->StartingUnit;
                                 $catalog_chargeTier->EndingUnit = $rpct->EndingUnit;
                                 $catalog_chargeTier->PriceFormat = $rpct->PriceFormat;
                                 array_push($catalog_charge->chargeTiers, $catalog_chargeTier);
                             }
                         }
                     }
                     //MD end new lines to get charge detail
                     array_push($catalog_rateplan->charges, $catalog_charge);
                 }
             }
             array_push($catalog_product->ratePlans, $catalog_rateplan);
         }
     }
     return $catalog_product;
 }
Пример #8
0
<?php

function __autoload($class)
{
    @(include './model/' . $class . '.php');
    @(include './controller/' . $class . '.php');
}
//send the user back to the select_products page when completed
header("location: ../account_view.html");
session_start();
global $messages;
$zapi;
try {
    $zapi = new zApi();
} catch (Exception $e) {
    throw new Exception("INVALID_ZLOGIN");
}
$accId = $_SESSION['accountId'];
//Get Default Payment Method Id for this accountl
$defaultPmId;
$accResult = $zapi->zQuery("SELECT DefaultPaymentMethodId FROM Account WHERE Id='" . $accId . "'");
if ($accResult->result->size == 0) {
    // throw new Exception('SUBSCRIPTION_DOES_NOT_EXIST');
    return 'PAYMENT_METHOD_DOES_NOT_EXIST';
}
foreach ($accResult->result->records as $acc) {
    $defaultPmId = $acc->DefaultPaymentMethodId;
}
date_default_timezone_set('America/Los_Angeles');
$date = date('Y-m-d\\TH:i:s');
$payAmt = (double) $_POST["pay_amt"];
Пример #9
0
<?php

function __autoload($class)
{
    @(include 'controller/' . $class . '.php');
}
session_start();
//Start of getting this invoice's body to view as PDF
$zapi;
try {
    $zapi = new zApi();
} catch (Exception $e) {
    return null;
}
$invPdfId = $_POST["pdf_inv_id"];
//Use this invoice and return the body
$invResult = $zapi->zQuery("SELECT Body FROM Invoice WHERE InvoiceNumber='" . $invPdfId . "'");
$body = $invResult->result->records[0]->Body;
header("Content-type: application/pdf");
echo base64_decode($body);
Пример #10
0
 /**
  * Creates dummy subscription with given cart, used to determine the value of the first invoice. Error codes are as follows:
  * 		EMPTY_CART: No items in the cart
  * 		RATE_PLAN_DOESNT_EXIST: No match was found for a rate plan
  * 		RATE_PLAN_EXPIRED: Rate Plan is outside of its effective period
  * @param $cart An instance of a Cart object that contains all rate plans and quantities that will be used in this subscription.
  * @return Subscribe_Preview Object with fields for invoice success result, invoiceAmount if successful, and error code if unsuccessful.
  */
 static function previewCart($cart)
 {
     // Need to FIX this to fail gracefully (not hard-code address info)
     // $firstName = isset($_SESSION['userFname']) ? $_SESSION['userFname'] : 'John';
     // $lastName = isset($_SESSION['userLname']) ? $_SESSION['userLname'] : 'Smith';
     // $Address1 = isset($_SESSION['userAddress1']) ? $_SESSION['userAddress1'] : '';
     // // $Address2 = isset($pm->CreditCardAddress2) ? $pm->CreditCardAddress2 : '';
     // $City = isset($_SESSION['userCity']) ? $_SESSION['userCity'] : '';
     // $Country = isset($_SESSION['userCountry']) ? $_SESSION['userCountry'] : 'USA'; // only USA if left blank
     // $PostalCode = isset($_SESSION['userPostalCode']) ? $_SESSION['userPostalCode'] : '';
     // $State = isset($_SESSION['userState']) ? $_SESSION['userState'] : 'CA'; // only CA if left blank
     // $Phone = isset($_SESSION['userPhone']) ? $_SESSION['userPhone'] : '';
     //Initialize Subscribe_Preview model
     $subscribePreview = new Subscribe_Preview();
     //If Cart is empty, return an empty cart message
     if (count($cart->cart_items) == 0) {
         $subscribePreview->invoiceAmount = 0;
         $subscribePreview->success = false;
         $subscribePreview->error = "EMPTY_CART";
         return $subscribePreview;
     }
     //Preview with SubscribeRequest
     $zapi = new zApi();
     date_default_timezone_set('America/Los_Angeles');
     //		$date = date('Y-m-d',time()) . 'T00:00:00';
     $date = date('Y-m-d\\T00:00:00', time());
     $today = getdate();
     $mday = $today['mday'];
     include "./config.php";
     //Set up account
     $account = array("AutoPay" => 0, "Currency" => $defaultCurrency, "Name" => 'TestName', "PaymentTerm" => "Net 30", "Batch" => "Batch1", "BillCycleDay" => $mday, "Status" => "Active");
     // FIX this
     //Set up contact
     $bcontact = array("Address1" => $Address1, "City" => $City, "Country" => 'USA', "FirstName" => 'John', "LastName" => 'Smith', "PostalCode" => $PostalCode, "State" => 'CA', "WorkEmail" => $userEmail, "WorkPhone" => $Phone);
     $subscribeOptions = array("GenerateInvoice" => true, "ProcessPayments" => false);
     $previewOptions = array("EnablePreviewMode" => true);
     //Set up subscription
     $subscription = array("ContractEffectiveDate" => $date, "ServiceActivationDate" => $date, "ContractAcceptanceDate" => $date, "TermStartDate" => $date, "TermType" => "TERMED", "InitialTerm" => 12, "RenewalTerm" => 12, "AutoRenew" => true, "Status" => "Active");
     $ratePlanData = SubscriptionManager::getRatePlanDataFromCart($cart);
     $subscriptionData = array("Subscription" => $subscription, "RatePlanData" => $ratePlanData);
     $subscribeRequest = array("Account" => $account, "BillToContact" => $bcontact, "SubscribeOptions" => $subscribeOptions, "PreviewOptions" => $previewOptions, "SubscriptionData" => $subscriptionData);
     $subResult = $zapi->zSubscribe($subscribeRequest);
     if ($subResult->result->Success == true) {
         if (isset($subResult->result->InvoiceData)) {
             $subscribePreview->invoiceAmount = $subResult->result->InvoiceData->Invoice->Amount;
             $subscribePreview->success = true;
         } else {
             $subscribePreview->invoiceAmount = number_format((double) 0, 2, '.', '');
             $subscribePreview->success = true;
         }
     } else {
         $subscribePreview->success = false;
         if (count($subResult->result->Errors) == 1) {
             $subResult->result->Errors = array($subResult->result->Errors);
         }
         $errorResponse = $subResult->result->Errors[0]->Message;
         if (strpos($errorResponse, 'ProductRatePlanId is invalid.')) {
             $subscribePreview->error = "RATE_PLAN_DOESNT_EXIST";
         } else {
             if (strpos($errorResponse, 'RatePlan is out of date.')) {
                 $subscribePreview->error = "RATE_PLAN_EXPIRED";
             } else {
                 $subscribePreview->error = $errorResponse;
             }
         }
     }
     return $subscribePreview;
 }