Function: tcp register payment plugin

Description

Allows to register a class like a payment plugin. The payment will appear in the Payment Shipping plugins menu. The class must extends the TCP_Plugin class.

Usage

<?php tcp_register_payment_plugin( $class_name, $object ); ?>

Parameters

$class_name
(String) The class name.
$object
(Object) An object of the type “class name”. If this value is not given, then a new object will be created

Examples

A WordPress-TheCartPress plugin to add an payment method:

<?php
/*
Plugin Name: My plugin name
Plugin URI: My URI
Description: My plugin description
Version: 1.0
Author: Me
Author URI: My URI
License: GPL
Parent: thecartpress
*/
require_once( WP_PLUGIN_DIR . '/thecartpress/classes/TCP_Plugin.class.php' );

class MY_PLUGIN extends TCP_Plugin {
	function __construct() {
		add_action( 'init', array( $this, 'init' ), 99 );
		if ( is_admin() )
			register_activation_hook( __FILE__, array( $this, 'activatePlugin' ) );
	}

	function getTitle() {
		return 'My plugin';
	}

	function getDescription() {
		return 'My plugin description<br>Author: <a href="my_url" target="_blank">Me</a>';
	}

	function showEditFields( $data ) {?>
		<tr valign="top">
		<th scope="row">
			<label for="field_1"><?php _e( 'Field 1', 'my_plugin' );?>:</label>
		</th><td>
			<input type="text" id="field_1" name="field_1" size="25" maxlength="25" value="<?php echo isset( $data['field_1'] ) ? $data['field_1'] : '';?>" />
		</td></tr><?php
	}

	function getCheckoutMethodLabel( $instance, $shippingCountry, $shoppingCart ) {
		return 'My Plugin Label';
	}

	function showPayForm( $instance, $shippingCountry, $shoppingCart, $order_id ) {
		$data = tcp_get_payment_plugin_data( get_class( $this ), $instance );
		$field_1 = $data['field_1'];
		<form action="url" method="POST">
			<input type="submit" name="submit" title="<?php _e( 'Click to pay with My Payment method', 'my_plugin' );?>" alt="<?php _e( 'Click to pay with My Payment method', 'my_plugin' );?>"/>
		</form><?php
	}

	function saveEditFields( $data ) {
		$data['field_1'] = isset( $_REQUEST['field_1'] ) ? $_REQUEST['field_1'] : '';
		return $data;
	}

	
	function init() {
		if ( ! function_exists( 'is_plugin_active' ) )
			require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
		if ( ! is_plugin_active( 'thecartpress/TheCartPress.class.php' ) )  {
			add_action( 'admin_notices', array( $this, 'adminNoticesDeactivated' ) );
		} else {
			tcp_register_payment_plugin( 'MY_PLUGIN' );
		}
	}

	function adminNoticesDeactivated() {
		echo '<div class="updated">
			<p>', __( '<strong>My plugin</strong> requires TheCartPress plugin activated.', 'my_plugin' ), '</p>
		</div>';
	}

	function activatePlugin() {
		if ( ! function_exists( 'is_plugin_active' ) )
			require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
		if ( ! is_plugin_active( 'thecartpress/TheCartPress.class.php' ) )
			exit( __( '<strong>My plugin</strong> requires TheCartPress plugin', 'my_plugin' ) );
	}
}

new My_PLUGIN();
?>

Change Log

Since 1.2.7, New parameter $object

Related

tcp_register_shipping_plugin