id = 'wpl_airsuggest'; $this->method_title = __('Airsuggest Checkout', 'wpl_woocommerce_airsuggest'); $this->method_description = __('This Plugin provides you feature for custom checkout option for all types of discount.', 'wpl_woocommerce_airsuggest'); $this->icon = $this->wpl_plugin_url() . '/images/icon.png'; $this->has_fields = true; $this->url = 'https://www.airsuggest.com/controller/api_checkout.php'; $this->init_form_fields(); $this->init_settings(); $this->responseVal = ''; $uploads = wp_upload_dir(); $this->txn_log = $uploads['basedir'] . "/txn_log/airsuggest"; wp_mkdir_p($this->txn_log); /// Create IPN Log files for backup transaction details $this->enabled = $this->settings['enabled']; ; if (isset($this->settings['thank_you_message'])) $this->thank_you_message = sanitize_text_field($this->settings['thank_you_message']); $this->title = sanitize_text_field($this->settings['title']); $this->description = sanitize_text_field($this->settings['description']); $this->api_key = sanitize_text_field($this->settings['api_key']); if (isset($_GET['wpl_airsuggest_callback']) && isset($_GET['results']) && esc_attr($_GET['wpl_airsuggest_callback']) == 1 && esc_attr($_GET['results']) != '') { $this->responseVal = $_GET['results']; add_filter(' ', array($this, 'wpl_airsuggest_thankyou')); } add_action('init', array(&$this, 'wpl_airsuggest_transaction')); add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'wpl_airsuggest_transaction')); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_receipt_' . $this->id, array($this, 'wpl_airsuggest_receipt_page')); } // End Constructor /** * init Gateway Form Fields * * @since 1.0 */ function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __('Enable/Disable:', 'wpl_woocommerce_airsuggest'), 'type' => 'checkbox', 'label' => __('Enable Airsuggest', 'wpl_woocommerce_airsuggest'), 'default' => 'yes' ), 'title' => array( 'title' => __('Title:', 'wpl_woocommerce_airsuggest'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'wpl_woocommerce_airsuggest'), 'default' => __('Airsuggest', 'wpl_woocommerce_airsuggest') ), 'description' => array( 'title' => __('Description:', 'wpl_woocommerce_airsuggest'), 'type' => 'textarea', 'description' => __('This controls the title which the user sees during checkout.', 'wpl_woocommerce_airsuggest'), 'default' => __('Airsuggest Checkout gives you automatic discount.', 'wpl_woocommerce_airsuggest'), ), 'api_key' => array( 'title' => __('Api Key:', 'wpl_woocommerce_airsuggest'), 'type' => 'text', 'custom_attributes' => array('required' => 'required'), 'description' => __('You can find Api key in your My Products section with Airsuggest', 'wpl_woocommerce_airsuggest'), 'default' => '' ), 'thank_you_message' => array( 'title' => __('Thank you page message:', 'wpl_woocommerce_airsuggest'), 'type' => 'textarea', 'description' => __('Thank you page order success message when order has been received', 'wpl_woocommerce_airsuggest'), 'default' => __('Thank you. Your order has been received.', 'wpl_woocommerce_airsuggest'), ), ); } // function init_form_fields() end /** * Get running plugin URL * * @since 1.0 */ private function wpl_plugin_url() { if (isset($this->wpl_plugin_url)) return $this->wpl_plugin_url; if (is_ssl()) { return $this->wpl_plugin_url = str_replace('http://', 'https://', WP_PLUGIN_URL) . '/' . plugin_basename(dirname(dirname(__FILE__))); } else { return $this->wpl_plugin_url = WP_PLUGIN_URL . '/' . plugin_basename(dirname(dirname(__FILE__))); } } // function wpl_plugin_url() end /** * WP Admin Options * * @since 1.0 */ public function admin_options() { ?>

