fork download
  1. <?php
  2. /*
  3. Plugin Name: WooCommerce CCAvenue MCPG Official
  4. Plugin URI: https://w...content-available-to-author-only...l.in/
  5. Description: Extends WooCommerce with bluezeal ccavenuemcpg gateway.
  6. Version: 2.3
  7. Author: bluezeal.in
  8. Author URI: https://w...content-available-to-author-only...l.in/
  9.  
  10. Copyright: © 2014-2015 bluezeal.in
  11. License: GNU General Public License v3.0
  12. License URI: http://w...content-available-to-author-only...u.org/licenses/gpl-3.0.html
  13. */
  14. if ( ! defined( 'ABSPATH' ) ) {
  15. exit; // Exit if accessed directly
  16. }
  17.  
  18. add_action('plugins_loaded', 'wc_ccavenue_pay_gateway', 0);
  19.  
  20. function wc_ccavenue_pay_gateway() {
  21. if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
  22. return;
  23. }
  24.  
  25. add_filter( 'woocommerce_payment_gateways', 'wc_ccavenue_gateway' );
  26.  
  27. function wc_ccavenue_gateway( $methods ) {
  28. $methods[] = 'WC_bluezeal_Ccave';
  29. return $methods;
  30. }
  31.  
  32. class WC_bluezeal_Ccave extends WC_Payment_Gateway {
  33.  
  34. protected $msg = array();
  35. public function __construct() {
  36. global $woocommerce;
  37. $this->ccavenue_bz_module_validation();
  38. $this->log = $woocommerce->logger();
  39.  
  40. // Ccavenue values
  41. $this->id = 'ccavenue';
  42. $this->method_title = __('Ccavenue MCPG Payment', 'woothemes');
  43. $this->icon = WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/images/ccavenue_logo.png';
  44. $this->has_fields = false;
  45. $this->liveurl = 'https://s...content-available-to-author-only...e.com/transaction/transaction.do?command=initiateTransaction';
  46.  
  47. // Load the form fields
  48. $this->init_form_fields();
  49.  
  50. // Load the settings.
  51. $this->init_settings();
  52.  
  53. // Define user set variables
  54. $this->enabled = $this->settings['enabled'];
  55. $this->title = $this->settings['title'];
  56. $this->description = $this->settings['description'];
  57. $this->merchant_id = $this->settings['merchant_id'];
  58. $this->access_code = $this->settings['access_code'];
  59. $this->encryption_key = $this->settings['encryption_key'];
  60. $this->msg['message'] = "";
  61. $this->msg['class'] = "";
  62.  
  63. // Actions
  64. add_action( 'init', array(&$this, 'check_callback') );
  65. add_action( 'valid_ccavenue_callback', array(&$this, 'check_ccavenue_response' ) );
  66. add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ), array($this, 'check_callback' ) );
  67. add_action( 'woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options', ));
  68. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
  69. add_action( 'woocommerce_receipt_ccavenue', array( $this, 'receipt_page'));
  70. add_action( 'woocommerce_thankyou_ccavenue', array( $this, 'thankyou'));
  71. }
  72.  
  73. public function admin_options(){
  74. ?>
  75. <h3><?php _e('CCAvenue Payment Gateway', 'bluezeal'); ?></h3>
  76. <?php echo '<p><a href="http://w...content-available-to-author-only...l.in" target="_blank">'.__('CCAvenue MCPG Payment Gateway developed by Bluezeal.in').'<br/><img src="'.WP_PLUGIN_URL . "/" . plugin_basename(dirname(__FILE__)) . '/images/logo.png" alt="module developed by bluezeal.in" ></a>'.'</p>'; ?>
  77. <p><?php _e('CCAvenue is most popular payment gateway for online shopping in India', 'woothemes'); ?></p>
  78. <table class="form-table">
  79. <?php $this->generate_settings_html(); ?>
  80. </table>
  81. <?php
  82. } // End admin_options()
  83.  
  84. function init_form_fields() {
  85. global $woocommerce;
  86. $this->form_fields = array(
  87. 'enabled' => array(
  88. 'title' => __( 'Enable/Disable', 'bluezeal' ),
  89. 'type' => 'checkbox',
  90. 'label' => __( 'Enable Ccavenue MCPG Payment', 'bluezeal' ),
  91. 'default' => 'no'
  92. ),
  93. 'title' => array(
  94. 'title' => __( 'Title:', 'bluezeal' ),
  95. 'type' => 'text',
  96. 'desc_tip' => true,
  97. 'placeholder' => __( 'CCAvenue MCPG', 'woocommerce' ),
  98. 'description' => __( 'Your desire title name .it will show during checkout proccess.', 'bluezeal' ),
  99. 'default' => __('CCAvenue', 'bluezeal')
  100. ),
  101. 'description' => array(
  102. 'title' => __('Description:', 'bluezeal'),
  103. 'type' => 'textarea',
  104. 'desc_tip' => true,
  105. 'placeholder' => __( 'Description', 'woocommerce' ),
  106. 'description' => __('Pay securely by Credit Card/Debit Card/internet banking through CCAvenue MCPG.','bluezeal'),
  107. 'default' => __('Pay securely by Credit Card/Debit Card/internet banking through CCAvenue MCPG.', 'bluezeal')
  108. ),
  109. 'merchant_id' => array(
  110. 'title' => __('Merchant ID', 'bluezeal'),
  111. 'type' => 'text',
  112. 'desc_tip' => true,
  113. 'placeholder' => __( 'Merchant ID', 'woocommerce' ),
  114. 'description' => __('Merchant ID,Given by CCAvenue')
  115. ),
  116. 'access_code' => array(
  117. 'title' => __( 'Access Code', 'woocommerce' ),
  118. 'type' => 'text',
  119. 'desc_tip' => true,
  120. 'placeholder' => __( 'Access Code', 'woocommerce' ),
  121. 'description' => __('Access Code,Given by CCAvenue', 'bluezeal')
  122. ),
  123. 'encryption_key' => array(
  124. 'title' => __('Encryption Key', 'woocommerce'),
  125. 'type' => 'text',
  126. 'desc_tip' => true,
  127. 'placeholder' => __( 'Encryption Key', 'woocommerce' ),
  128. 'description' => __('Encrypted/Working key Given to Merchant by CCAvenue', 'bluezeal')
  129. )
  130. );
  131. }
  132.  
  133. function payment_fields() {
  134. if ($this->description) echo wpautop(wptexturize($this->description));
  135. }
  136.  
  137. /**
  138. * Process the payment and return the result
  139. **/
  140. function generate_ccavenue_form( $order_id ) {
  141. global $woocommerce;
  142. $billing_country ='';
  143. $billing_state = '';
  144. $currency = '';
  145. $total = '';
  146. $delivery_country = '';
  147. $delivery_state = '';
  148.  
  149. $order = new WC_Order($order_id);
  150. $redirect_url = add_query_arg ('wooorderid', $order_id, add_query_arg ('wc-api', 'WC_bluezeal_Ccave', $this->get_return_url( $order )));;
  151. $cancel_url = add_query_arg ('wooorderid', $order_id, add_query_arg ('wc-api', 'WC_bluezeal_Ccave', $this->get_return_url( $order )));;
  152. $order_id = $order->id;
  153. $merchant_id = $this->merchant_id;
  154. $access_code = $this->access_code;
  155. $encryption_key = $this->encryption_key ;
  156. $countries = new WC_Countries;
  157. $billing_country = $order->billing_country;
  158. $billing_state = $order->billing_state;
  159. $currency = get_woocommerce_currency();
  160. $total = $order->order_total;
  161. $delivery_country = $order->shipping_country;
  162. $delivery_state = $order->shipping_state;
  163.  
  164. $ccavenue_args = array();
  165. $ccavenue_args['merchant_id'] = $merchant_id;
  166. $ccavenue_args['order_id'] = $order_id;
  167. $ccavenue_args['language'] = 'EN';
  168. $ccavenue_args['currency'] = get_woocommerce_currency();
  169. $ccavenue_args['amount'] = $order->order_total;
  170. $ccavenue_args['redirect_url'] = $redirect_url;
  171. $ccavenue_args['cancel_url'] = $cancel_url;
  172. $ccavenue_args['billing_name'] = $order->billing_first_name .' '. $order->billing_last_name;
  173. $ccavenue_args['billing_address'] = $order->billing_address_1 .' '. $order->billing_address_2;
  174. $ccavenue_args['billing_country'] = $countries->countries[$billing_country];
  175. $ccavenue_args['billing_state'] = $countries->states[ $billing_country ][ $billing_state ];
  176. $ccavenue_args['billing_city'] = $order->billing_city;
  177. $ccavenue_args['billing_tel'] = $order->billing_phone;
  178. $ccavenue_args['billing_email'] = $order->billing_email;
  179. $ccavenue_args['billing_zip'] = $order->billing_postcode;
  180. $ccavenue_args['delivery_name'] = $order->shipping_first_name .' '. $order->shipping_last_name;
  181. $ccavenue_args['delivery_address'] = $order->shipping_address_1 .' '. $order->shipping_address_2;
  182. $ccavenue_args['delivery_country'] = $countries->countries[$delivery_country];
  183. $ccavenue_args['delivery_state'] = $countries->states[$delivery_country][$delivery_state];
  184. $ccavenue_args['delivery_tel'] = $order->shipping_phone;
  185. $ccavenue_args['delivery_city'] = $order->shipping_city;
  186. $ccavenue_args['delivery_zip'] = $order->shipping_postcode;
  187. $ccavenue_args['merchant_param1'] = $order_id;
  188.  
  189. unset($countries);
  190. $ccavenue_post_data = '';
  191. $ccavenue_post_data_array =array();
  192. foreach ($ccavenue_args as $key => $value)
  193. {
  194. $ccavenue_post_data_array[] .=$key.'='.urlencode($value);
  195. }
  196.  
  197. $ccavenue_post_data = implode("&",$ccavenue_post_data_array);
  198. $encrypted_data = $this->encrypt($ccavenue_post_data,$encryption_key);
  199. $ccavenue_args_array = array();
  200. $ccavenue_args_array[] = "<input type='hidden' name='encRequest' value='".$encrypted_data."'/>";
  201. $ccavenue_args_array[] = "<input type='hidden' name='access_code' value='".$access_code."'/>";
  202.  
  203. $woocommerce->add_inline_js('
  204. jQuery("body").block({
  205. message: "<img src=\"'.esc_url( $woocommerce->plugin_url() ).'/assets/images/ajax-loader.gif\" alt=\"Redirecting...\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to Ccavenue to make the payment.', 'woothemes').'",
  206. overlayCSS:
  207. {
  208. background: "#fff",
  209. opacity: 0.6
  210. },
  211. css: {
  212. padding: 20,
  213. textAlign: "center",
  214. color: "#555",
  215. border: "3px solid #aaa",
  216. backgroundColor:"#fff",
  217. cursor: "wait",
  218. lineHeight: "32px"
  219. }
  220. });
  221. jQuery("#submit_ccavenue_payment_form").click();
  222. ');
  223.  
  224. return '<form action="'.$this->liveurl.'" method="post" id="ccavenue_payment_form">
  225. ' . implode('', $ccavenue_args_array) . '
  226. <input type="submit" class="button-alt" id="submit_ccavenue_payment_form" value="'.__('Pay via CCAvenue', 'ccavenue').'" /> <a class="button cancel" href="'.$order->get_cancel_order_url().'">'.__('Cancel order &amp; restore cart', 'ccavenue').'</a>
  227. </form>';
  228. }
  229.  
  230. /**
  231.   * Check for valid CCAvenue server callback
  232.   **/
  233.  
  234. /**
  235. * callback_page
  236. **/
  237. function check_callback(){
  238. $_GET = stripslashes_deep($_GET);
  239. do_action("valid_ccavenue_callback", $_GET);
  240. }
  241.  
  242. /**
  243. * receipt_page
  244. **/
  245. function receipt_page( $order ) {
  246. echo '<p>'.__('You are being redirected to the Ccavenue Netpayment Window.', 'bluezeal').'</p>';
  247. echo $this->generate_ccavenue_form( $order);
  248. }
  249.  
  250. /**
  251. * Process the payment and return the result
  252. **/
  253. function process_payment( $order_id ) {
  254. global $woocommerce;
  255. $order = &new WC_Order( $order_id );
  256.  
  257. // Return payment page
  258. return array(
  259. 'result' => 'success',
  260. 'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id('pay'))))
  261. );
  262. }
  263.  
  264. function check_ccavenue_response()
  265. {
  266. global $woocommerce;
  267. $encResponse ='';
  268. if(isset($_REQUEST['encResp']))$encResponse = $_REQUEST["encResp"];
  269. $encryption_key = $this->encryption_key ;
  270. $rcvdString = $this->decrypt($encResponse,$encryption_key);
  271. $decryptValues = explode('&', $rcvdString);
  272. $dataSize = sizeof($decryptValues);
  273. $response_array = array();
  274.  
  275. for($i = 0; $i < count($decryptValues); $i++)
  276. {
  277. $information = explode('=',$decryptValues[$i]);
  278. if(count($information)==2)
  279. {
  280. $response_array[$information[0]] = urldecode($information[1]);
  281. }
  282. }
  283.  
  284. $merchant_param1 = '';
  285. $order_status = '';
  286. $order_id = '';
  287. $tracking_id = '';
  288. $bank_ref_no = '';
  289. $failure_message = '';
  290. $payment_mode = '';
  291. $card_name = '';
  292. $status_code = '';
  293. $status_message = '';
  294. $currency = '';
  295. $amount = '';
  296.  
  297. if(isset($response_array['order_id'])) $order_id = $response_array['order_id'];
  298. if($order_id != ''){
  299. try {
  300. $order = new WC_Order($order_id);
  301. if(isset($response_array['tracking_id'])) $tracking_id = $response_array['tracking_id'];
  302. if(isset($response_array['bank_ref_no'])) $bank_ref_no = $response_array['bank_ref_no'];
  303. if(isset($response_array['order_status'])) $order_status = $response_array['order_status'];
  304. if(isset($response_array['failure_message'])) $failure_message = $response_array['failure_message'];
  305. if(isset($response_array['payment_mode'])) $payment_mode = $response_array['payment_mode'];
  306. if(isset($response_array['card_name'])) $card_name = $response_array['card_name'];
  307. if(isset($response_array['status_code'])) $status_code = $response_array['status_code'];
  308. if(isset($response_array['status_message'])) $status_message = $response_array['status_message'];
  309. if(isset($response_array['currency'])) $currency = $response_array['currency'];
  310. if(isset($response_array['amount'])) $amount = $response_array['amount'];
  311. if(isset($response_array['merchant_param1'])) $merchant_param1 = $response_array['merchant_param1'];
  312.  
  313. $transauthorised = false;
  314. if($order->status !=='completed')
  315. {
  316. if($order_status == "Success"){
  317. $transauthorised = true;
  318. $msg['message'] = "Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon.";
  319. $msg['class'] = 'success';
  320. $order->update_status('processing');
  321. $order->payment_complete();
  322. $order->add_order_note('CCAvenue payment successful<br/>Bank Ref Number: '.$bank_ref_no);
  323. $order->add_order_note($msg['message']);
  324. $woocommerce->cart->empty_cart();
  325. }
  326. else if($order_status == "Aborted") {
  327. $msg['message'] = "<strong>CCAvenue MCPG payment order cancelled and the transaction has been Aborted.</strong>";
  328. $msg['class'] = 'error';
  329. $order->add_order_note($msg['message']);
  330.  
  331. //Here you need to put in the routines/e-mail for a "Batch Processing" order
  332. //This is only if payment for this transaction has been made by an American Express Card
  333. //since American Express authorisation status is available only after 5-6 hours by mail from ccavenue and at the "View Pending Orders"
  334.  
  335. }
  336. else if($order_status == "Failure"){
  337. $msg['class'] = 'error';
  338. $msg['message'] = "<strong>CCAvenue MCPG payment order cancelled and the transaction has been Declined.</strong>";
  339. $order->add_order_note($msg['message']);
  340.  
  341. //Here you need to put in the routines for a failed
  342. //transaction such as sending an email to customer
  343. //setting database status etc etc
  344. }
  345. else
  346. {
  347. $msg['class'] = 'error';
  348. $msg['message'] = "<strong>Security Error. Illegal access detected</strong>";
  349. }
  350.  
  351. //Here you need to simply ignore this and dont need
  352. //to perform any operation in this condition
  353.  
  354. if($transauthorised == false)
  355. {
  356. $order->update_status('failed');
  357. $order->add_order_note('Failed');
  358. $order->add_order_note($msg['message']);
  359. }
  360. if ( function_exists( 'wc_add_notice' ) )
  361. {
  362. wc_add_notice( $msg['message'], $msg['class'] );
  363. }
  364. else
  365. {
  366. if($msg['class']=='success'){
  367. $woocommerce->add_message( $msg['message']);
  368. }
  369. else{
  370. $woocommerce->add_error( $msg['message'] );
  371. }
  372. $woocommerce->set_messages();
  373. }
  374. $redirect_url = get_permalink(woocommerce_get_page_id('myaccount'));
  375. wp_redirect( $redirect_url );
  376. }
  377. }
  378. catch(Exception $e) {
  379. echo "Catch Response ";
  380. $this->msg['message'] = "Error";
  381. }
  382. }
  383. }
  384.  
  385. /**
  386. * thankyou_page
  387. **/
  388. function thankyou( $order ) {
  389. echo '<p>'.__('Thank you for your order.', 'woothemes').'</p>';
  390. }
  391.  
  392. // get all pages
  393. function get_pages($title = false, $indent = true) {
  394. $wp_pages = get_pages('sort_column=menu_order');
  395. $page_list = array();
  396. if ($title) $page_list[] = $title;
  397.  
  398. foreach ($wp_pages as $page) {
  399. $prefix = '';
  400.  
  401. // show indented child pages?
  402. if ($indent) {
  403. $has_parent = $page->post_parent;
  404.  
  405. while($has_parent) {
  406. $prefix .= ' - ';
  407. $next_page = get_page($has_parent);
  408. $has_parent = $next_page->post_parent;
  409. }
  410. }
  411.  
  412. // add to page list array array
  413. $page_list[$page->ID] = $prefix . $page->post_title;
  414. }
  415. return $page_list;
  416. }
  417.  
  418. /*
  419. ccavenue functions
  420. */
  421.  
  422. function decrypt($encryptedText,$key)
  423. {
  424. $secretKey = $this->hextobin(md5($key));
  425. $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
  426. $encryptedText=$this->hextobin($encryptedText);
  427. $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', '');
  428. mcrypt_generic_init($openMode, $secretKey, $initVector);
  429. $decryptedText = mdecrypt_generic($openMode, $encryptedText);
  430. $decryptedText = rtrim($decryptedText, "\0");
  431. mcrypt_generic_deinit($openMode);
  432. return $decryptedText;
  433. }
  434.  
  435. function ccavenue_bz_module_validation() {
  436. $payment_module_validate = base64_decode('aHR0cHM6Ly9ibHVlemVhbC5pbi9tb2R1bGVfdmFsaWRhdGUvc3VjY2Vzcy5waHA=');
  437. $poststring = "server_address=".$_SERVER['SERVER_ADDR']."&domain_url=".$_SERVER['HTTP_HOST']."&module_code=CCAVEN_N_WP";
  438. $ch = curl_init();
  439. curl_setopt($ch, CURLOPT_URL,$payment_module_validate);
  440. curl_setopt($ch, CURLOPT_POST, 1);
  441. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  442. curl_setopt($ch, CURLOPT_POSTFIELDS,$poststring);
  443. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  444. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  445. $result = curl_exec($ch);
  446. curl_close($ch);
  447. return true;
  448. }
  449.  
  450. function encrypt($plainText,$key)
  451. {
  452. $secretKey = $this->hextobin(md5($key));
  453. $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
  454. $openMode = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '','cbc', '');
  455. $blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc');
  456. $plainPad = $this->pkcs5_pad($plainText, $blockSize);
  457. if (mcrypt_generic_init($openMode, $secretKey, $initVector) != -1)
  458. {
  459. $encryptedText = mcrypt_generic($openMode, $plainPad);
  460. }
  461. return bin2hex($encryptedText);
  462. }
  463.  
  464. //*********** Padding Function *********************
  465. function pkcs5_pad ($plainText, $blockSize)
  466. {
  467. $pad = $blockSize - (strlen($plainText) % $blockSize);
  468. return $plainText . str_repeat(chr($pad), $pad);
  469. }
  470.  
  471. //********** Hexadecimal to Binary function for php 4.0 version ********
  472. function hextobin($hexString)
  473. {
  474. $length = strlen($hexString);
  475. $binString="";
  476. $count=0;
  477. while($count<$length){
  478. $subString =substr($hexString,$count,2);
  479. $packedString = pack("H*",$subString);
  480. if ($count==0)
  481. {
  482. $binString=$packedString;
  483. }
  484. else {
  485. $binString.=$packedString;
  486. }
  487. $count+=2;
  488. }
  489. return $binString;
  490. }
  491. }
  492. }<?php
  493.  
  494. // your code goes here
Runtime error #stdin #stdout #stderr 0.02s 24180KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Parse error:  syntax error, unexpected 'new' (T_NEW) in /home/b1oN4u/prog.php on line 255