diff --git a/2checkout/2checkout/helper.php b/2checkout/2checkout/helper.php index 03b745c..63c84c9 100755 --- a/2checkout/2checkout/helper.php +++ b/2checkout/2checkout/helper.php @@ -1,29 +1,60 @@ params->get('secure_post'); $url = $this->params->get('sandbox') ? 'www.sandbox.paypal.com' : 'www.paypal.com'; - if ($secure_post) + + if ($secure_post) + { $url = 'https://' . $url . '/cgi-bin/webscr'; + } else + { $url = 'http://' . $url . '/cgi-bin/webscr'; - + } + return $url; } - - function Storelog($name,$logdata) + + /** + * Store log + * + * @param string $name name. + * + * @param array $logdata data. + * + * @since 1.0 + * @return list. + */ + public function Storelog($name,$logdata) { jimport('joomla.error.log'); $options = "{DATE}\t{TIME}\t{USER}\t{DESC}"; @@ -32,7 +63,7 @@ function Storelog($name,$logdata) JLog::addLogger( array( - 'text_file' => $logdata['JT_CLIENT'].'_'.$name.'.log', + 'text_file' => $logdata['JT_CLIENT'] . '_' . $name . '.log', 'text_entry_format' => $options ), JLog::INFO, @@ -40,52 +71,84 @@ function Storelog($name,$logdata) ); $logEntry = new JLogEntry('Transaction added', JLog::INFO, $logdata['JT_CLIENT']); - $logEntry->user = $my->name.'('.$my->id.')'; + $logEntry->user = $my->name . '(' . $my->id . ')'; $logEntry->desc = json_encode($logdata['raw_data']); JLog::add($logEntry); - //$logs = &JLog::getInstance($logdata['JT_CLIENT'].'_'.$name.'.log',$options,$path); - //$logs->addEntry(array('user' => $my->name.'('.$my->id.')','desc'=>json_encode($logdata['raw_data']))); + // $logs = &JLog::getInstance($logdata['JT_CLIENT'].'_'.$name.'.log',$options,$path); + // $logs->addEntry(array('user' => $my->name.'('.$my->id.')','desc'=>json_encode($logdata['raw_data']))); } - function validateIPN($data,$secret) - { - $incoming_md5 = strtoupper($data['md5_hash']); + /** + * validateIPN. + * + * @param string $data data + * @param string $secret data + * + * @since 2.2 + * + * @return string data + */ + public function validateIPN($data, $secret) + { + $incoming_md5 = strtoupper($data['md5_hash']); $calculated_md5 = md5( - $data['sale_id']. - $data['vendor_id']. - $data['invoice_id']. + $data['sale_id'] . + $data['vendor_id'] . + $data['invoice_id'] . $secret ); $calculated_md5 = strtoupper($calculated_md5); - + return ($calculated_md5 == $incoming_md5); - } - function log_ipn_results($success) { - - if (!$this->ipn_log) return; - - // Timestamp - $text = '['.date('m/d/Y g:i A').'] - '; - - // Success or failure being logged? - if ($success) $text .= "SUCCESS!\n"; - else $text .= 'FAIL: '.$this->last_error."\n"; - - // Log the POST variables - $text .= "IPN POST Vars from Paypal:\n"; - foreach ($this->ipn_data as $key=>$value) { - $text .= "$key=$value, "; - } - - // Log the response from the paypal server - $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response; - // Write to log - $fp=fopen($this->ipn_log_file,'a'); - fwrite($fp, $text . "\n\n"); - fclose($fp); // close file - } + /** + * log_ipn_results. + * + * @param string $success success + * + * @since 2.2 + * + * @return string success + */ + public function log_ipn_results($success) + { + if (!$this->ipn_log) + { + return; + } + + // Timestamp + $text = '[' . date('m/d/Y g:i A') . '] - '; + + // Success or failure being logged? + if ($success) + { + $text .= "SUCCESS!\n"; + } + else + { + $text .= 'FAIL: ' . $this->last_error . "\n"; + } + + // Log the POST variables + $text .= "IPN POST Vars from Paypal:\n"; + + foreach ($this->ipn_data as $key => $value) + { + $text .= "$key=$value, "; + } + + // Log the response from the paypal server + $text .= "\nIPN Response from Paypal Server:\n " . $this->ipn_response; + + // Write to log + $fp = fopen($this->ipn_log_file, 'a'); + fwrite($fp, $text . "\n\n"); + + // Close file + fclose($fp); + } } diff --git a/paypal_adaptive_payment/adaptive_paypal.php b/paypal_adaptive_payment/adaptive_paypal.php index 96fba14..5792b0c 100755 --- a/paypal_adaptive_payment/adaptive_paypal.php +++ b/paypal_adaptive_payment/adaptive_paypal.php @@ -6,173 +6,282 @@ * @license GNU General Public License version 2 or later. */ -// no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); -jimport( 'joomla.plugin.plugin' ); -if(JVERSION >='1.6.0') - require_once(JPATH_SITE.'/plugins/payment/adaptive_paypal/adaptive_paypal/helper.php'); +// No direct access +defined('_JEXEC') or die('Restricted access'); + +jimport('joomla.plugin.plugin'); + +if (JVERSION >= '1.6.0') +{ + require_once JPATH_SITE . '/plugins/payment/adaptive_paypal/adaptive_paypal/helper.php'; +} else - require_once(JPATH_SITE.'/plugins/payment/adaptive_paypal/helper.php'); -$lang = JFactory::getLanguage(); +{ + require_once JPATH_SITE . '/plugins/payment/adaptive_paypal/helper.php'; +} + +$lang = JFactory::getLanguage(); $lang->load('plg_payment_adaptive_paypal', JPATH_ADMINISTRATOR); -class plgPaymentAdaptive_Paypal extends JPlugin +/** + * PlgPaymentAdaptive_Paypal + * + * @package CPG + * @subpackage site + * @since 2.2 + */ +class PlgPaymentAdaptive_Paypal extends JPlugin { - - function __construct(& $subject, $config) + /** + * Constructor + * + * @param string &$subject subject + * + * @param string $config config + */ + public function __construct(&$subject, $config) { parent::__construct($subject, $config); - - //Set the language in the class + // Set the language in the class $config = JFactory::getConfig(); - //Define Payment Status codes in Paypal And Respective Alias in Framework + // Define Payment Status codes in Paypal And Respective Alias in Framework $this->responseStatus = array( - 'COMPLETED' => 'C', - 'INCOMPLETE' => 'P','PROCESSING'=>'P','PENDING'=>'P','CREATED'=>'P', - 'ERROR'=>'E','DENIED'=>'D','FAILED'=>'E', - 'PARTIALLY_REFUNDED'=>'RF','REVERSALERROR'=>'CRV','REFUNDED'=>'RF', - 'REVERSED'=>'RV' + 'COMPLETED' => 'C', + 'INCOMPLETE' => 'P', + 'PROCESSING' => 'P', + 'PENDING' => 'P', + 'CREATED' => 'P', + 'ERROR' => 'E', + 'DENIED' => 'D', + 'FAILED' => 'E', + 'PARTIALLY_REFUNDED' => 'RF', + 'REVERSALERROR' => 'CRV', + 'REFUNDED' => 'RF', + 'REVERSED' => 'RV' ); $this->headers = array( - "X-PAYPAL-SECURITY-USERID:".$this->params->get('apiuser'), - "X-PAYPAL-SECURITY-PASSWORD:".$this->params->get('apipass'), - "X-PAYPAL-SECURITY-SIGNATURE:".$this->params->get('apisign'), + "X-PAYPAL-SECURITY-USERID:" . $this->params->get('apiuser'), + "X-PAYPAL-SECURITY-PASSWORD:" . $this->params->get('apipass'), + "X-PAYPAL-SECURITY-SIGNATURE:" . $this->params->get('apisign'), "X-PAYPAL-REQUEST-DATA-FORMAT:JSON", "X-PAYPAL-RESPONSE-DATA-FORMAT:JSON", - "X-PAYPAL-APPLICATION-ID:".$this->params->get('apiid') + "X-PAYPAL-APPLICATION-ID:" . $this->params->get('apiid') ); $this->envelope = array( - "errorLanguage"=>"en_US", - "detailLevel"=>"ReturnAll" + "errorLanguage" => "en_US", + "detailLevel" => "ReturnAll" ); + $plugin = JPluginHelper::getPlugin('payment', 'adaptive_paypal'); $params = json_decode($plugin->params); - $this->apiurl = $params->sandbox ? 'https://svcs.sandbox.paypal.com/AdaptivePayments/' : 'https://svcs.paypal.com/AdaptivePayments/'; - $this->paypalurl = $params->sandbox ? 'https://www.sandbox.paypal.com/websrc?cmd=_ap-payment&paykey=' : 'https://www.paypal.com/websrc?cmd=_ap-payment&paykey='; + $svcs_url = 'https://svcs.sandbox.paypal.com/AdaptivePayments/'; + $this->apiurl = $params->sandbox ? $svcs_url : 'https://svcs.paypal.com/AdaptivePayments/'; + $sbox_url = 'https://www.sandbox.paypal.com/websrc?cmd=_ap-payment&paykey='; + $this->paypalurl = $params->sandbox ? $sbox_url : 'https://www.paypal.com/websrc?cmd=_ap-payment&paykey='; } - /* Internal use functions */ - function buildLayoutPath($layout) { + /** + * Build Layout path + * + * @param string $layout Layout name + * + * @since 2.2 + * + * @return string Layout Path + */ + public function buildLayoutPath($layout) + { $app = JFactory::getApplication(); - if($layout == 'recurring') + + if ($layout == 'recurring') + { $core_file = dirname(__FILE__) . '/' . $this->_name . '/tmpl/recurring.php'; + } else + { $core_file = dirname(__FILE__) . '/' . $this->_name . '/tmpl/default.php'; + $override = JPATH_BASE . '/' . 'templates' . '/' . $app->getTemplate() . '/html/plugins/' . + $this->_type . '/' . $this->_name . '/' . 'recurring.php'; + } - $override = JPATH_BASE . '/' . 'templates' . '/' . $app->getTemplate() . '/html/plugins/' . $this->_type . '/' . $this->_name . '/' . 'recurring.php'; - if(JFile::exists($override)) + if (JFile::exists($override)) { return $override; } else { - return $core_file; - } + return $core_file; + } } - //Builds the layout to be shown, along with hidden fields. - function buildLayout($vars, $layout = 'default' ) + /** + * Builds the layout to be shown, along with hidden fields. + * + * @param object $vars Data from component + * @param string $layout Layout name + * + * @since 2.2 + * + * @return string Layout Path + */ + public function buildLayout($vars, $layout = 'default' ) { // Load the layout & push variables ob_start(); - $layout = $this->buildLayoutPath($layout); - include($layout); - $html = ob_get_contents(); - ob_end_clean(); + $layout = $this->buildLayoutPath($layout); + include $layout; + $html = ob_get_contents(); + ob_end_clean(); + return $html; } -// Used to Build List of Payment Gateway in the respective Components - function onTP_GetInfo($config) + // Used to Build List of Payment Gateway in the respective Components + /** + * Builds the layout to be shown, along with hidden fields. + * + * @param object $config Plugin config + * + * @since 2.2 + * + * @return mixed return plugin config object + */ + public function onTP_GetInfo($config) { - if(!in_array($this->_name,$config)) - return; - $obj = new stdClass; - $obj->name = $this->params->get( 'plugin_name' ); - $obj->id = $this->_name; + if (!in_array($this->_name, $config)) + { + return; + } + + $obj = new stdClass; + $obj->name = $this->params->get('plugin_name'); + $obj->id = $this->_name; + return $obj; } - //Constructs the Payment form in case of On Site Payment gateways like Auth.net & constructs the Submit button in case of offsite ones like Paypal - function onTP_GetHTML($vars) + // Constructs the Payment form in case of On Site Payment gateways like Auth.net & constructs the Submit button in case of offsite ones like Paypal + + /** + * Builds the layout to be shown, along with hidden fields. + * + * @param object $vars Data from component + * + * @since 2.2 + * + * @return string Layout Path + */ + public function onTP_GetHTML($vars) { - $plgPaymentAdaptivePaypalHelper = new plgPaymentAdaptivePaypalHelper(); + $plgPaymentAdaptivePaypalHelper = new plgPaymentAdaptivePaypalHelper; $vars->action_url = $plgPaymentAdaptivePaypalHelper->buildPaypalUrl(); - //Take this receiver email address from plugin if component not provided it - if(empty($vars->business)) + + // Take this receiver email address from plugin if component not provided it + if (empty($vars->business)) + { $vars->business = $this->params->get('business'); + } - //if component does not provide cmd - if(empty($vars->cmd)) + // If component does not provide cmd + if (empty($vars->cmd)) + { $vars->cmd = '_xclick'; - $html = $this->buildLayout($vars); + } + + $html = $this->buildLayout($vars); + return $html; } - function onTP_ProcessSubmit($data,$vars) + /** + * Adds a row for the first time in the db, calls the layout view + * + * @param object $data Data from component + * @param object $vars Component data + * + * @since 2.2 + * + * @return object processeddata + */ + public function onTP_ProcessSubmit($data,$vars) { $adaptiveReceiverList = $vars->adaptiveReceiverList; - //Take this receiver email address from plugin if component not provided it - $plgPaymentAdaptivePaypalHelper = new plgPaymentAdaptivePaypalHelper(); + + // Take this receiver email address from plugin if component not provided it + $plgPaymentAdaptivePaypalHelper = new plgPaymentAdaptivePaypalHelper; $receiver = array(); $data = $this->getFormattedReceiver($vars->adaptiveReceiverList); $receiver = $data['receiver']; $receiverOptions = $data['receiverOptions']; - //create the pay request + + // Create the pay request $createPacket = array( - "actionType"=>"PAY", - "currencyCode"=>$vars->currency_code, - "receiverList"=>array( - "receiver"=>$receiverOptions + "actionType" => "PAY", + "currencyCode" => $vars->currency_code, + "receiverList" => array( + "receiver" => $receiverOptions ), - "returnUrl"=>$vars->return, - "cancelUrl"=>$vars->cancel_return, - "ipnNotificationUrl"=>$vars->notify_url,//ipnNotificationUrl notifyUrl - "trackingId"=>$vars->order_id, - "requestEnvelope"=>$this->envelope, - "feesPayer"=>"PRIMARYRECEIVER" + "returnUrl" => $vars->return, + "cancelUrl" => $vars->cancel_return, + "ipnNotificationUrl" => $vars->notify_url, + "trackingId" => $vars->order_id, + "requestEnvelope" => $this->envelope, + "feesPayer" => "PRIMARYRECEIVER" ); // Send packet - $response = $this->_paypalSend($createPacket,"Pay"); + $response = $this->_paypalSend($createPacket, "Pay"); - //store packet log - //@params packet response, component name, Item name - $this->_StorelogBeforePayment($response,$vars->client,$vars->item_name); + // Store packet log + // @params packet response, component name, Item name + $this->_StorelogBeforePayment($response, $vars->client, $vars->item_name); $paykey = $response['payKey']; - //Set payment detials + + // Set payment detials $detailsPacket = array( - "requestEnvelope"=>$this->envelope, - "payKey"=>$response['payKey'], - "receiverOptions"=>$receiver + "requestEnvelope" => $this->envelope, + "payKey" => $response['payKey'], + "receiverOptions" => $receiver ); - $response = $this->_paypalSend($detailsPacket,"SetPaymentOptions"); + $response = $this->_paypalSend($detailsPacket, "SetPaymentOptions"); $detls = $this->getPaymentOptions($paykey); $file = 'AdaptiveLog.txt'; + // The new person to add to the file $person = json_encode($_REQUEST); - //header to paypal - header("Location:".$this->paypalurl.$paykey); + + // Header to paypal + header("Location:" . $this->paypalurl . $paykey); } - /**Make plugin specific receiver format - * */ - function getFormattedReceiver($receiverList) { + + /** + * Make plugin specific receiver format + * + * @param array $receiverList List + * + * @since 2.2 + * + * @return array data + */ + public function getFormattedReceiver($receiverList) + { $receiver = array(); $receiverOptions = array(); - foreach($receiverList as $rec) { - $temp['amount'] = round($rec['amount'],2); + foreach ($receiverList as $rec) + { + $temp['amount'] = round($rec['amount'], 2); $temp['email'] = $rec['receiver']; $temp['primary'] = $rec['primary']; $receiverOptions[] = $temp; - $emails['email'] = $temp['email'] ; + $emails['email'] = $temp['email']; $r = array(); $r['receiver'] = $emails; $receiver[] = $r; @@ -183,11 +292,22 @@ function getFormattedReceiver($receiverList) { return $data; } - function onTP_Processpayment($data) + + /** + * Adds a row for the first time in the db, calls the layout view + * + * @param object $data Data from component + * + * @since 2.2 + * + * @return object processeddata + */ + public function onTP_Processpayment($data) { - /*$verify = plgPaymentAdaptivePaypalHelper::validateIPN($data); + /* $verify = plgPaymentAdaptivePaypalHelper::validateIPN($data); if (!$verify) { return false; } */ + $payment_status = $this->translateResponse($data['status']); $paymentDetails = $this->getTransactionDetails($data); @@ -204,29 +324,41 @@ function onTP_Processpayment($data) $primaryReceiver = $recIndex; break; } - } } $result = array( - 'order_id'=>$data['tracking_id'], - 'transaction_id'=>$data['pay_key'], - 'action_type'=>$data['action_type'], - 'status'=>$payment_status, - 'txn_type'=>$data['transaction_type'], - 'total_paid_amt'=>$paymentDetails['paymentInfoList']['paymentInfo'][$primaryReceiver]['receiver']['amount'], - 'raw_data'=>$paymentDetails, - 'error'=>$paymentDetails, - ); + 'order_id' => $data['tracking_id'], + 'transaction_id' => $data['pay_key'], + 'action_type' => $data['action_type'], + 'status' => $payment_status, + 'txn_type' => $data['transaction_type'], + 'total_paid_amt' => $paymentDetails['paymentInfoList']['paymentInfo'][$primaryReceiver]['receiver']['amount'], + 'raw_data' => $paymentDetails, + 'error' => $paymentDetails, + ); + return $result; } - function translateResponse($payment_status){ - foreach($this->responseStatus as $key=>$value) + /** + * This function transalate the response got from payment getway + * + * @param object $payment_status payment_status + * + * @since 2.2 + * + * @return string value + */ + public function translateResponse($payment_status) + { + foreach ($this->responseStatus as $key => $value) + { + if ($key == $payment_status) { - if($key == $payment_status) return $value; } + } } /** @@ -237,48 +369,90 @@ function translateResponse($payment_status){ * @since 2.2 * @return list. */ - function onTP_Storelog($data) + public function onTP_Storelog($data) { $log_write = $this->params->get('log_write', '0'); if ($log_write == 1) { - $log = plgPaymentAdaptivePaypalHelper::Storelog($this->_name,$data); + $log = plgPaymentAdaptivePaypalHelper::Storelog($this->_name, $data); } } - function _StorelogBeforePayment($data, $client, $item_name) + /** + * Store log + * + * @param array $data data. + * @param string $client client. + * @param string $item_name name. + * + * @since 2.2 + * @return list. + */ + public function _StorelogBeforePayment($data, $client, $item_name) { $log = plgPaymentAdaptivePaypalHelper::StorelogBeforePayment($this->_name, $data, $client, $item_name); } - function _paypalSend($data,$call){ + /** + * Function _paypalSend + * + * @param array $data data. + * @param string $call call. + * + * @since 2.2 + * @return list. + */ + public function _paypalSend($data,$call) + { $ch = curl_init(); - curl_setopt($ch,CURLOPT_URL,$this->apiurl.$call); - curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE); - curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE); - curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE); - curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($data)); - curl_setopt($ch,CURLOPT_HTTPHEADER,$this->headers); - return json_decode(curl_exec($ch),TRUE); + curl_setopt($ch, CURLOPT_URL, $this->apiurl . $call); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); + + return json_decode(curl_exec($ch), true); } - //Wrapper for getting payment details - function getPaymentOptions($paykey){ + + // Wrapper for getting payment details + /** + * Function getPaymentOptions + * + * @param string $paykey key. + * + * @since 2.2 + * @return object. + */ + public function getPaymentOptions($paykey) + { $packet = array( - "requestEnvelope"=>$this->envelope, - "payKey"=>$paykey + "requestEnvelope" => $this->envelope, + "payKey" => $paykey ); - return $this->_paypalSend($packet,"GetPaymentOptions"); + + return $this->_paypalSend($packet, "GetPaymentOptions"); } - //get the complete transaction details - function getTransactionDetails($data) + + // Get the complete transaction details + /** + * Function getTransactionDetails + * + * @param array $data key. + * + * @since 2.2 + * @return object. + */ + public function getTransactionDetails($data) { $detailsPacket = array( - "payKey"=>$data['pay_key'], - "requestEnvelope"=>$this->envelope + "payKey" => $data['pay_key'], + "requestEnvelope" => $this->envelope ); - $res = $this->_paypalSend($detailsPacket,'PaymentDetails'); + $res = $this->_paypalSend($detailsPacket, 'PaymentDetails'); + return $res; } } diff --git a/payu/payu/helper.php b/payu/payu/helper.php index d39523b..e5aa273 100755 --- a/payu/payu/helper.php +++ b/payu/payu/helper.php @@ -8,34 +8,53 @@ */ defined('_JEXEC') or die('Restricted access'); - jimport('joomla.html.html'); - jimport( 'joomla.plugin.helper' ); - jimport('joomla.html.parameter'); -class plgPaymentPayuHelper -{ +jimport('joomla.html.html'); +jimport('joomla.plugin.helper'); +jimport('joomla.html.parameter'); - //gets the Payu URL - function buildPayuUrl($secure = true) +/** + * PlgPaymentPayuHelper + * + * @package CPG + * @subpackage site + * @since 2.2 + */ +class PlgPaymentPayuHelper +{ + // Gets the paypal URL + /** + * buildPaypalUrl. + * + * @param string $secure Layout name + * + * @since 2.2 + * + * @return string secure + */ + public function buildPayuUrl($secure = true) { $plugin = JPluginHelper::getPlugin('payment', 'payu'); $params = json_decode($plugin->params); $url = $params->sandbox? 'test.payu.in/_payment' : 'secure.payu.in/_payment'; - if ($secure) { + + if ($secure) + { $url = 'https://' . $url; } + return $url; } /** * Store log * - * @param string $data data. + * @param string $name data. * @param array $logdata data. * * @since 1.0 * @return list. */ - function Storelog($name, $logdata) + public function Storelog($name, $logdata) { jimport('joomla.error.log'); $options = "{DATE}\t{TIME}\t{USER}\t{DESC}"; @@ -43,7 +62,7 @@ function Storelog($name, $logdata) JLog::addLogger( array( - 'text_file' => $logdata['JT_CLIENT'] . '_' . $name.'.log', + 'text_file' => $logdata['JT_CLIENT'] . '_' . $name . '.log', 'text_entry_format' => $options ), JLog::INFO, @@ -56,7 +75,7 @@ function Storelog($name, $logdata) JLog::add($logEntry); - // $logs = &JLog::getInstance($logdata['JT_CLIENT'].'_'.$name.'.log',$options,$path); + // $logs = &JLog::getInstance($logdata['JT_CLIENT'].'_'.$name.'.log',$options,$path); // $logs->addEntry(array('user' => $my->name.'('.$my->id.')','desc'=>json_encode($logdata['raw_data']))); } }