| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmPayPalLiteHooksController { |
| 7 |
|
| 8 |
/** |
| 9 |
* @return void |
| 10 |
*/ |
| 11 |
public static function load_hooks() { |
| 12 |
add_action( 'frm_enqueue_form_scripts', 'FrmPayPalLiteActionsController::maybe_load_scripts' ); |
| 13 |
add_filter( 'frm_validate_credit_card_field_entry', 'FrmPayPalLiteActionsController::remove_cc_validation', 20, 3 ); |
| 14 |
|
| 15 |
add_filter( 'frm_payment_gateways', 'FrmPayPalLiteAppController::add_gateway' ); |
| 16 |
|
| 17 |
add_action( 'init', 'FrmPayPalLiteConnectHelper::check_for_redirects' ); |
| 18 |
|
| 19 |
// Use 20 so this happens after the Stripe add-on. |
| 20 |
add_filter( 'frm_pro_show_card_callback', 'FrmPayPalLiteActionsController::maybe_show_card', 20, 2 ); |
| 21 |
|
| 22 |
add_filter( 'frm_show_normal_field_type', 'FrmPayPalLiteFieldsController::hide_paypal_order_fields', 10, 3 ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public static function load_admin_hooks() { |
| 29 |
add_action( 'frm_add_form_option_section', 'FrmPayPalLiteActionsController::actions_js' ); |
| 30 |
|
| 31 |
// Use 99 so we overwrite the PayPal add-on settings. |
| 32 |
// These are called explicitly below the Lite PayPal settings. |
| 33 |
add_filter( 'frm_add_settings_section', 'FrmPayPalLiteSettingsController::add_settings_section', 99 ); |
| 34 |
add_action( 'frm_update_settings', 'FrmPayPalLiteSettingsController::process_form' ); |
| 35 |
|
| 36 |
// Hook into update_option to preserve test_mode when add-on saves |
| 37 |
add_action( 'update_option_frm_paypal_options', 'FrmPayPalLiteSettingsController::preserve_test_mode_on_update', 10, 2 ); |
| 38 |
|
| 39 |
add_filter( 'frm_before_save_payment_action', 'FrmPayPalLiteActionsController::before_save_settings', 20, 2 ); |
| 40 |
|
| 41 |
// Hook into after payment type to render Product Name and Product Type fields. |
| 42 |
add_action( 'frm_payments_settings_recurring_product_info', 'FrmPayPalLiteActionsController::add_paypal_subscription_settings_from_hook' ); |
| 43 |
|
| 44 |
// Hook into after recurring to render PayPal Settings and PayPal Button Settings sections. |
| 45 |
add_action( 'frm_payments_settings_after_recurring', 'FrmPayPalLiteActionsController::add_action_options' ); |
| 46 |
add_action( 'frm_payments_settings_after_recurring', 'FrmPayPalLiteActionsController::add_button_settings_section', 99 ); |
| 47 |
|
| 48 |
add_filter( |
| 49 |
'frm_paypal_action_options', |
| 50 |
function ( $options ) { |
| 51 |
// Make actions using the PayPal add-on use the same icon we use in Lite. |
| 52 |
$options['classes'] = 'frmfont frm_paypal_icon'; |
| 53 |
$options['is_beta'] = true; |
| 54 |
return $options; |
| 55 |
} |
| 56 |
); |
| 57 |
|
| 58 |
add_action( 'frm_field_options_before_label', 'FrmPayPalLiteFieldsController::add_paypal_order_field_note', 10, 3 ); |
| 59 |
|
| 60 |
if ( defined( 'DOING_AJAX' ) ) { |
| 61 |
self::load_ajax_hooks(); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
private static function load_ajax_hooks() { |
| 69 |
add_action( 'wp_ajax_frm_paypal_oauth', 'FrmPayPalLiteAppController::handle_oauth' ); |
| 70 |
add_action( 'wp_ajax_frm_paypal_disconnect', 'FrmPayPalLiteAppController::handle_disconnect' ); |
| 71 |
|
| 72 |
$frm_paypal_events_controller = new FrmPayPalLiteEventsController(); |
| 73 |
add_action( 'wp_ajax_nopriv_frm_paypal_process_events', array( &$frm_paypal_events_controller, 'process_events' ) ); |
| 74 |
add_action( 'wp_ajax_frm_paypal_process_events', array( &$frm_paypal_events_controller, 'process_events' ) ); |
| 75 |
|
| 76 |
// Verify PayPal Lite sites. |
| 77 |
add_action( 'wp_ajax_nopriv_frm_paypal_lite_verify', 'FrmPayPalLiteConnectHelper::verify' ); |
| 78 |
|
| 79 |
add_action( 'wp_ajax_frm_paypal_get_amount', 'FrmPayPalLiteAppController::get_amount' ); |
| 80 |
add_action( 'wp_ajax_nopriv_frm_paypal_get_amount', 'FrmPayPalLiteAppController::get_amount' ); |
| 81 |
|
| 82 |
add_action( 'wp_ajax_frm_paypal_create_order', 'FrmPayPalLiteAppController::create_order' ); |
| 83 |
add_action( 'wp_ajax_nopriv_frm_paypal_create_order', 'FrmPayPalLiteAppController::create_order' ); |
| 84 |
|
| 85 |
add_action( 'wp_ajax_frm_paypal_create_subscription', 'FrmPayPalLiteAppController::create_subscription' ); |
| 86 |
add_action( 'wp_ajax_nopriv_frm_paypal_create_subscription', 'FrmPayPalLiteAppController::create_subscription' ); |
| 87 |
|
| 88 |
add_action( 'wp_ajax_frm_paypal_report_error', 'FrmPayPalLiteAppController::report_error' ); |
| 89 |
add_action( 'wp_ajax_nopriv_frm_paypal_report_error', 'FrmPayPalLiteAppController::report_error' ); |
| 90 |
|
| 91 |
add_action( 'wp_ajax_frm_paypal_render_seller_status', 'FrmPayPalLiteConnectHelper::handle_render_seller_status' ); |
| 92 |
|
| 93 |
add_action( 'wp_ajax_frm_add_form_action', 'FrmPayPalLiteActionsController::maybe_modify_new_action_post_data', 1 ); |
| 94 |
} |
| 95 |
} |
| 96 |
|