The page you are looking at now is at this URL: http://pastoid.com/av2
This paste was last updated on April 18, 2009 at 11:54 am.
<?php /** * Our test CC module adapter */ class Mage_Arb_Model_ArbPayment extends Mage_Payment_Model_Method_Abstract { /** * unique internal payment method identifier * * @var string [a-z0-9_] */ protected $_code = 'arb'; protected $_formBlockType = 'Arb/form'; protected $_isGateway = true; protected $_canAuthorize = true; protected $_canCapture = true; protected $_canCapturePartial = false; protected $_canRefund = false; protected $_canVoid = true; protected $_canUseInternal = true; protected $_canUseCheckout = true; protected $_canUseForMultishipping = false; protected $_canSaveCc = false; private $_arb_version = '1.0.0'; private $test = false; private $params = array(); private $sucess = false; private $error = true; private $xml; private $response; private $resultCode; private $code; private $text; private $subscrId; public function getCheckout() { return Mage::getSingleton("checkout/session"); } public function getQuote() { return $this->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 = "<ul>\n"; foreach ($this->getQuote()->getAllItems() as $item) { if ($item->getParentItem()) continue; $items .= "<li>" . $item->getQty() . " x : " . $item->getName() . "</li>\n"; } $items .= "<ul>\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 = "<?xml version='1.0' encoding='utf-8'?> <ARBCreateSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'> <merchantAuthentication> <name>" . $this->xml_escape($api_login) . "</name> <transactionKey>" . $this->xml_escape($transaction_k) . "</transactionKey> </merchantAuthentication> <refId>" . $this->xml_escape($order_id) . "</refId> <subscription> <name>" . $this->xml_escape($subscrName) . "</name> <paymentSchedule> <interval> <length>". $this->xml_escape($interval_length) ."</length> <unit>". $this->xml_escape($interval_unit) ."</unit> </interval> <startDate>" . $this->xml_escape($startDate) . "</startDate> <totalOccurrences>". $this->xml_escape($totalOccurrences) . "</totalOccurrences> <trialOccurrences>". $this->xml_escape($trialOccurrences) . "</trialOccurrences> </paymentSchedule> <amount>". $this->xml_escape($amount) ."</amount> <trialAmount>" . $this->xml_escape($trialAmount) . "</trialAmount> <payment> <creditCard> <cardNumber>" . $this->params['cardNumber'] . "</cardNumber> <expirationDate>" . $this->params['expirationDate'] . "</expirationDate> </creditCard> </payment> <billTo> <firstName>". $this->xml_escape($a->getFirstname()) . "</firstName> <lastName>" . $this->xml_escape($a->getLastname()) . "</lastName> <address>" . $this->xml_escape($address) . "</address> <city>" . $this->xml_escape($a->getCity()) . "</city> <state>" . $this->xml_escape($a->getState()) . "</state> <zip>" . $this->xml_escape($a->getPostcode()) . "</zip> <country>" . $this->xml_escape($a->getCountry()) . "</country> </billTo> </subscription> </ARBCreateSubscriptionRequest>"; $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 = "<?xml version='1.0' encoding='utf-8'?> <ARBCreateSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'> <merchantAuthentication> <name>" . self::LOGIN . "</name> <transactionKey>" . self::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> </billTo> </subscription> </ARBCreateSubscriptionRequest>"; $this->process(); } public function updateAccount() { $this->xml = "<?xml version='1.0' encoding='utf-8'?> <ARBUpdateSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'> <merchantAuthentication> <name>" . self::LOGIN . "</name> <transactionKey>" . self::TRANSKEY . "</transactionKey> </merchantAuthentication> <refId>" . $this->params['refID'] ."</refId> <subscriptionId>" . $this->params['subscrId'] . "</subscriptionId> <subscription> <payment> <creditCard> <cardNumber>" . $this->params['cardNumber'] . "</cardNumber> <expirationDate>" . $this->params['expirationDate'] . "</expirationDate> </creditCard> </payment> </subscription> </ARBUpdateSubscriptionRequest>"; $this->process(); } public function deleteAccount() { $this->xml = "<?xml version='1.0' encoding='utf-8'?> <ARBCancelSubscriptionRequest xmlns='AnetApi/xml/v1/schema/AnetApiSchema.xsd'> <merchantAuthentication> <name>" . self::LOGIN . "</name> <transactionKey>" . self::TRANSKEY . "</transactionKey> </merchantAuthentication> <refId>" . $this->params['refID'] ."</refId> <subscriptionId>" . $this->params['subscrId'] . "</subscriptionId> </ARBCancelSubscriptionRequest>"; $this->process(); } 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) { $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; } } ?>
| Referring Domain | Hits |
|---|---|
| Unknown Referer | 127 |
| www.google.nl | 21 |
| www.google.com | 11 |
| www.google.de | 5 |
| www.google.pl | 1 |
| www.google.cl | 1 |
| www.google.ca | 1 |
| www.articleshmarticle.com | 1 |
| search.live.com | 1 |
Tip: Use Pastoid to shorten URLs with this bookmarklet: Pastoid This