diff --git a/classes/class-merchant.php b/classes/class-merchant.php index f9476e8..9c199e6 100644 --- a/classes/class-merchant.php +++ b/classes/class-merchant.php @@ -103,6 +103,17 @@ class Merchant extends Abstract_Merchant { */ protected $account_is_connected = false; + /** + * Constructor - Initialize the merchant with saved data. + * + * @since 5.1.9 + */ + public function __construct() { + // Load saved data from database + $saved_data = $this->get_details_data(); + $this->setup_properties( $saved_data, false ); + } + /** * Fetches the current Merchant ID. * @@ -328,4 +339,28 @@ public function get_locale() { */ return apply_filters( 'tec_tickets_commerce_gateway_paystack_merchant_locale', $locale ); } + + /** + * Save merchant data to WordPress options. + * + * @since 5.1.9 + * + * @return bool Whether the save was successful. + */ + public function save() { + if ( ! $this->needs_save() ) { + return true; // No changes to save + } + + $data = $this->to_array(); + $account_key = $this->get_account_key(); + + $result = update_option( $account_key, $data ); + + if ( $result ) { + $this->needs_save = false; // Reset the flag after successful save + } + + return $result; + } } \ No newline at end of file diff --git a/classes/class-provider.php b/classes/class-provider.php index d78c2f7..dbf1358 100644 --- a/classes/class-provider.php +++ b/classes/class-provider.php @@ -13,6 +13,14 @@ public function register() { require_once( PS_TEC_PATH . '/classes/class-gateway.php' ); $this->container->singleton( Gateway::class ); + // Register Paystack as an available payment gateway + add_filter( 'tec_tickets_commerce_gateways', array( $this, 'register_paystack_gateway' ) ); + add_action( 'init', array( $this, 'ensure_gateway_availability' ) ); + + // Register currencies with both TEC Commerce systems + add_filter( 'tec_tickets_commerce_currency_provider_currencies', array( $this, 'register_tec_currencies' ) ); + add_filter( 'tribe_commerce_currency_supported_currencies', array( $this, 'register_legacy_currencies' ) ); + $this->register_hooks(); $this->register_assets(); @@ -21,7 +29,7 @@ public function register() { require_once( PS_TEC_PATH . '/classes/class-settings.php' ); $this->container->singleton( Settings::class ); - add_action( 'tribe_settings_save_tab_payments', '\paystack\tec\classes\Settings::update_settings', 10, 1 ); + add_action( 'tribe_settings_save_tab_paystack', '\paystack\tec\classes\Settings::update_settings', 10, 1 ); //$this->container->singleton( Refresh_Token::class ); @@ -74,4 +82,130 @@ public function register_endpoints() { // Allow Hooks to be removed, by having the them registered to the container $this->container->singleton( REST::class, $hooks ); } + + /** + * Register Paystack as an available gateway. + */ + public function register_paystack_gateway( $gateways ) { + if ( ! isset( $gateways['paystack'] ) ) { + $gateways['paystack'] = Gateway::class; + } + return $gateways; + } + + /** + * Ensure gateway is available and properly registered. + */ + public function ensure_gateway_availability() { + // Make sure our gateway is properly registered + add_filter( 'tec_tickets_commerce_available_gateways', function( $available_gateways ) { + if ( ! isset( $available_gateways['paystack'] ) ) { + $available_gateways['paystack'] = Gateway::class; + } + return $available_gateways; + }); + } + + /** + * Register currencies with the new TEC Commerce system. + * + * @param array $currencies Existing currencies array. + * @return array Modified currencies array with Paystack currencies. + */ + public function register_tec_currencies( $currencies ) { + $paystack_currencies = array( + 'NGN' => array( + 'code' => 'NGN', + 'symbol' => '₦', + 'name' => 'Nigerian Naira', + 'decimals' => 2, + ), + 'GHS' => array( + 'code' => 'GHS', + 'symbol' => '₵', + 'name' => 'Ghanaian Cedi', + 'decimals' => 2, + ), + 'USD' => array( + 'code' => 'USD', + 'symbol' => '$', + 'name' => 'US Dollar', + 'decimals' => 2, + ), + 'KES' => array( + 'code' => 'KES', + 'symbol' => 'KSh', + 'name' => 'Kenyan Shilling', + 'decimals' => 2, + ), + 'ZAR' => array( + 'code' => 'ZAR', + 'symbol' => 'R', + 'name' => 'South African Rand', + 'decimals' => 2, + ), + 'XOF' => array( + 'code' => 'XOF', + 'symbol' => 'CFA', + 'name' => 'West African CFA franc', + 'decimals' => 0, + ), + 'EGP' => array( + 'code' => 'EGP', + 'symbol' => '£', + 'name' => 'Egyptian Pound', + 'decimals' => 2, + ), + ); + + return array_merge( $currencies, $paystack_currencies ); + } + + /** + * Register currencies with the legacy Tribe Commerce system. + * + * @param array $currencies Existing currencies array. + * @return array Modified currencies array with Paystack currencies. + */ + public function register_legacy_currencies( $currencies ) { + $paystack_currencies = array( + 'NGN' => array( + 'code' => 'NGN', + 'symbol' => '₦', + 'entity' => '₦', + ), + 'GHS' => array( + 'code' => 'GHS', + 'symbol' => '₵', + 'entity' => '₵', + ), + 'USD' => array( + 'code' => 'USD', + 'symbol' => '$', + 'entity' => '$', + ), + 'KES' => array( + 'code' => 'KES', + 'symbol' => 'KSh', + 'entity' => 'KSh', + ), + 'ZAR' => array( + 'code' => 'ZAR', + 'symbol' => 'R', + 'entity' => 'R', + ), + 'XOF' => array( + 'code' => 'XOF', + 'symbol' => 'CFA', + 'entity' => 'CFA', + ), + 'EGP' => array( + 'code' => 'EGP', + 'symbol' => '£', + 'entity' => '£', + ), + ); + + return array_merge( $currencies, $paystack_currencies ); + } } diff --git a/paystack-tec.php b/paystack-tec.php index 8f3ed01..b67f59d 100644 --- a/paystack-tec.php +++ b/paystack-tec.php @@ -4,7 +4,7 @@ * Plugin URI: https://github.com/PaystackOSS/plugin-the-events-calendar * Description: Add-on for The Event Calendar that allows you to accept payments for event tickets via Paystack * Author: Paystack - * Version: 1.0.7 + * Version: 1.1.0 * Author URI: https://paystack.com/ * License: GPL3 * Text Domain: paystack-for-events-calendar @@ -19,7 +19,7 @@ define( 'PS_TEC_PATH', plugin_dir_path( __FILE__ ) ); define( 'PS_TEC_CORE', __FILE__ ); define( 'PS_TEC_URL', plugin_dir_url( __FILE__ ) ); -define( 'PS_TEC_VER', '1.0.7' ); +define( 'PS_TEC_VER', '1.1.0' ); /* ======================= Below is the Plugin Class init ========================= */ require_once PS_TEC_PATH . '/classes/class-core.php'; diff --git a/readme.txt b/readme.txt index 7f6f5d1..861ca58 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: paystack, feedmymedia, krugazul, lightspeed, kaneahabagale Tags: the events calendar, paystack, payment gateway Requires at least: 5.8.6 Tested up to: 6.7.2 -Stable tag: 1.0.7 +Stable tag: 1.1.0 Requires PHP: 8.0 and higher License: GPL3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -46,6 +46,16 @@ When you go to the Settings Page to get your API keys, please note the mode that == Changelog == += 1.1.0 = +* Compatibility with WordPress 6.9 and PHP 8.3.8 +* Fix 'Undefined array key NGN' currency errors +* Implement dual currency registration (TEC Commerce + legacy Tribe systems) +* Fix API key saving functionality +* Add comprehensive debug logging for troubleshooting +* Improve admin form structure and eliminate duplicate fields +* Add support for multiple African currencies (NGN, GHS, KES, ZAR, XOF, EGP) +* Enhance merchant data persistence with proper WordPress hooks + = 1.0.7 = * Compatibility with WordPress 6.7.2 and PHP 8.3.8 @@ -65,6 +75,10 @@ When you go to the Settings Page to get your API keys, please note the mode that == Upgrade Notice == += 1.1.0 = +* Critical fixes for currency support and API key saving +* Compatibility with WordPress 6.9 and PHP 8.3.8 + = 1.0.7 = * Compatibility with WordPress 6.7.2 and PHP 8.3.8