Plugin Directory

Changeset 2710252


Ignore:
Timestamp:
04/15/2022 02:59:06 PM (4 years ago)
Author:
transact
Message:

currency selection for USD, GBP, EUR, CAD

Location:
transact
Files:
10 edited
17 copied

Legend:

Unmodified
Added
Removed
  • transact/tags/5.8.0/admin/controllers/transact-admin-settings-menu.php

    r2592925 r2710252  
    77use Transact\Admin\Api\TransactApi;
    88require_once  plugin_dir_path(__FILE__) . '/transact-api.php';
     9
     10use Transact\Utils\Settings\CurrencyUtils;
     11require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
    912
    1013
     
    114117
    115118        /*
     119         * Button Styles Manager
     120         */
     121        add_settings_section(
     122            'transact_general', // ID
     123            'General Settings', // Title
     124            function() { esc_html_e('','transact'); },
     125            'transact-settings'
     126        );
     127
     128        // Adding Currency key field
     129        add_settings_field(
     130            'transact_currency',
     131            'Primary Currency',
     132            array( $this, 'display_currency_callback' ),
     133            'transact-settings',
     134            'transact_general',
     135            array(
     136                'id' => 'transact_currency',
     137                'default_val' => 'PROD') // Default value
     138        );
     139
     140        add_settings_field(
     141            'display_cents_dollars',
     142            'Price Display Format',
     143            array( $this, 'display_cents_dollars_callback' ),
     144            'transact-settings',
     145            'transact_general',
     146            array(
     147                'id' => 'transact_purchase_button_text',
     148                'default_val' => 'cents') // Default value
     149        );
     150
     151        add_settings_field(
     152            'transact_search_engine_access',
     153            'Search Engine Access',
     154            array( $this, 'display_search_engine_callback' ),
     155            'transact-settings',
     156            'transact_general',
     157            array(
     158                'id' => 'transact_search_engine_access',
     159                'default_val' => 'seo_no_access') // Default value
     160        );
     161
     162
     163
     164        add_settings_field(
     165            'default_purchase_type',
     166            'Default Post Purchase Type',
     167            array( $this, 'default_purchase_type_callback' ),
     168            'transact-settings',
     169            'transact_general',
     170            array(
     171                'id' => 'transact_default_purchase_type',
     172                'default_val' => 'subscribe_purchase') // Default value
     173        );
     174
     175        /*
    116176         * Post Types Manager
    117177         */
     
    232292            'xct_button_style',
    233293            array(false) // Default value
    234         );
    235 
    236         add_settings_field(
    237             'display_cents_dollars',
    238             'Price Display Format',
    239             array( $this, 'display_cents_dollars_callback' ),
    240             'transact-settings',
    241             'xct_button_style',
    242             array(
    243                 'id' => 'transact_purchase_button_text',
    244                 'default_val' => 'cents') // Default value
    245         );
    246 
    247         add_settings_field(
    248             'transact_search_engine_access',
    249             'Search Engine Access',
    250             array( $this, 'display_search_engine_callback' ),
    251             'transact-settings',
    252             'xct_button_style',
    253             array(
    254                 'id' => 'transact_search_engine_access',
    255                 'default_val' => 'seo_no_access') // Default value
    256         );
    257 
    258 
    259 
    260         add_settings_field(
    261             'default_purchase_type',
    262             'Default Post Purchase Type',
    263             array( $this, 'default_purchase_type_callback' ),
    264             'transact-settings',
    265             'xct_button_style',
    266             array(
    267                 'id' => 'transact_default_purchase_type',
    268                 'default_val' => 'subscribe_purchase') // Default value
    269294        );
    270295
     
    637662    }
    638663
     664    public function display_currency_callback($args)
     665    {
     666        $currency_options = array('PROD', 'GBP', 'EUR', 'JPY', 'CAD');
     667        $option_labels = array(
     668            'PROD' => 'USD',
     669            'GBP' => 'GBP',
     670            'EUR' => 'EUR',
     671            'JPY' => 'JPY',
     672            'CAD' => 'CAD'
     673        );
     674        $currency_utils = new CurrencyUtils();
     675        $selected_option = $currency_utils->get_currency_from_options();
     676        ?>
     677        <script>
     678            // Sets the real setting field
     679            function setCurrencyValue(val) {
     680                jQuery('#transact_currency').val(val);
     681            }
     682        </script>
     683        <input
     684            id="transact_currency"
     685            type="hidden"
     686            name="transact-settings[transact_currency]"
     687            value="<?php echo esc_attr($selected_option); ?>"
     688            />
     689
     690        <?php
     691        for($i = 0; $i < count($currency_options); $i++) {
     692            $i_option = $currency_options[$i];
     693            $field_id = "transact_currency_" . $i_option;
     694            $is_checked = $i_option === $selected_option ? 'checked' : '';
     695
     696            ?>
     697                <input <?php echo esc_attr($is_checked); ?>
     698                    id="<?php echo esc_html($field_id); ?>"
     699                    type="radio"
     700                    onclick="setCurrencyValue('<?php echo esc_attr($i_option); ?>')"
     701                    name="uf-transact_currency"
     702                    value="<?php echo esc_attr($i_option); ?>"
     703                />
     704                <label for="<?php echo esc_html($field_id); ?>"><?php echo esc_html($option_labels[$i_option]); ?></label>
     705                <br />
     706            <?php
     707        }
     708    }
     709
    639710    public function default_purchase_type_callback($args)
    640711    {
     
    714785        $options = get_option('transact-settings');
    715786        return $options['secret_key'];
    716     }
    717 
    718     /**
    719      * Gets environment from Settings
    720      * @return string
    721      */
    722     public function get_env()
    723     {
    724         $options = get_option('transact-settings');
    725         return $options['environment'];
    726787    }
    727788
  • transact/tags/5.8.0/admin/controllers/transact-admin-settings-post.php

    r2685584 r2710252  
    99
    1010require_once  plugin_dir_path(__FILE__) . 'transact-shortcode.php';
     11
     12use Transact\Utils\Settings\CurrencyUtils;
     13require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
    1114
    1215
     
    185188            return;
    186189        }
     190
     191        $currency_utils = new CurrencyUtils();
    187192
    188193        // Add an nonce field so we can check for it later.
     
    499504            <div id="transact_price_field" class="transact_meta_field">
    500505                <span class="transact-price-input">
     506                    <span class="currency_symbol"><?php echo esc_html($currency_utils->get_currency_symbol()); ?></span>
    501507                    <input type="number" min="0.01" step="0.01" id="transact_price" class="transact-price-input__field"
    502508                        onchange="check_transact_price()"
  • transact/tags/5.8.0/admin/controllers/transact-api.php

    r2420344 r2710252  
    4343        $ret = wp_remote_get($url);
    4444
    45         if (empty($ret)) {
     45        if (empty($ret) || is_wp_error(($ret))) {
    4646            return false;
    4747        }
  • transact/tags/5.8.0/frontend/assets/style.css

    r2584433 r2710252  
    211211  font-size: 15px;
    212212}
    213 .transact-price-input::before {
    214   content: '$';
     213.transact-price-input .currency_symbol {
    215214  position: absolute;
    216215  top: 50%;
    217216  left: 10px;
    218   line-height: 0;
     217  line-height: 3px;
    219218  z-index: 10;
    220219}
  • transact/tags/5.8.0/frontend/assets/transact_post.js

    r2685584 r2710252  
    5858
    5959            if (promoBlock && promoBlock.length) {
    60                 promoBlock.css('color', transact_params.theme.background_color);
    61                 // this text comes from transact.io who we trust
    62                 // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
    63                 promoBlock.html(result.text);
     60                if (result) {
     61                    promoBlock.css('color', transact_params.theme.background_color);
     62                    // this text comes from transact.io who we trust
     63                    // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
     64                    promoBlock.html(result.text);
     65                } else {
     66                    promoBlock.css('display', 'none');
     67                }
    6468            }
    6569        });
  • transact/tags/5.8.0/frontend/controllers/transact-api.php

    r2685584 r2710252  
    11<?php
    22namespace Transact\FrontEnd\Controllers\Api;
     3
     4use Transact\Utils\Settings\CurrencyUtils;
     5require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
    36
    47/**
     
    8992    function get_transact_information()
    9093    {
     94        $currency_utils = new CurrencyUtils();
    9195        $settings_menu_dashboard = new AdminSettingsMenuExtension();
    9296        $this->recipient_id = $settings_menu_dashboard->get_account_id();
    9397        $this->secret_id    = $settings_menu_dashboard->get_secret();
    9498        $this->get_search_engine_access = $settings_menu_dashboard->get_search_engine_access();
    95         $this->env          = 'PROD'; // TEST or PROD
     99        $this->env          = $currency_utils->get_currency_from_options(); // TEST, PROD, or another currency code
    96100
    97101        $settings_post = new AdminSettingsPostExtension($this->post_id);
     
    238242        }
    239243
    240         // Required:  Set PROD to use real money,  TEST for testing
     244        // Required:  Set PROD to use USD,  TEST for testing money, or any currency code (USD/GBP)
    241245        $transact->setClass($this->env);
    242246
  • transact/tags/5.8.0/frontend/controllers/transact-handle-buttons.php

    r2685584 r2710252  
    22
    33namespace Transact\FrontEnd\Controllers\Buttons;
     4
     5use Transact\Utils\Settings\CurrencyUtils;
     6require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
     7
    48
    59
     
    405409                    $button_text = $this->options['transact_purchase_button_text'] . ' '.  $price . ' ' . $token_text;
    406410                } else {
    407                     $button_text = $this->options['transact_purchase_button_text'] . ' $'.  $price / 100;
     411                    $currency_util = new CurrencyUtils();
     412
     413                    $button_text = $this->options['transact_purchase_button_text'] . ' ' . $currency_util->localize_currency_from_options($price);
    408414                }
    409415
  • transact/tags/5.8.0/readme.txt

    r2685584 r2710252  
    55Requires at least: 5.0
    66Requires PHP: 5.6
    7 Tested up to: 5.9.1
    8 Stable tag: 5.7.0
     7Tested up to: 5.9.3
     8Stable tag: 5.8.0
    99License: APACHE-2.0
    1010License URI: https://www.apache.org/licenses/LICENSE-2.0
     
    8282== Changelog ==
    8383
     84= 5.8.0 =
     85* Primary currency selection for USD, GBP, EUR, CAD
     86
    8487= 5.7.0 =
    8588* Add feature to login with transact.
  • transact/tags/5.8.0/transact-plugin.php

    r2685584 r2710252  
    33 * Plugin Name: transact.io
    44 * Description: Integrates transact.io services into WP
    5  * Version: 5.7.0
     5 * Version: 5.8.0
    66 * Author: transact.io
    77 * Author URI: https://transact.io
    88 * Plugin URI: https://wordpress.org/plugins/transact/
    99 */
    10 define('TRANSACT_VERSION', '5.7.0'); // Cache busting
     10define('TRANSACT_VERSION', '5.8.0'); // Cache busting
    1111
    1212/**
  • transact/trunk/admin/controllers/transact-admin-settings-menu.php

    r2592925 r2710252  
    77use Transact\Admin\Api\TransactApi;
    88require_once  plugin_dir_path(__FILE__) . '/transact-api.php';
     9
     10use Transact\Utils\Settings\CurrencyUtils;
     11require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
    912
    1013
     
    114117
    115118        /*
     119         * Button Styles Manager
     120         */
     121        add_settings_section(
     122            'transact_general', // ID
     123            'General Settings', // Title
     124            function() { esc_html_e('','transact'); },
     125            'transact-settings'
     126        );
     127
     128        // Adding Currency key field
     129        add_settings_field(
     130            'transact_currency',
     131            'Primary Currency',
     132            array( $this, 'display_currency_callback' ),
     133            'transact-settings',
     134            'transact_general',
     135            array(
     136                'id' => 'transact_currency',
     137                'default_val' => 'PROD') // Default value
     138        );
     139
     140        add_settings_field(
     141            'display_cents_dollars',
     142            'Price Display Format',
     143            array( $this, 'display_cents_dollars_callback' ),
     144            'transact-settings',
     145            'transact_general',
     146            array(
     147                'id' => 'transact_purchase_button_text',
     148                'default_val' => 'cents') // Default value
     149        );
     150
     151        add_settings_field(
     152            'transact_search_engine_access',
     153            'Search Engine Access',
     154            array( $this, 'display_search_engine_callback' ),
     155            'transact-settings',
     156            'transact_general',
     157            array(
     158                'id' => 'transact_search_engine_access',
     159                'default_val' => 'seo_no_access') // Default value
     160        );
     161
     162
     163
     164        add_settings_field(
     165            'default_purchase_type',
     166            'Default Post Purchase Type',
     167            array( $this, 'default_purchase_type_callback' ),
     168            'transact-settings',
     169            'transact_general',
     170            array(
     171                'id' => 'transact_default_purchase_type',
     172                'default_val' => 'subscribe_purchase') // Default value
     173        );
     174
     175        /*
    116176         * Post Types Manager
    117177         */
     
    232292            'xct_button_style',
    233293            array(false) // Default value
    234         );
    235 
    236         add_settings_field(
    237             'display_cents_dollars',
    238             'Price Display Format',
    239             array( $this, 'display_cents_dollars_callback' ),
    240             'transact-settings',
    241             'xct_button_style',
    242             array(
    243                 'id' => 'transact_purchase_button_text',
    244                 'default_val' => 'cents') // Default value
    245         );
    246 
    247         add_settings_field(
    248             'transact_search_engine_access',
    249             'Search Engine Access',
    250             array( $this, 'display_search_engine_callback' ),
    251             'transact-settings',
    252             'xct_button_style',
    253             array(
    254                 'id' => 'transact_search_engine_access',
    255                 'default_val' => 'seo_no_access') // Default value
    256         );
    257 
    258 
    259 
    260         add_settings_field(
    261             'default_purchase_type',
    262             'Default Post Purchase Type',
    263             array( $this, 'default_purchase_type_callback' ),
    264             'transact-settings',
    265             'xct_button_style',
    266             array(
    267                 'id' => 'transact_default_purchase_type',
    268                 'default_val' => 'subscribe_purchase') // Default value
    269294        );
    270295
     
    637662    }
    638663
     664    public function display_currency_callback($args)
     665    {
     666        $currency_options = array('PROD', 'GBP', 'EUR', 'JPY', 'CAD');
     667        $option_labels = array(
     668            'PROD' => 'USD',
     669            'GBP' => 'GBP',
     670            'EUR' => 'EUR',
     671            'JPY' => 'JPY',
     672            'CAD' => 'CAD'
     673        );
     674        $currency_utils = new CurrencyUtils();
     675        $selected_option = $currency_utils->get_currency_from_options();
     676        ?>
     677        <script>
     678            // Sets the real setting field
     679            function setCurrencyValue(val) {
     680                jQuery('#transact_currency').val(val);
     681            }
     682        </script>
     683        <input
     684            id="transact_currency"
     685            type="hidden"
     686            name="transact-settings[transact_currency]"
     687            value="<?php echo esc_attr($selected_option); ?>"
     688            />
     689
     690        <?php
     691        for($i = 0; $i < count($currency_options); $i++) {
     692            $i_option = $currency_options[$i];
     693            $field_id = "transact_currency_" . $i_option;
     694            $is_checked = $i_option === $selected_option ? 'checked' : '';
     695
     696            ?>
     697                <input <?php echo esc_attr($is_checked); ?>
     698                    id="<?php echo esc_html($field_id); ?>"
     699                    type="radio"
     700                    onclick="setCurrencyValue('<?php echo esc_attr($i_option); ?>')"
     701                    name="uf-transact_currency"
     702                    value="<?php echo esc_attr($i_option); ?>"
     703                />
     704                <label for="<?php echo esc_html($field_id); ?>"><?php echo esc_html($option_labels[$i_option]); ?></label>
     705                <br />
     706            <?php
     707        }
     708    }
     709
    639710    public function default_purchase_type_callback($args)
    640711    {
     
    714785        $options = get_option('transact-settings');
    715786        return $options['secret_key'];
    716     }
    717 
    718     /**
    719      * Gets environment from Settings
    720      * @return string
    721      */
    722     public function get_env()
    723     {
    724         $options = get_option('transact-settings');
    725         return $options['environment'];
    726787    }
    727788
  • transact/trunk/admin/controllers/transact-admin-settings-post.php

    r2685584 r2710252  
    99
    1010require_once  plugin_dir_path(__FILE__) . 'transact-shortcode.php';
     11
     12use Transact\Utils\Settings\CurrencyUtils;
     13require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
    1114
    1215
     
    185188            return;
    186189        }
     190
     191        $currency_utils = new CurrencyUtils();
    187192
    188193        // Add an nonce field so we can check for it later.
     
    499504            <div id="transact_price_field" class="transact_meta_field">
    500505                <span class="transact-price-input">
     506                    <span class="currency_symbol"><?php echo esc_html($currency_utils->get_currency_symbol()); ?></span>
    501507                    <input type="number" min="0.01" step="0.01" id="transact_price" class="transact-price-input__field"
    502508                        onchange="check_transact_price()"
  • transact/trunk/admin/controllers/transact-api.php

    r2420344 r2710252  
    4343        $ret = wp_remote_get($url);
    4444
    45         if (empty($ret)) {
     45        if (empty($ret) || is_wp_error(($ret))) {
    4646            return false;
    4747        }
  • transact/trunk/frontend/assets/style.css

    r2584433 r2710252  
    211211  font-size: 15px;
    212212}
    213 .transact-price-input::before {
    214   content: '$';
     213.transact-price-input .currency_symbol {
    215214  position: absolute;
    216215  top: 50%;
    217216  left: 10px;
    218   line-height: 0;
     217  line-height: 3px;
    219218  z-index: 10;
    220219}
  • transact/trunk/frontend/assets/transact_post.js

    r2685584 r2710252  
    5858
    5959            if (promoBlock && promoBlock.length) {
    60                 promoBlock.css('color', transact_params.theme.background_color);
    61                 // this text comes from transact.io who we trust
    62                 // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
    63                 promoBlock.html(result.text);
     60                if (result) {
     61                    promoBlock.css('color', transact_params.theme.background_color);
     62                    // this text comes from transact.io who we trust
     63                    // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
     64                    promoBlock.html(result.text);
     65                } else {
     66                    promoBlock.css('display', 'none');
     67                }
    6468            }
    6569        });
  • transact/trunk/frontend/controllers/transact-api.php

    r2685584 r2710252  
    11<?php
    22namespace Transact\FrontEnd\Controllers\Api;
     3
     4use Transact\Utils\Settings\CurrencyUtils;
     5require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
    36
    47/**
     
    8992    function get_transact_information()
    9093    {
     94        $currency_utils = new CurrencyUtils();
    9195        $settings_menu_dashboard = new AdminSettingsMenuExtension();
    9296        $this->recipient_id = $settings_menu_dashboard->get_account_id();
    9397        $this->secret_id    = $settings_menu_dashboard->get_secret();
    9498        $this->get_search_engine_access = $settings_menu_dashboard->get_search_engine_access();
    95         $this->env          = 'PROD'; // TEST or PROD
     99        $this->env          = $currency_utils->get_currency_from_options(); // TEST, PROD, or another currency code
    96100
    97101        $settings_post = new AdminSettingsPostExtension($this->post_id);
     
    238242        }
    239243
    240         // Required:  Set PROD to use real money,  TEST for testing
     244        // Required:  Set PROD to use USD,  TEST for testing money, or any currency code (USD/GBP)
    241245        $transact->setClass($this->env);
    242246
  • transact/trunk/frontend/controllers/transact-handle-buttons.php

    r2685584 r2710252  
    22
    33namespace Transact\FrontEnd\Controllers\Buttons;
     4
     5use Transact\Utils\Settings\CurrencyUtils;
     6require_once  plugin_dir_path(__FILE__) . '../../utils/transact-currency-utils.php';
     7
    48
    59
     
    405409                    $button_text = $this->options['transact_purchase_button_text'] . ' '.  $price . ' ' . $token_text;
    406410                } else {
    407                     $button_text = $this->options['transact_purchase_button_text'] . ' $'.  $price / 100;
     411                    $currency_util = new CurrencyUtils();
     412
     413                    $button_text = $this->options['transact_purchase_button_text'] . ' ' . $currency_util->localize_currency_from_options($price);
    408414                }
    409415
  • transact/trunk/readme.txt

    r2685584 r2710252  
    55Requires at least: 5.0
    66Requires PHP: 5.6
    7 Tested up to: 5.9.1
    8 Stable tag: 5.7.0
     7Tested up to: 5.9.3
     8Stable tag: 5.8.0
    99License: APACHE-2.0
    1010License URI: https://www.apache.org/licenses/LICENSE-2.0
     
    8282== Changelog ==
    8383
     84= 5.8.0 =
     85* Primary currency selection for USD, GBP, EUR, CAD
     86
    8487= 5.7.0 =
    8588* Add feature to login with transact.
  • transact/trunk/transact-plugin.php

    r2685584 r2710252  
    33 * Plugin Name: transact.io
    44 * Description: Integrates transact.io services into WP
    5  * Version: 5.7.0
     5 * Version: 5.8.0
    66 * Author: transact.io
    77 * Author URI: https://transact.io
    88 * Plugin URI: https://wordpress.org/plugins/transact/
    99 */
    10 define('TRANSACT_VERSION', '5.7.0'); // Cache busting
     10define('TRANSACT_VERSION', '5.8.0'); // Cache busting
    1111
    1212/**
Note: See TracChangeset for help on using the changeset viewer.