login = $login; $this->transkey = $transkey; $this->test = $test; $subdomain = ($this->test) ? 'apitest' : 'api'; $this->url = "https://" . $subdomain . ".authorize.net/xml/v1/request.api"; } function getString() { if (!$this->params) { return (string) $this; } $output = ""; $output .= '' . "\n"; $output .= '' . "\n\t\t" . '' . "\n" . '' . "\n"; foreach ($this->params as $key => $value) { $output .= "\t" . '' . "\n\t\t" . ''; $output .= '' . "\n" . '' . "\n"; } $output .= '
Outgoing Parameters
' . $key . '' . $value . '
' . "\n"; return $output; } function process($retries = 3) { $count = 0; while ($count < $retries) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->xml); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $this->response = curl_exec($ch); $this->parseResults(); if ($this->resultCode === "Ok") { $this->success = true; $this->error = false; break; } else { $this->success = false; $this->error = true; break; } $count++; } curl_close($ch); } function createAccount() { $this->xml = " " . $this->login . " " . $this->transkey . " " . $this->params['refID'] ." ". $this->params['subscrName'] ." ". $this->params['interval_length'] ." ". $this->params['interval_unit'] ." " . $this->params['startDate'] . " ". $this->params['totalOccurrences'] . " ". $this->params['trialOccurrences'] . " ". $this->params['amount'] ." " . $this->params['trialAmount'] . " " . $this->params['cardNumber'] . " " . $this->params['expirationDate'] . " ". $this->params['firstName'] . " " . $this->params['lastName'] . "
" . $this->params['address'] . "
" . $this->params['city'] . " " . $this->params['state'] . " " . $this->params['zip'] . " " . $this->params['country'] . "
"; $this->process(); } function updateAccount() { $this->xml = " " . $this->login . " " . $this->transkey . " " . $this->params['refID'] ." " . $this->params['subscrId'] . " " . $this->params['cardNumber'] . " " . $this->params['expirationDate'] . " "; $this->process(); } function deleteAccount() { $this->xml = " " . $this->login . " " . $this->transkey . " " . $this->params['refID'] ." " . $this->params['subscrId'] . " "; $this->process(); } function parseResults() { $this->resultCode = $this->substring_between($this->response,'',''); $this->code = $this->substring_between($this->response,'',''); $this->text = $this->substring_between($this->response,'',''); $this->subscrId = $this->substring_between($this->response,'',''); } function substring_between($haystack,$start,$end) { if (strpos($haystack,$start) === false || strpos($haystack,$end) === false) { return false; } else { $start_position = strpos($haystack,$start)+strlen($start); $end_position = strpos($haystack,$end); return substr($haystack,$start_position,$end_position-$start_position); } } function setParameter($field = "", $value = null) { $field = (is_string($field)) ? trim($field) : $field; $value = (is_string($value)) ? trim($value) : $value; if (!is_string($field)) { die("setParameter() arg 1 must be a string or integer: " . gettype($field) . " given."); } if (!is_string($value) && !is_numeric($value) && !is_bool($value)) { die("setParameter() arg 2 must be a string, integer, or boolean value: " . gettype($value) . " given."); } if (empty($field)) { die("setParameter() requires a parameter field to be named."); } if ($value === "") { die("setParameter() requires a parameter value to be assigned: $field"); } $this->params[$field] = $value; } function isSuccessful() { return $this->success; } function isError() { return $this->error; } function getResponse() { return $this->text; } function getRawResponse() { return $this->response; } function getResultCode() { return $this->resultCode; } function getSubscriberID() { return $this->subscrId; } }