event-tickets-mail-in-payment/event-tickets-mail-in-payment.php
Ruben Ramirez 8fd8d9708c Initial commit: Complete Event Tickets Mail-In Payment Gateway
- Complete mail-in payment gateway for Event Tickets Commerce
- Support for check payments with collapsible checkout interface
- Admin interface for managing check payments and order status
- Professional asset organization with proper WordPress enqueuing
- Order management with status tracking (pending, received, bounced)
- Template system with responsive design and accessibility features
- Integration with Event Tickets Commerce order system
- Settings page for configuring payment instructions and addresses
2025-06-30 21:56:49 -04:00

185 lines
No EOL
5.2 KiB
PHP

<?php
/**
* Plugin Name: Event Tickets - Mail-In Payment Gateway
* Plugin URI: https://github.com/yourusername/event-tickets-mail-in-payment
* Description: Adds a mail-in payment gateway for Event Tickets Commerce to accept check payments.
* Version: 1.0.0
* Requires at least: 6.6
* Requires PHP: 7.4
* Author: Your Name
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: event-tickets-mail-in
* Domain Path: /languages/
*/
// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Define plugin constants
define( 'ET_MAIL_IN_VERSION', '1.0.0' );
define( 'ET_MAIL_IN_FILE', __FILE__ );
define( 'ET_MAIL_IN_PATH', plugin_dir_path( __FILE__ ) );
define( 'ET_MAIL_IN_URL', plugin_dir_url( __FILE__ ) );
/**
* Main plugin class
*/
class ET_Mail_In_Payment {
/**
* Single instance of the class
*
* @var ET_Mail_In_Payment
*/
private static $instance;
/**
* Get single instance
*
* @return ET_Mail_In_Payment
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
add_action( 'plugins_loaded', [ $this, 'init' ] );
register_activation_hook( __FILE__, [ $this, 'activate' ] );
register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] );
}
/**
* Initialize the plugin
*/
public function init() {
// Check if Event Tickets is active
if ( ! $this->is_event_tickets_active() ) {
add_action( 'admin_notices', [ $this, 'event_tickets_missing_notice' ] );
return;
}
// Load text domain
load_plugin_textdomain( 'event-tickets-mail-in', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// Include required files
$this->includes();
// Initialize components
$this->init_components();
}
/**
* Check if Event Tickets is active
*
* @return bool
*/
private function is_event_tickets_active() {
return class_exists( 'Tribe__Tickets__Main' ) &&
class_exists( 'TEC\Tickets\Commerce\Module' );
}
/**
* Include required files
*/
private function includes() {
require_once ET_MAIL_IN_PATH . 'src/Gateway.php';
require_once ET_MAIL_IN_PATH . 'src/Order.php';
require_once ET_MAIL_IN_PATH . 'src/Settings.php';
require_once ET_MAIL_IN_PATH . 'src/Provider.php';
require_once ET_MAIL_IN_PATH . 'src/Hooks.php';
}
/**
* Initialize components
*/
private function init_components() {
// Register our provider with dependency injection container
tribe_register_provider( ET_Mail_In_Payment\Provider::class );
}
/**
* Plugin activation
*/
public function activate() {
// Check dependencies
if ( ! $this->is_event_tickets_active() ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die(
__( 'Event Tickets - Mail-In Payment Gateway requires Event Tickets to be installed and activated.', 'event-tickets-mail-in' ),
__( 'Plugin Activation Error', 'event-tickets-mail-in' ),
[ 'back_link' => true ]
);
}
// Set default options if they don't exist
$this->set_default_options();
}
/**
* Plugin deactivation
*/
public function deactivate() {
// Clean up if needed
}
/**
* Get default payment instructions
*
* @return string
*/
private function get_default_instructions() {
return __( 'Please mail your check to the address provided below. Your tickets will be reserved for 7 days while we wait for your payment to arrive. Include your order number on the check memo line.', 'event-tickets-mail-in' );
}
/**
* Set default options on activation
*/
private function set_default_options() {
// Set default options if they don't exist
if ( false === tribe_get_option( 'tickets-commerce-mail-in-enabled' ) ) {
tribe_update_option( 'tickets-commerce-mail-in-enabled', true );
}
if ( empty( tribe_get_option( 'tickets-commerce-mail-in-title' ) ) ) {
tribe_update_option( 'tickets-commerce-mail-in-title', __( 'Mail-In Payment (Check)', 'event-tickets-mail-in' ) );
}
if ( empty( tribe_get_option( 'tickets-commerce-mail-in-description' ) ) ) {
tribe_update_option( 'tickets-commerce-mail-in-description', __( 'Pay by mailing a check to our address.', 'event-tickets-mail-in' ) );
}
if ( empty( tribe_get_option( 'tickets-commerce-mail-in-instructions' ) ) ) {
tribe_update_option( 'tickets-commerce-mail-in-instructions', $this->get_default_instructions() );
}
// For testing purposes, set some default values
if ( empty( tribe_get_option( 'tickets-commerce-mail-in-address' ) ) ) {
tribe_update_option( 'tickets-commerce-mail-in-address', "123 Main Street\nAnytown, ST 12345\nUSA" );
}
if ( empty( tribe_get_option( 'tickets-commerce-mail-in-payable-to' ) ) ) {
tribe_update_option( 'tickets-commerce-mail-in-payable-to', "Your Organization Name" );
}
}
/**
* Display admin notice when Event Tickets is missing
*/
public function event_tickets_missing_notice() {
echo '<div class="notice notice-error"><p>';
echo esc_html__( 'Event Tickets - Mail-In Payment Gateway requires Event Tickets to be installed and activated.', 'event-tickets-mail-in' );
echo '</p></div>';
}
}
// Initialize the plugin
ET_Mail_In_Payment::instance();