Changeset 3173212
- Timestamp:
- 10/22/2024 12:02:56 AM (15 months ago)
- Location:
- mesomb-for-woocommerce/trunk
- Files:
-
- 2 edited
-
Me-somb-woo.php (modified) (16 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mesomb-for-woocommerce/trunk/Me-somb-woo.php
r2978142 r3173212 5 5 Plugin URI: https://mesomb.hachther.com 6 6 Description: Plugin to integrate Mobile payment on WooCommerce using Hachther MeSomb 7 Version: 1.2. 4-17 Version: 1.2.5-2 8 8 Author: Hachther LLC <[email protected]> 9 9 Author URI: https://hachther.com … … 27 27 return 300; 28 28 } 29 30 //function t($key) {31 // $locale = substr(get_locale(), 0, 2);32 // $transaction = array(33 // 'en' => array(34 // 'Pay_with_your' => 'Pay with your',35 // 'Pay_with_your_mobile_account' => 'Pay with your Mobile/Orange Money account.',36 // 'Phone_Number' => 'Phone Number',37 // 'Error_invalid_service' => "Invalid operator it should be Mobile Money or Orange Money",38 // 'Error_invalid_phone' => "Your phone number format is invalid. It should be in the local format of MTN or Orange expl: 670000000",39 // 'Success_payment_done' => "Hey, your order is paid! Thank you!",40 // 'General_error' => "Error during the payment process!\nPlease try again and contact the admin if the issue is continue",41 // 'Title_Title' => 'Title',42 // 'Title_Description' => 'This controls the title which the user sees during checkout.',43 // 'Title_Default' => 'MeSomb Mobile Payment',44 // 'Enable_Disable_Title' => 'Enable/Disable',45 // 'Enable_MeSomb_Gateway' => 'Enable MeSomb Gateway',46 // 'Description_Title' => 'Description',47 // 'Description_Description' => 'This controls the description which the user sees during checkout.',48 // 'Description_Default' => 'Pay with your Mobile/Orange Money account.',49 // 'Fees_Included_Title' => 'Fees Included',50 // 'Fees_Included_Label' => 'Fees are already included in the displayed price',51 // 'Fees_Included_Description' => 'This control if the MeSomb fees is already included in the price shown to users',52 // 'Application_Title' => 'MeSomb Application Key',53 // 'method_description' => 'Allow user to make payment with Mobile Money or Orange Money'54 // ),55 // 'fr' => array(56 // 'Pay_with_your' => 'Payez avec',57 // 'Pay_with_your_mobile_account' => 'Payez avec votre compte Mobile/Orange Money.',58 // 'Phone_Number' => 'Numéro de Téléphone',59 // 'Error_invalid_service' => "Opérateur non valide, cela devrait être Mobile Money ou Orange Money",60 // 'Error_invalid_phone' => "Le format de votre numéro de téléphone n'est pas valide. Il doit être au format local MTN ou Orange expl: 670000000",61 // 'Success_payment_done' => "Hé, votre commande est payée! Merci!",62 // 'General_error' => "Erreur lors du processus de paiement!\nVeuillez réessayer et contacter l'administrateur si le problème persiste",63 // 'Title_Title' => 'Titre',64 // 'Title_Description' => "Ceci contrôle le titre que l'utilisateur voit lors du paiement.",65 // 'Title_Default' => 'Paiement Mobile MeSomb',66 // 'Enable_Disable_Title' => 'Activer/Désactiver',67 // 'Enable_MeSomb_Gateway' => 'Activer la Passerelle MeSomb',68 // 'Description_Title' => 'Description',69 // 'Description_Description' => "Ceci contrôle la description que l'utilisateur voit lors du paiement.",70 // 'Description_Default' => 'Payez avec votre compte Mobile/Orange Money.',71 // 'Fees_Included_Title' => 'Frais inclus',72 // 'Fees_Included_Label' => 'Les frais sont déjà inclus dans le prix affiché',73 // 'Fees_Included_Description' => 'Ceci contrôle si les frais MeSomb sont déjà inclus dans le prix affiché aux utilisateurs',74 // 'Application_Title' => "Clé d'Application MeSomb",75 // 'method_description' => "Autoriser l'utilisateur à effectuer un paiement avec Mobile Money ou Orange Money"76 // ),77 // );78 // return $transaction[$locale][$key];79 //}80 29 81 30 class Signature … … 178 127 } 179 128 129 function get_client_ip() { 130 if(!empty($_SERVER['HTTP_CLIENT_IP'])) { 131 return $_SERVER['HTTP_CLIENT_IP']; 132 } 133 //if user is from the proxy 134 elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 135 return $_SERVER['HTTP_X_FORWARDED_FOR']; 136 } 137 //if user is from the remote address 138 else{ 139 return $_SERVER['REMOTE_ADDR']; 140 } 141 } 142 180 143 add_action('plugins_loaded', 'mesomb_init_gateway_class'); 181 144 function mesomb_init_gateway_class() … … 186 149 class WC_MeSomb_Gateway extends WC_Payment_Gateway 187 150 { 188 189 public function __construct() 151 /** 152 * @var array 153 */ 154 private $availableCountries; 155 156 /** 157 * @var array[] 158 */ 159 private $providers; 160 161 /** 162 * @var string 163 */ 164 private $application; 165 166 /** 167 * @var string 168 */ 169 private $accessKey; 170 171 /** 172 * @var string 173 */ 174 private $secretKey; 175 176 /** 177 * @var boolean 178 */ 179 private $feesIncluded; 180 181 /** 182 * @var boolean 183 */ 184 private $conversion; 185 186 /** 187 * @var array 188 */ 189 private $selectedCountries; 190 191 public function __construct() 190 192 { 191 193 $this->id = 'mesomb'; … … 200 202 'refunds', 201 203 ); 202 $this-> countriesList= array(204 $this->availableCountries = array( 203 205 'CM' => __('Cameroon', 'mesomb-for-woocommerce'), 204 206 'NE' => __('Niger', 'mesomb-for-woocommerce') … … 230 232 // Load the settings. 231 233 $this->init_settings(); 234 235 232 236 $this->title = $this->get_option('title'); 233 237 $this->description = $this->get_option('description'); 234 238 $this->enabled = $this->get_option('enabled'); 235 $this->testmode = 'yes' === $this->get_option('testmode');239 // $this->testmode = 'yes' === $this->get_option('testmode'); 236 240 $this->application = $this->get_option('application'); 237 241 $this->accessKey = $this->get_option('accessKey'); 238 242 $this->secretKey = $this->get_option('secretKey'); 239 $this->countries = $this->get_option('countries'); 240 $this->account = $this->get_option('account'); 241 $this->fees_included = $this->get_option('fees_included'); 243 $this->selectedCountries = $this->get_option('countries'); 244 $this->feesIncluded = $this->get_option('fees_included'); 242 245 $this->conversion = $this->get_option('conversion'); 243 246 … … 250 253 // You can also register a webhook here 251 254 // add_action( 'woocommerce_api_{webhook name}', array( $this, 'webhook' ) ); 252 $this->country = is_array($this->countries) && count($this->countries) > 0 ? $this->countries[0] : 'CM';253 $this->countryCode = array(254 'CM' => '237',255 'NE' => '227'256 );257 255 } 258 256 … … 313 311 'type' => 'multiselect', 314 312 'default' => 'CM', 315 'options' => $this-> countriesList,313 'options' => $this->availableCountries, 316 314 'description' => __('You can receive payments from which countries', 'mesomb-for-woocommerce'), 317 315 ), … … 348 346 349 347 // in most payment processors you have to use PUBLIC KEY to obtain a token 350 wp_localize_script('woocommerce_mesomb', 'mesomb_params', array(351 'apiKey' => $this->application352 ));348 // wp_localize_script('woocommerce_mesomb', 'mesomb_params', array( 349 // 'apiKey' => $this->application 350 // )); 353 351 354 352 wp_enqueue_script('woocommerce_mesomb'); … … 369 367 370 368 // I recommend to use inique IDs, because other gateways could already use #ccNo, #expdate, #cvc 371 if (is_array($this-> countries) && count($this->countries) > 1) {369 if (is_array($this->selectedCountries) && count($this->selectedCountries) > 1) { 372 370 echo '<div class="form-row form-row-wide validate-required"> 373 371 <label class="field-label">'.__('Country', 'mesomb-for-woocommerce').' <span class="required">*</span></label> 374 372 <div class="woocommerce-input-wrapper" id="countries-field">'; 375 foreach ($this-> countries as $country) {373 foreach ($this->selectedCountries as $country) { 376 374 echo '<label> 377 <input required id="mesomb-country-'.$country.'" type="radio" autocomplete="off" name="country" class="input-radio" value="'.$country.'" /> '.$this-> countriesList[$country].'375 <input required id="mesomb-country-'.$country.'" type="radio" autocomplete="off" name="country" class="input-radio" value="'.$country.'" /> '.$this->availableCountries[$country].' 378 376 </label>'; 379 377 } … … 386 384 <div id="providers" style="display: flex; flex-direction: row; flex-wrap: wrap;">'; 387 385 $provs = array_filter($this->providers, function($k, $v) { 388 return count(array_intersect($k['countries'], (array)$this-> countries)) > 0;386 return count(array_intersect($k['countries'], (array)$this->selectedCountries)) > 0; 389 387 }, ARRAY_FILTER_USE_BOTH); 390 388 foreach ($provs as $provider) { … … 431 429 return false; 432 430 } 433 if (is_array($this-> countries) && count($this->countries) > 1 && empty($_POST['country'])) {431 if (is_array($this->selectedCountries) && count($this->selectedCountries) > 1 && empty($_POST['country'])) { 434 432 wc_add_notice('<strong>Your must select a the country</strong>', 'error'); 435 433 return false; … … 457 455 } 458 456 $service = $_POST['service']; 459 $country = isset($_POST['country']) ? $_POST['country'] : $this->country; 457 if (!isset($_POST['country'])) { 458 $country = is_array($this->selectedCountries) && count($this->selectedCountries) > 0 ? $this->selectedCountries[0] : 'CM'; 459 } else { 460 $country = $_POST['country']; 461 } 460 462 $payer = sanitize_text_field($_POST['payer']); 461 463 $payer = ltrim($payer, '00'); 462 $payer = ltrim($payer, $this->countryCode[$country]); 464 $payer = ltrim($payer, array( 465 'CM' => '237', 466 'NE' => '227' 467 )[$country]); 463 468 464 469 if (!in_array($service, ['ORANGE', 'MTN', 'AIRTEL'])) { … … 476 481 'payer' => $payer, 477 482 'service' => $service, 478 'fees' => $this->fees _included == 'yes',483 'fees' => $this->feesIncluded == 'yes', 479 484 'conversion' => $this->conversion == 'yes', 480 485 'currency' => $order->get_currency(), … … 494 499 ), 495 500 'products' => $products, 496 'source' => 'WordPress/v'.get_bloginfo('version') 501 'location' => [ 502 'ip' => get_client_ip() 503 ], 504 'source' => 'WordPress/v'.get_bloginfo('version'), 497 505 ); 498 506 $lang = $locale == 'fr' ? 'fr' : 'en'; … … 504 512 $endpoint = empty($this->accessKey) ? 'online/' : 'collect/'; 505 513 if (empty($this->accessKey)) { 514 $url = "https://mesomb.hachther.com/api/$version/payment/$endpoint"; 515 } else { 506 516 $url = "https://mesomb.hachther.com/api/$version/payment/$endpoint"; 507 } else {508 $url = "https://mesomb.hachther.com/$lang/api/$version/payment/$endpoint";509 // $url = "http://127.0.0.1:8000/$lang/api/$version/payment/$endpoint";510 517 } 511 518 -
mesomb-for-woocommerce/trunk/readme.txt
r2978142 r3173212 2 2 Contributors: Hachther LLC 3 3 Tags: ecommerce, payment, mobile money, orange money, woo commerce, Cameroon, Niger 4 Tested up to: 6. 3.14 Tested up to: 6.6.2 5 5 Requires PHP: 7.0 6 Stable tag: 1.2.5- 16 Stable tag: 1.2.5-2 7 7 License: GPLv3 8 8 License URI: https://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset
for help on using the changeset viewer.