Plugin Directory

Changeset 3173212


Ignore:
Timestamp:
10/22/2024 12:02:56 AM (15 months ago)
Author:
hachther
Message:

Tested up to: 6.3.1

Location:
mesomb-for-woocommerce/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mesomb-for-woocommerce/trunk/Me-somb-woo.php

    r2978142 r3173212  
    55Plugin URI: https://mesomb.hachther.com
    66Description: Plugin to integrate Mobile payment on WooCommerce using Hachther MeSomb
    7 Version: 1.2.4-1
     7Version: 1.2.5-2
    88Author: Hachther LLC <[email protected]>
    99Author URI: https://hachther.com
     
    2727    return 300;
    2828}
    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 //}
    8029
    8130class Signature
     
    178127}
    179128
     129function 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
    180143add_action('plugins_loaded', 'mesomb_init_gateway_class');
    181144function mesomb_init_gateway_class()
     
    186149    class WC_MeSomb_Gateway extends WC_Payment_Gateway
    187150    {
    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()
    190192        {
    191193            $this->id = 'mesomb';
     
    200202                'refunds',
    201203            );
    202             $this->countriesList = array(
     204            $this->availableCountries = array(
    203205                'CM' => __('Cameroon', 'mesomb-for-woocommerce'),
    204206                'NE' => __('Niger', 'mesomb-for-woocommerce')
     
    230232            // Load the settings.
    231233            $this->init_settings();
     234
     235
    232236            $this->title = $this->get_option('title');
    233237            $this->description = $this->get_option('description');
    234238            $this->enabled = $this->get_option('enabled');
    235             $this->testmode = 'yes' === $this->get_option('testmode');
     239//            $this->testmode = 'yes' === $this->get_option('testmode');
    236240            $this->application = $this->get_option('application');
    237241            $this->accessKey = $this->get_option('accessKey');
    238242            $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');
    242245            $this->conversion = $this->get_option('conversion');
    243246
     
    250253            // You can also register a webhook here
    251254            // 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             );
    257255        }
    258256
     
    313311                    'type' => 'multiselect',
    314312                    'default' => 'CM',
    315                     'options' => $this->countriesList,
     313                    'options' => $this->availableCountries,
    316314                    'description' => __('You can receive payments from which countries', 'mesomb-for-woocommerce'),
    317315                ),
     
    348346
    349347            // 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->application
    352             ));
     348//            wp_localize_script('woocommerce_mesomb', 'mesomb_params', array(
     349//                'apiKey' => $this->application
     350//            ));
    353351
    354352            wp_enqueue_script('woocommerce_mesomb');
     
    369367
    370368            // 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) {
    372370                echo '<div class="form-row form-row-wide validate-required">
    373371                    <label class="field-label">'.__('Country', 'mesomb-for-woocommerce').' <span class="required">*</span></label>
    374372                    <div class="woocommerce-input-wrapper" id="countries-field">';
    375                 foreach ($this->countries as $country) {
     373                foreach ($this->selectedCountries as $country) {
    376374                    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].'
    378376                    </label>';
    379377                }
     
    386384                    <div id="providers" style="display: flex; flex-direction: row; flex-wrap: wrap;">';
    387385            $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;
    389387            }, ARRAY_FILTER_USE_BOTH);
    390388            foreach ($provs as $provider) {
     
    431429                return false;
    432430            }
    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'])) {
    434432                wc_add_notice('<strong>Your must select a the country</strong>', 'error');
    435433                return false;
     
    457455            }
    458456            $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            }
    460462            $payer = sanitize_text_field($_POST['payer']);
    461463            $payer = ltrim($payer, '00');
    462             $payer = ltrim($payer, $this->countryCode[$country]);
     464            $payer = ltrim($payer, array(
     465                'CM' => '237',
     466                'NE' => '227'
     467            )[$country]);
    463468
    464469            if (!in_array($service, ['ORANGE', 'MTN', 'AIRTEL'])) {
     
    476481                'payer' => $payer,
    477482                'service' => $service,
    478                 'fees' => $this->fees_included == 'yes',
     483                'fees' => $this->feesIncluded == 'yes',
    479484                'conversion' => $this->conversion == 'yes',
    480485                'currency' => $order->get_currency(),
     
    494499                ),
    495500                'products' => $products,
    496                 'source' => 'WordPress/v'.get_bloginfo('version')
     501                'location' => [
     502                    'ip' => get_client_ip()
     503                ],
     504                'source' => 'WordPress/v'.get_bloginfo('version'),
    497505            );
    498506            $lang = $locale == 'fr' ? 'fr' : 'en';
     
    504512            $endpoint = empty($this->accessKey) ? 'online/' : 'collect/';
    505513            if (empty($this->accessKey)) {
     514                $url = "https://mesomb.hachther.com/api/$version/payment/$endpoint";
     515            } else {
    506516                $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";
    510517            }
    511518
  • mesomb-for-woocommerce/trunk/readme.txt

    r2978142 r3173212  
    22Contributors: Hachther LLC
    33Tags: ecommerce, payment, mobile money, orange money, woo commerce, Cameroon, Niger
    4 Tested up to: 6.3.1
     4Tested up to: 6.6.2
    55Requires PHP: 7.0
    6 Stable tag: 1.2.5-1
     6Stable tag: 1.2.5-2
    77License: GPLv3
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset for help on using the changeset viewer.