Plugin Directory

Changeset 2276066


Ignore:
Timestamp:
04/04/2020 08:44:11 PM (6 years ago)
Author:
sujon3g
Message:

Adding some fixes of the plugin

Location:
bkash
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • bkash/trunk/bkash.php

    r1810760 r2276066  
    1 <?php 
     1<?php
    22/*
    3 Plugin Name: bKash
    4 Plugin URI:  http://softtech-it.com 
    5 Description: bKash is money transfer system of Bangladesh by facilitating money transfer through mobile phones. This plugin depends on woocommerce and will provide an extra payment gateway through bKash in checkout page.
    6 Version:     1.2.0
    7 Author:      Mtm Sujan
    8 Author URI:  http://facebook.com/sujan4g 
     3Plugin Name: SoftTech-IT bKash for woocommerce
     4Plugin URI:  http://softtech-it.com
     5Description: This plugin helps users to integrate bkash payment gateway with woocommerce. bKash is money transfer system of Bangladesh by facilitating money transfer through mobile phones. This plugin depends on woocommerce and will provide an extra payment gateway through bKash in checkout page.
     6Version:     1.3.0
     7Author:      Md Toriqul Mowla Sujan
     8Author URI:  http://facebook.com/sujan4g
    99License:     GPL2
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2424 */
    2525if( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ){
    26    
    27     /**
    28     * bKash gateway register
    29     */
    30     add_filter('woocommerce_payment_gateways', 'softtech_bkash_payment_gateways');
    31     function softtech_bkash_payment_gateways( $gateways ){
    32         $gateways[] = 'SoftTechIT_Bkash';
    33         return $gateways;
    34     }
    35 
    36     /**
    37     * bKash gateway init
    38     */
    39     add_action('plugins_loaded', 'softtech_bkash_plugin_activation');
    40     function softtech_bkash_plugin_activation(){
    41        
    42         class SoftTechIT_Bkash extends WC_Payment_Gateway {
    43 
    44             public $bkash_number;
    45             public $number_type;
    46             public $order_status;
    47             public $instructions;
    48             public $bkash_charge;
    49 
    50             public function __construct(){
    51                 $this->id                   = 'softtech_bkash';
    52                 $this->title                = $this->get_option('title', 'bKash Gateway');
    53                 $this->description          = $this->get_option('description', 'bKash payment Gateway');
    54                 $this->method_title         = esc_html__("bKash", "stb");
    55                 $this->method_description   = esc_html__("bKash Payment Gateway Options", "stb" );
    56                 $this->icon                 = plugins_url('images/bkash.png', __FILE__);
    57                 $this->has_fields           = true;
    58 
    59                 $this->softtech_bkash_options_fields();
    60                 $this->init_settings();
    61                
    62                 $this->bkash_number = $this->get_option('bkash_number');
    63                 $this->number_type  = $this->get_option('number_type');
    64                 $this->order_status = $this->get_option('order_status');
    65                 $this->instructions = $this->get_option('instructions');
    66                 $this->bkash_charge = $this->get_option('bkash_charge');
    67 
    68                 add_action( 'woocommerce_update_options_payment_gateways_'.$this->id, array( $this, 'process_admin_options' ) );
    69                 add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'softtech_bkash_thankyou_page' ) );
    70                 add_action( 'woocommerce_email_before_order_table', array( $this, 'softtech_bkash_email_instructions' ), 10, 3 );
    71             }
    72 
    73 
    74             public function softtech_bkash_options_fields(){
    75                 $this->form_fields = array(
    76                     'enabled'   =>  array(
    77                         'title'     => esc_html__( 'Enable/Disable', "stb" ),
    78                         'type'      => 'checkbox',
    79                         'label'     => esc_html__( 'bKash Payment', "stb" ),
    80                         'default'   => 'yes'
    81                     ),
    82                     'title'     => array(
    83                         'title'     => esc_html__( 'Title', "stb" ),
    84                         'type'      => 'text',
    85                         'default'   => esc_html__( 'bKash', "stb" )
    86                     ),
    87                     'description' => array(
    88                         'title'     => esc_html__( 'Description', "stb" ),
    89                         'type'      => 'textarea',
    90                         'default'   => esc_html__( 'Please complete your bKash payment at first, then fill up the form below.', "stb" ),
    91                         'desc_tip'    => true
    92                     ),
    93                     'order_status' => array(
    94                         'title'       => esc_html__( 'Order Status', "stb" ),
    95                         'type'        => 'select',
    96                         'class'       => 'wc-enhanced-select',
    97                         'description' => esc_html__( 'Choose whether status you wish after checkout.', "stb" ),
    98                         'default'     => 'wc-on-hold',
    99                         'desc_tip'    => true,
    100                         'options'     => wc_get_order_statuses()
    101                     ),             
    102                     'bkash_number'  => array(
    103                         'title'         => esc_html__( 'bKash Number', "stb" ),
    104                         'description'   => esc_html__( 'Add a bKash mobile no which will be shown in checkout page', "stb" ),
    105                         'type'          => 'text',
    106                         'desc_tip'      => true
    107                     ),
    108                     'number_type'   => array(
    109                         'title'         => esc_html__( 'Agent/Personal', "stb" ),
    110                         'type'          => 'select',
    111                         'class'         => 'wc-enhanced-select',
    112                         'description'   => esc_html__( 'Select bKash account type', "stb" ),
    113                         'options'   => array(
    114                             'Agent'     => esc_html__( 'Agent', "stb" ),
    115                             'Personal'  => esc_html__( 'Personal', "stb" )
    116                         ),
    117                         'desc_tip'      => true
    118                     ),
    119                     'bkash_charge'  =>  array(
    120                         'title'         => esc_html__( 'Enable bKash Charge', "stb" ),
    121                         'type'          => 'checkbox',
    122                         'label'         => esc_html__( 'Add 2% bKash "Send Money" charge to net price', "stb" ),
    123                         'description'   => esc_html__( 'If a product price is 1000 then customer have to pay ( 1000 + 20 ) = 1020. Here 20 is bKash send money charge', "stb" ),
    124                         'default'       => 'no',
    125                         'desc_tip'      => true
    126                     ),                     
    127                     'instructions' => array(
    128                         'title'         => esc_html__( 'Instructions', "stb" ),
    129                         'type'          => 'textarea',
    130                         'description'   => esc_html__( 'Instructions that will be added to the thank you page and emails.', "stb" ),
    131                         'default'       => esc_html__( 'Thanks for purchasing through bKash. We will check and give you update as soon as possible.', "stb" ),
    132                         'desc_tip'      => true
    133                     ),                             
    134                 );
    135             }
    136 
    137 
    138             public function payment_fields(){
    139 
    140                 global $woocommerce;
    141                 $bkash_charge = ($this->bkash_charge == 'yes') ? esc_html__(' Also note that 2% bKash "SEND MONEY" cost will be added with net price. Total amount you need to send us at', "stb" ). ' ' . get_woocommerce_currency_symbol() . $woocommerce->cart->total : '';
    142                 echo wpautop( wptexturize( esc_html__( $this->description, "stb" ) ) . $bkash_charge  );
    143                 echo wpautop( wptexturize( "bKash ".$this->number_type." Number : ".$this->bkash_number ) );
    144 
    145                 ?>
    146                     <p>
    147                         <label for="bkash_number"><?php esc_html_e( 'bKash Number', "stb" );?></label>
    148                         <input type="text" name="bkash_number" id="bkash_number" placeholder="017XXXXXXXX">
    149                     </p>
    150                     <p>
    151                         <label for="bkash_transaction_id"><?php esc_html_e( 'bKash Transaction ID', "stb" );?></label>
    152                         <input type="text" name="bkash_transaction_id" id="bkash_transaction_id" placeholder="8N7A6D5EE7M">
    153                     </p>
    154                 <?php
    155             }
    156            
    157 
    158             public function process_payment( $order_id ) {
    159                 global $woocommerce;
    160                 $order = new WC_Order( $order_id );
    161                
    162                 $status = 'wc-' === substr( $this->order_status, 0, 3 ) ? substr( $this->order_status, 3 ) : $this->order_status;
    163                 // Mark as on-hold (we're awaiting the bKash)
    164                 $order->update_status( $status, esc_html__( 'Checkout with bKash payment. ', "stb" ) );
    165 
    166                 // Reduce stock levels
    167                 $order->reduce_order_stock();
    168 
    169                 // Remove cart
    170                 $woocommerce->cart->empty_cart();
    171 
    172                 // Return thankyou redirect
    173                 return array(
    174                     'result' => 'success',
    175                     'redirect' => $this->get_return_url( $order )
    176                 );
    177             }   
    178 
    179 
    180             public function softtech_bkash_thankyou_page() {
    181                 $order_id = get_query_var('order-received');
    182                 $order = new WC_Order( $order_id );
    183                 if( $order->payment_method == $this->id ){
    184                     $thankyou = $this->instructions;
    185                     return $thankyou;               
    186                 } else {
    187                     return esc_html__( 'Thank you. Your order has been received.', "stb" );
    188                 }
    189 
    190             }
    191 
    192 
    193             public function softtech_bkash_email_instructions( $order, $sent_to_admin, $plain_text = false ) {
    194                 if( $order->payment_method != $this->id )
    195                     return;         
    196                 if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method ) {
    197                     echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
    198                 }
    199             }
    200 
    201         }
    202 
    203     }
    204 
    205     /**
    206     * Add settings page link in plugins
    207     */
    208     add_filter( "plugin_action_links_". plugin_basename(__FILE__), 'softtech_bkash_settings_link' );
    209     function softtech_bkash_settings_link( $links ) {
    210        
    211         $settings_links = array();
    212         $settings_links[] ='<a href="https://www.facebook.com/softtechitinstitute/" target="_blank">' . esc_html__( 'Follow US', 'stb' ) . '</a>';
    213         $settings_links[] ='<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=softtech_bkash' ) . '">' . esc_html__( 'Settings', 'stb' ) . '</a>';
    214        
     26
     27    /**
     28    * bKash gateway register
     29    */
     30    add_filter('woocommerce_payment_gateways', 'softtech_bkash_payment_gateways');
     31    function softtech_bkash_payment_gateways( $gateways ){
     32        $gateways[] = 'SoftTechIT_Bkash';
     33        return $gateways;
     34    }
     35
     36    /**
     37    * bKash gateway init
     38    */
     39    add_action('plugins_loaded', 'softtech_bkash_plugin_activation');
     40    function softtech_bkash_plugin_activation(){
     41
     42        class SoftTechIT_Bkash extends WC_Payment_Gateway {
     43
     44            public $bkash_number;
     45            public $number_type;
     46            public $order_status;
     47            public $instructions;
     48            public $bkash_charge;
     49
     50            public function __construct(){
     51                $this->id                     = 'softtech_bkash';
     52                $this->title                 = $this->get_option('title', 'bKash Gateway');
     53                $this->description             = $this->get_option('description', 'bKash payment Gateway');
     54                $this->method_title         = esc_html__("bKash", "stb");
     55                $this->method_description     = esc_html__("bKash Payment Gateway Options", "stb" );
     56                $this->icon                 = plugins_url('images/bkash.png', __FILE__);
     57                $this->has_fields             = true;
     58
     59                $this->softtech_bkash_options_fields();
     60                $this->init_settings();
     61
     62                $this->bkash_number = $this->get_option('bkash_number');
     63                $this->number_type     = $this->get_option('number_type');
     64                $this->order_status = $this->get_option('order_status');
     65                $this->instructions = $this->get_option('instructions');
     66                $this->bkash_charge = $this->get_option('bkash_charge');
     67
     68                add_action( 'woocommerce_update_options_payment_gateways_'.$this->id, array( $this, 'process_admin_options' ) );
     69                add_filter( 'woocommerce_thankyou_order_received_text', array( $this, 'softtech_bkash_thankyou_page' ) );
     70                add_action( 'woocommerce_email_before_order_table', array( $this, 'softtech_bkash_email_instructions' ), 10, 3 );
     71            }
     72
     73
     74            public function softtech_bkash_options_fields(){
     75                $this->form_fields = array(
     76                    'enabled'     =>    array(
     77                        'title'        => esc_html__( 'Enable/Disable', "stb" ),
     78                        'type'         => 'checkbox',
     79                        'label'        => esc_html__( 'bKash Payment', "stb" ),
     80                        'default'    => 'yes'
     81                    ),
     82                    'title'     => array(
     83                        'title'     => esc_html__( 'Title', "stb" ),
     84                        'type'         => 'text',
     85                        'default'    => esc_html__( 'bKash', "stb" )
     86                    ),
     87                    'description' => array(
     88                        'title'        => esc_html__( 'Description', "stb" ),
     89                        'type'         => 'textarea',
     90                        'default'    => esc_html__( 'Please complete your bKash payment at first, then fill up the form below.', "stb" ),
     91                        'desc_tip'    => true
     92                    ),
     93                    'order_status' => array(
     94                        'title'       => esc_html__( 'Order Status', "stb" ),
     95                        'type'        => 'select',
     96                        'class'       => 'wc-enhanced-select',
     97                        'description' => esc_html__( 'Choose whether status you wish after checkout.', "stb" ),
     98                        'default'     => 'wc-on-hold',
     99                        'desc_tip'    => true,
     100                        'options'     => wc_get_order_statuses()
     101                    ),
     102                    'bkash_number'    => array(
     103                        'title'            => esc_html__( 'bKash Number', "stb" ),
     104                        'description'     => esc_html__( 'Add a bKash mobile no which will be shown in checkout page', "stb" ),
     105                        'type'            => 'text',
     106                        'desc_tip'      => true
     107                    ),
     108                    'number_type'    => array(
     109                        'title'            => esc_html__( 'Agent/Personal', "stb" ),
     110                        'type'            => 'select',
     111                        'class'           => 'wc-enhanced-select',
     112                        'description'     => esc_html__( 'Select bKash account type', "stb" ),
     113                        'options'    => array(
     114                            'Agent'        => esc_html__( 'Agent', "stb" ),
     115                            'Personal'    => esc_html__( 'Personal', "stb" )
     116                        ),
     117                        'desc_tip'      => true
     118                    ),
     119                    'bkash_charge'     =>    array(
     120                        'title'            => esc_html__( 'Enable bKash Charge', "stb" ),
     121                        'type'             => 'checkbox',
     122                        'label'            => esc_html__( 'Add 2% bKash "Send Money" charge to net price', "stb" ),
     123                        'description'     => esc_html__( 'If a product price is 1000 then customer have to pay ( 1000 + 20 ) = 1020. Here 20 is bKash send money charge', "stb" ),
     124                        'default'        => 'no',
     125                        'desc_tip'        => true
     126                    ),
     127                    'instructions' => array(
     128                        'title'           => esc_html__( 'Instructions', "stb" ),
     129                        'type'            => 'textarea',
     130                        'description'     => esc_html__( 'Instructions that will be added to the thank you page and emails.', "stb" ),
     131                        'default'         => esc_html__( 'Thanks for purchasing through bKash. We will check and give you update as soon as possible.', "stb" ),
     132                        'desc_tip'        => true
     133                    ),
     134                );
     135            }
     136
     137
     138            public function payment_fields(){
     139
     140                global $woocommerce;
     141                $bkash_charge = ($this->bkash_charge == 'yes') ? esc_html__(' Also note that 2% bKash "SEND MONEY" cost will be added with net price. Total amount you need to send us at', "stb" ). ' ' . get_woocommerce_currency_symbol() . $woocommerce->cart->total : '';
     142                echo wpautop( wptexturize( esc_html__( $this->description, "stb" ) ) . $bkash_charge  );
     143                echo wpautop( wptexturize( "bKash ".$this->number_type." Number : ".$this->bkash_number ) );
     144
     145                ?>
     146                    <p>
     147                        <label for="bkash_number"><?php esc_html_e( 'bKash Number', "stb" );?></label>
     148                        <input type="text" name="bkash_number" id="bkash_number" placeholder="017XXXXXXXX">
     149                    </p>
     150                    <p>
     151                        <label for="bkash_transaction_id"><?php esc_html_e( 'bKash Transaction ID', "stb" );?></label>
     152                        <input type="text" name="bkash_transaction_id" id="bkash_transaction_id" placeholder="8N7A6D5EE7M">
     153                    </p>
     154                <?php
     155            }
     156
     157
     158            public function process_payment( $order_id ) {
     159                global $woocommerce;
     160                $order = new WC_Order( $order_id );
     161
     162                $status = 'wc-' === substr( $this->order_status, 0, 3 ) ? substr( $this->order_status, 3 ) : $this->order_status;
     163                // Mark as on-hold (we're awaiting the bKash)
     164                $order->update_status( $status, esc_html__( 'Checkout with bKash payment. ', "stb" ) );
     165
     166                // Reduce stock levels
     167                $order->reduce_order_stock();
     168
     169                // Remove cart
     170                $woocommerce->cart->empty_cart();
     171
     172                // Return thankyou redirect
     173                return array(
     174                    'result' => 'success',
     175                    'redirect' => $this->get_return_url( $order )
     176                );
     177            }
     178
     179
     180            public function softtech_bkash_thankyou_page() {
     181                $order_id = get_query_var('order-received');
     182                $order = new WC_Order( $order_id );
     183                if( $order->get_payment_method() == $this->id ){
     184                    $thankyou = $this->instructions;
     185                    return $thankyou;
     186                } else {
     187                    return esc_html__( 'Thank you. Your order has been received.', "stb" );
     188                }
     189
     190            }
     191
     192
     193            public function softtech_bkash_email_instructions( $order, $sent_to_admin, $plain_text = false ) {
     194                if( $order->get_payment_method() != $this->id )
     195                    return;
     196                if ( $this->instructions && ! $sent_to_admin && $this->id === $order->get_payment_method() ) {
     197                    echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
     198                }
     199            }
     200
     201        }
     202
     203    }
     204
     205    /**
     206    * Add settings page link in plugins
     207    */
     208    add_filter( "plugin_action_links_". plugin_basename(__FILE__), 'softtech_bkash_settings_link' );
     209    function softtech_bkash_settings_link( $links ) {
     210
     211        $settings_links = array();
     212        $settings_links[] ='<a href="https://www.facebook.com/softtechitinstitute/" target="_blank">' . esc_html__( 'Follow US', 'stb' ) . '</a>';
     213        $settings_links[] ='<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=softtech_bkash' ) . '">' . esc_html__( 'Settings', 'stb' ) . '</a>';
     214
    215215        // add the links to the list of links already there
    216         foreach($settings_links as $link) {
    217             array_unshift($links, $link);
    218         }
    219 
    220         return $links;
    221     }   
    222 
    223     /**
    224      * If bKash charge is activated
    225      */
    226     $bkash_charge = get_option( 'woocommerce_softtech_bkash_settings' );
    227     if( $bkash_charge['bkash_charge'] == 'yes' ){
    228 
    229         add_action( 'wp_enqueue_scripts', 'softtech_bkash_script' );
    230         function softtech_bkash_script(){
    231             wp_enqueue_script( 'stb-script', plugins_url( 'js/scripts.js', __FILE__ ), array('jquery'), '1.0', true );
    232         }
    233 
    234         add_action( 'woocommerce_cart_calculate_fees', 'softtech_bkash_charge' );
    235         function softtech_bkash_charge(){
    236 
    237             global $woocommerce;
    238             $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
    239             $current_gateway = '';
    240 
    241             if ( !empty( $available_gateways ) ) {
    242                 if ( isset( $woocommerce->session->chosen_payment_method ) && isset( $available_gateways[ $woocommerce->session->chosen_payment_method ] ) ) {
    243                     $current_gateway = $available_gateways[ $woocommerce->session->chosen_payment_method ];
    244                 }
    245             }
    246            
    247             if( $current_gateway!='' ){
    248 
    249                 $current_gateway_id = $current_gateway->id;
    250 
    251                 if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    252                     return;
    253 
    254                 if ( $current_gateway_id =='softtech_bkash' ) {
    255                     $percentage = 0.02;
    256                     $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;   
    257                     $woocommerce->cart->add_fee( esc_html__('bKash Charge', 'stb'), $surcharge, true, '' );
    258                 }
    259                
    260             }       
    261            
    262         }
    263        
    264     }
    265 
    266     /**
    267      * Empty field validation
    268      */
    269     add_action( 'woocommerce_checkout_process', 'softtech_bkash_payment_process' );
    270     function softtech_bkash_payment_process(){
    271 
    272         if($_POST['payment_method'] != 'softtech_bkash')
    273             return;
    274 
    275         $bkash_number = sanitize_text_field( $_POST['bkash_number'] );
    276         $bkash_transaction_id = sanitize_text_field( $_POST['bkash_transaction_id'] );
    277 
    278         $match_number = isset($bkash_number) ? $bkash_number : '';
    279         $match_id = isset($bkash_transaction_id) ? $bkash_transaction_id : '';
    280 
    281         $validate_number = preg_match( '/^01[5-9]\d{8}$/', $match_number );
    282         $validate_id = preg_match( '/[a-zA-Z0-9]+/',  $match_id );
    283 
    284         if( !isset($bkash_number) || empty($bkash_number) )
    285             wc_add_notice( esc_html__( 'Please add your mobile number', 'stb'), 'error' );
    286 
    287         if( !empty($bkash_number) && $validate_number == false )
    288             wc_add_notice( esc_html__( 'Incorrect mobile number. It must be 11 digit, starts with 015 / 016 / 017 / 018 / 019', 'stb'), 'error' );
    289 
    290         if( !isset($bkash_transaction_id) || empty($bkash_transaction_id) )
    291             wc_add_notice( esc_html__( 'Please add your bKash transaction ID', 'stb' ), 'error' );
    292 
    293         if( !empty($bkash_transaction_id) && $validate_id == false )
    294             wc_add_notice( esc_html__( 'Only number or letter is acceptable', 'stb'), 'error' );
    295 
    296     }
    297 
    298     /**
    299      * Update bKash field to database
    300      */
    301     add_action( 'woocommerce_checkout_update_order_meta', 'softtech_bkash_additional_fields_update' );
    302     function softtech_bkash_additional_fields_update( $order_id ){
    303 
    304         if($_POST['payment_method'] != 'softtech_bkash' )
    305             return;
    306 
    307         $bkash_number = sanitize_text_field( $_POST['bkash_number'] );
    308         $bkash_transaction_id = sanitize_text_field( $_POST['bkash_transaction_id'] );
    309 
    310         $number = isset($bkash_number) ? $bkash_number : '';
    311         $transaction = isset($bkash_transaction_id) ? $bkash_transaction_id : '';
    312 
    313         update_post_meta($order_id, '_bkash_number', $number);
    314         update_post_meta($order_id, '_bkash_transaction', $transaction);
    315 
    316     }
    317 
    318     /**
    319      * Admin order page bKash data output
    320      */
    321     add_action('woocommerce_admin_order_data_after_billing_address', 'softtech_bkash_admin_order_data' );
    322     function softtech_bkash_admin_order_data( $order ){
    323        
    324         if( $order->payment_method != 'softtech_bkash' )
    325             return;
    326 
    327         $number = (get_post_meta($order->id, '_bkash_number', true)) ? get_post_meta($order->id, '_bkash_number', true) : '';
    328         $transaction = (get_post_meta($order->id, '_bkash_transaction', true)) ? get_post_meta($order->id, '_bkash_transaction', true) : '';
    329 
    330         ?>
    331         <div class="form-field form-field-wide">
    332             <img src='<?php echo plugins_url("images/bkash.png", __FILE__); ?>' alt="bKash">   
    333             <table class="wp-list-table widefat fixed striped posts">
    334                 <tbody>
    335                     <tr>
    336                         <th><strong><?php esc_html_e('bKash No', 'stb') ;?></strong></th>
    337                         <td>: <?php echo esc_attr( $number );?></td>
    338                     </tr>
    339                     <tr>
    340                         <th><strong><?php esc_html_e('Transaction ID', 'stb') ;?></strong></th>
    341                         <td>: <?php echo esc_attr( $transaction );?></td>
    342                     </tr>
    343                 </tbody>
    344             </table>
    345         </div>
    346         <?php
    347        
    348     }
    349 
    350     /**
    351      * Order review page bKash data output
    352      */
    353     add_action('woocommerce_order_details_after_customer_details', 'softtech_bkash_additional_info_order_review_fields' );
    354     function softtech_bkash_additional_info_order_review_fields( $order ){
    355        
    356         if( $order->payment_method != 'softtech_bkash' )
    357             return;
    358 
    359         $number = (get_post_meta($order->id, '_bkash_number', true)) ? get_post_meta($order->id, '_bkash_number', true) : '';
    360         $transaction = (get_post_meta($order->id, '_bkash_transaction', true)) ? get_post_meta($order->id, '_bkash_transaction', true) : '';
    361 
    362         ?>
    363             <tr>
    364                 <th><?php esc_html_e('bKash No:', 'stb');?></th>
    365                 <td><?php echo esc_attr( $number );?></td>
    366             </tr>
    367             <tr>
    368                 <th><?php esc_html_e('Transaction ID:', 'stb');?></th>
    369                 <td><?php echo esc_attr( $transaction );?></td>
    370             </tr>
    371         <?php
    372        
    373     }   
    374 
    375     /**
    376      * Register new admin column
    377      */
    378     add_filter( 'manage_edit-shop_order_columns', 'softtech_bkash_admin_new_column' );
    379     function softtech_bkash_admin_new_column($columns){
    380 
    381         $new_columns = (is_array($columns)) ? $columns : array();
    382         unset( $new_columns['order_actions'] );
    383         $new_columns['mobile_no']   = esc_html__('bKash No', 'stb');
    384         $new_columns['tran_id']     = esc_html__('Tran. ID', 'stb');
    385 
    386         $new_columns['order_actions'] = $columns['order_actions'];
    387         return $new_columns;
    388 
    389     }
    390 
    391     /**
    392      * Load data in new column
    393      */
    394     add_action( 'manage_shop_order_posts_custom_column', 'softtech_bkash_admin_column_value', 2 );
    395     function softtech_bkash_admin_column_value($column){
    396 
    397         global $post;
    398 
    399         $mobile_no = (get_post_meta($post->ID, '_bkash_number', true)) ? get_post_meta($post->ID, '_bkash_number', true) : '';
    400         $tran_id = (get_post_meta($post->ID, '_bkash_transaction', true)) ? get_post_meta($post->ID, '_bkash_transaction', true) : '';
    401 
    402         if ( $column == 'mobile_no' ) {   
    403             echo esc_attr( $mobile_no );
    404         }
    405         if ( $column == 'tran_id' ) {   
    406             echo esc_attr( $tran_id );
    407         }
    408     }
     216        foreach($settings_links as $link) {
     217            array_unshift($links, $link);
     218        }
     219
     220        return $links;
     221    }
     222
     223    /**
     224     * If bKash charge is activated
     225     */
     226    $bkash_charge = get_option( 'woocommerce_softtech_bkash_settings' );
     227    if( isset($bkash_charge['bkash_charge']) ){
     228        if( $bkash_charge['bkash_charge'] == 'yes' ){
     229
     230            add_action( 'wp_enqueue_scripts', 'softtech_bkash_script' );
     231            function softtech_bkash_script(){
     232                wp_enqueue_script( 'stb-script', plugins_url( 'js/scripts.js', __FILE__ ), array('jquery'), '1.0', true );
     233            }
     234
     235            add_action( 'woocommerce_cart_calculate_fees', 'softtech_bkash_charge' );
     236            function softtech_bkash_charge(){
     237
     238                global $woocommerce;
     239                $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
     240                $current_gateway = '';
     241
     242                if ( !empty( $available_gateways ) ) {
     243                    if ( isset( $woocommerce->session->chosen_payment_method ) && isset( $available_gateways[ $woocommerce->session->chosen_payment_method ] ) ) {
     244                        $current_gateway = $available_gateways[ $woocommerce->session->chosen_payment_method ];
     245                    }
     246                }
     247
     248                if( $current_gateway!='' ){
     249
     250                    $current_gateway_id = $current_gateway->id;
     251
     252                    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
     253                        return;
     254
     255                    if ( $current_gateway_id =='softtech_bkash' ) {
     256                        $percentage = 0.02;
     257                        $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
     258                        $woocommerce->cart->add_fee( esc_html__('bKash Charge', 'stb'), $surcharge, true, '' );
     259                    }
     260
     261                }
     262
     263            }
     264
     265        }
     266    }
     267
     268    /**
     269     * Empty field validation
     270     */
     271    add_action( 'woocommerce_checkout_process', 'softtech_bkash_payment_process' );
     272    function softtech_bkash_payment_process(){
     273
     274        if($_POST['payment_method'] != 'softtech_bkash')
     275            return;
     276
     277        $bkash_number = sanitize_text_field( $_POST['bkash_number'] );
     278        $bkash_transaction_id = sanitize_text_field( $_POST['bkash_transaction_id'] );
     279
     280        $match_number = isset($bkash_number) ? $bkash_number : '';
     281        $match_id = isset($bkash_transaction_id) ? $bkash_transaction_id : '';
     282
     283        $validate_number = preg_match( '/^01[5-9]\d{8}$/', $match_number );
     284        $validate_id = preg_match( '/[a-zA-Z0-9]+/',  $match_id );
     285
     286        if( !isset($bkash_number) || empty($bkash_number) )
     287            wc_add_notice( esc_html__( 'Please add your mobile number', 'stb'), 'error' );
     288
     289        if( !empty($bkash_number) && $validate_number == false )
     290            wc_add_notice( esc_html__( 'Incorrect mobile number. It must be 11 digit, starts with 015 / 016 / 017 / 018 / 019', 'stb'), 'error' );
     291
     292        if( !isset($bkash_transaction_id) || empty($bkash_transaction_id) )
     293            wc_add_notice( esc_html__( 'Please add your bKash transaction ID', 'stb' ), 'error' );
     294
     295        if( !empty($bkash_transaction_id) && $validate_id == false )
     296            wc_add_notice( esc_html__( 'Only number or letter is acceptable', 'stb'), 'error' );
     297
     298    }
     299
     300    /**
     301     * Update bKash field to database
     302     */
     303    add_action( 'woocommerce_checkout_update_order_meta', 'softtech_bkash_additional_fields_update' );
     304    function softtech_bkash_additional_fields_update( $order_id ){
     305
     306        if($_POST['payment_method'] != 'softtech_bkash' )
     307            return;
     308
     309        $bkash_number = sanitize_text_field( $_POST['bkash_number'] );
     310        $bkash_transaction_id = sanitize_text_field( $_POST['bkash_transaction_id'] );
     311
     312        $number = isset($bkash_number) ? $bkash_number : '';
     313        $transaction = isset($bkash_transaction_id) ? $bkash_transaction_id : '';
     314
     315        update_post_meta($order_id, '_bkash_number', $number);
     316        update_post_meta($order_id, '_bkash_transaction', $transaction);
     317
     318    }
     319
     320    /**
     321     * Admin order page bKash data output
     322     */
     323    add_action('woocommerce_admin_order_data_after_billing_address', 'softtech_bkash_admin_order_data' );
     324    function softtech_bkash_admin_order_data( $order ){
     325
     326        if( $order->get_payment_method() != 'softtech_bkash' )
     327            return;
     328
     329
     330        $number = (get_post_meta($_GET['post'], '_bkash_number', true)) ? get_post_meta($_GET['post'], '_bkash_number', true) : '';
     331        $transaction = (get_post_meta($_GET['post'], '_bkash_transaction', true)) ? get_post_meta($_GET['post'], '_bkash_transaction', true) : '';
     332
     333        ?>
     334        <div class="form-field form-field-wide">
     335            <img src='<?php echo plugins_url("images/bkash.png", __FILE__); ?>' alt="bKash">
     336            <table class="wp-list-table widefat fixed striped posts">
     337                <tbody>
     338                    <tr>
     339                        <th><strong><?php esc_html_e('bKash No', 'stb') ;?></strong></th>
     340                        <td>: <?php echo esc_attr( $number );?></td>
     341                    </tr>
     342                    <tr>
     343                        <th><strong><?php esc_html_e('Transaction ID', 'stb') ;?></strong></th>
     344                        <td>: <?php echo esc_attr( $transaction );?></td>
     345
     346                    </tr>
     347                </tbody>
     348            </table>
     349        </div>
     350        <?php
     351
     352    }
     353
     354    /**
     355     * Order review page bKash data output
     356     */
     357    add_action('woocommerce_order_details_after_customer_details', 'softtech_bkash_additional_info_order_review_fields' );
     358    function softtech_bkash_additional_info_order_review_fields( $order ){
     359
     360        if( $order->get_payment_method() != 'softtech_bkash' )
     361            return;
     362
     363        global $wp;
     364
     365        // Get the order ID
     366        $order_id  = absint( $wp->query_vars['order-received'] );
     367
     368        $number = (get_post_meta($order_id, '_bkash_number', true)) ? get_post_meta($order_id, '_bkash_number', true) : '';
     369        $transaction = (get_post_meta($order_id, '_bkash_transaction', true)) ? get_post_meta($order_id, '_bkash_transaction', true) : '';
     370
     371        ?>
     372        <table>
     373            <tr>
     374                <th><?php esc_html_e('bKash No:', 'stb');?></th>
     375                <td><?php echo esc_attr( $number );?></td>
     376            </tr>
     377            <tr>
     378                <th><?php esc_html_e('Transaction ID:', 'stb');?></th>
     379                <td><?php echo esc_attr( $transaction );?></td>
     380            </tr>
     381        </table>
     382        <?php
     383
     384    }
     385
     386    /**
     387     * Register new admin column
     388     */
     389    add_filter( 'manage_edit-shop_order_columns', 'softtech_bkash_admin_new_column' );
     390    function softtech_bkash_admin_new_column($columns){
     391
     392        $new_columns = (is_array($columns)) ? $columns : array();
     393        unset( $new_columns['order_actions'] );
     394        $new_columns['mobile_no']     = esc_html__('bKash No', 'stb');
     395        $new_columns['tran_id']     = esc_html__('Tran. ID', 'stb');
     396
     397        $new_columns['order_actions'] = $columns['order_actions'];
     398        return $new_columns;
     399
     400    }
     401
     402    /**
     403     * Load data in new column
     404     */
     405    add_action( 'manage_shop_order_posts_custom_column', 'softtech_bkash_admin_column_value', 2 );
     406    function softtech_bkash_admin_column_value($column){
     407
     408        global $post;
     409
     410        $mobile_no = (get_post_meta($post->ID, '_bkash_number', true)) ? get_post_meta($post->ID, '_bkash_number', true) : '';
     411        $tran_id = (get_post_meta($post->ID, '_bkash_transaction', true)) ? get_post_meta($post->ID, '_bkash_transaction', true) : '';
     412
     413        if ( $column == 'mobile_no' ) {
     414            echo esc_attr( $mobile_no );
     415        }
     416        if ( $column == 'tran_id' ) {
     417            echo esc_attr( $tran_id );
     418        }
     419    }
    409420
    410421} else {
    411     /**
    412     * Admin Notice
    413     */
    414     add_action( 'admin_notices', 'softtech_bkash_admin_notice__error' );
    415     function softtech_bkash_admin_notice__error() {
    416         ?>
    417         <div class="notice notice-error">
    418             <p><a href="http://wordpress.org/extend/plugins/woocommerce/"><?php esc_html_e( 'Woocommerce', 'stb' ); ?></a> <?php esc_html_e( 'plugin need to active if you wanna use bKash plugin.', 'stb' ); ?></p>
    419         </div>
    420         <?php
    421     }
    422    
    423     /**
    424     * Deactivate Plugin
    425     */
    426     add_action( 'admin_init', 'softtech_bkash_deactivate' );
    427     function softtech_bkash_deactivate() {
    428         deactivate_plugins( plugin_basename( __FILE__ ) );
    429         unset( $_GET['activate'] );
    430     }
     422    /**
     423    * Admin Notice
     424    */
     425    add_action( 'admin_notices', 'softtech_bkash_admin_notice__error' );
     426    function softtech_bkash_admin_notice__error() {
     427        ?>
     428        <div class="notice notice-error">
     429            <p><a href="http://wordpress.org/extend/plugins/woocommerce/"><?php esc_html_e( 'Woocommerce', 'stb' ); ?></a> <?php esc_html_e( 'plugin needs to actived if you want to install this plugin.', 'stb' ); ?></p>
     430        </div>
     431        <?php
     432    }
     433
     434    /**
     435    * Deactivate Plugin
     436    */
     437    add_action( 'admin_init', 'softtech_bkash_deactivate' );
     438    function softtech_bkash_deactivate() {
     439        deactivate_plugins( plugin_basename( __FILE__ ) );
     440        unset( $_GET['activate'] );
     441    }
    431442}
  • bkash/trunk/readme.txt

    r1810760 r2276066  
    11=== Plugin Name ===
    22Contributors: sujon3g, developerzinan
    3 Tags: woocommerce, bkash, Bangladesh, BDT, gateway, custom
     3Tags: woocommerce, bkash, Bangladesh, BDT, gateway, woocommerce bkash, sujan, softtech, softtech-it, mtm sujan, toriqul, toriqul mowla, toriqul mowla sujan
    44Requires at least: 4.5.0
    5 Tested up to: 4.9.1
    6 Stable tag: 1.2.0
     5Tested up to: 5.4
     6Stable tag: 1.3.0
    77Stable tag: trunk
    88License: GPLv2 or later
     
    1313== Description ==
    1414
    15 This is a cool plugin to integrate bKash payment gateway in any woocommerce based website. It is lightweight and very easy to use. 
     15This is a cool plugin to integrate bKash payment gateway in any woocommerce based website. It is lightweight and very easy to use.
    1616
    1717Please note:
     
    6363== Changelog ==
    6464
     65= 1.3 =
     66* Fix - issues has been fixed while activating the plugin
     67* Fix - Errors has been fixed in order page of dashboard
     68* Change - Changed the name and logo of the plugin because of some issues with bkash trademark
     69
    6570= 1.2 =
    6671* Added - Woocommerce activation checked
Note: See TracChangeset for help on using the changeset viewer.