From 1167d279564dc551a86148f94757425e521a94f1 Mon Sep 17 00:00:00 2001 From: Sanjivani Patil Date: Fri, 20 Feb 2015 12:10:46 +0530 Subject: [PATCH] common blank plugin --- code/plugins/blank/blank.php | 356 ++++++++++++------ code/plugins/blank/blank.xml | 30 +- code/plugins/blank/blank/helper.php | 306 +++++++++------ code/plugins/blank/blank/index.html | 0 code/plugins/blank/blank/tmpl/default.php | 74 +--- code/plugins/blank/blank/tmpl/index.html | 0 .../blank/en-GB/en-GB.plg_payment_blank.ini | 11 +- 7 files changed, 465 insertions(+), 312 deletions(-) mode change 100644 => 100755 code/plugins/blank/blank.php mode change 100644 => 100755 code/plugins/blank/blank.xml mode change 100644 => 100755 code/plugins/blank/blank/helper.php mode change 100644 => 100755 code/plugins/blank/blank/index.html mode change 100644 => 100755 code/plugins/blank/blank/tmpl/default.php mode change 100644 => 100755 code/plugins/blank/blank/tmpl/index.html diff --git a/code/plugins/blank/blank.php b/code/plugins/blank/blank.php old mode 100644 new mode 100755 index 7052782..612179d --- a/code/plugins/blank/blank.php +++ b/code/plugins/blank/blank.php @@ -1,176 +1,283 @@ load('plg_payment_blank', JPATH_ADMINISTRATOR); -require_once(dirname(__FILE__) . '/blank/helper.php'); -class plgpaymentblank extends JPlugin + +if (JVERSION >= '1.6.0') +{ + require_once JPATH_SITE . '/plugins/payment/blank/blank/helper.php'; +} +else +{ + require_once JPATH_SITE . '/plugins/payment/blank/helper.php'; +} +$lang = JFactory::getLanguage(); +$lang->load('plg_payment_blank', JPATH_ADMINISTRATOR); + +/** + * blank Payment class. + * + * @package Joomla.Payment.Plugin + * + * @since 1.0 + */ +class plgpaymentblank extends JPlugin { + /** + * @var string Store Payment name. + * @var string Log store. + * @since 1.0 + */ var $_payment_gateway = 'payment_blank'; + var $_log = null; + /** + * Constructor. + * + * @param array $subject Payment Status codes And Respective Alias in Framework. + * @param array $config Payment config. + * + * @see JPlugin + * + * @since 1.0 + */ function __construct(& $subject, $config) { - parent::__construct($subject, $config); - /* - * @var $this->responseStatus array Payment Status codes And Respective Alias in Framework - * */ + parent::__construct($subject, $config); + //Set the language in the class + $config = JFactory::getConfig(); + + + //Define Payment Status codes in Paypal And Respective Alias in Framework $this->responseStatus= array( - 'Completed' => 'C','Pending' => 'P', - 'Failed'=>'E','Denied'=>'D', - 'Refunded'=>'RF', - 'Canceled_Reversal'=>'CRV', - 'Reversed'=>'RV','ERROR' => 'E'); - + 'Completed' => 'C', + 'Pending' => 'P', + 'Failed'=>'E','Denied'=>'D', + 'Refunded'=>'RF','Canceled_Reversal'=>'CRV', + 'Reversed'=>'RV' + ); } - - /* This function falls under STEP 1 of the Common Payment Gateway flow - * It is Used to Build List of Payment Gateway in the respective Components - * - * @param $config array list of payment plugin names from component settings/config - * @return object Object with 'name' set as in the param plugin_name and 'id' set as the plugin's filename - * */ - function onTP_GetInfo($config) + /** + * This function falls under STEP 1 of the Common Payment Gateway flow, + * It is Used to Build List of Payment Gateway in the respective Components. + * + * @param array $config list of payment plugin names from component settings/config. + * + * @return Object with 'name' set as in the param plugin_name and 'id' set as the plugin's filename + * + * @since 1.0 + */ + public function onTP_GetInfo($config) { - if(!in_array($this->_name,$config)) /*check if payment plugin is in config*/ - return; + if (!in_array($this->_name, $config)) + { + /*check if payment plugin is in config*/ + return; + } + $obj = new stdClass; - $obj->name = $this->params->get( 'plugin_name' ); + $obj->name = $this->params->get('plugin_name'); $obj->id = $this->_name; + return $obj; } - /* This function falls under STEP 2 of the Common Payment Gateway flow + /** + * This function falls under STEP 1 of the Common Payment Gateway flow, * It Constructs the Payment form in case of On Site Payment gateways like Auth.net * OR constructs the Submit button in case of offsite - * - * @param $vars object list of all data required by payment plugin constructed by the component - * @return string HTML to display - * */ - function onTP_GetHTML($vars) + * + * @param object $vars list of all data required by payment plugin constructed by the component. + * + * @return string HTML Paymet form Html. + * + * @since 1.0 + */ + public function onTP_GetHTML($vars) { - /* add on any payment plugin specific data to $vars*/ - $vars->action_url = plgPaymentBlankHelper::buildBlankUrl(); - $html = $this->buildLayout($vars); /*pass $vars to buildLayout to get the payment form/html */ + $vars->action_url = 'http://secure.blank.com/transaction/transaction.do?command=initiateTransaction';//$plgPaymentPaypalHelper->buildPaypalUrl(); + // Add on any payment plugin specific data to $vars + $html = $this->buildLayout($vars); + + // Pass $vars to buildLayout to get the payment form/html. return $html; } -/* This function falls under STEP 3 of the Common Payment Gateway flow - * If Process on the post data from the payment and pass a fixed format data to component for further process - * - * @param $data array Post data from gateway to notify url - * @return associative array gateway specific fixed format data required by the component to process payment - * */ - function onTP_Processpayment($data,$vars) + /** + * Reconstruct Payment form - to avoid change in amount or etc from Hidden form + * + * @param array $data Post data of item form. + * @param array $vars list of all data required by payment plugin constructed by the component. + * + * @return void. + * + * @since 1.0 + */ + public function onTP_ProcessSubmit($data, $vars) { - /*NOTE : for onsite payment the code for sending data to payment gateway via cURL or any other method will come here*/ - $isValid = true; - $error = array(); - $error['code'] = ''; - $error['desc'] = ''; - $trxnstatus=''; - $verify = plgPaymentBlankHelper::validateIPN($data); /*verification of IPN*/ - if (!$verify) { return false; } - - //3.compare response order id and send order id in notify URL - $res_orderid = ''; - /* // SAMPLE CODE - $res_orderid = $result->InvoiceReference; // THIS SHOULD BE RESPONSE ORDERID - if($isValid ) { - if(!empty($vars) && $res_orderid != $vars->order_id ) - { - $trxnstatus = 'ERROR'; - $isValid = false; - $error['desc'] = "ORDER_MISMATCH " . " Invalid ORDERID; notify order_is ". $vars->order_id .", and response ".$res_orderid; - } - }*/ - - // SAMPLE CODE TO CHECK RESPONSE AMOUNT AND ORIGINAL AMOUNT - /*if($isValid ) { - if(!empty($vars)) - { - // Check that the amount is correct - $order_amount=(float) $vars->amount; - $retrunamount = (float)$gross_amt; //RESPONSE AMOUNT - $epsilon = 0.01; - - if(($order_amount - $retrunamount) > $epsilon) - { - $trxnstatus = 'ERROR'; // change response status to ERROR FOR AMOUNT ONLY - $isValid = false; - $error['desc'] = "ORDER_AMOUNT_MISTMATCH - order amount= ".$order_amount . ' response order amount = '.$retrunamount; - } - } - }*/ - /*translate the status response depending upon you payment gateway*/ - $payment_status = ''; - // Translaet Payment status - if($trxnstatus == 'ERROR'){ - $payment_status = $this->translateResponse($trxnstatus); - }else { - $payment_status = $this->translateResponse($data['payment_status']); - } - + // Take this receiver email address from plugin if component not provided it + // Reconstruct Payment FORM using $vars + + $submitVaues['order_id'] =$vars->order_id; + $submitVaues['user_id'] =$vars->user_id; + $submitVaues['return'] =$vars->return; + $submitVaues['amount'] =$vars->amount; + $submitVaues['plugin_payment_method'] ='onsite'; + $submitVaues['cardfname'] =$data['cardfname']; + $submitVaues['cardlname'] =$data['cardlname']; + $submitVaues['cardaddress1'] =$data['cardaddress1']; + $submitVaues['cardaddress2'] =$data['cardaddress2']; + $submitVaues['cardcity'] =$data['cardcity']; + $submitVaues['cardstate'] =$data['cardstate']; + $submitVaues['cardzip'] =$data['cardzip']; + $submitVaues['cardcountry'] =$data['cardcountry']; + $submitVaues['email'] =$data['email']; + $submitVaues['cardnum'] =$data['cardnum']; + $submitVaues['cardexp'] =$data['cardexp']; + $submitVaues['cardcvv'] =$data['cardcvv']; + + // Build action URL + $plgPaymentPaypalHelper = new plgPaymentPaypalHelper; + $postaction = $plgPaymentPaypalHelper->buildPaypalUrl(); + /* for offsite plugin */ + $postvalues = http_build_query($submitVaues); + header('Location: ' . $postaction . '?' . $postvalues); + } + + /** + * This function calls under STEP 3 of the Common Payment Gateway flow + * If Process on the post data from the payment and pass a fixed format data to component for further process. + * + * @param array $data ost data from gateway to notify url. + * + * @return associative array Gateway specific fixed format data required by the component to process payment. + * + * @since 1.0 + */ + public function onTP_Processpayment($data) + { + /** + * NOTE : for onsite payment the code for sending data to payment + * gateway via cURL or any other method will come here + * */ + + //~ $verify = PlgPaymentblankHelper::validateIPN($data); +//~ + //~ /*verification of IPN*/ + //~ if (!$verify) + //~ { + //~ return false; + //~ } + + // Translate the status response depending upon you payment gateway. + $payment_status = $this->translateResponse($data['payment_status']); $result = array( - 'order_id'=>$data['custom'], - 'transaction_id'=>$data['txn_id'], - 'buyer_email'=>$data['payer_email'], - 'status'=>$payment_status, - 'subscribe_id'=>$data['subscr_id'], - 'txn_type'=>$data['txn_type'], - 'total_paid_amt'=>$data['mc_gross'], - 'raw_data'=>$data, - 'error'=>$error, + 'order_id' => $data['custom'], + 'transaction_id' => $data['txn_id'], + 'buyer_email' => $data['payer_email'], + 'status' => $payment_status, + 'subscribe_id' => $data['subscr_id'], + 'txn_type' => $data['txn_type'], + 'total_paid_amt' => $data['mc_gross'], + 'raw_data' => $data, + 'error' => $error, ); + return $result; } -/* This function falls under STEP 3 of the Common Payment Gateway flow - * It Logs the payment process data */ - function onTP_Storelog($data) + /** + * This function calls under STEP 3 of the Common Payment Gateway flow + * It Logs the payment process data. + * + * @param array $data ost data from gateway to notify url. + * + * @return void. + * + * @since 1.0 + */ + public function onTP_Storelog($data) { - $log = plgPaymentBlankHelper::Storelog($this->_name,$data); + $log = PlgPaymentBlankHelper::Storelog($this->_name, $data); } -/* Internal use functions @TODO move to common helper -translate the status response depending upon you payment gateway*/ - function translateResponse($payment_status){ - foreach($this->responseStatus as $key=>$value) + /** + * Internal use functions @TODO move to common helper + * translate the status response depending upon you payment gateway + * + * @param string $payment_status Short form of payment status e.g. P:pending. + * + * @return string Return Status name. + * + * @since 1.0 + */ + public function translateResponse($payment_status) + { + foreach ($this->responseStatus as $key => $value) { - if($key == $payment_status) - return $value; + if ($key == $payment_status) + { + return $value; + } } } -/* Internal use functions @TODO move to common helper - * Builds the layout to be shown, along with hidden fields. - * */ - function buildLayout($vars, $layout = 'default' ) + /** + * Internal use functions @TODO move to common helper + * Builds the layout to be shown, along with hidden fields. + * + * @param array $vars Payment related varible array. + * @param string $layout Payment layout name. + * + * @return string html of form. + * + * @since 1.0 + */ + public function buildLayout($vars, $layout = 'default' ) { // Load the layout & push variables + ob_start(); $layout = $this->buildLayoutPath($layout); - include($layout); + include $layout; $html = ob_get_contents(); ob_end_clean(); + return $html; } -/** Internal use functions @TODO move to common helper*/ - function buildLayoutPath($layout) { + /** + * Internal use functions @TODO move to common helper + * Builds the layout path and check override the layout of payment. + * + * @param string $layout Payment layout name. + * + * @return string path of layout. + * + * @since 1.0 + */ + public function buildLayoutPath($layout) + { $app = JFactory::getApplication(); - $core_file = dirname(__FILE__) . '/' . $this->_name . '/tmpl/default.php'; - $override = JPATH_BASE . '/' . 'templates' . '/' . $app->getTemplate() . '/html/plugins/' . $this->_type . '/' . $this->_name . '/' . $layout.'.php'; - if(JFile::exists($override)) + $core_file = dirname(__FILE__) . DS . $this->_name . DS . 'tmpl' . DS . 'default.php'; + $override = JPATH_BASE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS; + $override .= 'plugins' . DS . $this->_type . DS . $this->_name . DS . $layout . ' .php'; + + if (JFile::exists($override)) { return $override; } @@ -178,7 +285,6 @@ function buildLayoutPath($layout) { { return $core_file; } - } -} - + } +} diff --git a/code/plugins/blank/blank.xml b/code/plugins/blank/blank.xml old mode 100644 new mode 100755 index 2b580e8..eba332a --- a/code/plugins/blank/blank.xml +++ b/code/plugins/blank/blank.xml @@ -1,32 +1,32 @@ - + Blank Payment Gateway - TechJoomla - 25th Sep 2013 - Techjoomla. All Rights Reserved. - extensions@techjoomla.com - http://www.techjoomla.com + Tekdi + 2th Feb 2015 + Tekdi. All Rights Reserved. + sanjivani_p@tekdi.net + http://www.tekdi.net http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL - 1.1 - PayBy check plugin from Techjoomla. + 1.0 + Blank plugin from Tekdi. blank.php - blank + blank - + en-GB/en-GB.plg_payment_blank.ini - + - - + +
- - + +
diff --git a/code/plugins/blank/blank/helper.php b/code/plugins/blank/blank/helper.php old mode 100644 new mode 100755 index af56b89..f595c76 --- a/code/plugins/blank/blank/helper.php +++ b/code/plugins/blank/blank/helper.php @@ -1,132 +1,216 @@ params->get('secure_post'); - - //2. check whether sandbox mode is ON /OFF - $url = $this->params->get('sandbox') ? 'www.sandbox.blank.com' : 'www.blank.com'; - if ($secure_post) + // 1. check for https or http to use + $secure_post = '';//$this->params->get('secure_post'); + + // 2. check whether sandbox mode is ON /OFF + //$url = $this->params->get('sandbox') ? 'www.sandbox.blank.com' : 'www.blank.com'; + $url = $secure_post ? 'www.sandbox.blank.com' : 'www.blank.com'; + + if ($secure_post) + { $url = 'https://' . $url . '/cgi-bin/webscr'; + } else + { $url = 'http://' . $url . '/cgi-bin/webscr'; + } + return $url; - } -/*Function for Logging payment data */ - function Storelog($name,$logdata) + /** + * Function for Logging payment data + * + * @param string $name Name for refernce the log. + * @param RAW $logdata payment data for log. + * + * @return string + * + * @since 1.0 + */ + public function Storelog($name, $logdata) { jimport('joomla.error.log'); + $options = array('format' => "{DATE}\t{TIME}\t{USER}\t{DESC}"); - $path = dirname(__FILE__); - $my = &JFactory::getUser(); - $logs = &JLog::getInstance($logdata['JT_CLIENT'].'_'.$name.'.log',$options,$path); - $logs->addEntry(array('user' => $my->name.'('.$my->id.')','desc'=>json_encode($logdata['raw_data']))); + + if (JVERSION >= '1.6.0') + { + $path = JPATH_SITE . '/plugins/payment/' . $name . '/' . $name . '/'; + } + else + { + $path = JPATH_SITE . '/plugins/payment/' . $name . '/'; + } + + $my = JFactory::getUser(); + $logs = JLog::getInstance($logdata['JT_CLIENT'] . '_' . $name . ' . log', $options, $path); + $logs->addEntry(array('user' => $my->name . '(' . $my->id . ')','desc' => json_encode($logdata['raw_data']))); } + /** * Validates the incoming data. + * + * @param RAW $data payment data. + * + * @return string + * + * @since 1.0 + */ + static function validateIPN($data) + { + // Parse the blank URL + + $url = PlgPaymentBlankHelper::buildBlankUrl(); + //$this->blank_url = $url; + $url_parsed = parse_url($url); + + /** + generate the post string from the _POST vars aswell as load the + POST vars into an arry so we can play with them from the calling + script. + Append ipn command + Open the connection to blank + */ + $fp = fsockopen($url_parsed[host], "80", $err_num, $err_str, 30); + + if (!$fp) + { + // Could not open the connection. If loggin is on, the error message + // will be in the log. + $this->last_error = "fsockopen error no. $errnum: $errstr"; + plgPaymentBlankHelper::log_ipn_results(false); + + return false; + } + else + { + $post_string = ''; + + foreach ($data as $field => $value) + { + $this->ipn_data["$field"] = $value; + $post_string .= $field . '=' . urlencode(stripslashes($value)) . '&'; + } + + $post_string .= "cmd=_notify-validate"; + + // Post the data back to blank + fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); + fputs($fp, "Host: $url_parsed[host]\r\n"); + fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); + fputs($fp, "Content-length: " . strlen($post_string) . "\r\n"); + fputs($fp, "Connection: close\r\n\r\n"); + fputs($fp, $post_string . "\r\n\r\n"); + + // Loop through the response from the server and append to variable + while (!feof($fp)) + { + $this->ipn_response .= fgets($fp, 1024); + } + + // Close connection + fclose($fp); + } + + if (eregi("verified", $post_string)) + { + // Valid IPN transaction. + PlgPaymentBlankHelper::log_ipn_results(true); + + return true; + } + else + { + // Invalid IPN transaction. Check the log for details. + $this->last_error = 'IPN Validation Failed.'; + PlgPaymentBlankHelper::log_ipn_results(false); + + return false; + } + } + + /** + * Log the IPN data. + * + * @param string $success result of payment. + * + * @return string + * + * @since 1.0 */ - function validateIPN( $data) + public function log_ipn_results($success) { - // parse the blank URL - $url = plgPaymentBlankHelper::buildBlankUrl(); - $this->blank_url = $url; - $url_parsed = parse_url($url); - - // generate the post string from the _POST vars aswell as load the - // _POST vars into an arry so we can play with them from the calling - // script. - // append ipn command - // open the connection to blank - $fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30); - // $fp = fsockopen ($this->blank_url, 80, $errno, $errstr, 30); - - if(!$fp) { - - // could not open the connection. If loggin is on, the error message - // will be in the log. - $this->last_error = "fsockopen error no. $errnum: $errstr"; - plgPaymentBlankHelper::log_ipn_results(false); - return false; - - } else { - $post_string = ''; - foreach ($data as $field=>$value) { - $this->ipn_data["$field"] = $value; - $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; - } - $post_string.="cmd=_notify-validate"; - - // Post the data back to blank - fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); - fputs($fp, "Host: $url_parsed[host]\r\n"); - fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); - fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); - fputs($fp, "Connection: close\r\n\r\n"); - fputs($fp, $post_string . "\r\n\r\n"); - - // loop through the response from the server and append to variable - while(!feof($fp)) { - $this->ipn_response .= fgets($fp, 1024); - } - - fclose($fp); // close connection - - } - - if (eregi("verified",$post_string)) { - - // Valid IPN transaction. - plgPaymentBlankHelper::log_ipn_results(true); - return true; - - } else { - - // Invalid IPN transaction. Check the log for details. - $this->last_error = 'IPN Validation Failed.'; - plgPaymentBlankHelper::log_ipn_results(false); - return false; - - } - + 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 payment server:\n"; + + foreach ($this->ipn_data as $key => $value) + { + $text .= "$key=$value, "; + } + + // Log the response from the payment server + $text .= "\nIPN Response from payment 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 the IPN data - 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 payment server:\n"; - foreach ($this->ipn_data as $key=>$value) { - $text .= "$key=$value, "; - } - - // Log the response from the payment server - $text .= "\nIPN Response from payment Server:\n ".$this->ipn_response; - // Write to log - $fp = fopen($this->ipn_log_file,'a'); - fwrite($fp, $text . "\n\n"); - fclose($fp); // close file - } - - - } diff --git a/code/plugins/blank/blank/index.html b/code/plugins/blank/blank/index.html old mode 100644 new mode 100755 diff --git a/code/plugins/blank/blank/tmpl/default.php b/code/plugins/blank/blank/tmpl/default.php old mode 100644 new mode 100755 index 3bc98a9..fad187e --- a/code/plugins/blank/blank/tmpl/default.php +++ b/code/plugins/blank/blank/tmpl/default.php @@ -1,66 +1,28 @@ -custom_email=="") - $email = JText::_('NO_ADDRS'); - else - $email = $vars->custom_email; +defined('_JEXEC') or die('Restricted access'); ?> -
-
-
-
- -
custom_name);?>
-
-
- -
- - - -
+ + + + + + + + + + + + + +
+
-
- -
- -
-
-
- - - - - - -
- -
- +
diff --git a/code/plugins/blank/blank/tmpl/index.html b/code/plugins/blank/blank/tmpl/index.html old mode 100644 new mode 100755 diff --git a/code/plugins/blank/en-GB/en-GB.plg_payment_blank.ini b/code/plugins/blank/en-GB/en-GB.plg_payment_blank.ini index 3a7affe..a7b8f59 100644 --- a/code/plugins/blank/en-GB/en-GB.plg_payment_blank.ini +++ b/code/plugins/blank/en-GB/en-GB.plg_payment_blank.ini @@ -1,11 +1,12 @@ ;backend -PLG_NAME="Plugin Name" -PLG_MAIL="Mail Address" -PLG_MAIL_DES="This will be the mail address for the payment proccess" +PLG_BLANK_PLG_NAME="Plugin Name" +PLG_BLANK_PLG_NAME_DESC="Please enter plugin name.
which is display in frontend payment list." +PLG_BLANK_MAIL="Mail Address" +PLG_BLANK_MAIL_DES="This will be the mail address for the payment proccess" ;frontend -SAVE_SUCCESS="Operation done Successfully" +PLG_BLANKSAVE_SUCCESS="Operation done Successfully" ;Added by sagar -AD_REVIEW="Your Ad will be Reviewed by Admin." +PLG_BLANKAD_REVIEW="Your Ad will be Reviewed by Admin." ;End Added by sagar PLG_NAME="Plugin Name" PLG_DESC="Plugin Name"