Esempio n. 1
0
 /**
  * Update the given user's information
  * @param $accountName Name of the target account
  * @param $firstName user's new first name
  * @param $lastName user's new last name
  * @param $address user's new address
  * @param $city user's new first city
  * @param $state user's new first state
  * @param $postalCode user's new postalCode
  * @param $country user's new country
  * @return SaveResult
  */
 public static function updateContact($contactId, $firstName, $lastName, $address, $city, $state, $postalCode, $country)
 {
     $zapi;
     try {
         $zapi = new zApi();
     } catch (Exception $e) {
         return 'INVALID_ZLOGIN';
     }
     if ($contactId == NULL) {
         return 'USER_DOESNT_EXIST';
     }
     //Get Contact with this contactId
     $conResult = $zapi->zQuery("SELECT Id,FirstName,LastName,Country,Address1,City,State,PostalCode FROM Contact WHERE Id='" . $contactId . "'");
     if (count($conResult) == 0) {
         return 'CONTACT_DOESNT_EXIST';
     }
     $con = NULL;
     foreach ($conResult->result->records as $icon) {
         $con = $icon;
     }
     //Create a Contact record with this ID, and all parameters that were passed in.
     $updCon = array("Id" => $contactId);
     if ($firstName != NULL && $con->FirstName != $firstName) {
         $updCon["FirstName"] = $firstName;
     }
     if ($lastName != NULL && $con->LastName != $lastName) {
         $updCon["LastName"] = $lastName;
     }
     if ($country != NULL && (!isset($con->Country) || $con->Country != $country)) {
         $updCon["Country"] = $country;
     }
     if ($address != NULL && (!isset($con->Address1) || $con->Address1 != $address)) {
         $updCon["Address1"] = $address;
     }
     if ($postalCode != NULL && (!isset($con->postalCode) || $con->PostalCode != $postalCode)) {
         $updCon["PostalCode"] = $postalCode;
     }
     if ($city != NULL && (!isset($con->city) || $con->City != $city)) {
         $updCon["City"] = $city;
     }
     if ($state != NULL && (!isset($con->state) || $con->State != $state)) {
         $updCon["State"] = $state;
     }
     $updCons = array($updCon);
     $updRes = $zapi->zCreateUpdate('update', $updCons, 'Contact');
     return $updRes->result;
 }
Esempio n. 2
0
function test_zApi_Create()
{
    printResultStart(__FUNCTION__);
    $messages = array();
    //Test
    try {
        $zapi = new zApi();
        $newProduct1 = array("Name" => "TestProduct1", "EffectiveStartDate" => "2000-01-01T00:00:00.000-08:00", "EffectiveEndDate" => "3000-01-01T00:00:00.000-08:00");
        $newProduct2 = array("Name" => "TestProduct2", "EffectiveStartDate" => "2000-01-01T00:00:00.000-08:00", "EffectiveEndDate" => "3000-01-01T00:00:00.000-08:00");
        $objs = array($newProduct1, $newProduct2);
        $createResult = $zapi->zCreateUpdate('create', $objs, 'Product');
        print_r_html($createResult);
    } catch (Exception $e) {
        array_push($messages, "Create Exception.");
        array_push($messages, "Exception: " . $e->getMessage());
    }
    //Report
    printResultEnd($messages);
}
Esempio n. 3
0
 /**
  * Sets the default payment method of the given user to a different paymentmethod on their account
  * @param $accountName Name of the target account
  * @param $pmId ID of new active payment method
  */
 public static function changePaymentMethod($accId, $pmId)
 {
     $zapi;
     try {
         $zapi = new zApi();
     } catch (Exception $e) {
         throw new Exception('INVALID_ZLOGIN');
     }
     if ($accId == NULL) {
         throw new Exception('ACCOUNT_DOESNT_EXIST');
     }
     $uAcc = array("Id" => $accId, "DefaultPaymentMethodId" => $pmId);
     $objs = array($uAcc);
     $updResult = $zapi->zCreateUpdate('update', $objs, 'Account');
     return $updResult;
 }
Esempio n. 4
0
}
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"];
$invId = $_POST["inv_id"];
$invBal = (double) $_POST["inv_bal"];
echo "<br>inv_num: " . $invId;
echo "<br>pay_amt: " . $payAmt;
echo "<br>inv_bal: " . $invBal;
if ($payAmt > $invBal) {
    $credBal = $payAmt - $invBal;
    $appliedPayAmt = $invBal;
} else {
    $credBal = (double) 0.0;
    $appliedPayAmt = $payAmt;
}
$myInvoicePayment = array("Amount" => $appliedPayAmt, "InvoiceId" => $invId);
$invoicePayments = array("InvoicePayment" => $myInvoicePayment);
$newPayment = array('AccountId' => $accId, 'AppliedCreditBalanceAmount' => $credBal, 'EffectiveDate' => $date, 'PaymentMethodId' => $defaultPmId, 'Type' => 'Electronic', 'Status' => 'Processed', 'InvoicePaymentData' => $invoicePayments);
$objs = array($newPayment);
try {
    $createPaymentResult = $zapi->zCreateUpdate('create', $objs, 'Payment');
} catch (Exception $e) {
    array_push($messages, "Create Exception.");
    array_push($messages, "Exception: " . $e->getMessage());
}
$responseArray = $createPaymentResult->result[0];
return $createPaymentResult->result;