generate_settings_html(); ?>
api_key; //$hash_data['txnid'] = $txnid; foreach ($order->get_items() as $item_id => $item_data) { // Get an instance of corresponding the WC_Product object $product = $item_data->get_product(); $image = wp_get_attachment_image_url($product->get_image_id(), 'post-thumbnail'); $productinfo[] = array("name" => $product->get_name(), "sku" => $product->get_sku(), "price" => $product->get_price(), "image" => $image, "order_qty" => $item_data->get_quantity()); //$product_name = $product->get_name(); // Get the product name $hash_data['total_qty'] = $hash_data['total_qty'] + $item_data->get_quantity(); // Get the item quantity //$item_total = $item_data->get_total(); // Get the item line total } $hash_data['product_total'] = $order->get_subtotal(); $hash_data['vendor_order_id'] = $order_id; $hash_data['currency'] = get_woocommerce_currency(); $hash_data['product_info'] = wp_json_encode($productinfo); $hash_data['shipping'] = $order->get_shipping_total(); $hash_data['tax'] = $order->get_total_tax(); $hash_data['plugin'] = "WooCommerce"; $hash_data['blogkey'] = isset($_SESSION['blogkey']) ? $_SESSION['blogkey'] : ''; // echo"
";print_r($hash_data);echo"
";die; update_post_meta($order_id, '_transaction_id', $txnid); $returnURL = $woocommerce->api_request_url(strtolower(get_class($this))); $hash_data['success_url'] = $returnURL; $payuform = ''; foreach ($hash_data as $key => $value) { if ($value) { // echo $key." : ".$value."
"; $payuform .= "" . "\n"; } } // if (session_status() == PHP_SESSION_NONE) { // session_start(); // } // print_r($_SESSION); // echo"
";
//        print_r($hash_data);
//        echo"
"; // die; $posturl = $this->url; return '
' . $payuform . ' ' . __('Cancel order & restore cart', 'wpl_woocommerce_airsuggest') . '
'; } // function wpl_generate_airsuggest_form() end /** * Process the payment for checkout. * * @since 1.0 */ function process_payment($order_id) { $this->wpl_airsuggest_clear_cache(); global $woocommerce; $order = new WC_Order($order_id); return array( 'result' => 'success', 'redirect' => $order->get_checkout_payment_url(true) ); } // function process_payment() end /** * Page after cheout button and redirect to PayU payment page. * * @since 1.0 */ function wpl_airsuggest_receipt_page($order_id) { $this->wpl_airsuggest_clear_cache(); global $woocommerce; $order = new WC_Order($order_id); echo '

' . __('Thank you for your order, please click the button below to pay.', 'wpl_woocommerce_airsuggest') . '

'; echo $this->wpl_generate_airsuggest_form($order_id); } // function wpl_airsuggest_receipt_page() end /** * Clear the cache data for browser * * @since 1.0 */ private function wpl_airsuggest_clear_cache() { header("Pragma: no-cache"); header("Cache-Control: no-cache"); header("Expires: 0"); } // function wpl_airsuggest_clear_cache() end /** * Check the status of current transaction and get response with $_POST * * @since 1.0 */ function wpl_airsuggest_transaction() { global $woocommerce; $order_id = absint(WC()->session->get('order_awaiting_payment')); $order = new WC_Order($order_id); if (!empty($_POST)) { $apiKey = $this->api_key; if ($apiKey != $_POST['key']) { die('invalid Api key!'); } else { $postData = $_POST; } } else { die('No transaction data was passed!'); } $status = sanitize_text_field($postData['status']); $msg = sanitize_text_field($postData['msg']); // print_r($status); // echo "status" . $status. "
msg".$msg; die; if ($status == 'success') { $order->payment_complete($postData['transactionID']); $order->add_order_note('Payment successful.
Transaction id: ' . sanitize_text_field($postData['transactionID']) . '|| Amount: ' . sanitize_text_field($postData['totalCost'])); } elseif ($status == 'error') { $order->update_status('failed'); wc_add_notice('Error on payment: ' . $msg, 'error'); $order->add_order_note($msg); wp_redirect($order->get_checkout_payment_url(false)); } $results = urlencode(base64_encode(json_encode($_POST))); $return_url = add_query_arg(array('wpl_airsuggest_callback' => 1, 'results' => $results, 'rul' => urlencode_deep(get_home_url())), $this->get_return_url($order)); // print_r($return_url);die; wp_redirect($return_url); } // function wpl_airsuggest_transaction() end /** * send request and get Transaction verification * @since 1.0 */ private function wpl_send_request($host, $data) { $response = wp_remote_post($host, array( 'headers' => array(), 'body' => $data, )); $response_body = json_decode(wp_remote_retrieve_body($response), true); return $response_body; } // function wpl_send_request() end /** * Thank you page success data * @since 1.0 */ // orderdetail table function function wpl_airsuggest_thankyou() { $wpl_airsuggest_response = json_decode(base64_decode(urldecode($this->responseVal)), true); // echo "Hello"; // print_r($wpl_airsuggest_response);die; if (strtolower($wpl_airsuggest_response['status']) == 'success') { $added_text = '

' . $this->thank_you_message . '

Transaction details

Transaction id: ' . $wpl_airsuggest_response['transactionID'] . '
Total Amount Paid: $' . $wpl_airsuggest_response['totalCost'] . '
'; } else { wc_add_notice('Error on payment', 'error'); wp_redirect($order->get_checkout_payment_url(false)); } return $added_text; } // function wpl_airsuggest_thankyou() end } // End Wpl_PayLabs_WC_Payu Class