function test_sApi_createAccount() { printResultStart(__FUNCTION__); $messages = array(); //Test try { $sfdcRes = sApi::createSfdcAccount('NEW-ECOMMERCE-TEST-ACCOUNT'); print_r_html($sfdcRes); } catch (Exception $e) { array_push($messages, $e->getMessage()); } printResultEnd($messages); }
function setAccountInfo() { global $messages; $_SESSION['userEmail'] = $_REQUEST['userEmail']; $_SESSION['userFname'] = $_REQUEST['userFname']; $_SESSION['userLname'] = $_REQUEST['userLname']; $_SESSION['userPhone'] = $_REQUEST['userPhone']; $_SESSION['userAddress1'] = $_REQUEST['userAddress1']; $_SESSION['userCity'] = $_REQUEST['userCity']; $_SESSION['userCountry'] = $_REQUEST['userCountry']; $_SESSION['countryIso'] = $_REQUEST['countryIso']; $_SESSION['userState'] = $_REQUEST['userState']; $_SESSION['stateFullName'] = $_REQUEST['stateFullName']; $_SESSION['userPostalCode'] = $_REQUEST['userPostalCode']; try { // create SFDC lead $sfdcResponse = sApi::createSfdcLead(); if ($sfdcResponse->success) { $_SESSION["LeadId"] = $sfdcResponse->id; } } catch (Exception $e) { error_log('Lead: ' . $userEmail . ' could not be created in Salesforce: ' . $e->getMessage()); } $acctInfo = array($_SESSION['userEmail'], $_SESSION['userFname'], $_SESSION['userLname'], $_SESSION['userPhone'], $_SESSION['userAddress1'], $_SESSION['userCity'], $_SESSION['userCountry'], $_SESSION['userState'], $_SESSION['userPostalCode'], $_SESSION["LeadId"]); $messages = $acctInfo; }
/** * Creates a subscription after a user has successfully submitted their payment information. Subscribes using email address as account name, contact information from the created payment method, and rate plan data from the given Cart * @param $userEmail User's given Email address * @param $cart An instance of a Cart object that contains all rate plans and quantities that will be used in this subscription. * @param $pmId PaymentMethod ID that was created in Zuora by the Z-Payments Page * @return SubscribeResult. If the email has already been used in this tenant, returns the error string, 'DUPLICATE_EMAIL', If the Payment Method ID passed doesn't exist, returns the error string, 'INVALID_PMID' */ static function subscribeWithCart($userEmail, $pmId, $cart) { $zapi = new zApi(); if ($cart == null || !isset($cart->cart_items)) { return 'CART_NOT_INITIALIZED'; } $firstName = isset($_SESSION['userFname']) ? $_SESSION['userFname'] : ''; $lastName = isset($_SESSION['userLname']) ? $_SESSION['userLname'] : ''; $Address1 = isset($_SESSION['userAddress1']) ? $_SESSION['userAddress1'] : ''; // $Address2 = isset($pm->CreditCardAddress2) ? $pm->CreditCardAddress2 : ''; $City = isset($_SESSION['userCity']) ? $_SESSION['userCity'] : ''; $Country = isset($_SESSION['userCountry']) ? $_SESSION['userCountry'] : ''; $PostalCode = isset($_SESSION['userPostalCode']) ? $_SESSION['userPostalCode'] : ''; $State = isset($_SESSION['userState']) ? $_SESSION['userState'] : ''; $Phone = isset($_SESSION['userPhone']) ? $_SESSION['userPhone'] : ''; date_default_timezone_set('America/Los_Angeles'); $date = date('Y-m-d\\TH:i:s', time()); $today = getdate(); $mday = $today['mday']; include "./config.php"; //Set up account $account = array("AutoPay" => $defaultAutopay, "Currency" => $defaultCurrency, "Name" => $userEmail, "PaymentTerm" => $defaultPaymentTerm, "Batch" => $defaultBatch, "BillCycleDay" => $mday, "Status" => "Active"); if ($makeSfdcAccount == true) { try { //Integrate with Salesforce $sfdcResponse = sApi::convertSfdcLead(); if ($sfdcResponse->success) { $account["CrmId"] = $sfdcResponse->accountId; } } catch (Exception $e) { error_log('Account ' . $userEmail . ' could not be created in Salesforce: ' . $e->getMessage()); } } //Set up Payment Method $pm = array("Id" => $pmId); //Set up contact $bcontact = array("Address1" => $Address1, "City" => $City, "Country" => $Country, "FirstName" => $firstName, "LastName" => $lastName, "PostalCode" => $PostalCode, "State" => $State, "WorkEmail" => $userEmail, "WorkPhone" => $Phone); $subscribeOptions = array("GenerateInvoice" => true, "ProcessPayments" => true); $previewOptions = array("EnablePreviewMode" => false); //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, "PaymentMethod" => $pm, "SubscribeOptions" => $subscribeOptions, "SubscriptionData" => $subscriptionData); $subResult = $zapi->zSubscribe($subscribeRequest); $subResult->sfdcResponse = $sfdcResponse; return $subResult; }