Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions classes/class-merchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
136 changes: 135 additions & 1 deletion classes/class-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 );

Expand Down Expand Up @@ -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 );
}
}
4 changes: 2 additions & 2 deletions paystack-tec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand Down
16 changes: 15 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down