Plugin Directory

Changeset 3227974


Ignore:
Timestamp:
01/24/2025 10:42:18 AM (14 months ago)
Author:
webtonative
Message:

Deploy plugin version 2.7.2

Location:
webtonative/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • webtonative/trunk/README.md

    r3225472 r3227974  
    44Requires at least: 2.0.2
    55Tested up to: 6.7.1
    6 Stable tag: 2.7.1
     6Stable tag: 2.7.2
    77License: GPLv2 or later
    88
  • webtonative/trunk/admin/iap/index.php

    r3034141 r3227974  
    11<?php
     2if (!defined('ABSPATH')) {
     3  exit(); // Exit if accessed directly
     4}
    25
    3 if (!defined('ABSPATH')) {
    4   exit();
    5 } // Exit if accessed directly
    6 
     6// Import required files
    77require_once __DIR__ . '/woo-commerce.php';
    88require_once __DIR__ . '/rest.php';
    99
     10// Utility class for managing IAP settings
     11class WebtonativeIAPUtil
     12{
     13  public static function getIAPSettings()
     14  {
     15    $defaults = array(
     16      'cart_button_text' => 'Buy Now',
     17      'processing_button_text' => 'Processing...',
     18      'failed_button_text' => 'Payment Failed',
     19      'payment_completed_button_text' => 'Payment Completed'
     20    );
     21
     22    // return wp_parse_args(get_option('wtn_iap_settings'), $defaults);
     23
     24    $saved_settings = get_option('wtn_iap_settings', array());
     25
     26    // Explicitly merge saved settings with defaults
     27    foreach ($defaults as $key => $value) {
     28      if (!isset($saved_settings[$key]) || empty($saved_settings[$key])) {
     29        $saved_settings[$key] = $value;
     30      }
     31    }
     32
     33    return $saved_settings;
     34  }
     35
     36  public static function saveIAPSettings($settings)
     37  {
     38    update_option('wtn_iap_settings', $settings);
     39  }
     40}
     41
     42// Main class for Webtonative IAP
    1043class WebtonativeIAP
    1144{
    1245  public function __construct()
    1346  {
     47    // Initialize REST controller
    1448    new WebtonativeIAPRestController();
     49
     50    // Add submenu for IAP settings
     51    add_action('admin_menu', array($this, 'add_submenu'));
     52  }
     53
     54  // Add submenu for IAP settings
     55  public function add_submenu()
     56  {
     57    add_submenu_page(
     58      'webtonative-settings',             // Parent menu slug
     59      'WooCommerce IAP Settings',         // Page title
     60      'WooCommerce IAP',                  // Submenu title
     61      'manage_options',                   // Capability
     62      'wtn_woocom_iap_settings',          // Menu slug
     63      array($this, 'settings_page_html')  // Callback for page HTML
     64    );
     65  }
     66
     67  // HTML for the IAP settings page
     68  public function settings_page_html()
     69  {
     70    // Check user capability
     71    if (!current_user_can('manage_options')) {
     72      wp_die(__('Sorry, you are not allowed to access this page.'));
     73    }
     74
     75    $settings = WebtonativeIAPUtil::getIAPSettings();
     76
     77    $cartButtonText = $settings['cart_button_text'];
     78    $processingButtonText = $settings['processing_button_text'];
     79    $failedButtonText = $settings['failed_button_text'];
     80    $paymentCompletedButtonText = $settings['payment_completed_button_text'];
     81
     82    // Handle form submission
     83    if (
     84      $_SERVER['REQUEST_METHOD'] === 'POST' &&
     85      isset($_POST['iap_settings_nonce']) &&
     86      wp_verify_nonce($_POST['iap_settings_nonce'], 'wtn-iap-settings_nonce')
     87    ) {
     88
     89      // Save settings
     90      $newSettings = array(
     91        'cart_button_text' => sanitize_text_field($_POST['cart_button_text']),
     92        'processing_button_text' => sanitize_text_field($_POST['processing_button_text']),
     93        'failed_button_text' => sanitize_text_field($_POST['failed_button_text']),
     94        'payment_completed_button_text' => sanitize_text_field($_POST['payment_completed_button_text']),
     95      );
     96
     97      WebtonativeIAPUtil::saveIAPSettings($newSettings);
     98      $settings = $newSettings; // Update displayed values
     99      echo '<div class="updated"><p>Settings saved successfully!</p></div>';
     100    }
     101?>
     102    <div class="wrap">
     103      <h1>WooCommerce IAP Settings</h1>
     104      <form method="post">
     105        <?php wp_nonce_field('wtn-iap-settings_nonce', 'iap_settings_nonce'); ?>
     106
     107        <table class="form-table">
     108          <tr>
     109            <th scope="row">
     110              <label for="cart_button_text">Cart Button Text</label>
     111            </th>
     112            <td>
     113              <input type="text" name="cart_button_text" id="cart_button_text"
     114                value="<?php echo esc_attr($cartButtonText); ?>" class="regular-text" />
     115            </td>
     116          </tr>
     117          <tr>
     118            <th scope="row">
     119              <label for="processing_button_text">Processing Button Text</label>
     120            </th>
     121            <td>
     122              <input type="text" name="processing_button_text" id="processing_button_text"
     123                value="<?php echo esc_attr($processingButtonText); ?>" class="regular-text" />
     124            </td>
     125          </tr>
     126          <tr>
     127            <th scope="row">
     128              <label for="failed_button_text">Failed Button Text</label>
     129            </th>
     130            <td>
     131              <input type="text" name="failed_button_text" id="failed_button_text"
     132                value="<?php echo esc_attr($failedButtonText); ?>" class="regular-text" />
     133            </td>
     134          </tr>
     135          <tr>
     136            <th scope="row">
     137              <label for="payment_completed_button_text">Payment Completed Button Text</label>
     138            </th>
     139            <td>
     140              <input type="text" name="payment_completed_button_text" id="payment_completed_button_text"
     141                value="<?php echo esc_attr($paymentCompletedButtonText); ?>" class="regular-text" />
     142            </td>
     143          </tr>
     144        </table>
     145
     146        <?php submit_button('Save Settings'); ?>
     147      </form>
     148    </div>
     149<?php
    15150  }
    16151}
     152
     153// Initialize the IAP plugin
     154add_action('plugins_loaded', function () {
     155  new WebtonativeIAP();
     156});
  • webtonative/trunk/admin/iap/rest.php

    r3225472 r3227974  
    5252    $app_store_secret = isset($webtonative_settings['appStoreSecret']) ? $webtonative_settings['appStoreSecret'] : '';
    5353    $isTest = isset($webtonative_settings['isTest']) && $webtonative_settings['isTest'] === 'yes';
     54
     55    if (empty($app_store_secret)) {
     56      error_log('App Store secret not configured');
     57      return false;
     58    }
    5459
    5560    // $isTest = $payment_gateway->isTest === 'yes';
  • webtonative/trunk/index.php

    r3225472 r3227974  
    33  Plugin Name: webtonative
    44  Description: webtonative Plugin
    5   Version: 2.7.1
     5  Version: 2.7.2
    66  Author: webtonative
    77*/
  • webtonative/trunk/simple-iap/js/wtn-iap.js

    r3223359 r3227974  
    22    if (!window.WTN) return;
    33
     4    const isAndroidApp = window.WTN.isAndroidApp;
     5    const isLoggedIn = simpleIAPData.isLoggedIn;
     6    const iosSecretKey = simpleIAPData.iosSecretKey;
     7
    48    document.querySelectorAll('.iap-button').forEach(button => {
    59        button.addEventListener('click', function () {
     10            if (!isLoggedIn) {
     11                alert('Please login to continue');
     12                return;
     13            }
     14
     15            if(!isAndroidApp && !iosSecretKey) {
     16                alert('Please configure the App store secret key in settings');
     17                return;
     18            }
     19
    620            const dataToProcess = {
    7                 productId: window.WTN.isAndroidApp ? button.dataset.googlePlayId : button.dataset.appStoreId,
     21                productId: isAndroidApp ? button.dataset.googlePlayId : button.dataset.appStoreId,
    822                productType: button.dataset.productType,
    923                isConsumable: button.dataset.isConsumable === 'true',
  • webtonative/trunk/simple-iap/simple-iap.php

    r3223359 r3227974  
    8585        'ajax_url' => admin_url('admin-ajax.php'),
    8686        'nonce'    => wp_create_nonce('simple_iap_nonce'),
     87        'isLoggedIn' => is_user_logged_in(),
     88        'iosSecretKey' => get_option('simple_iap_appstore_secret')
    8789    ]);
    8890});
  • webtonative/trunk/website/iap.php

    r3034141 r3227974  
    2020  public function load_scripts()
    2121  {
     22    $saved_settings = get_option('wtn_iap_settings', array());
     23    $webtonative_settings = get_option('woocommerce_webtonative_settings');
     24
    2225    wp_register_script('webtonative-iap', plugins_url('scripts/woocommerce.js', __FILE__), array('webtonative', 'jquery'), '', true);
     26    wp_localize_script('webtonative-iap', 'wtn_biometric_settings', array(
     27      'btn_proccessing_text' => $saved_settings['processing_button_text'],
     28      'btn_failed_text' => $saved_settings['failed_button_text'],
     29      'btn_payment_completed_text' => $saved_settings['payment_completed_button_text'],
     30      'btn_buy_now_text' => $saved_settings['cart_button_text'],
     31      'isLoggedIn'     => is_user_logged_in(),
     32      'iosSecretKey' => $webtonative_settings['appStoreSecret'],
     33    ));
    2334    wp_localize_script('webtonative-iap', 'webtonative_payment_settings', array(
    2435      'rest_url' => get_rest_url(null, 'webtonative/iap'),
  • webtonative/trunk/website/scripts/woocommerce.js

    r3225349 r3227974  
    44  }
    55
    6   const addCartButton = $('.single_add_to_cart_button, .add_to_cart_button');
    76  const nonce = webtonative_payment_settings.nonce;
    87  const resturl = webtonative_payment_settings.rest_url;
     8
     9  const isLoggedIn = wtn_biometric_settings.isLoggedIn === '1';
     10  const iosSecretKey = wtn_biometric_settings.iosSecretKey;
     11
     12  const btnBuyNowText = wtn_biometric_settings?.btn_buy_now_text ?? 'Buy Now';
     13  const btnProcessingText = wtn_biometric_settings?.btn_processing_text ?? 'Processing...';
     14  const btnSuccessText = wtn_biometric_settings?.btn_payment_completed_text ?? 'Payment completed';
     15  const btnFailedText = wtn_biometric_settings?.btn_failed_text ?? 'Payment failed';
    916
    1017  const response = await fetch(resturl + '/list');
     
    7582        success: function (response) {
    7683          if (response.status === 'success') {
    77             button.text('Payment created');
     84            button.text(btnSuccessText);
    7885            return;
    7986          }
    8087        },
    8188        error: function (error) {
    82           alert('Payment failed' + JSON.stringify(error));
    83           button.text('Payment failed');
     89          alert(btnFailedText + JSON.stringify(error));
     90          button.text(btnFailedText);
    8491        },
    8592      });
    8693    }
    8794
    88     button.text('Processing...');
     95    button.text(btnProcessingText);
    8996    button.prop('disabled', true);
    9097
     
    98105          button.prop('disabled', false);
    99106          if (!data.isSuccess) {
    100             alert('Payment failed');
    101             button.text('Buy Now');
     107            alert(btnFailedText);
     108            button.text(btnBuyNowText);
    102109            return;
    103110          }
     
    124131      const newButton = $('<button>')
    125132        .addClass(button.attr('class')) // Copy classes from the original anchor tag
    126         .text('Buy Now.')
     133        .text(btnBuyNowText)
    127134        .attr('style', button.attr('style')) // Copy inline styles
    128135        .data('product_id', productId); // Preserve data attributes
     
    139146    e.stopImmediatePropagation();
    140147
     148    if (!isLoggedIn) {
     149      alert('Please login to continue');
     150      return;
     151    }
     152    if(WTN.isIosApp && !iosSecretKey){
     153      alert("Please configure App store secret key in settings");
     154      return;
     155    }
     156
    141157    const button = $(this);
    142158    const productId = button.data('product_id') || button.val();
Note: See TracChangeset for help on using the changeset viewer.