Latest News: (loading..)

ersiranjeevi

Members
  • Content count

    4
  • Joined

  • Last visited

  1. Instead of doing this on oscom admin, I want this action to be implemented in my payment module code? for example below is how our woocommerce code works using add_action and do_action with IPN ... <?php /* /* Plugin Name: WooCommerce STPay Plugin URI: https://Solidtrustpay.com/shopping-carts Description: Extends WooCommerce with Solid Trust Pay gateway. Version: 1.0 Author Tech: https://solidtrustpay.com Copyright: © 2016 STPay. License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html */ function logit($filename, $msg) { //logit(“bjgen-log.txt”, “message”); // die(“Could not connect to database”); // open file $fd = fopen($filename, "a"); // append date/time to message $str = "[" . date("Y/m/d h:i:s", time()) . "] " . $msg; // write string fwrite($fd, $str . "\n"); // close file fclose($fd); } if ( ! defined( 'ABSPATH' ) ) exit; add_action('plugins_loaded', 'woocommerce_STPay_init'); function woocommerce_STPay_init() { if ( !class_exists( 'WC_Payment_Gateway' ) ) return; /** * Gateway class */ class WC_STPay extends WC_Payment_Gateway { public function __construct() { $this->id = 'solidtrust'; $this->icon = plugins_url( 'images/stp_b88x31.gif', __FILE__ ); $this->has_fields = false; $this->liveurl = 'https://www.solidtrustpay.com/handle.php'; $this->testurl = 'https://www.solidtrustpay.com/handle.php'; $this->method_title = __( 'SolidTrust', 'woocommerce' ); // $this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_SolidTrustPay', home_url( '/' ) ) ); // Load the settings. $this->init_form_fields(); $this->init_settings(); $this->merchantAccount = $this->settings['merchantAccount']; $this->sci_name = $this->settings['sci_name']; $this->testmode = $this->settings ['testmode']; $this->sci_password = $this->settings['sci_password']; // Define user set variables $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->email = $this->get_option( 'email' ); $this->receiver_email = $this->get_option( 'receiver_email', $this->email ); $this->send_shipping = $this->get_option( 'send_shipping' ); $this->address_override = $this->get_option( 'address_override' ); $this->debug = $this->get_option( 'debug' ); $this->form_submission_method = $this->get_option( 'form_submission_method' ) == 'yes' ? true : false; $this->page_style = $this->get_option( 'page_style' ); $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' ); $this->notify_url = WC()->api_request_url( 'WC_Gateway_STPAY' ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action('woocommerce_thankyou_'.$this->id, array( $this, 'thankyou_page' ) ); add_action('woocommerce_receipt_'.$this->id, array( $this, 'receipt_page' )); //IPN action // Payment listener/API hook add_action( 'woocommerce_api_wc_gateway_stpay', array( $this, 'check_blah' ) ); add_action( 'woocommerce_api_wc_gateway_stpay', array( $this, 'check_stpay_response' ) ); } function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable STPAY', 'woocommerce' ), 'default' => 'yes' ), 'description' => array( 'title' => __( 'Description', 'woocommerce' ), 'type' => 'textarea', 'default' => __('Pay via SolidTrustPay, use Credit Card or BTC if no STPay account', 'woocommerce') ), 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable SolidTrustPay', 'woocommerce' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'woocommerce' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'default' => __( 'SolidTrustPay', 'woocommerce' ), 'desc_tip' => true, ), 'merchantAccount' => array( 'title' => __( 'SolidTrustPay Username', 'woocommerce' ), 'type' => 'text', 'description' => __( 'Please enter your SolidTrustPay username.', 'woocommerce' ), 'default' => '', 'desc_tip' => true, 'placeholder' => 'your username' ), 'sci_name' => array( 'title' => __( 'sci name', 'woocommerce' ), 'type' => 'text', 'description' => __( 'Enter your sci name.', 'woocommerce' ), 'default' => '', 'desc_tip' => true, 'placeholder' => 'sciname' ), 'sci_password' => array( 'title' => __( 'Payment Button Password', 'woocommerce' ), 'type' => 'password', 'description' => __( 'Enter your Payment Button Password.', 'woocommerce' ), 'default' => '', 'desc_tip' => true, 'placeholder' => 'Payment Button Password' ), 'testmode' => array( 'title' => __( 'test mode', 'woocommerce' ), 'type' => 'text', 'description' => __( 'Set ON for test payments', 'woocommerce' ), 'default' => 'OFF', 'desc_tip' => true, 'placeholder' => 'testmode' ), 'invoice_prefix' => array( 'title' => __( 'Invoice Prefix', 'woocommerce' ), 'type' => 'text', 'description' => __( 'Please enter a prefix for your invoice numbers.', 'woocommerce' ), 'default' => 'WC-', 'desc_tip' => true, ) ); } /** * Admin Panel Options * - Options for bits like 'title' and availability on a country-by-country basis **/ public function admin_options() { echo '<h3>'.__('STPay', 'woocommerce').'</h3>'; echo '<p>'.__('STPay Payment', 'woocommerce').'</p>'; echo '<table class="form-table">'; $this->generate_settings_html(); echo '</table>'; } /** * There are no payment fields for STpay, but we want to show the description if set. **/ function payment_fields() { if ($this->description) echo wpautop(wptexturize($this->description)); } /** * Receipt Page **/ function receipt_page( $order ) { echo '<p>'.__('Thank you for your order, please click the button below to pay with STPay.', 'woocommerce').'</p>'; echo $this->generate_invoice_args( $order ); } /** * Process the payment and return the result **/ function process_payment( $order_id ) { $order = new WC_Order( $order_id ); return array( 'result' => 'success', //'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id('pay')))) 'redirect' => $order->get_checkout_payment_url( true ) ); } /** * Check for valid OKPAY server callback **/ function check_stpay_response() { global $woocommerce; $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); foreach($_POST as $k=>$v) $$k=urldecode($v); $msg['class'] = 'error'; $msg['message'] = "Thank you for shopping with us. However, the transaction has been declined."; $currency_should = get_woocommerce_currency(); $pwd = $this->sci_password; $pwd = md5($pwd.'s+E_a*'); $parsed_hash = MD5($_POST['tr_id'].":".MD5($pwd).":".$_POST['amount'].":".$_POST['merchantAccount'].":".$_POST['payerAccount']); // Check if IPN request is valid if($parsed_hash == $hash) { $order = new WC_Order($user1); switch($status) { case 'COMPLETE': //check amount and currency are correct if($amount == $order->order_total && $currency_should == $currency) { $order->payment_complete(); $msg['message'] = "Thank you for shopping with us. Your account has been charged and your transaction is successful. We will be shipping your order to you soon."; $msg['class'] = "success"; } else{ $order->update_status('processing'); $msg['message'] = "Thank you for shopping with us. We will your payment as soon as possible."; } break; case 'PENDING': if($amount == $order->order_total && $currency_should == $currency) { $order->update_status('processing'); } else{ $order->update_status('processing'); $msg['message'] = "Thank you for shopping with us. We will your payment as soon as possible."; } break; case 'CANCELLED': $order->update_status('cancelled'); break; break; default: // IPN not verified or connection errors // If status != 200 IPN will be repeated later logTransaction($GATEWAY["name"], $_POST, "Connection error"); header("HTTP/1.1 404 Not Found"); exit; break; // Set message if ( function_exists('wc_add_notice') ) { wc_add_notice( $msg['message'], $msg['class'] ); } else { if($msg['class']=='success') { $woocommerce->add_message( $msg['message']); } else { $woocommerce->add_error( $msg['message'] ); } $woocommerce->set_messages(); } $redirect_url = get_permalink(woocommerce_get_page_id('myaccount')); wp_redirect( $redirect_url ); exit; } } } function thankyou_page() { if ($this->description) { echo wpautop(wptexturize($this->description)); } echo '<h2>'.__('Our Details', 'woocommerce').'</h2>'; echo '<ul class="order_details ppay_details">'; $fields = array( 'ppay_number'=> __('STPay', 'woocommerce') ); foreach ($fields as $key=>$value) : if(!empty($this->$key)) : echo '<li class="'.$key.'">'.$value.': <strong>'.wptexturize($this->$key).'</strong></li>'; endif; endforeach; echo '</ul>'; } function generate_invoice_args( $order_id ) { global $woocommerce; $order = new WC_Order($order_id); $form = ""; $params = array('cmd' => '_cart', 'merchantAccount' => $this->merchantAccount, 'iswoo' => 1, 'sci_name' => $this->sci_name, 'testmode' => $this->testmode, 'currency' => get_woocommerce_currency(), 'charset' => 'UTF-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return_url' => add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ), 'cancel_url' => $order->get_cancel_order_url(), 'page_style' => $this->page_style, // Order key + ID 'item_id' => $this->invoice_prefix . ltrim( $order->get_order_number(), '#' ), // IPN 'notify_url' => $this->notify_url, 'amount' => $order->order_total, 'user1' => $order_id , 'user2' => get_woocommerce_currency(), 'user3' => $order_id*256, 'user4' => '1', 'user5' => 'EN', 'user6'=> 'Order #'.$order_id.'', 'user7' =>$order->order_total ); function get_invoice_args( $order ) { global $woocommerce; if ( $this->testmode == 'yes' ): $solidtrustpay_adr = $this->testurl . '?test_ipn=1&'; else : $solidtrustpay_adr = $this->liveurl . '?'; endif; $params = array_merge( array( 'cmd' => '_cart', 'merchantAccount' => $this->merchantAccount, 'iswoo' => 1, 'sci_name' => $this->sci_name, 'testmode' => $this->testmode, 'currency' => get_woocommerce_currency(), 'charset' => 'UTF-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return_url' => add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ), 'cancel_url' => $order->get_cancel_order_url(), 'page_style' => $this->page_style, // Order key + ID 'item_id' => $this->invoice_prefix . ltrim( $order->get_order_number(), '#' ), 'custom' => serialize( array( $order_id, $order->order_key ) ), // IPN 'notify_url' => add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ), 'amount' => $order->order_total, ), $phone_args ); } $invoice_args_array = array(); foreach($params as $key => $value){ $invoice_args_array[] = "<input type='hidden' name='$key' value='$value'/>"; } $form .= '<form id="stpaysubmit" action="https://solidtrustpay.com/handle.php" method="POST" name="stpayprocess" target="_top">'; $form .= implode(PHP_EOL, $invoice_args_array); $form .= '<input type="submit" class="button-alt" id="submit_stpay_payment_form" value="'.__('Pay via STPay', 'woocommerce').'" />'; $form .= '<a class="button cancel" href="'.esc_url( $order->get_cancel_order_url() ).'">'.__('Cancel order &amp; restore cart', 'woocommerce').'</a>'; $form .= '</form>'; wc_enqueue_js( ' $.blockUI({ message: "' . esc_js( __( 'Thank you for your order. We are now redirecting you to STPay to make payment.', 'woocommerce' ) ) . '", baseZ: 99999, overlayCSS: { background: "#fff", opacity: 0.6 }, css: { padding: "20px", zindex: "9999999", textAlign: "center", color: "#555", border: "3px solid #aaa", backgroundColor:"#fff", cursor: "wait", lineHeight: "24px", } }); document.stpayprocess.submit(); ' ); return $form; } } /** * Add the gateway to WooCommerce **/ function woocommerce_add_STPay_gateway($methods) { $methods[] = 'WC_STPAY'; return $methods; } add_filter('woocommerce_payment_gateways', 'woocommerce_add_STPay_gateway' ); add_filter( 'woocommerce_payment_complete_order_status', 'rfvc_update_order_status', 10, 2 ); function rfvc_update_order_status( $order_status, $order_id ) { $order = new WC_Order( $order_id ); if ( 'processing' == $order_status && ( 'on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status ) ) { return 'completed'; } return $order_status; } } ?>
  2. I don't want to do it manually, is there any other way that this status can change automatically? like after the payment gateway posted the data to oscom notify url.
  3. What exactly required above to make my pending orders to automatically change it to completed Payments received successfully from the gateway, also notifications too successful...
  4. How to make pending orders to complete automatically? What exactly required here to make my pending order to complete automatically oscomstpay.php oscomstpay.php