test) ? 'apitest' : 'api'; $this->url = "https://" . $subdomain . ".authorize.net/xml/v1/request.api"; $this->params['interval_unit'] = 'months'; $this->params['interval_length'] = 1; $this->params['startDate'] = date("Y-m-d", strtotime("+ 1 month")); $this->params['totalOccurrences'] = 9999; $this->params['trialOccurrences'] = 0; $this->params['trialAmount'] = 0.00; } private 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); } public function createAccount() { $this->xml = "<?xml version='1.0' encoding='utf-8'?> <ARBCreateSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'> <merchantAuthentication> <name>" . $this->login . "</name> <transactionKey>" . $this->transkey . "</transactionKey> </merchantAuthentication> <refId>" . $this->params['refID'] ."</refId> <subscription> <name>". $this->params['subscrName'] ."</name> <paymentSchedule> <interval> <length>". $this->params['interval_length'] ."</length> <unit>". $this->params['interval_unit'] ."</unit> </interval> <startDate>" . $this->params['startDate'] . "</startDate> <totalOccurrences>". $this->params['totalOccurrences'] . "</totalOccurrences> <trialOccurrences>". $this->params['trialOccurrences'] . "</trialOccurrences> </paymentSchedule> <amount>". $this->params['amount'] ."</amount> <trialAmount>" . $this->params['trialAmount'] . "</trialAmount> <payment> <creditCard> <cardNumber>" . $this->params['cardNumber'] . "</cardNumber> <expirationDate>" . $this->params['expirationDate'] . "</expirationDate> </creditCard> </payment> <billTo> <firstName>". $this->params['firstName'] . "</firstName> <lastName>" . $this->params['lastName'] . "</lastName> <address>" . $this->params['address'] . "</address> <city>" . $this->params['city'] . "</city> <state>" . $this->params['state'] . "</state> <zip>" . $this->params['zip'] . "</zip> </billTo> </subscription> </ARBCreateSubscriptionRequest>"; $this->process(); } public function setParameter($field = "", $value = null) { $field = (is_string($field)) ? trim($field) : $field; $value = (is_string($value)) ? trim($value) : $value; $this->params[$field] = $value; } private function parseResults() { $this->resultCode = $this->parseXML('<resultCode>', '</resultCode>'); $this->code = $this->parseXML('<code>', '</code>'); $this->text = $this->parseXML('<text>', '</text>'); $this->subscrId = $this->parseXML('<subscriptionId>', '</subscriptionId>'); } private function ParseXML($start, $end) { return preg_replace('|^.*?'.$start.'(.*?)'.$end.'.*?$|i', '$1', substr($this->response, 335)); } public function getSubscriberID() { return $this->subscrId; } public function isSuccessful() { return $this->success; } public function isError() { return $this->error; } } ?>