Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Paytrace
 
rajeesh
Jr. Member
 
Total Posts:  5
Joined:  2008-08-31
 

app/code/local/Mage/NewModule/Model/PaymentMethod.php

<?php
/**
* Our test CC module adapter
*/
class Mage_Paytrace_Model_PaymentMethod extends Mage_Payment_Model_Method_Cc
{
protected $_code = 'paytrace';

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 = true;
protected $_canSaveCc = false;

const RESPONSE_CODE_APPROVED = 1;
const RESPONSE_CODE_DECLINED = 2;
const RESPONSE_CODE_ERROR = 3;
const RESPONSE_CODE_HELD = 4;


public function paytrace(Mage_Payment_Model_Method_Cc $payment, $amount)
{
if($amount>0){
$order = $payment->getOrder();
$billing = $order->getBillingAddress();
$ccnum = $payment->getCcNumber();
$expmth = $payment->getCcExpMonth();
$expyr = $payment->getCcExpYear();

$parmlist = "parmlist=UN~demo123|PSWD~demo123|TERMS~Y|";
$parmlist .= "METHOD~ProcessTranx|TRANXTYPE~Sale|";
$parmlist .= "CC~$ccnum|EXPMNTH~$expmth|EXPYR~$expyr|";
$parmlist .= "AMOUNT~$amount|CSC~999|";
$parmlist .= "BADDRESS~$billing->getStreet(1) Main|BZIP~$billing->getPostcode()|";

$header = array("MIME-Version: 1.0","Content-type: application/x-www-form-urlencoded","Contenttransfer-encoding: text");

//point the cUrl to PayTrace's servers
$url = "https://paytrace.com/api/default.pay";

$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
//Depending on your PHP Host, you may need to specify their proxy server
//curl_setopt ($ch, CURLOPT_PROXY, "http://proxyaddress:port");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parmlist);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
// grab URL and pass it to the browser
$response = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);

//parse through the response.
$responseArr = explode('|', $response);
foreach ($responseArr as $pair ){
$tmp = explode('~',$pair);
$vars[$tmp[0]] = $tmp[1];
}
$approved = False;

//search through the name/value pairs for the APCODE
foreach($vars as $key => $value){
if ( $key == "APPCODE" ) {
if ( $value != "" ) {
$approved = True;
}
} elseif ( $key == "ERROR" ) {
$ErrorMessage .= $value;
}
} // end for loop

if ( $ErrorMessage != "" ) {
$error = Mage::helper('paytrace')->__('Your transaction was not successful per this response, ' . $ErrorMessage . '<br>');
//Not approved because an error caught by PayTrace (i.e. invalid card number, amount, etc.)
} else {
if ( $approved == True ) {
$error = Mage::helper('paytrace')->__('Your transaction was successfully approved.<br>');
} else {
$error = Mage::helper('paytrace')->__('Your transaction was not successful was not approved.<br>');
//Not approved by issuing bank.
} //end if transaction was approved
} //end if error message
} else {
$error = Mage::helper('paytrace')->__('Invalid amount for authorization.');
}

if ($error !== false) {
Mage::throwException($error);
}
return $this;
}
}

?>

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top