| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Square Gateway Hooks. |
| 4 |
* |
| 5 |
* Action/filter hooks used for handling payments through the Square gateway. |
| 6 |
* |
| 7 |
* @package Charitable Square/Hooks/Gateway |
| 8 |
* @author David Bisset |
| 9 |
* @copyright Copyright (c) 2018, WP Charitable LLC |
| 10 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 11 |
* @since 1.8.7 |
| 12 |
*/ |
| 13 |
|
| 14 |
// Exit if accessed directly. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Only register Square Core hooks if Square Core is active. |
| 21 |
*/ |
| 22 |
function charitable_maybe_register_square_core_hooks() { |
| 23 |
// Check if Square Core gateway class exists. |
| 24 |
if ( ! class_exists( 'Charitable_Gateway_Square' ) ) { |
| 25 |
if ( charitable_is_debug( 'square' ) ) { |
| 26 |
error_log( '[Charitable Square Core] Hooks not registered - Square Core class not found' ); // phpcs:ignore |
| 27 |
} |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
// Check if Square Core is active. |
| 32 |
if ( ! Charitable_Gateway_Square::is_square_core_active() ) { |
| 33 |
if ( charitable_is_debug( 'square' ) ) { |
| 34 |
error_log( '[Charitable Square Core] Hooks not registered - Square Core is not active' ); // phpcs:ignore |
| 35 |
} |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
if ( charitable_is_debug( 'square' ) ) { |
| 40 |
error_log( '[Charitable Square Core] Registering Square Core hooks' ); // phpcs:ignore |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Register our new gateway. |
| 45 |
* |
| 46 |
* @see Charitable_Gateway_Stripe_AM::register_gateway() |
| 47 |
*/ |
| 48 |
add_filter( 'charitable_payment_gateways', array( 'Charitable_Gateway_Square', 'register_gateway' ) ); |
| 49 |
|
| 50 |
/** |
| 51 |
* Save more complex settings for the Square gateway. |
| 52 |
* |
| 53 |
* @see Charitable_Gateway_Square::save_settings() |
| 54 |
*/ |
| 55 |
add_filter( 'charitable_save_settings', array( Charitable_Gateway_Square::get_instance(), 'save_settings' ), 10, 3 ); |
| 56 |
|
| 57 |
/** |
| 58 |
* Renew the Square token. |
| 59 |
* |
| 60 |
* @see Charitable_Gateway_Square::square_renew_token() |
| 61 |
*/ |
| 62 |
add_action( 'admin_init', array( Charitable_Gateway_Square::get_instance(), 'square_renew_token' ), 10 ); |
| 63 |
|
| 64 |
add_action( 'admin_init', array( Charitable_Square_Connect::get_instance(), 'handle_actions' ), 1 ); |
| 65 |
|
| 66 |
/** |
| 67 |
* Enqueue the Square scripts. |
| 68 |
* |
| 69 |
* @see Charitable_Gateway_Square::enqueue_square_scripts() |
| 70 |
*/ |
| 71 |
add_action( 'wp_enqueue_scripts', array( Charitable_Gateway_Square::get_instance(), 'enqueue_square_scripts' ), 999 ); |
| 72 |
|
| 73 |
/** |
| 74 |
* When a donation is processed, update the Payment Intent with additional information. |
| 75 |
*/ |
| 76 |
add_filter( 'charitable_process_donation_square_core', array( Charitable_Gateway_Square::get_instance(), 'process_donation' ), 10, 3 ); |
| 77 |
|
| 78 |
// Debug: Log that the Square Core hook is registered. |
| 79 |
if ( charitable_is_debug( 'square' ) ) { |
| 80 |
error_log( '[Square Core] Hook registered: charitable_process_donation_square_core' ); // phpcs:ignore |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Refund a donation from the dashboard. |
| 85 |
* |
| 86 |
* @see Charitable_Gateway_Stripe_AM::refund_donation_from_dashboard() |
| 87 |
*/ |
| 88 |
add_action( 'charitable_process_refund_square_core', array( Charitable_Gateway_Square::get_instance(), 'refund_donation_from_dashboard' ), 10, 3 ); |
| 89 |
|
| 90 |
// Debug: Log that the Square Core refund hook is registered. |
| 91 |
if ( charitable_is_debug( 'square' ) ) { |
| 92 |
error_log( '[Square Core] Refund Hook registered: charitable_process_refund_square_core' ); // phpcs:ignore |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Process the Square IPN. |
| 97 |
* |
| 98 |
* @see Charitable_Gateway_Square::process_ipn() |
| 99 |
*/ |
| 100 |
add_action( 'charitable_process_ipn_square_core', array( 'Charitable_Square_Webhook_Processor', 'process' ) ); |
| 101 |
|
| 102 |
// Debug: Log that the Square Core IPN hook is registered. |
| 103 |
if ( charitable_is_debug( 'square' ) ) { |
| 104 |
error_log( '[Square Core] IPN Hook registered: charitable_process_ipn_square_core' ); // phpcs:ignore |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Initialize the Square payment gateway. |
| 109 |
* |
| 110 |
* @see Charitable_Square_Initialization::initialize_square() |
| 111 |
*/ |
| 112 |
add_action( 'wp_ajax_charitable_square_initialize', array( Charitable_Square_Initialization::get_instance(), 'initialize_square' ) ); |
| 113 |
add_action( 'wp_ajax_nopriv_charitable_square_initialize', array( Charitable_Square_Initialization::get_instance(), 'initialize_square' ) ); |
| 114 |
|
| 115 |
/** |
| 116 |
* Cancel a subscription from the dashboard. |
| 117 |
* |
| 118 |
* @see Charitable_Gateway_Square::cancel_subscription() |
| 119 |
*/ |
| 120 |
add_action( 'charitable_process_cancellation_square_core', array( Charitable_Gateway_Square::get_instance(), 'cancel_subscription' ), 10, 2 ); |
| 121 |
|
| 122 |
/** |
| 123 |
* Validate a donation. |
| 124 |
*/ |
| 125 |
add_filter( 'charitable_validate_donation_form_submission_gateway', array( 'Charitable_Gateway_Square', 'validate_donation' ), 10, 3 ); |
| 126 |
|
| 127 |
/** |
| 128 |
* Add the 14-day cron schedule. |
| 129 |
*/ |
| 130 |
add_filter( 'cron_schedules', array( Charitable_Gateways::get_instance(), 'add_cron_schedules' ) ); |
| 131 |
|
| 132 |
/** |
| 133 |
* Hook up the Square token renewal cron job. |
| 134 |
*/ |
| 135 |
add_action( 'charitable_square_token_renewal', array( Charitable_Gateways::get_instance(), 'renew_square_token_cron' ) ); |
| 136 |
} |
| 137 |
|
| 138 |
// Register hooks when WordPress is ready. |
| 139 |
add_action( 'init', 'charitable_maybe_register_square_core_hooks', 5 ); |
| 140 |
|