Changeset 3012402
- Timestamp:
- 12/20/2023 10:43:10 AM (2 years ago)
- Location:
- paystack-for-events-calendar
- Files:
-
- 8 edited
- 1 copied
-
tags/1.0.5 (copied) (copied from paystack-for-events-calendar/trunk)
-
tags/1.0.5/classes/REST/Order_Endpoint.php (modified) (7 diffs)
-
tags/1.0.5/classes/class-gateway.php (modified) (2 diffs)
-
tags/1.0.5/paystack-tec.php (modified) (2 diffs)
-
tags/1.0.5/readme.txt (modified) (2 diffs)
-
trunk/classes/REST/Order_Endpoint.php (modified) (7 diffs)
-
trunk/classes/class-gateway.php (modified) (2 diffs)
-
trunk/paystack-tec.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
paystack-for-events-calendar/tags/1.0.5/classes/REST/Order_Endpoint.php
r2847454 r3012402 252 252 'success' => false, 253 253 ); 254 254 $path = $request->get_route(); 255 256 if($path == "/tribe/tickets/v1/commerce/paystack/order/webhook"){ 257 return $this->handle_webhook( $request ); 258 } 255 259 $order_id = $request->get_param( 'reference' ); 256 257 $order = tec_tc_orders()->by_args( array( 258 'status' => tribe( Pending::class )->get_wp_slug(), 259 'gateway_order_id' => $order_id, 260 ) )->first(); 261 262 if ( ! $order ) { 263 return new WP_Error( 'tec-tc-gateway-paystack-nonexistent-order-id', $messages['nonexistent-order-id'], $order ); 264 } 260 $order = tec_tc_get_order($order_id); 261 262 if (!$order) { 263 return new WP_Error('tec-tc-gateway-paystack-nonexistent-order-id-d', $messages['nonexistent-order-id'], $order); 264 } 265 265 266 266 $transaction_status = $request->get_param( 'status' ); … … 321 321 public function handle_webhook( WP_REST_Request $request ) { 322 322 // only a post with paystack signature header gets our attention 323 if ( ( strtoupper( $_SERVER['REQUEST_METHOD']) != 'POST' ) || ! array_key_exists( 'x-paystack-signature', $_SERVER ) ) { 324 exit(); 325 } 323 if ( ( strtoupper( $_SERVER['REQUEST_METHOD']) != 'POST' ) || ! array_key_exists( 'HTTP_X_PAYSTACK_SIGNATURE', $_SERVER ) ) { 324 return new WP_Error( 'tec-tc-gateway-paystack-unauthorized-webhookk', $messages['unauthorized-webhook'], $input );exit(); 325 } 326 $response = array( 327 'success' => false, 328 ); 326 329 327 330 // Retrieve the request's body 328 331 $input = @file_get_contents( "php://input" ); 329 332 $client = tribe( Client::class ); 330 333 $decodedInput = json_decode($input); 334 $jsonString = json_encode($decodedInput, JSON_UNESCAPED_SLASHES); 335 $jsonString = stripslashes($jsonString); 331 336 // validate event do all at once to avoid timing attack 332 if( $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac( 'sha512', $input, $client->get_barer_key() ) ) { 333 exit(); 337 $secret = $client->get_barer_key(); // Replace with your actual secret key 338 $hash = hash_hmac('sha512', $jsonString, $secret); 339 $paystackSignature = $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] ?? ''; 340 if( $paystackSignature !== $hash ) { 341 return new WP_Error( 'tec-tc-gateway-paystack-unauthorized-webhook', $messages['unauthorized-webhook'], 'invalid-signature' ); 334 342 } 335 343 … … 340 348 $event = json_decode( $input ); 341 349 342 if ( isset( $event->event ) && in_array( $event->event, array( 'transfer.success','charge.success' ) ) ) {350 if ( isset( $event->event ) && in_array( $event->event, array('charge.success' ) ) ) { 343 351 if ( isset( $event->data ) && isset( $event->data->reference ) && isset( $event->data->status ) && '' !== $event->data->reference ) { 344 345 $order = tec_tc_orders()->by_args( array( 346 'status' => tribe( Pending::class )->get_wp_slug(), 347 'gateway_order_id' => $event->data->reference, 348 ) )->first(); 349 352 $order_id = $event->data->reference; 353 $order = tec_tc_get_order($order_id); 354 $response['order_id'] = $order_id; 350 355 if ( ! $order ) { 351 356 return new WP_Error( 'tec-tc-gateway-paystack-nonexistent-order-id', $messages['nonexistent-order-id'], $order ); … … 360 365 // Flag the order as Completed. 361 366 tribe( Order::class )->modify_status( 362 $order ->ID,367 $order_id, 363 368 Completed::SLUG, 364 369 array( … … 367 372 ) 368 373 ); 374 $response['success'] = true; 375 $response['order_status'] = 'complete'; 369 376 } else if ( 'failed' === $event->data->status ) { 370 377 … … 372 379 // Flag the order as Completed. 373 380 tribe( Order::class )->modify_status( 374 $order ->ID,381 $order_id, 375 382 Denied::SLUG, 376 383 array( … … 379 386 ) 380 387 ); 388 $response['success'] = true; 389 $response['order_status'] = 'denied'; 381 390 } 382 391 } 383 392 } 393 return new WP_REST_Response( $response ); 384 394 exit(); 385 395 } -
paystack-for-events-calendar/tags/1.0.5/classes/class-gateway.php
r2847454 r3012402 33 33 * @inheritDoc 34 34 */ 35 protected static $supported_currencies = array( 'NGN', 'GHS', 'USD', 'KES', ' CZK', 'ZAR', 'XOF' );35 protected static $supported_currencies = array( 'NGN', 'GHS', 'USD', 'KES', 'ZAR', 'XOF', 'EGP' ); 36 36 37 37 /** … … 117 117 public function render_unsupported_currency_notice() { 118 118 $notice_header = esc_html__( 'Paystack doesn\'t support your selected currency', 'paystack-for-events-calendar' ); 119 $notice_text = esc_html__( 'Paystack does not support your store currency. Kindly set it to either NGN (₦), GHS (₵), USD ($), KES (KSh), ZAR (R), or XOF (CFA)', 'paystack-for-events-calendar' );119 $notice_text = esc_html__( 'Paystack does not support your store currency. Kindly set it to either NGN (₦), GHS (₵), USD ($), KES (KSh), ZAR (R), XOF (CFA), or EGP (£) ', 'paystack-for-events-calendar' ); 120 120 121 121 return sprintf( -
paystack-for-events-calendar/tags/1.0.5/paystack-tec.php
r2847454 r3012402 5 5 * Description: Add-on for The Event Calendar that allows you to accept payments for event tickets via Paystack 6 6 * Author: Paystack 7 * Version: 1.0. 37 * Version: 1.0.5 8 8 * Author URI: https://paystack.com/ 9 9 * License: GPL3 … … 20 20 define( 'PS_TEC_CORE', __FILE__ ); 21 21 define( 'PS_TEC_URL', plugin_dir_url( __FILE__ ) ); 22 define( 'PS_TEC_VER', '1.0. 3' );22 define( 'PS_TEC_VER', '1.0.5' ); 23 23 24 24 /* ======================= Below is the Plugin Class init ========================= */ -
paystack-for-events-calendar/tags/1.0.5/readme.txt
r2974746 r3012402 4 4 Requires at least: 5.8.6 5 5 Tested up to: 6.2.2 6 Stable tag: 1.0. 46 Stable tag: 1.0.5 7 7 Requires PHP: 8.0 and higher 8 8 License: GPL3 … … 47 47 == Changelog == 48 48 49 = 1.0.5 = 50 * Bug fixes 51 49 52 = 1.0.4 = 50 53 * Compatibility with WordPress 6.2.2 and PHP 8.1.17 -
paystack-for-events-calendar/trunk/classes/REST/Order_Endpoint.php
r2847454 r3012402 252 252 'success' => false, 253 253 ); 254 254 $path = $request->get_route(); 255 256 if($path == "/tribe/tickets/v1/commerce/paystack/order/webhook"){ 257 return $this->handle_webhook( $request ); 258 } 255 259 $order_id = $request->get_param( 'reference' ); 256 257 $order = tec_tc_orders()->by_args( array( 258 'status' => tribe( Pending::class )->get_wp_slug(), 259 'gateway_order_id' => $order_id, 260 ) )->first(); 261 262 if ( ! $order ) { 263 return new WP_Error( 'tec-tc-gateway-paystack-nonexistent-order-id', $messages['nonexistent-order-id'], $order ); 264 } 260 $order = tec_tc_get_order($order_id); 261 262 if (!$order) { 263 return new WP_Error('tec-tc-gateway-paystack-nonexistent-order-id-d', $messages['nonexistent-order-id'], $order); 264 } 265 265 266 266 $transaction_status = $request->get_param( 'status' ); … … 321 321 public function handle_webhook( WP_REST_Request $request ) { 322 322 // only a post with paystack signature header gets our attention 323 if ( ( strtoupper( $_SERVER['REQUEST_METHOD']) != 'POST' ) || ! array_key_exists( 'x-paystack-signature', $_SERVER ) ) { 324 exit(); 325 } 323 if ( ( strtoupper( $_SERVER['REQUEST_METHOD']) != 'POST' ) || ! array_key_exists( 'HTTP_X_PAYSTACK_SIGNATURE', $_SERVER ) ) { 324 return new WP_Error( 'tec-tc-gateway-paystack-unauthorized-webhookk', $messages['unauthorized-webhook'], $input );exit(); 325 } 326 $response = array( 327 'success' => false, 328 ); 326 329 327 330 // Retrieve the request's body 328 331 $input = @file_get_contents( "php://input" ); 329 332 $client = tribe( Client::class ); 330 333 $decodedInput = json_decode($input); 334 $jsonString = json_encode($decodedInput, JSON_UNESCAPED_SLASHES); 335 $jsonString = stripslashes($jsonString); 331 336 // validate event do all at once to avoid timing attack 332 if( $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac( 'sha512', $input, $client->get_barer_key() ) ) { 333 exit(); 337 $secret = $client->get_barer_key(); // Replace with your actual secret key 338 $hash = hash_hmac('sha512', $jsonString, $secret); 339 $paystackSignature = $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] ?? ''; 340 if( $paystackSignature !== $hash ) { 341 return new WP_Error( 'tec-tc-gateway-paystack-unauthorized-webhook', $messages['unauthorized-webhook'], 'invalid-signature' ); 334 342 } 335 343 … … 340 348 $event = json_decode( $input ); 341 349 342 if ( isset( $event->event ) && in_array( $event->event, array( 'transfer.success','charge.success' ) ) ) {350 if ( isset( $event->event ) && in_array( $event->event, array('charge.success' ) ) ) { 343 351 if ( isset( $event->data ) && isset( $event->data->reference ) && isset( $event->data->status ) && '' !== $event->data->reference ) { 344 345 $order = tec_tc_orders()->by_args( array( 346 'status' => tribe( Pending::class )->get_wp_slug(), 347 'gateway_order_id' => $event->data->reference, 348 ) )->first(); 349 352 $order_id = $event->data->reference; 353 $order = tec_tc_get_order($order_id); 354 $response['order_id'] = $order_id; 350 355 if ( ! $order ) { 351 356 return new WP_Error( 'tec-tc-gateway-paystack-nonexistent-order-id', $messages['nonexistent-order-id'], $order ); … … 360 365 // Flag the order as Completed. 361 366 tribe( Order::class )->modify_status( 362 $order ->ID,367 $order_id, 363 368 Completed::SLUG, 364 369 array( … … 367 372 ) 368 373 ); 374 $response['success'] = true; 375 $response['order_status'] = 'complete'; 369 376 } else if ( 'failed' === $event->data->status ) { 370 377 … … 372 379 // Flag the order as Completed. 373 380 tribe( Order::class )->modify_status( 374 $order ->ID,381 $order_id, 375 382 Denied::SLUG, 376 383 array( … … 379 386 ) 380 387 ); 388 $response['success'] = true; 389 $response['order_status'] = 'denied'; 381 390 } 382 391 } 383 392 } 393 return new WP_REST_Response( $response ); 384 394 exit(); 385 395 } -
paystack-for-events-calendar/trunk/classes/class-gateway.php
r2847454 r3012402 33 33 * @inheritDoc 34 34 */ 35 protected static $supported_currencies = array( 'NGN', 'GHS', 'USD', 'KES', ' CZK', 'ZAR', 'XOF' );35 protected static $supported_currencies = array( 'NGN', 'GHS', 'USD', 'KES', 'ZAR', 'XOF', 'EGP' ); 36 36 37 37 /** … … 117 117 public function render_unsupported_currency_notice() { 118 118 $notice_header = esc_html__( 'Paystack doesn\'t support your selected currency', 'paystack-for-events-calendar' ); 119 $notice_text = esc_html__( 'Paystack does not support your store currency. Kindly set it to either NGN (₦), GHS (₵), USD ($), KES (KSh), ZAR (R), or XOF (CFA)', 'paystack-for-events-calendar' );119 $notice_text = esc_html__( 'Paystack does not support your store currency. Kindly set it to either NGN (₦), GHS (₵), USD ($), KES (KSh), ZAR (R), XOF (CFA), or EGP (£) ', 'paystack-for-events-calendar' ); 120 120 121 121 return sprintf( -
paystack-for-events-calendar/trunk/paystack-tec.php
r2847454 r3012402 5 5 * Description: Add-on for The Event Calendar that allows you to accept payments for event tickets via Paystack 6 6 * Author: Paystack 7 * Version: 1.0. 37 * Version: 1.0.5 8 8 * Author URI: https://paystack.com/ 9 9 * License: GPL3 … … 20 20 define( 'PS_TEC_CORE', __FILE__ ); 21 21 define( 'PS_TEC_URL', plugin_dir_url( __FILE__ ) ); 22 define( 'PS_TEC_VER', '1.0. 3' );22 define( 'PS_TEC_VER', '1.0.5' ); 23 23 24 24 /* ======================= Below is the Plugin Class init ========================= */ -
paystack-for-events-calendar/trunk/readme.txt
r2974746 r3012402 4 4 Requires at least: 5.8.6 5 5 Tested up to: 6.2.2 6 Stable tag: 1.0. 46 Stable tag: 1.0.5 7 7 Requires PHP: 8.0 and higher 8 8 License: GPL3 … … 47 47 == Changelog == 48 48 49 = 1.0.5 = 50 * Bug fixes 51 49 52 = 1.0.4 = 50 53 * Compatibility with WordPress 6.2.2 and PHP 8.1.17
Note: See TracChangeset
for help on using the changeset viewer.