WooCommerce – APG SMS Notifications – Add Mvayoo

This sparked off after a mail by a colleague turned out with a very quick reply by the original authors. The nutshell was that “We’re sorry, but we can’t spent more free time with our plugins”. Well that is quite justifyable. But the donation requested was way too much for our considerations. And today morning I just sat down with an insight to look deeper into the original code by Art Project Group. Thanks to the Google Translator, and the wonderful code by the Art Project Group. Should not forget the contributions of one of my old colleague Niju NB, for creating the mVaayoo api as a php class. The whole integration took less than 15 minutes with all the available peripherals.

I am adding a diff for the WooCommerce – APG SMS Notifications version 1.3, which has the version pinning, with due acknowledgement for the original snippet (Disable plugin update …). If in any case this does not work, ie the patching does not work, the following steps could be taken. I cannot guarantee that this will work for all but still this could be a starting point.

Deep dive
In “formulario.php” for array $proveedores, add new api information “mvayoo_api” => “Mvayoo API”, which would add this to the drop down list of api providers, and below that around line 37, after the first closing “tr”, add the following piece which would add the necessary options for the mVayoo api in the settings page. The class=”key” is the important part such that the corresponding settings form will be displayed using the jQuery methods included by the original authors.


      <tr valign="top" class="mvayoo_api"><!-- Mvayoo API -->
        <th scope="row" class="titledesc"> <label for="apg_sms_settings[login_mvayoo_api]">
            <?php _e('Login:''apg_sms'); ?>
          </label>
          <img class="help_tip" data-tip="<?php echo sprintf(__('The %s for your account in %s''apg_sms'), __('login''apg_sms'), "Mvayoo API"); ?>" src="<?php echo plugins_url'woocommerce/assets/images/help.png');?>" height="16" width="16" /> </th>
        <td class="forminp forminp-number"><input type="text" id="apg_sms_settings[clave_mvayoo_api]" name="apg_sms_settings[clave_mvayoo_api]" size="50" value="<?php echo (isset($configuracion['clave_mvayoo_api']) ? $configuracion['clave_mvayoo_api'] : ''); ?>" tabindex="<?php echo $tab++; ?>" /></td>
      </tr>
      <tr valign="top" class="mvayoo_api"><!-- Mvayoo API -->
        <th scope="row" class="titledesc"> <label for="apg_sms_settings[passwd_mvayoo_api]">
            <?php _e('Password:''apg_sms'); ?>
          </label>
          <img class="help_tip" data-tip="<?php echo sprintf(__('The %s for your account in %s''apg_sms'), __('password''apg_sms'), "Mvayoo API"); ?>" src="<?php echo plugins_url'woocommerce/assets/images/help.png');?>" height="16" width="16" /> </th>
        <td class="forminp forminp-number"><input type="text" id="apg_sms_settings[passwd_mvayoo_api]" name="apg_sms_settings[passwd_mvayoo_api]" size="50" value="<?php echo (isset($configuracion['passwd_mvayoo_api']) ? $configuracion['passwd_mvayoo_api'] : ''); ?>" tabindex="<?php echo $tab++; ?>" /></td>
      </tr>
      <tr valign="top" class="mvayoo_api"><!-- Mvayoo API -->
        <th scope="row" class="titledesc"> <label for="apg_sms_settings[campid_mvayoo_api]">
            <?php _e('Campaign ID:''apg_sms'); ?>
          </label>
          <img class="help_tip" data-tip="<?php echo sprintf(__('The %s for your account in %s, no need to change it if once created, if empty will create automatically''apg_sms'), __('campaign''apg_sms'), "Mvayoo API"); ?>" src="<?php echo plugins_url'woocommerce/assets/images/help.png');?>" height="16" width="16" /> </th>
        <td class="forminp forminp-number"><input type="text" id="apg_sms_settings[campid_mvayoo_api]" name="apg_sms_settings[campid_mvayoo_api]" size="50" value="<?php echo (isset($configuracion['campid_mvayoo_api']) ? $configuracion['campid_mvayoo_api'] : ''); ?>" tabindex="<?php echo $tab++; ?>" /></td>
      </tr>
      <tr valign="top" class="mvayoo_api"><!-- Mvayoo API -->
        <th scope="row" class="titledesc"> <label for="apg_sms_settings[senderid_mvayoo_api]">
            <?php _e('Sender Name:''apg_sms'); ?>
          </label>
          <img class="help_tip" data-tip="<?php echo sprintf(__('The %s for your account in %s, if empty will use TEST SMS''apg_sms'), __('sender name''apg_sms'), "Mvayoo API"); ?>" src="<?php echo plugins_url'woocommerce/assets/images/help.png');?>" height="16" width="16" /> </th>
        <td class="forminp forminp-number"><input type="text" id="apg_sms_settings[senderid_mvayoo_api]" name="apg_sms_settings[senderid_mvayoo_api]" size="50" value="<?php echo (isset($configuracion['senderid_mvayoo_api']) ? $configuracion['senderid_mvayoo_api'] : ''); ?>" tabindex="<?php echo $tab++; ?>" /></td>
      </tr>
 

Now to add the functionality, the mVayoo API which is converted a bit to be adopted with apg_sms is included as a separate download. This should be copied into the “lib” folder. And to integrate this two locations need the changes in the “apg-sms.php”. First is around line 235, “function apg_sms_prefijo”, there was a set of or conditions nested in an if, my preference to check using in_array is applied here.. the function could be changed as below, or add the “mvayoo_api” to the or condition to return true incase this api is selected.

//Mira si necesita el prefijo telefónico internacional
function apg_sms_prefijo($servicio) {
    
$need_prefix = array("mvayoo_api""clockwork" "clickatell" "bulksms" "msg91""twillio");
    return 
in_array($servicio$need_prefix);
}
 

The next is where the actual sms being sent. around line 146 in “function apg_sms_envia_sms”, to the series of if else if, I added one on the top just before the first if

if ($configuracion['servicio'] == "mvayoo_api")
    {
        require_once(
"lib/mvsms.php");
        
$mvsms = new MvSMS($configuracion['clave_mvayoo_api'], $configuracion['passwd_mvayoo_api'],$configuracion['campid_mvayoo_api'],$configuracion['senderid_mvayoo_api']);
        
$respuesta $mvsms->sendSMS($telefono$mensaje);
        
$campID $mvsms->campID;
        if(
$configuracion['campid_mvayoo_api'] !== $campID){
            
$configuracion['campid_mvayoo_api'] = $campID;
            
update_option('apg_sms_settings'$configuracion);
        }        
    }
    else 

Finally to pin down the version and avoid the update nag from wordpress, failing which all these patch will be lost when original authors release an updated version and the plugin users will upgrade seeing the nag.

/* pinning down the version such that updates will not affect */
function dd_remove_update_nag($value) {
 unset(
$value->responseplugin_basename(__FILE__) ]);
 return 
$value;
}
 
add_filter('site_transient_update_plugins''dd_remove_update_nag');

Well in the above code, we do an update_option such that the campid which gets auto generated will be saved for future usage. This was part of the mVayoo sms api. I am sure this will get obsolete when Art Project Group decides to update their version with this information. Lets hope so, and then I will come out with another api, and finally this “WooCommerce – APG SMS Notifications”, could be truely made Indian with more services for Indian portals from India.

Note: there was an error in the above which has been corrected, the ‘new MvSMS’ was being passed with an invalid parameter, $configuracion[‘login_mvayoo_api’], which should be $configuracion[‘clave_mvayoo_api’] and has been changed, though the diff is not corrected.

Download
Download