getCheckout()->getQuote();
}
public function getOrderPlaceRedirectUrl() {
return Mage::getUrl("arb/arbPayment/redirect", array("_secure" => true));
}
public function startTransaction() {
var_dump($payment); exit;
$a = $this->getQuote()->getBillingAddress();
$b = $this->getQuote()->getShippingAddress();
$checkout = $this->getCheckout();
$api_login = Mage::getStoreConfig("payment/arb/account_id");
$transation_k = Mage::getStoreConfig('payment/arb/site_id');
$api_server = Mage::getStoreConfig("payment/arb/api_server");
$storename = Mage::getStoreConfig('system/store/name');
$order_id = $checkout->getLastRealOrderId();
$amount = $b->getGrandTotal() * 100;
$currency = "USD";
// send an order e-mail
$order = Mage::getSingleton('sales/order')->loadByIncrementId($order_id);
$order->sendNewOrderEmail();
$order->setEmailSent(true);
$order->save();
// generate items list
$items = "
\n";
foreach ($this->getQuote()->getAllItems() as $item) {
if ($item->getParentItem())
continue;
$items .= "- " . $item->getQty() . " x : " . $item->getName() . "
\n";
}
$items .= "\n";
// calculate signature
$signature = md5(
$amount .
$currency .
$account_id .
$site_id .
$order_id
);
// split address
$street_address = $a->getStreet(1);
$address = $street_address;
$apartment = "";
$offset = strlen($street_address);
while (($offset = $this->rstrpos($street_address, ' ', $offset)) !== false) {
if (is_numeric($street_address[$offset + 1])) {
$address = trim(substr($street_address, 0, $offset));
$apartment = trim(substr($street_address, $offset + 1));
break;
}
}
if (empty($apartment) && is_numeric($street_address[0])) {
$pos = strpos($street_address, ' ');
if ($pos !== false) {
$apartment = trim(substr($street_address, 0, $pos), ", \t\n\r\0\x0B");
$address = trim(substr($street_address, $pos + 1));
}
}
// forwarded ip
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$forward_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$forward_ip = '';
}
$interval_length = 1;
$interval_unit = 'months';
$startDate = date("Y-m-d");
$totalOccurrences = 2;
$trialOccurrences = 0;
$trialAmount = 0.00;
$subscName = 'X3Pure Workshop Subscription';
$this->xml = "
" . $this->xml_escape($api_login) . "
" . $this->xml_escape($transaction_k) . "
" . $this->xml_escape($order_id) . "
" . $this->xml_escape($subscrName) . "
". $this->xml_escape($interval_length) ."
". $this->xml_escape($interval_unit) ."
" . $this->xml_escape($startDate) . "
". $this->xml_escape($totalOccurrences) . "
". $this->xml_escape($trialOccurrences) . "
". $this->xml_escape($amount) ."
" . $this->xml_escape($trialAmount) . "
" . $this->params['cardNumber'] . "
" . $this->params['expirationDate'] . "
". $this->xml_escape($a->getFirstname()) . "
" . $this->xml_escape($a->getLastname()) . "
" . $this->xml_escape($address) . "
" . $this->xml_escape($a->getCity()) . "
" . $this->xml_escape($a->getState()) . "
" . $this->xml_escape($a->getPostcode()) . "
" . $this->xml_escape($a->getCountry()) . "
";
$this->process();
}
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 = "
" . self::LOGIN . "
" . self::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->process();
}
public function updateAccount() {
$this->xml = "
" . self::LOGIN . "
" . self::TRANSKEY . "
" . $this->params['refID'] ."
" . $this->params['subscrId'] . "
" . $this->params['cardNumber'] . "
" . $this->params['expirationDate'] . "
";
$this->process();
}
public function deleteAccount() {
$this->xml = "
" . self::LOGIN . "
" . self::TRANSKEY . "
" . $this->params['refID'] ."
" . $this->params['subscrId'] . "
";
$this->process();
}
private function parseResults() {
$this->resultCode = $this->parseXML('', '');
$this->code = $this->parseXML('', '');
$this->text = $this->parseXML('', '');
$this->subscrId = $this->parseXML('', '');
}
private function ParseXML($start, $end) {
$start_position = strpos($this->response, $start) + strlen($end);
$end_position = strpos($this->response, $start);
return substr($this->response, $start_position - 1, $end_position - $start_position);
}
public function setParameter($field = "", $value = null) {
$field = (is_string($field)) ? trim($field) : $field;
$value = (is_string($value)) ? trim($value) : $value;
if (!is_string($field)) {
throw new AuthnetARBException("setParameter() arg 1 must be a string or integer: " . gettype($field) . " given.");
}
if (!is_string($value) && !is_numeric($value) && !is_bool($value)) {
throw new AuthnetARBException("setParameter() arg 2 must be a string, integer, or boolean value: " . gettype($value) . " given.");
}
if (empty($field)) {
throw new AuthnetARBException("setParameter() requires a parameter field to be named.");
}
if ($value === "") {
throw new AuthnetARBException("setParameter() requires a parameter value to be assigned: $field");
}
$this->params[$field] = $value;
}
public function isSuccessful() {
return $this->success;
}
public function isError() {
return $this->error;
}
public function getResponse() {
return $this->text;
}
public function getSubscriberID() {
return $this->subscrId;
}
}
?>