Exemplo n.º 1
0
function test_zApi_Subscribe()
{
    printResultStart(__FUNCTION__);
    $messages = array();
    try {
        $zapi = new zApi();
        $date = date('Y-m-d\\TH:i:s', time());
        $today = getdate();
        $mday = $today['mday'];
        //Set up account
        $account = array("AutoPay" => 0, "Currency" => "USD", "Name" => "TestSubscriber", "PaymentTerm" => "Net 30", "Batch" => "Batch1", "BillCycleDay" => $mday, "Status" => "Active");
        //Set up contact
        $bcontact = array("Address1" => "123 Main", "Address2" => "Apt 1", "City" => "Santa Clara", "Country" => "United States", "FirstName" => "John", "LastName" => "Smith", "PostalCode" => "99999", "State" => "California", "WorkEmail" => "*****@*****.**", "WorkPhone" => "555-555-5555");
        $scontact = array("Address1" => "123 Main", "Address2" => "Apt 1", "City" => "Santa Clara", "Country" => "United States", "FirstName" => "John", "LastName" => "Smith", "PostalCode" => "99999", "State" => "California", "WorkEmail" => "*****@*****.**", "WorkPhone" => "555-555-5555");
        $subscribeOptions = array("GenerateInvoice" => false, "ProcessPayments" => false);
        $previewOptions = array("EnablePreviewMode" => false);
        //Set up subscription
        $subscription = array("AutoRenew" => 0, "InitialTerm" => 12, "RenewalTerm" => 12, "ContractEffectiveDate" => $date, "ServiceActivationDate" => $date, "ContractAcceptanceDate" => $date, "TermStartDate" => $date, "TermType" => "TERMED", "Status" => "Active");
        $ratePlanData = array(array("RatePlan" => array("ProductRatePlanId" => "4028e69737d27a3f0137f11e73b307c7")));
        $subscriptionData = array("Subscription" => $subscription, "RatePlanData" => $ratePlanData);
        $subscribeRequest = array("Account" => $account, "BillToContact" => $bcontact, "SoldToContact" => $scontact, "SubscribeOptions" => $subscribeOptions, "SubscriptionData" => $subscriptionData);
        print_r_html($subscribeRequest);
        //Subscribe
        $subResult = $zapi->zSubscribe($subscribeRequest);
        print_r_html($subResult);
        echo "Deleting subscription.<br>";
        $deleteResult = $zapi->zDelete(array($subResult->result->AccountId), 'Account');
        print_r_html($deleteResult);
    } catch (Exception $e) {
        array_push($messages, "Test Exception: " . $e->getMessage());
    }
    //Report
    printResultEnd($messages);
}
Exemplo n.º 2
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;
 }