Plugin Directory

Changeset 2678231


Ignore:
Timestamp:
02/14/2022 06:54:27 AM (4 years ago)
Author:
Ahaenor
Message:
  • Mixplat Gateway tmp. reverted back to pre-pull request state.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • leyka/trunk/gateways/mixplat/leyka-class-mixplat-gateway.php

    r2678084 r2678231  
    1313
    1414        $this->_id = 'mixplat';
    15         $this->_title = __('MIXPLAT - SMS', 'leyka');
     15        $this->_title = __('MIXPLAT', 'leyka');
    1616
    1717        $this->_description = apply_filters(
     
    2424        $this->_registration_link = '//mixplat.ru/#join';
    2525
    26         $this->_min_commission = 2.5;
     26        $this->_min_commission = 3;
    2727        $this->_receiver_types = ['legal'];
    2828
     
    3636
    3737        $this->_options = [
     38            $this->_id.'_new_api' => [
     39                'type' => 'checkbox',
     40                'default' => false,
     41                'title' => sprintf(__('Use %s new API', 'leyka'), $this->_title),
     42                'comment' => sprintf(__('Check if your %s connection uses MIXPLAT API v3', 'leyka'), $this->_title),
     43                'short_format' => true,
     44            ],
    3845            'mixplat_service_id' => [
    3946                'type' => 'text',
    40                 'title' => __('MIXPLAT Project ID', 'leyka'),
    41                 'comment' => __('Enter your project ID. It can be found in your MIXPLAT project settings page on MIXPLAT site.', 'leyka'),
     47                'title' => __('MIXPLAT project ID', 'leyka'),
     48                'comment' => __('Please, enter your MIXPLAT project ID here. It can be found in your MIXPLAT project settings page on MIXPLAT site.', 'leyka'),
    4249                'required' => true,
    4350                'placeholder' => sprintf(__('E.g., %s', 'leyka'), '100359'),
     
    4552            'mixplat_secret_key' => [
    4653                'type' => 'text',
    47                 'title' => __('MIXPLAT API key', 'leyka'),
    48                 'comment' => __('Enter your API key. It can be found in your MIXPLAT project settings page on MIXPLAT site.', 'leyka'),
     54                'title' => __('MIXPLAT project secret API key', 'leyka'),
     55                'comment' => __('Please, enter your MIXPLAT project secret key (or API key for the new API) here. It can be found in your MIXPLAT project settings page on MIXPLAT site.', 'leyka'),
    4956                'required' => true,
    5057                'placeholder' => sprintf(__('E.g., %s', 'leyka'), 'c23a4398db8ef7b3ae1f4b07aeeb7c54f8e3c7c9'),
     58            ],
     59            'mixplat_test_mode' => [
     60                'type' => 'checkbox',
     61                'default' => true,
     62                'title' => __('Payments testing mode', 'leyka'),
     63                'comment' => __('Check if the gateway integration is in test mode.', 'leyka'),
     64                'short_format' => true,
     65                'required' => false,
    5166            ],
    5267        ];
     
    139154        $is_success = false;
    140155
    141                 // Use only API v3
     156        if(leyka_options()->opt('mixplat_new_api')) { // API v3
    142157
    143158            require_once LEYKA_PLUGIN_DIR.'gateways/mixplat/lib/autoload.php';
     
    158173            $new_payment->paymentMethod = \MixplatClient\MixplatVars::PAYMENT_METHOD_MOBILE;
    159174            $new_payment->userPhone = $phone;
    160               $new_payment->userEmail = $donation->donor_email;
    161175            $new_payment->amount = $amount;
    162176            $new_payment->merchantFields = [
     
    164178                'email' => $donation->donor_email,
    165179                'payment_title' => $donation->payment_title,
    166                 'campaign_id' => leyka_options()->opt('mixplat-sms_default_campaign_id'),
    167180            ];
    168181
     
    175188            }
    176189
     190        } else { // Older APIs
     191
     192            $ch = curl_init();
     193            curl_setopt_array($ch, [
     194                CURLOPT_URL => 'http://api.mixplat.com/mc/create_payment',
     195                CURLOPT_CUSTOMREQUEST => 'POST',
     196                CURLOPT_POSTFIELDS => json_encode([
     197                    'service_id' => leyka_options()->opt('mixplat_service_id'),
     198                    'phone' => $phone,
     199                    'amount' => $amount,
     200                    'currency' => $currency,
     201                    'external_id' => $donation_id,
     202                    'test' => $is_test,
     203                    'signature' => md5(
     204                        leyka_options()->opt('mixplat_service_id').$phone.$amount.$currency.$donation_id.$is_test
     205                        .leyka_options()->opt('mixplat_secret_key')
     206                    ),
     207                ]),
     208                CURLOPT_VERBOSE => true,
     209                CURLOPT_RETURNTRANSFER => true,
     210                CURLOPT_CONNECTTIMEOUT => 60,
     211            ]);
     212            $answer = curl_exec($ch);
     213            curl_close($ch);
     214
     215            $json = null;
     216            if($answer) {
     217                try {
     218                    $json = json_decode($answer, true);
     219                } catch(Exception $ex) {
     220                    error_log($ex);
     221                }
     222            }
     223
     224            if($json) {
     225
     226                $donation->add_gateway_response($json);
     227
     228                if($json['result'] == 'ok') {
     229                    $is_success = true;
     230                }
     231
     232            }
     233
     234        }
    177235
    178236        if($is_success) {
     
    599657        $this->_description = apply_filters(
    600658            'leyka_pm_description',
    601             __('Mobile payment is performed from user mobile account without sending SMS.', 'leyka'),
     659            __('MIXPLAT allows a simple and safe way to pay for goods and services with your mobile phone by sending SMS.', 'leyka'),
    602660            $this->_id,
    603661            $this->_gateway_id,
     
    644702
    645703    }
    646     protected function _set_options_defaults() {
    647 
    648         if($this->_options) {
    649             return;
    650         }
    651 
    652         $this->_options = [
    653             'mixplat_test_mode' => [
    654                 'type' => 'checkbox',
    655                 'default' => false,
    656                 'title' => __('Payments testing mode', 'leyka'),
    657                 'comment' => __('Check if the gateway integration is in test mode.', 'leyka'),
    658                 'short_format' => true,
    659         'required' => false,
    660             ],
    661         ];
    662 
    663     }
    664704
    665705}
     
    677717        $this->_description = apply_filters(
    678718            'leyka_pm_description',
    679             __('Payments via SMS are common way of collecting donations by sending SMS with keyword to short 4-digit number.', 'leyka'),
     719            __('MIXPLAT allows a simple and safe way to pay for goods and services with your mobile phone by sending SMS.', 'leyka'),
    680720            $this->_id,
    681721            $this->_gateway_id,
     
    725765                'list_entries' => 'leyka_get_campaigns_list',
    726766            ],
     767            $this->full_id.'_description' => [
     768                'type' => 'html',
     769                'title' => __('Comment to the message of donations via SMS', 'leyka'),
     770                'comment' => __('Please, set a text of payments via SMS description.', 'leyka'),
     771            ],
    727772            $this->full_id.'_details' => [
    728773                'type' => 'html',
    729                 'default' => __('Donate by sending SMS to short number 3434 with text XXXX and your donation amount.', 'leyka'),
    730                 'title' => __('Text how to donate via SMS', 'leyka'),
    731                 'comment' => __('Enter text describing donation via SMS. Change XXXX to your registered keyword in MIXPLAT system.', 'leyka'),
     774                'default' => __('You can make a donation by sending an SMS on the number XXXX.', 'leyka'),
     775                'title' => __('Ways to donate via SMS', 'leyka'),
     776                'comment' => __('Please, set a text to describe a donation via SMS.', 'leyka'),
    732777                'required' => true,
    733778            ],
Note: See TracChangeset for help on using the changeset viewer.