Plugin Directory

Changeset 1592857


Ignore:
Timestamp:
02/09/2017 11:38:22 PM (8 years ago)
Author:
instamojo
Message:
  • Updated supported WordPress version to 4.7.2
  • Fixed issue related to checking WooCommerce and cURL before plugin activation.
Location:
woo-instamojo
Files:
14 added
4 edited

Legend:

Unmodified
Added
Removed
  • woo-instamojo/README.md

    r1578634 r1592857  
    6060Changelog
    6161---------
     62
     63**1.0.6**
     64
     65* Updated supported WordPress version to 4.7.2
     66* Fixed issue related to checking WooCommerce and cURL before plugin activation.
    6267
    6368**1.0.5**
  • woo-instamojo/trunk/lib/curl.php

    r1553272 r1592857  
    2020    function __construct()
    2121    {
     22         if (!function_exists('curl_init')) {
     23            throw new Exception('<b>Instamojo</b> <a href="https://www.digitalocean.com/community/questions/curl-is-not-installed-in-your-php-installation">plugin requires <b>cURL</b> to be installed first</a>');
     24           
     25         }
    2226         $this->ch = curl_init();
    2327         $this->cookie_file = dirname(__FILE__)."/cookie.txt";
  • woo-instamojo/trunk/readme.txt

    r1578634 r1592857  
    44Tags: commerce, e-commerce, ecommerce, online store, sell digital downloads, sell online, shop, store, wordpress ecommerce, WordPress shopping cart, sell event tickets, sell subscriptions, sell memberships, sell physical goods, payments, easy payments, payments button, widget
    55Requires at least: 3.3
    6 Tested up to: 4.7.1
    7 Stable tag: 1.0.5
     6Tested up to: 4.7.2
     7Stable tag: 1.0.6
    88License: MIT
    99License URI: http://opensource.org/licenses/MIT
     
    5353
    5454== Changelog ==
     55
     56= 1.0.6 =
     57
     58* Updated supported WordPress version to 4.7.2
     59* Fixed issue related to checking WooCommerce and cURL before plugin activation.
    5560
    5661= 1.0.5 =
  • woo-instamojo/trunk/woo-instamojo.php

    r1578634 r1592857  
    44Plugin URI: http://www.instamojo.com
    55Description: Instamojo Payment Gateway for WooCommerce. Instamojo lets you collect payments instantly.
    6 Version: 1.0.5
     6Version: 1.0.6
    77Author: instamojo
    88Email: [email protected]
     
    1616}
    1717
    18 $activate = TRUE;
    19 if (!in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins')))){
    20     $activate = FALSE;
    21     $message = '<b>Instamojo</b> Plugin requires <a href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a> to be Installed First!';
    22 }
    23 else if (!function_exists('curl_init')) {
    24     $activate = FALSE;
    25     $message = '<b>Instamojo</b> <a href="https://www.digitalocean.com/community/questions/curl-is-not-installed-in-your-php-installation">Plugin requires <b>cURL</b> to be installed first</a>';
    26 }
    27 if(!$activate){
    28     deactivate_plugins(basename(__FILE__));
    29     exit($message);
    30 }
    31 
    32 
    3318// Add settings link on plugin page
    3419function your_plugin_settings_link($links) {
     
    5439add_filter( 'query_vars', 'add_query_vars_filter' );
    5540
     41function instamojo_activation_hook(){
     42   
     43    $condition1 = !class_exists( 'WC_Payment_Gateway' );
     44    $condition2 = !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins')));
     45
     46    if ($condition1 or $condition2) {
     47      $message = '<b>Instamojo</b> Plugin requires <a href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a> to be installed and activated first!';
     48      echo $message;
     49      @trigger_error(__($message, 'ap'), E_USER_ERROR);
     50    }
     51    else if (!function_exists('curl_init')) {
     52        $message = '<b>Instamojo</b> <a href="https://www.digitalocean.com/community/questions/curl-is-not-installed-in-your-php-installation">Plugin requires <b>cURL</b> to be installed first</a>';
     53        echo $message;
     54        @trigger_error(__($message, 'ap'), E_USER_ERROR);
     55    }
     56
     57}
     58register_activation_hook(__FILE__, 'instamojo_activation_hook');
     59
    5660# initialize your Gateway Class
    5761add_action( 'plugins_loaded', 'init_instamojo_payment_gateway' );
    5862function init_instamojo_payment_gateway()
    5963{
    60     include_once "payment_gateway.php";
     64    if (!class_exists('WC_Payment_Gateway')){
     65        return;   
     66    }
     67       
     68    Class WP_Gateway_Instamojo extends WC_Payment_Gateway{
     69
     70      private $testmode;
     71      private $client_id;
     72      private $client_secret;
     73     
     74     
     75      public function __construct()
     76      {
     77        $this->id = "instamojo";
     78        $this->icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAeZJREFUOI19krtuE0EUhv9zdmd3LYSECEi20WJBBVTAM8RGioREFwrAtNBQ2E4DNU3WFNSQyJYtpUsaF7kg3gAQUPACdoQgEsQ49to7cyiIE+2uzUinmTPfN/9cKFfZvkfEzwgYYNYgUpGYyveg9HVmGwAuVXY3OHNmWSYhBJLgGaInQ2PM7f36nW9JAaPTetkNivfN8KgBywKMjpXoCcCcIeZP2ZXd62mB0BV02ofd+uJjGYVNUl46pzEgYpcFH5ISBmEMzz2LTvtH91WxLGHYmCkRA2L2khIGAGgNWNYFdFo//yUZNUm585J4LPiYq2xfOxWcSOyF0yTjBjkZgO14EYNtxyXmL/nazk07tsNJkvZBd2lxIV/d+0UkN4SgE6cBAbaAV+KC45jwvPN41yjzgXorF8e3mEgnlwmEyYgXFxAByga4/8BvXv0jOflMcIHE3wAIbCmYcPDcTsHOUbmwVhhE2WgL2gCShsl2oMN+tbdaqvPxHGDbgBo98t8UfuscNiHzYAUzCWu91VJ9+goEpQA1fFhY9/smjy0x+j/wuNYLisF0lkHkQA6f+muX+1FWNiHzYCcFT8PDf/J+Wc7xhuhoxoUBZCmYKKxOY8d6+erOXYBbINEEmBQNOEbkxX5Qej2jh79RaeQT2vwcPgAAAABJRU5ErkJggg==";
     79        $this->has_fields = false;
     80        $this->method_title = "Instamojo";
     81        $this->method_description = "Online Payment Gateway";
     82     
     83        $this->init_form_fields();
     84        $this->init_settings();
     85       
     86        $this->title          = $this->get_option( 'title' );
     87        $this->description    = $this->get_option( 'description' );
     88        $this->testmode       = 'yes' === $this->get_option( 'testmode', 'no' );
     89        $this->client_id      = $this->get_option( 'client_id' );
     90        $this->client_secret  = $this->get_option( 'client_secret' );
     91        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     92      }
     93     
     94      public function init_form_fields()
     95      {
     96        $this->form_fields = include("instamojo-settings.php");   
     97      }
     98     
     99      public function process_payment($orderId)
     100      {
     101        include_once "lib/Instamojo.php";
     102        $this->log("Creating Instamojo Order for order id: $orderId");
     103        $this->log("Client ID: $this->client_id | Client Secret: $this->client_secret  | Testmode: $this->testmode ");
     104       
     105        $order = new WC_Order( $orderId );
     106        try{
     107         
     108          $api = new Instamojo($this->client_id, $this->client_secret, $this->testmode);
     109         
     110          $api_data['name'] = substr(trim((html_entity_decode( $order->billing_first_name ." ".$order->billing_last_name, ENT_QUOTES, 'UTF-8'))), 0, 20);
     111          $api_data['email']      = substr($order->billing_email, 0, 75);
     112          $api_data['phone']      = substr(html_entity_decode($order->billing_phone, ENT_QUOTES, 'UTF-8'), 0, 20);
     113          $api_data['amount']     = $this->get_order_total();
     114          $api_data['currency']     = "INR";
     115          $api_data['redirect_url']   = get_site_url();
     116          $api_data['transaction_id'] = time()."-". $orderId;
     117          $this->log("Data sent for creating order ".print_r($api_data,true));
     118         
     119          $response = $api->createOrderPayment($api_data);
     120          $this->log("Response from server on creating order".print_r($response,true));
     121          if(isset($response->order))
     122          {
     123            $url = $response->payment_options->payment_url;
     124            WC()->session->set( 'payment_request_id',  $response->order->id);
     125            // die( json_encode(array("result"=>"success", "redirect"=>$url)));
     126            return array(
     127                        'result' => 'success',
     128                        'redirect' => $url
     129                    );
     130          }
     131       
     132        }catch(CurlException $e){
     133          $this->log("An error occurred on line " . $e->getLine() . " with message " .  $e->getMessage());
     134          $this->log("Traceback: " . (string)$e);
     135          $json = array(
     136            "result"=>"failure",
     137            "messages"=>"<ul class=\"woocommerce-error\">\n\t\t\t<li>" . $e->getMessage() . "</li>\n\t</ul>\n",
     138            "refresh"=>"false",
     139            "reload"=>"false"
     140            );
     141           
     142          die(json_encode($json));
     143        }catch(ValidationException $e){
     144          $this->log("Validation Exception Occured with response ".print_r($e->getResponse(), true));
     145          $errors_html = "<ul class=\"woocommerce-error\">\n\t\t\t";
     146          foreach( $e->getErrors() as $error)
     147          {
     148            $errors_html .="<li>".$error."</li>";
     149           
     150          }
     151          $errors_html .= "</ul>";
     152          $json = array(
     153            "result"=>"failure",
     154            "messages"=>$errors_html,
     155            "refresh"=>"false",
     156            "reload"=>"false"
     157            );
     158          die(json_encode($json));
     159        }
     160        catch(Exception $e){
     161         
     162          $this->log("An error occurred on line " . $e->getLine() . " with message " .  $e->getMessage());
     163          $this->log("Traceback: " . $e->getTraceAsString());
     164          $json = array(
     165            "result"=>"failure",
     166            "messages"=>"<ul class=\"woocommerce-error\">\n\t\t\t<li>".$e->getMessage()."</li>\n\t</ul>\n",
     167            "refresh"=>"false",
     168            "reload"=>"false"
     169            );
     170          die(json_encode($json));
     171         
     172        }
     173      }
     174     
     175      public static function log( $message )
     176      {
     177        insta_log($message);
     178      }
     179     
     180    }
     181
    61182}
    62183
Note: See TracChangeset for help on using the changeset viewer.