Changeset 3227974
- Timestamp:
- 01/24/2025 10:42:18 AM (14 months ago)
- Location:
- webtonative/trunk
- Files:
-
- 8 edited
-
README.md (modified) (1 diff)
-
admin/iap/index.php (modified) (1 diff)
-
admin/iap/rest.php (modified) (1 diff)
-
index.php (modified) (1 diff)
-
simple-iap/js/wtn-iap.js (modified) (1 diff)
-
simple-iap/simple-iap.php (modified) (1 diff)
-
website/iap.php (modified) (1 diff)
-
website/scripts/woocommerce.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
webtonative/trunk/README.md
r3225472 r3227974 4 4 Requires at least: 2.0.2 5 5 Tested up to: 6.7.1 6 Stable tag: 2.7. 16 Stable tag: 2.7.2 7 7 License: GPLv2 or later 8 8 -
webtonative/trunk/admin/iap/index.php
r3034141 r3227974 1 1 <?php 2 if (!defined('ABSPATH')) { 3 exit(); // Exit if accessed directly 4 } 2 5 3 if (!defined('ABSPATH')) { 4 exit(); 5 } // Exit if accessed directly 6 6 // Import required files 7 7 require_once __DIR__ . '/woo-commerce.php'; 8 8 require_once __DIR__ . '/rest.php'; 9 9 10 // Utility class for managing IAP settings 11 class 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 10 43 class WebtonativeIAP 11 44 { 12 45 public function __construct() 13 46 { 47 // Initialize REST controller 14 48 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 15 150 } 16 151 } 152 153 // Initialize the IAP plugin 154 add_action('plugins_loaded', function () { 155 new WebtonativeIAP(); 156 }); -
webtonative/trunk/admin/iap/rest.php
r3225472 r3227974 52 52 $app_store_secret = isset($webtonative_settings['appStoreSecret']) ? $webtonative_settings['appStoreSecret'] : ''; 53 53 $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 } 54 59 55 60 // $isTest = $payment_gateway->isTest === 'yes'; -
webtonative/trunk/index.php
r3225472 r3227974 3 3 Plugin Name: webtonative 4 4 Description: webtonative Plugin 5 Version: 2.7. 15 Version: 2.7.2 6 6 Author: webtonative 7 7 */ -
webtonative/trunk/simple-iap/js/wtn-iap.js
r3223359 r3227974 2 2 if (!window.WTN) return; 3 3 4 const isAndroidApp = window.WTN.isAndroidApp; 5 const isLoggedIn = simpleIAPData.isLoggedIn; 6 const iosSecretKey = simpleIAPData.iosSecretKey; 7 4 8 document.querySelectorAll('.iap-button').forEach(button => { 5 9 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 6 20 const dataToProcess = { 7 productId: window.WTN.isAndroidApp ? button.dataset.googlePlayId : button.dataset.appStoreId,21 productId: isAndroidApp ? button.dataset.googlePlayId : button.dataset.appStoreId, 8 22 productType: button.dataset.productType, 9 23 isConsumable: button.dataset.isConsumable === 'true', -
webtonative/trunk/simple-iap/simple-iap.php
r3223359 r3227974 85 85 'ajax_url' => admin_url('admin-ajax.php'), 86 86 'nonce' => wp_create_nonce('simple_iap_nonce'), 87 'isLoggedIn' => is_user_logged_in(), 88 'iosSecretKey' => get_option('simple_iap_appstore_secret') 87 89 ]); 88 90 }); -
webtonative/trunk/website/iap.php
r3034141 r3227974 20 20 public function load_scripts() 21 21 { 22 $saved_settings = get_option('wtn_iap_settings', array()); 23 $webtonative_settings = get_option('woocommerce_webtonative_settings'); 24 22 25 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 )); 23 34 wp_localize_script('webtonative-iap', 'webtonative_payment_settings', array( 24 35 'rest_url' => get_rest_url(null, 'webtonative/iap'), -
webtonative/trunk/website/scripts/woocommerce.js
r3225349 r3227974 4 4 } 5 5 6 const addCartButton = $('.single_add_to_cart_button, .add_to_cart_button');7 6 const nonce = webtonative_payment_settings.nonce; 8 7 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'; 9 16 10 17 const response = await fetch(resturl + '/list'); … … 75 82 success: function (response) { 76 83 if (response.status === 'success') { 77 button.text( 'Payment created');84 button.text(btnSuccessText); 78 85 return; 79 86 } 80 87 }, 81 88 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); 84 91 }, 85 92 }); 86 93 } 87 94 88 button.text( 'Processing...');95 button.text(btnProcessingText); 89 96 button.prop('disabled', true); 90 97 … … 98 105 button.prop('disabled', false); 99 106 if (!data.isSuccess) { 100 alert( 'Payment failed');101 button.text( 'Buy Now');107 alert(btnFailedText); 108 button.text(btnBuyNowText); 102 109 return; 103 110 } … … 124 131 const newButton = $('<button>') 125 132 .addClass(button.attr('class')) // Copy classes from the original anchor tag 126 .text( 'Buy Now.')133 .text(btnBuyNowText) 127 134 .attr('style', button.attr('style')) // Copy inline styles 128 135 .data('product_id', productId); // Preserve data attributes … … 139 146 e.stopImmediatePropagation(); 140 147 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 141 157 const button = $(this); 142 158 const productId = button.data('product_id') || button.val();
Note: See TracChangeset
for help on using the changeset viewer.