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
2 changes: 1 addition & 1 deletion classes/REST/Order_Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Order_Endpoint extends Abstract_REST_Endpoint {
*
* @var string
*/
protected $path = '/commerce/paystack/order';
protected string $path = '/commerce/paystack/order';

/**
* Register the actual endpoint on WP Rest API.
Expand Down
56 changes: 51 additions & 5 deletions classes/class-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,59 @@ class Gateway extends Abstract_Gateway {
/**
* @inheritDoc
*/
protected static $key = 'paystack';
protected static string $key = 'paystack';

/**
* @inheritDoc
*/
protected static $settings = Settings::class;
protected static string $settings = Settings::class;

/**
* @inheritDoc
*/
protected static $merchant = Merchant::class;
protected static string $merchant = Merchant::class;

/**
* @inheritDoc
*/
protected static $supported_currencies = array( 'NGN', 'GHS', 'USD', 'KES', 'ZAR', 'XOF', 'EGP' );

protected static array $supported_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' => '£',
)
);

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -86,6 +122,16 @@ public static function is_enabled(): bool {
return static::is_connected();
}

/**
* Check if a currency is supported by Paystack.
*
* @param string $currency_code The currency code to check.
* @return bool True if supported, false otherwise.
*/
public static function is_currency_supported( $currency_code ) {
return isset( static::$supported_currencies[ $currency_code ] );
}

/**
* Filter to add any admin notices that might be needed.
*
Expand Down
57 changes: 41 additions & 16 deletions classes/class-merchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,38 @@ public function delete_data() {
return $status;
}

/**
* Save merchant data to database.
*
* @since 5.1.9
*
* @return bool
*/
public function save() {
error_log( 'Merchant Save: needs_save = ' . ( $this->needs_save() ? 'TRUE' : 'FALSE' ) );

if ( ! $this->needs_save() ) {
error_log( 'Merchant Save: No changes to save, returning true' );
return true; // No changes to save
}

$data = $this->to_array();
$account_key = $this->get_account_key();

error_log( 'Merchant Save: account_key = ' . $account_key );
error_log( 'Merchant Save: data = ' . print_r( $data, true ) );

$result = update_option( $account_key, $data );

error_log( 'Merchant Save: update_option result = ' . ( $result ? 'SUCCESS' : 'FAILED' ) );

if ( $result ) {
$this->needs_save = false; // Reset the flag after successful save
}

return $result;
}

/**
* Disconnects the merchant completely.
*
Expand Down Expand Up @@ -341,26 +373,19 @@ public function get_locale() {
}

/**
* Save merchant data to WordPress options.
* Gets the client secret for merchant.
*
* @since 5.1.9
* @since 5.24.0
*
* @return bool Whether the save was successful.
* @return ?string
*/
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
public function get_client_secret(): ?string {
if ( 'test' === $this->paystack_mode ) {
return $this->secret_key_test ?: null;
} elseif ( 'live' === $this->paystack_mode ) {
return $this->secret_key_live ?: null;
}

return $result;
return null;
}
}
6 changes: 4 additions & 2 deletions classes/class-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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' ) );
Expand All @@ -29,7 +30,7 @@ public function register() {

require_once( PS_TEC_PATH . '/classes/class-settings.php' );
$this->container->singleton( Settings::class );
add_action( 'tribe_settings_save_tab_paystack', '\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 @@ -83,6 +84,7 @@ public function register_endpoints() {
$this->container->singleton( REST::class, $hooks );
}


/**
* Register Paystack as an available gateway.
*/
Expand Down Expand Up @@ -147,7 +149,7 @@ public function register_tec_currencies( $currencies ) {
'XOF' => array(
'code' => 'XOF',
'symbol' => 'CFA',
'name' => 'West African CFA franc',
'name' => 'West African CFA Franc',
'decimals' => 0,
),
'EGP' => array(
Expand Down
15 changes: 13 additions & 2 deletions classes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,26 @@ private function format_errors( $errors ) {
*/
public static function update_settings() {
$section = tribe_get_request_var( 'tc-section', false );

// Debug logging
error_log( 'Paystack Settings: tc-section = ' . $section );
error_log( 'Paystack Settings: POST data = ' . print_r( $_POST, true ) );

if ( 'paystack' === $section ) {
$merchant = tribe( Merchant::class );

foreach ( self::$fields as $key => $value ) {
$to_save = tribe_get_request_var( self::$field_prefix . $key, $value );
$field_name = self::$field_prefix . $key;
$to_save = tribe_get_request_var( $field_name, $value );

// Debug logging for each field
error_log( "Paystack Settings: Looking for field '{$field_name}', found: '{$to_save}'" );

$merchant->set_prop( $key, $to_save );
}

$merchant->save();
$save_result = $merchant->save();
error_log( 'Paystack Settings: Save result = ' . ( $save_result ? 'SUCCESS' : 'FAILED' ) );
}
}
}
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.1.0
* Version: 1.0.7
* 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.1.0' );
define( 'PS_TEC_VER', '1.0.7' );

/* ======================= Below is the Plugin Class init ========================= */
require_once PS_TEC_PATH . '/classes/class-core.php';
Expand Down
14 changes: 14 additions & 0 deletions paystack/admin-views/connect/active.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
}
?>
<div class="tec-tickets__admin-settings-tickets-commerce-gateway-connected">

<!-- Hidden field to identify this as paystack section -->
<input type="hidden" name="tc-section" value="paystack" />

<!-- Add save button for connected state -->
<div class="tec-tickets__admin-settings-tickets-commerce-gateway-connect-button">
<input
type="submit"
name="tribeSaveSettings"
class="button button-primary"
value="<?php esc_attr_e( 'Save Settings', 'paystack-for-events-calendar' ); ?>"
/>
</div>

<h3><?php esc_html_e( 'Additional Settings', 'paystack-for-events-calendar' ); ?></h3>
<?php
$checkout_mode_args = array(
Expand Down
4 changes: 4 additions & 0 deletions paystack/admin-views/connect/inactive.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
</p>

<div class="tec-tickets__admin-settings-tickets-commerce-gateway-signup-links">

<!-- Hidden field to identify this as paystack section -->
<input type="hidden" name="tc-section" value="paystack" />

<?php
echo wp_kses(
$signup->get_link_html(),
Expand Down
16 changes: 1 addition & 15 deletions 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.1.0
Stable tag: 1.0.7
Requires PHP: 8.0 and higher
License: GPL3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -46,16 +46,6 @@ 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 @@ -75,10 +65,6 @@ 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