'shop_order',
'post_status' => 'wc-pending',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_payment_method',
'value' => '2c2p',
'compare' => 'LIKE',
)
)
);
$loop = new WP_Query($args);
try {
while ( $loop->have_posts() ) : $loop->the_post();
$order = new WC_Order($loop->post->ID);
$order->update_status('awaiting-payment');
endwhile;
} catch (Exception $e) {
}
}
function fun2c2p_register_deactivation_hook() {
global $woocommerce;
$args = array(
'post_type' => 'shop_order',
'post_status' => 'wc-awaiting-payment',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_payment_method',
'value' => '2c2p',
'compare' => 'LIKE',
)
)
);
$loop = new WP_Query($args);
try {
while ( $loop->have_posts() ) : $loop->the_post();
$order = new WC_Order($loop->post->ID);
$order->update_status('pending');
endwhile;
} catch (Exception $e) {
}
}
/* This function is set the 2c2p icon in admin panel */
function fun2c2p_backorder_font_icon() {
echo '';
}
/* This function is used to add custom order status into post */
function fun2c2p_register_awaiting_payment_order_status() {
register_post_status('wc-awaiting-payment', array(
'label' => 'Awaiting Payment',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Awaiting Payment (%s)', 'Awaiting Payment (%s)' )
));
}
// Add to list of WC Order statuses
function fun2c2p_add_awaiting_payment_to_order_statuses( $order_statuses ) {
$new_order_statuses = array();
// add new order status after processing
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
if ( 'wc-processing' === $key ) {
$new_order_statuses['wc-awaiting-payment'] = 'Awaiting Payment';
}
}
return $new_order_statuses;
}
function fun2c2p_init()
{
if (!class_exists('WC_Payment_Gateway')) return;
//Included required files.
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-constant.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-request-helper.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-hash-helper.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-validation-helper.php');
require_once(dirname(__FILE__) . '/Includes/wc-2c2p-meta-data-helper.php');
//Gateway class
class WC_Gateway_2c2p extends WC_Payment_Gateway {
//Make __construct()
public function __construct(){
$this->id = '2c2p'; // ID for WC to associate the gateway values
$this->method_title = '2C2P'; // Gateway Title as seen in Admin Dashboad
$this->method_description = '2C2P - Redefining Payments, Simplifying Lives'; // Gateway Description as seen in Admin Dashboad
$this->has_fields = false; // Inform WC if any fileds have to be displayed to the visitor in Frontend
$this->init_form_fields(); // defines your settings to WC
$this->init_settings(); // loads the Gateway settings into variables for WC
// Special settigns if gateway is on Test Mode
$test_title = '';
$test_description = '';
if (strcasecmp($this->settings['test_mode'], 'demo2') == 0 ) {
$demo = '2C2PFrontEnd/';
$test_description = '
Test Mode is ACTIVE Do not use personal detail to pay. Use only test detail for payment.
';
}
else {
$demo = '';
}
//END--test_mode=yes
$this->title = $this->settings['title'] . $test_title; // Title as displayed on Frontend
$this->description = $this->settings['description'] . $test_description; // Description as displayed on Frontend
$this->liveurl = 'https://' . $this->settings['test_mode'] . '.2c2p.com/' . $demo . 'RedirectV3/payment';
$this->service_provider = array_key_exists('service_provider', $this->settings) ? $this->settings['service_provider'] : "";
$this->msg['message'] = '';
$this->msg['class'] = '';
add_action('init', array(&$this,'check_2c2p_response'));
add_action('woocommerce_api_' . strtolower(get_class($this)), array($this,'check_2c2p_response')); //update for woocommerce >2.0
add_action('woocommerce_receipt_2c2p', array(&$this,'receipt_page'));
add_action('woocommerce_checkout_update_order_meta', array(&$this,'wc_2c2p_custom_checkout_field_update_order_meta'));
//Load script's
add_action('wp_enqueue_scripts', array( &$this, 'wc_2c2p_load_scripts'));
if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this,'process_admin_options')); //update for woocommerce >2.0
}
else {
add_action('woocommerce_update_options_payment_gateways', array(&$this,'process_admin_options')); // WC-1.6.6
}
} //END-__construct
/* Validating 123 payment expiry textbox */
public function validate_wc_2c2p_123_payment_expiry_field( $key, $value ) {
if (empty($value)) {
WC_Admin_Settings::add_error( esc_html__( 'Please enter 123 payment expiry like (8 - 720)', 'woo_2c2p'));
return $value = 0;
}
else if(!is_numeric($value)){
WC_Admin_Settings::add_error( esc_html__( 'Please enter 123 payment expiry in numeric like (8 - 720)', 'woo_2c2p'));
return $value = 0;
}
else if(!($value >= 8 && $value <= 720)){
WC_Admin_Settings::add_error( esc_html__( 'Please enter 123 payment expiry in between 8 - 720 hours only', 'woo_2c2p'));
return $value = 0;
}
return $value;
}
public function validate_key_id_field( $key, $value ) {
if (empty($value)) {
WC_Admin_Settings::add_error( esc_html__( 'Please Enter Merchant Id', 'woo_2c2p'));
return $value;
}
return $value;
}
public function validate_wc_2c2p_fixed_description_field( $key, $value ) {
if(strlen($value) > 250) {
WC_Admin_Settings::add_error( esc_html__( 'Fixed description field value should be less than 250 charactors.', 'woo_2c2p'));
return $value;
}
return $value;
}
public function validate_key_secret_field( $key, $value ) {
if (empty($value)) {
WC_Admin_Settings::add_error( esc_html__( 'Please Enter Secret Key', 'woo_2c2p'));
return $value;
}
return $value;
}
function wc_2c2p_custom_checkout_field_update_order_meta($order_id){
if(!isset($_POST['wc_2c2p_stored_card']) && empty($_POST['wc_2c2p_stored_card']))
return;
if(!intval($_POST['wc_2c2p_stored_card']))
return;
if ($_POST['wc_2c2p_stored_card'] > 0) {
update_post_meta($order_id, 'wc_2c2p_stored_card_token_id', intval($_POST['wc_2c2p_stored_card']));
}
}
/* load script for 2c2p payment. */
function wc_2c2p_load_scripts(){
wp_enqueue_script('wc-2c2p-scripts', plugin_dir_url( __FILE__ ) . 'Includes/wc-2c2p-script.js',array('jquery'), NULL, false);
}
public function wc_2c2p_get_setting(){
return $this->settings;
}
/* Get the plugin response URL */
public function wc_2c2p_response_url($order_Id){
$order = new WC_Order($order_Id);
$redirect_url = $this->get_return_url($order);
if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) {
$redirect_url = add_query_arg('wc-api', get_class($this), $redirect_url);
}
return $redirect_url;
}
/* Initiate Form Fields in the Admin Backend */
function init_form_fields(){
$this->form_fields = include(dirname(__FILE__) . '/Includes/wc-2c2p-setting.php');
}
/* Admin Panel Options.Show info on Admin Backend */
public function admin_options() {
echo '
' . esc_html__('2C2P provides a wide range of payment. you just save your account detail in it and enjoy shopping just in one click on 2C2P','woo_2c2p') . '
'; echo '' . esc_html__('Confirm your Mode: Is it LIVE or TEST.','woo_2c2p') . '
'; echo '| Select my card | "; echo ""; echo " | "; echo " |
|---|
' . esc_html__('Thank you for your order.','woo_2c2p') . '
' . esc_html__('The payment page will open if you click on button "Pay via 2C2P".','woo_2c2p') . '