<?php
/*
Plugin Name: AppThemes Balanced Payments
Description: Allows escrow orders to be transferred by Balanced Payments

AppThemes ID: appthemes-balanced-payments

Version: 1.0.0
Author: AppThemes
Author URI: http://appthemes.com
Text Domain: appthemes-balanced-payments
*/

add_action( 'init', 'appthemes_bp_setup' );

$locale = apply_filters( 'plugin_locale', get_locale(), 'appthemes-balanced-payments' );
load_textdomain( 'appthemes-balanced-payments', WP_LANG_DIR . "/plugins/app-bp-$locale.mo" );

function appthemes_bp_setup(){
	if ( !current_theme_supports( 'app-payments' ) ) {
	  	add_action( 'admin_notices', 'appthemes_bp_display_version_warning' );
		return;
	}
	
	require( __DIR__ . '/compatibility.php' );

	require(__DIR__ . "/httpful/bootstrap.php");
	require(__DIR__ . "/restful/bootstrap.php");
	require(__DIR__ . "/balanced-php/bootstrap.php");

	\Httpful\Bootstrap::init();
	\RESTful\Bootstrap::init();
	\Balanced\Bootstrap::init();

	require dirname(__FILE__) . '/bp-gateway.php';
	appthemes_register_gateway( 'APP_Balanced_Payments_Gateway' );
}

function appthemes_bp_display_version_warning(){

	$message = __( 'AppThemes Balanced Payments Payment Gateway could not run.', 'appthemes-balanced-payments' );

	if( !current_theme_supports( 'app-payments' ) ) {
		$message = __( 'AppThemes Balanced Payments Payment Gateway does not support the current theme. Please use a compatible AppThemes Product.', 'appthemes-balanced-payments' );
	}

	echo '<div class="error fade"><p>' . esc_html( $message ) .'</p></div>';
	deactivate_plugins( plugin_basename( __FILE__ ) );
}
