Skip to content

Commit 2cdb90c

Browse files
Merge pull request #19 from GREENFONTS/main
fix: PHP 7.4 typed property compatibility with Event Tickets 5.6+
2 parents 8029839 + 795396d commit 2cdb90c

10 files changed

Lines changed: 132 additions & 44 deletions

File tree

classes/REST/Order_Endpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Order_Endpoint extends Abstract_REST_Endpoint {
3838
*
3939
* @var string
4040
*/
41-
protected $path = '/commerce/paystack/order';
41+
protected string $path = '/commerce/paystack/order';
4242

4343
/**
4444
* Register the actual endpoint on WP Rest API.

classes/class-gateway.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,59 @@ class Gateway extends Abstract_Gateway {
1717
/**
1818
* @inheritDoc
1919
*/
20-
protected static $key = 'paystack';
20+
protected static string $key = 'paystack';
2121

2222
/**
2323
* @inheritDoc
2424
*/
25-
protected static $settings = Settings::class;
25+
protected static string $settings = Settings::class;
2626

2727
/**
2828
* @inheritDoc
2929
*/
30-
protected static $merchant = Merchant::class;
30+
protected static string $merchant = Merchant::class;
3131

3232
/**
3333
* @inheritDoc
3434
*/
35-
protected static $supported_currencies = array( 'NGN', 'GHS', 'USD', 'KES', 'ZAR', 'XOF', 'EGP' );
36-
35+
protected static array $supported_currencies = array(
36+
'NGN' => array(
37+
'code' => 'NGN',
38+
'symbol' => '',
39+
'entity' => '₦',
40+
),
41+
'GHS' => array(
42+
'code' => 'GHS',
43+
'symbol' => '',
44+
'entity' => '',
45+
),
46+
'USD' => array(
47+
'code' => 'USD',
48+
'symbol' => '$',
49+
'entity' => '$',
50+
),
51+
'KES' => array(
52+
'code' => 'KES',
53+
'symbol' => 'KSh',
54+
'entity' => 'KSh',
55+
),
56+
'ZAR' => array(
57+
'code' => 'ZAR',
58+
'symbol' => 'R',
59+
'entity' => 'R',
60+
),
61+
'XOF' => array(
62+
'code' => 'XOF',
63+
'symbol' => 'CFA',
64+
'entity' => 'CFA',
65+
),
66+
'EGP' => array(
67+
'code' => 'EGP',
68+
'symbol' => '£',
69+
'entity' => '£',
70+
)
71+
);
72+
3773
/**
3874
* @inheritDoc
3975
*/
@@ -86,6 +122,16 @@ public static function is_enabled(): bool {
86122
return static::is_connected();
87123
}
88124

125+
/**
126+
* Check if a currency is supported by Paystack.
127+
*
128+
* @param string $currency_code The currency code to check.
129+
* @return bool True if supported, false otherwise.
130+
*/
131+
public static function is_currency_supported( $currency_code ) {
132+
return isset( static::$supported_currencies[ $currency_code ] );
133+
}
134+
89135
/**
90136
* Filter to add any admin notices that might be needed.
91137
*

classes/class-merchant.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,38 @@ public function delete_data() {
261261
return $status;
262262
}
263263

264+
/**
265+
* Save merchant data to database.
266+
*
267+
* @since 5.1.9
268+
*
269+
* @return bool
270+
*/
271+
public function save() {
272+
error_log( 'Merchant Save: needs_save = ' . ( $this->needs_save() ? 'TRUE' : 'FALSE' ) );
273+
274+
if ( ! $this->needs_save() ) {
275+
error_log( 'Merchant Save: No changes to save, returning true' );
276+
return true; // No changes to save
277+
}
278+
279+
$data = $this->to_array();
280+
$account_key = $this->get_account_key();
281+
282+
error_log( 'Merchant Save: account_key = ' . $account_key );
283+
error_log( 'Merchant Save: data = ' . print_r( $data, true ) );
284+
285+
$result = update_option( $account_key, $data );
286+
287+
error_log( 'Merchant Save: update_option result = ' . ( $result ? 'SUCCESS' : 'FAILED' ) );
288+
289+
if ( $result ) {
290+
$this->needs_save = false; // Reset the flag after successful save
291+
}
292+
293+
return $result;
294+
}
295+
264296
/**
265297
* Disconnects the merchant completely.
266298
*
@@ -341,26 +373,19 @@ public function get_locale() {
341373
}
342374

343375
/**
344-
* Save merchant data to WordPress options.
376+
* Gets the client secret for merchant.
345377
*
346-
* @since 5.1.9
378+
* @since 5.24.0
347379
*
348-
* @return bool Whether the save was successful.
380+
* @return ?string
349381
*/
350-
public function save() {
351-
if ( ! $this->needs_save() ) {
352-
return true; // No changes to save
353-
}
354-
355-
$data = $this->to_array();
356-
$account_key = $this->get_account_key();
357-
358-
$result = update_option( $account_key, $data );
359-
360-
if ( $result ) {
361-
$this->needs_save = false; // Reset the flag after successful save
382+
public function get_client_secret(): ?string {
383+
if ( 'test' === $this->paystack_mode ) {
384+
return $this->secret_key_test ?: null;
385+
} elseif ( 'live' === $this->paystack_mode ) {
386+
return $this->secret_key_live ?: null;
362387
}
363388

364-
return $result;
389+
return null;
365390
}
366391
}

classes/class-provider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function register() {
1313
require_once( PS_TEC_PATH . '/classes/class-gateway.php' );
1414
$this->container->singleton( Gateway::class );
1515

16+
1617
// Register Paystack as an available payment gateway
1718
add_filter( 'tec_tickets_commerce_gateways', array( $this, 'register_paystack_gateway' ) );
1819
add_action( 'init', array( $this, 'ensure_gateway_availability' ) );
@@ -29,7 +30,7 @@ public function register() {
2930

3031
require_once( PS_TEC_PATH . '/classes/class-settings.php' );
3132
$this->container->singleton( Settings::class );
32-
add_action( 'tribe_settings_save_tab_paystack', '\paystack\tec\classes\Settings::update_settings', 10, 1 );
33+
add_action( 'tribe_settings_save_tab_paystack', '\paystack\tec\classes\Settings::update_settings', 10, 1 );
3334

3435
//$this->container->singleton( Refresh_Token::class );
3536

@@ -83,6 +84,7 @@ public function register_endpoints() {
8384
$this->container->singleton( REST::class, $hooks );
8485
}
8586

87+
8688
/**
8789
* Register Paystack as an available gateway.
8890
*/
@@ -147,7 +149,7 @@ public function register_tec_currencies( $currencies ) {
147149
'XOF' => array(
148150
'code' => 'XOF',
149151
'symbol' => 'CFA',
150-
'name' => 'West African CFA franc',
152+
'name' => 'West African CFA Franc',
151153
'decimals' => 0,
152154
),
153155
'EGP' => array(

classes/class-settings.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,26 @@ private function format_errors( $errors ) {
188188
*/
189189
public static function update_settings() {
190190
$section = tribe_get_request_var( 'tc-section', false );
191+
192+
// Debug logging
193+
error_log( 'Paystack Settings: tc-section = ' . $section );
194+
error_log( 'Paystack Settings: POST data = ' . print_r( $_POST, true ) );
195+
191196
if ( 'paystack' === $section ) {
192197
$merchant = tribe( Merchant::class );
193198

194199
foreach ( self::$fields as $key => $value ) {
195-
$to_save = tribe_get_request_var( self::$field_prefix . $key, $value );
200+
$field_name = self::$field_prefix . $key;
201+
$to_save = tribe_get_request_var( $field_name, $value );
202+
203+
// Debug logging for each field
204+
error_log( "Paystack Settings: Looking for field '{$field_name}', found: '{$to_save}'" );
205+
196206
$merchant->set_prop( $key, $to_save );
197207
}
198208

199-
$merchant->save();
209+
$save_result = $merchant->save();
210+
error_log( 'Paystack Settings: Save result = ' . ( $save_result ? 'SUCCESS' : 'FAILED' ) );
200211
}
201212
}
202213
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tec-paystack",
3-
"version": "1.0.7",
3+
"version": "1.1.1",
44
"description": "Paystack for The Events Calendar",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

paystack-tec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/PaystackOSS/plugin-the-events-calendar
55
* Description: Add-on for The Event Calendar that allows you to accept payments for event tickets via Paystack
66
* Author: Paystack
7-
* Version: 1.1.0
7+
* Version: 1.1.1
88
* Author URI: https://paystack.com/
99
* License: GPL3
1010
* Text Domain: paystack-for-events-calendar
@@ -19,7 +19,7 @@
1919
define( 'PS_TEC_PATH', plugin_dir_path( __FILE__ ) );
2020
define( 'PS_TEC_CORE', __FILE__ );
2121
define( 'PS_TEC_URL', plugin_dir_url( __FILE__ ) );
22-
define( 'PS_TEC_VER', '1.1.0' );
22+
define( 'PS_TEC_VER', '1.1.1' );
2323

2424
/* ======================= Below is the Plugin Class init ========================= */
2525
require_once PS_TEC_PATH . '/classes/class-core.php';

paystack/admin-views/connect/active.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
}
2121
?>
2222
<div class="tec-tickets__admin-settings-tickets-commerce-gateway-connected">
23+
24+
<!-- Hidden field to identify this as paystack section -->
25+
<input type="hidden" name="tc-section" value="paystack" />
26+
27+
<!-- Add save button for connected state -->
28+
<div class="tec-tickets__admin-settings-tickets-commerce-gateway-connect-button">
29+
<input
30+
type="submit"
31+
name="tribeSaveSettings"
32+
class="button button-primary"
33+
value="<?php esc_attr_e( 'Save Settings', 'paystack-for-events-calendar' ); ?>"
34+
/>
35+
</div>
36+
2337
<h3><?php esc_html_e( 'Additional Settings', 'paystack-for-events-calendar' ); ?></h3>
2438
<?php
2539
$checkout_mode_args = array(

paystack/admin-views/connect/inactive.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
</p>
1919

2020
<div class="tec-tickets__admin-settings-tickets-commerce-gateway-signup-links">
21+
22+
<!-- Hidden field to identify this as paystack section -->
23+
<input type="hidden" name="tc-section" value="paystack" />
24+
2125
<?php
2226
echo wp_kses(
2327
$signup->get_link_html(),

readme.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: paystack, feedmymedia, krugazul, lightspeed, kaneahabagale
33
Tags: the events calendar, paystack, payment gateway
44
Requires at least: 5.8.6
55
Tested up to: 6.7.2
6-
Stable tag: 1.1.0
6+
Stable tag: 1.1.1
77
Requires PHP: 8.0 and higher
88
License: GPL3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -46,16 +46,6 @@ When you go to the Settings Page to get your API keys, please note the mode that
4646

4747
== Changelog ==
4848

49-
= 1.1.0 =
50-
* Compatibility with WordPress 6.9 and PHP 8.3.8
51-
* Fix 'Undefined array key NGN' currency errors
52-
* Implement dual currency registration (TEC Commerce + legacy Tribe systems)
53-
* Fix API key saving functionality
54-
* Add comprehensive debug logging for troubleshooting
55-
* Improve admin form structure and eliminate duplicate fields
56-
* Add support for multiple African currencies (NGN, GHS, KES, ZAR, XOF, EGP)
57-
* Enhance merchant data persistence with proper WordPress hooks
58-
5949
= 1.0.7 =
6050
* Compatibility with WordPress 6.7.2 and PHP 8.3.8
6151

@@ -75,10 +65,6 @@ When you go to the Settings Page to get your API keys, please note the mode that
7565

7666
== Upgrade Notice ==
7767

78-
= 1.1.0 =
79-
* Critical fixes for currency support and API key saving
80-
* Compatibility with WordPress 6.9 and PHP 8.3.8
81-
8268
= 1.0.7 =
8369
* Compatibility with WordPress 6.7.2 and PHP 8.3.8
8470

0 commit comments

Comments
 (0)