Plugin Directory

Changeset 2754548


Ignore:
Timestamp:
07/11/2022 12:15:00 PM (4 years ago)
Author:
switips
Message:
  1. Получение валют
  2. Получение адреса домена для запросов к апи
Location:
switips
Files:
4 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • switips/tags/1.2/common/SWSettings.php

    r2551253 r2754548  
    11<?php
     2
     3if (!class_exists('Switips')) {
     4  require_once( 'switips-core.php' );
     5}
     6
    27if ( !class_exists('switips_settings') ) {
    38    class switips_settings {
     
    4752       
    4853        public function settings_save() {
    49             $opts = $this->merge_settings_post();
     54            $opts = $this->merge_settings_post();           
     55           
     56            if($opts['url_api'] == ''){
     57              $SwitipsCls = new Switips('empty');           
     58              $opts['url_api'] = $SwitipsCls->getDefaultDomain();
     59            }
    5060   
    5161            // treat boolean values
     
    302312            $value = $this->get_option($name);
    303313           
     314            $obj = new Switips('empty');
     315            $api_url = $obj->getDefaultDomain();
     316            $available = $obj->getAvailableCurrencies($api_url);
     317
    304318            ?>
    305319            <tr valign="top">
     
    310324                    <select name="<?php echo $name ?>">
    311325                        <?php foreach ( (array) $options as $optVal => $optLabel ): ?>
     326                   
     327                        <?php if(in_array($optVal, $available)):?>
     328                   
     329                   
    312330                            <option <?php if ( $value == $optVal ): ?>selected<?php endif; ?>
    313331                                    value="<?php echo $optVal ?>"><?php echo $optLabel; ?></option>
     332                        <?php endif; ?>
    314333                        <?php endforeach; ?>
    315334                    </select>
  • switips/tags/1.2/sw_log.log

    r2551253 r2754548  
    1 [Thu Apr 29 08:24:32 2021] {"merchant_id":"merchant_id","user_id":"WP0000512263","campaign_id":0,"category_id":0,"transaction_id":127,"transaction_amount":"333.00","currency":"RUB","transaction_amount_currency":"333.00","tt_date":1619684672,"stat":"new","secret_key":"secret_key","commission_amount":15,"switips_status":"error","sw_error":"Internal server error"}
    2 [Thu Apr 29 08:24:32 2021] {"merchant_id":"merchant_id","user_id":"WP0000512263","campaign_id":0,"category_id":0,"transaction_id":127,"transaction_amount":"333.00","currency":"RUB","transaction_amount_currency":"333.00","tt_date":1619684672,"stat":"new","secret_key":"secret_key","commission_amount":15,"switips_status":"error","sw_error":"Internal server error"}
    3 [Thu Apr 29 08:28:22 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000512263","campaign_id":0,"category_id":0,"transaction_id":128,"transaction_amount":"336.00","currency":"RUB","transaction_amount_currency":"336.00","tt_date":1619684901,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":14,"switips_status":"ok","sw_error":null}
    4 [Mon Jun 07 10:21:09 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000000001","campaign_id":0,"category_id":0,"transaction_id":130,"transaction_amount":"336.00","currency":"RUB","transaction_amount_currency":"336.00","tt_date":1623061268,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":24,"switips_status":"error","sw_error":"merchant not active"}
    5 [Mon Jun 07 10:21:10 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000000001","campaign_id":0,"category_id":0,"transaction_id":130,"transaction_amount":"336.00","currency":"RUB","transaction_amount_currency":"336.00","tt_date":1623061270,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":24,"switips_status":"error","sw_error":"merchant not active"}
    6 [Mon Jun 07 10:26:00 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000000001","campaign_id":0,"category_id":0,"transaction_id":131,"transaction_amount":"318.00","currency":"RUB","transaction_amount_currency":"318.00","tt_date":1623061559,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":12,"switips_status":"ok","sw_error":null}
    7 [Wed Jun 09 12:50:55 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":132,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243055,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    8 [Wed Jun 09 12:54:51 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":133,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243291,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    9 [Wed Jun 09 12:57:54 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":134,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243474,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    10 [Wed Jun 09 12:58:14 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":135,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243494,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    11 [Wed Jun 09 12:59:31 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":136,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243571,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    12 [Wed Jun 09 13:07:07 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":137,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623244027,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    13 [Wed Jun 09 13:08:23 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":137,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623244103,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    14 [Tue Jun 15 11:58:54 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":138,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758333,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
    15 [Tue Jun 15 11:58:55 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":138,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758335,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
    16 [Tue Jun 15 12:00:24 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":139,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758423,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
    17 [Tue Jun 15 12:00:25 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":139,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758424,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
  • switips/tags/1.2/switips-core.php

    r2551253 r2754548  
    11<?php
    22/**
    3  * Switips API
    4  * @link   http://outcode.ru
     3 * @package   Switips
     4 * @author    Outcode https://outcode.ru/
     5 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
    56 */
    67
     
    89 
    910  public $api_url;
    10   public $currencies = [
    11           'RUB',        // Российский рубль
    12           'UAH',        // Украинская гривна
    13           'USD',        // Доллар США
    14           'EUR',        // Евро
    15           'GBP',        // Фунт стерлингов Велико­британии
    16          ];
     11  public $currencies = [];
    1712  public $states = [
    1813          'new',        // Создан
     
    2015          'canceled',   // Отменен
    2116          'confirmed',  // Подтвержден
    22   ];         
     17  ];
     18
     19  public $url_without_domain = '/rest/partner/track';
    2320
    2421  public function __construct($api_url, $currencies = null, $states = null){
    2522   
    26     if(is_null($api_url) || $api_url == ''){
     23    if((is_null($api_url) || $api_url == '') && $api_url != 'empty'){
    2724      throw new Exception('Не указан url для запроса к API Switips');
    2825    }
     
    3431        $this->currencies[] = $currency;
    3532      }
    36     }
     33    }else{
     34      $this->currencies = $this->getAvailableCurrencies($this->api_url);
     35    }
    3736
    3837    if(is_array($states)){
     
    159158    }
    160159  }
     160 
     161  public function getDefaultDomain($api_url = ''){
     162    if($api_url == ''){
     163      $json = file_get_contents('https://swwwp.s3.eu-central-1.amazonaws.com/d.json');
     164
     165      if($json == false){
     166        return $api_url;
     167      }
     168     
     169      $json = json_decode($json);
     170
     171      return 'https://'.$json->mirror->merchant_api.$this->url_without_domain;
     172    }
     173   
     174    return $api_url;
     175  }
     176
     177  public function getAvailableCurrencies($api_url = ''){
     178   
     179    if($api_url == ''){
     180      $api_url = $this->api_url;
     181    }
     182   
     183    $url = parse_url($api_url);
     184
     185    if(isset($url['scheme'])){
     186      $api_url = $url['scheme'].'://'.$url['host'].'/rest/partner/available_currencies';
     187
     188      if ($curl = curl_init()) {
     189        curl_setopt($curl, CURLOPT_URL, $api_url);
     190        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     191        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     192        curl_setopt($curl, CURLOPT_HTTPHEADER, [
     193          'Accept: */*'
     194        ]);
     195
     196        $out = curl_exec($curl);
     197        curl_close($curl);
     198       
     199        if($out == false){
     200          return ['MXN', 'EUR', 'KZT', 'MDL', 'BYN', 'USD', 'UAH', 'RUB'];
     201        }
     202
     203        return json_decode($out);
     204      }else{
     205        throw new Exception('cURL - не установлен');
     206      }
     207    }
     208  }
    161209
    162210  public function sendRequestPost($args){
    163211
    164212    if (is_array($args)) {
    165      
     213
    166214      $args = $this->campaignId($args);
    167215      $args = $this->commissionAmount($args);     
     
    178226    }
    179227
    180     $response = wp_remote_post( $this->api_url, array(
    181         'headers'     => array('Content-Type' => 'application/json; charset=utf-8'),
    182         'body'        => $args,
    183         'method'      => 'POST',
    184         'data_format' => 'body',
    185     ));
    186 
    187     if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
    188         return json_decode('{"status" : "error", "error" : "Service unavailable"}');
    189     }
    190 
    191     return json_decode(wp_remote_retrieve_body($response));
     228    if ($curl = curl_init()) {
     229      curl_setopt($curl, CURLOPT_URL, $this->api_url);
     230      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
     231      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     232      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     233      curl_setopt($curl, CURLOPT_POST, true);
     234      curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
     235      curl_setopt($curl, CURLOPT_HTTPHEADER, array(
     236          'Content-Type: application/json',
     237      ));
     238
     239      $out = curl_exec($curl);
     240      curl_close($curl);
     241
     242      return json_decode($out);
     243    }else{
     244      throw new Exception('cURL - не установлен');
     245    }
    192246  }
    193247}
  • switips/tags/1.2/wc-switips.php

    r2617266 r2754548  
    326326  function switips_product_custom_fields_save($post_id){
    327327      $woocommerce_custom_product_commission_amount = sanitize_text_field($_POST['_custom_product_commission_amount']);
    328 
    329       //if (!empty($woocommerce_custom_product_commission_amount)) {
     328      if (!empty($woocommerce_custom_product_commission_amount)) {
    330329        update_post_meta($post_id, '_custom_product_commission_amount', esc_attr($woocommerce_custom_product_commission_amount));
    331       //}
    332       //esc_attr($woocommerce_custom_product_commission_amount);
     330      }
     331      esc_attr($woocommerce_custom_product_commission_amount);
     332
    333333  }
    334334
     
    346346      $term_id = $term->term_id;
    347347      $sw_commission = get_term_meta($term_id, '_custom_product_category_commission_amount', true);
    348 
    349348      ?>
    350349      <tr class="form-field">
     
    358357  }
    359358
    360   //function woocommerce_save_product_category_custom_fields($term_id) {
    361   function switips_save_product_category_custom_fields($term_id) {
    362     $sw_commission = filter_input(INPUT_POST, '_custom_product_category_commission_amount');   
     359  function woocommerce_save_product_category_custom_fields($term_id) {
     360    $sw_commission = filter_input(INPUT_POST, '_custom_product_category_commission_amount');
    363361    update_term_meta($term_id, '_custom_product_category_commission_amount', $sw_commission);
    364362  }
  • switips/trunk/common/SWSettings.php

    r2531063 r2754548  
    11<?php
     2
     3if (!class_exists('Switips')) {
     4  require_once( 'switips-core.php' );
     5}
     6
    27if ( !class_exists('switips_settings') ) {
    38    class switips_settings {
     
    4752       
    4853        public function settings_save() {
    49             $opts = $this->merge_settings_post();
     54            $opts = $this->merge_settings_post();           
     55           
     56            if($opts['url_api'] == ''){
     57              $SwitipsCls = new Switips('empty');           
     58              $opts['url_api'] = $SwitipsCls->getDefaultDomain();
     59            }
    5060   
    5161            // treat boolean values
     
    302312            $value = $this->get_option($name);
    303313           
     314            $obj = new Switips('empty');
     315            $api_url = $obj->getDefaultDomain();
     316            $available = $obj->getAvailableCurrencies($api_url);
     317
    304318            ?>
    305319            <tr valign="top">
     
    310324                    <select name="<?php echo $name ?>">
    311325                        <?php foreach ( (array) $options as $optVal => $optLabel ): ?>
     326                   
     327                        <?php if(in_array($optVal, $available)):?>
     328                   
     329                   
    312330                            <option <?php if ( $value == $optVal ): ?>selected<?php endif; ?>
    313331                                    value="<?php echo $optVal ?>"><?php echo $optLabel; ?></option>
     332                        <?php endif; ?>
    314333                        <?php endforeach; ?>
    315334                    </select>
  • switips/trunk/sw_log.log

    r2551253 r2754548  
    1 [Thu Apr 29 08:24:32 2021] {"merchant_id":"merchant_id","user_id":"WP0000512263","campaign_id":0,"category_id":0,"transaction_id":127,"transaction_amount":"333.00","currency":"RUB","transaction_amount_currency":"333.00","tt_date":1619684672,"stat":"new","secret_key":"secret_key","commission_amount":15,"switips_status":"error","sw_error":"Internal server error"}
    2 [Thu Apr 29 08:24:32 2021] {"merchant_id":"merchant_id","user_id":"WP0000512263","campaign_id":0,"category_id":0,"transaction_id":127,"transaction_amount":"333.00","currency":"RUB","transaction_amount_currency":"333.00","tt_date":1619684672,"stat":"new","secret_key":"secret_key","commission_amount":15,"switips_status":"error","sw_error":"Internal server error"}
    3 [Thu Apr 29 08:28:22 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000512263","campaign_id":0,"category_id":0,"transaction_id":128,"transaction_amount":"336.00","currency":"RUB","transaction_amount_currency":"336.00","tt_date":1619684901,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":14,"switips_status":"ok","sw_error":null}
    4 [Mon Jun 07 10:21:09 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000000001","campaign_id":0,"category_id":0,"transaction_id":130,"transaction_amount":"336.00","currency":"RUB","transaction_amount_currency":"336.00","tt_date":1623061268,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":24,"switips_status":"error","sw_error":"merchant not active"}
    5 [Mon Jun 07 10:21:10 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000000001","campaign_id":0,"category_id":0,"transaction_id":130,"transaction_amount":"336.00","currency":"RUB","transaction_amount_currency":"336.00","tt_date":1623061270,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":24,"switips_status":"error","sw_error":"merchant not active"}
    6 [Mon Jun 07 10:26:00 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000000001","campaign_id":0,"category_id":0,"transaction_id":131,"transaction_amount":"318.00","currency":"RUB","transaction_amount_currency":"318.00","tt_date":1623061559,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":12,"switips_status":"ok","sw_error":null}
    7 [Wed Jun 09 12:50:55 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":132,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243055,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    8 [Wed Jun 09 12:54:51 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":133,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243291,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    9 [Wed Jun 09 12:57:54 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":134,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243474,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    10 [Wed Jun 09 12:58:14 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":135,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243494,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    11 [Wed Jun 09 12:59:31 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":136,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623243571,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    12 [Wed Jun 09 13:07:07 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":137,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623244027,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    13 [Wed Jun 09 13:08:23 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"WP0000315659","campaign_id":0,"category_id":0,"transaction_id":137,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623244103,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"ok","sw_error":null}
    14 [Tue Jun 15 11:58:54 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":138,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758333,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
    15 [Tue Jun 15 11:58:55 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":138,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758335,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
    16 [Tue Jun 15 12:00:24 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":139,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758423,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
    17 [Tue Jun 15 12:00:25 2021] {"merchant_id":"eccb52e3-7683-44be-8fa6-b4f72c5754b0","user_id":"555555555","campaign_id":0,"category_id":0,"transaction_id":139,"transaction_amount":"15.00","currency":"RUB","transaction_amount_currency":"15.00","tt_date":1623758424,"stat":"new","secret_key":"5a52a6680dc5f9495cd01470e53d095078870ad072b49f9bd12b0b978a8e1441","commission_amount":3,"switips_status":"error","sw_error":"user not found"}
  • switips/trunk/switips-core.php

    r2531063 r2754548  
    11<?php
    22/**
    3  * Switips API
    4  * @link   http://outcode.ru
     3 * @package   Switips
     4 * @author    Outcode https://outcode.ru/
     5 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
    56 */
    67
     
    89 
    910  public $api_url;
    10   public $currencies = [
    11           'RUB',        // Российский рубль
    12           'UAH',        // Украинская гривна
    13           'USD',        // Доллар США
    14           'EUR',        // Евро
    15           'GBP',        // Фунт стерлингов Велико­британии
    16          ];
     11  public $currencies = [];
    1712  public $states = [
    1813          'new',        // Создан
     
    2015          'canceled',   // Отменен
    2116          'confirmed',  // Подтвержден
    22   ];         
     17  ];
     18
     19  public $url_without_domain = '/rest/partner/track';
    2320
    2421  public function __construct($api_url, $currencies = null, $states = null){
    2522   
    26     if(is_null($api_url) || $api_url == ''){
     23    if((is_null($api_url) || $api_url == '') && $api_url != 'empty'){
    2724      throw new Exception('Не указан url для запроса к API Switips');
    2825    }
     
    3431        $this->currencies[] = $currency;
    3532      }
    36     }
     33    }else{
     34      $this->currencies = $this->getAvailableCurrencies($this->api_url);
     35    }
    3736
    3837    if(is_array($states)){
     
    159158    }
    160159  }
     160 
     161  public function getDefaultDomain($api_url = ''){
     162    if($api_url == ''){
     163      $json = file_get_contents('https://swwwp.s3.eu-central-1.amazonaws.com/d.json');
     164
     165      if($json == false){
     166        return $api_url;
     167      }
     168     
     169      $json = json_decode($json);
     170
     171      return 'https://'.$json->mirror->merchant_api.$this->url_without_domain;
     172    }
     173   
     174    return $api_url;
     175  }
     176
     177  public function getAvailableCurrencies($api_url = ''){
     178   
     179    if($api_url == ''){
     180      $api_url = $this->api_url;
     181    }
     182   
     183    $url = parse_url($api_url);
     184
     185    if(isset($url['scheme'])){
     186      $api_url = $url['scheme'].'://'.$url['host'].'/rest/partner/available_currencies';
     187
     188      if ($curl = curl_init()) {
     189        curl_setopt($curl, CURLOPT_URL, $api_url);
     190        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     191        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     192        curl_setopt($curl, CURLOPT_HTTPHEADER, [
     193          'Accept: */*'
     194        ]);
     195
     196        $out = curl_exec($curl);
     197        curl_close($curl);
     198       
     199        if($out == false){
     200          return ['MXN', 'EUR', 'KZT', 'MDL', 'BYN', 'USD', 'UAH', 'RUB'];
     201        }
     202
     203        return json_decode($out);
     204      }else{
     205        throw new Exception('cURL - не установлен');
     206      }
     207    }
     208  }
    161209
    162210  public function sendRequestPost($args){
    163211
    164212    if (is_array($args)) {
    165      
     213
    166214      $args = $this->campaignId($args);
    167215      $args = $this->commissionAmount($args);     
     
    178226    }
    179227
    180     $response = wp_remote_post( $this->api_url, array(
    181         'headers'     => array('Content-Type' => 'application/json; charset=utf-8'),
    182         'body'        => $args,
    183         'method'      => 'POST',
    184         'data_format' => 'body',
    185     ));
    186 
    187     if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
    188         return json_decode('{"status" : "error", "error" : "Service unavailable"}');
    189     }
    190 
    191     return json_decode(wp_remote_retrieve_body($response));
     228    if ($curl = curl_init()) {
     229      curl_setopt($curl, CURLOPT_URL, $this->api_url);
     230      curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
     231      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     232      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     233      curl_setopt($curl, CURLOPT_POST, true);
     234      curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
     235      curl_setopt($curl, CURLOPT_HTTPHEADER, array(
     236          'Content-Type: application/json',
     237      ));
     238
     239      $out = curl_exec($curl);
     240      curl_close($curl);
     241
     242      return json_decode($out);
     243    }else{
     244      throw new Exception('cURL - не установлен');
     245    }
    192246  }
    193247}
  • switips/trunk/wc-switips.php

    r2617263 r2754548  
    326326  function switips_product_custom_fields_save($post_id){
    327327      $woocommerce_custom_product_commission_amount = sanitize_text_field($_POST['_custom_product_commission_amount']);
    328 
    329       //if (!empty($woocommerce_custom_product_commission_amount)) {
     328      if (!empty($woocommerce_custom_product_commission_amount)) {
    330329        update_post_meta($post_id, '_custom_product_commission_amount', esc_attr($woocommerce_custom_product_commission_amount));
    331       //}
    332       //esc_attr($woocommerce_custom_product_commission_amount);
     330      }
     331      esc_attr($woocommerce_custom_product_commission_amount);
     332
    333333  }
    334334
     
    346346      $term_id = $term->term_id;
    347347      $sw_commission = get_term_meta($term_id, '_custom_product_category_commission_amount', true);
    348 
    349348      ?>
    350349      <tr class="form-field">
     
    358357  }
    359358
    360   //function woocommerce_save_product_category_custom_fields($term_id) {
    361   function switips_save_product_category_custom_fields($term_id) {
    362     $sw_commission = filter_input(INPUT_POST, '_custom_product_category_commission_amount');   
     359  function woocommerce_save_product_category_custom_fields($term_id) {
     360    $sw_commission = filter_input(INPUT_POST, '_custom_product_category_commission_amount');
    363361    update_term_meta($term_id, '_custom_product_category_commission_amount', $sw_commission);
    364362  }
Note: See TracChangeset for help on using the changeset viewer.