bloor

onetiu.com

Jul 8th, 2014
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.10 KB | None | 0 0
  1. <?php
  2. /**
  3.  * WC wcCpg1 Gateway Class.
  4.  * Built the wcCpg1 method.
  5.  */
  6. class WC_Custom_Payment_Gateway_1 extends WC_Payment_Gateway {
  7.  
  8.     /**
  9.      * Constructor for the gateway.
  10.      *
  11.      * @return void
  12.      */
  13.     public function __construct() {
  14.         global $woocommerce;
  15.  
  16.         $this->id             = 'wcCpg1';
  17.         $this->icon           = apply_filters( 'woocommerce_wcCpg1_icon', '' );
  18.         $this->has_fields     = false;
  19.         $this->method_title   = __( 'Custom Payment Gateways 1', 'wcwcCpg1' );
  20.         $this->mid            = "44840979312";
  21.         $this->key            = "D78AA8E43636C5B40CAAC5FA12E74EEFC17C3C9F";
  22.  
  23.  
  24.         // Load the form fields.
  25.         $this->init_form_fields();
  26.  
  27.         // Load the settings.
  28.         $this->init_settings();
  29.  
  30.         // Define user set variables.
  31.         $this->title          = $this->settings['title'];
  32.         $this->description    = $this->settings['description'];
  33.         $this->instructions       = $this->get_option( 'instructions' );
  34.         $this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
  35.         $this->responseurl           = $this->get_option('responseurl');
  36.  
  37.  
  38.         // Actions.
  39.         if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) )
  40.             add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
  41.         else
  42.             add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
  43.  
  44.         add_action('woocommerce_receipt_wcCpg1', array(&$this, 'receipt_page'));
  45.  
  46.  
  47.     }
  48.  
  49.  
  50.     /* Admin Panel Options.*/
  51.     function admin_options() {
  52.         ?>
  53.         <h3><?php _e('Custom Payment Gateways 1','wcwcCpg1'); ?></h3>
  54.         <table class="form-table">
  55.             <?php $this->generate_settings_html(); ?>
  56.         </table> <?php
  57.     }
  58.  
  59.     /* Initialise Gateway Settings Form Fields. */
  60.     public function init_form_fields() {
  61.         global $woocommerce;
  62.  
  63.         $shipping_methods = array();
  64.  
  65.         if ( is_admin() )
  66.             foreach ( $woocommerce->shipping->load_shipping_methods() as $method ) {
  67.                 $shipping_methods[ $method->id ] = $method->get_title();
  68.             }
  69.            
  70.         $this->form_fields = array(
  71.             'enabled' => array(
  72.                 'title' => __( 'Enable/Disable', 'wcwcCpg1' ),
  73.                 'type' => 'checkbox',
  74.                 'label' => __( 'Enable Custom Payment Gateways 1', 'wcwcCpg1' ),
  75.                 'default' => 'no'
  76.             ),
  77.             'title' => array(
  78.                 'title' => __( 'Title', 'wcwcCpg1' ),
  79.                 'type' => 'text',
  80.                 'description' => __( 'This controls the title which the user sees during checkout.', 'wcwcCpg1' ),
  81.                 'desc_tip' => true,
  82.                 'default' => __( 'Custom Payment Gateways 1', 'wcwcCpg1' )
  83.             ),
  84.             'description' => array(
  85.                 'title' => __( 'Description', 'wcwcCpg1' ),
  86.                 'type' => 'textarea',
  87.                 'description' => __( 'This controls the description which the user sees during checkout.', 'wcwcCpg1' ),
  88.                 'default' => __( 'Desctiptions for Custom Payment Gateways 1.', 'wcwcCpg1' )
  89.             ),
  90.             'instructions' => array(
  91.                 'title' => __( 'Instructions', 'wcwcCpg1' ),
  92.                 'type' => 'textarea',
  93.                 'description' => __( 'Instructions that will be added to the thank you page.', 'wcwcCpg1' ),
  94.                 'default' => __( 'Instructions for Custom Payment Gateways 1.', 'wcwcCpg1' )
  95.             ),
  96.             'responseurl' => array(
  97.                 'title' => __( 'Response URL', 'woocommerce' ),
  98.                 'type' => 'textarea',
  99.                 'description' => __( 'This is the URL which needs to be configured into the Merchant Administration Console - Response URL', 'woocommerce' ),
  100.                 'default' => __(home_url() . "/?wc-api=WC_techprocess" , 'woocommerce')
  101.             ),    
  102.             'enable_for_methods' => array(
  103.                 'title'         => __( 'Enable for shipping methods', 'wcwcCpg1' ),
  104.                 'type'          => 'multiselect',
  105.                 'class'         => 'chosen_select',
  106.                 'css'           => 'width: 450px;',
  107.                 'default'       => '',
  108.                 'description'   => __( 'If wcCpg1 is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'wcwcCpg1' ),
  109.                 'options'       => $shipping_methods,
  110.                 'desc_tip'      => true,
  111.             )
  112.         );
  113.  
  114.     }
  115.  
  116.     /* Process the payment and return the result. */
  117.     function process_payment ($order_id) {
  118.         global $woocommerce;
  119.  
  120.         $order = new WC_Order( $order_id );
  121.  
  122.         // // Mark as on-hold
  123.         // $order->update_status('on-hold', __( 'Your order wont be shipped until the funds have cleared in our account.', 'woocommerce' ));
  124.  
  125.         // // Reduce stock levels
  126.         // $order->reduce_order_stock();
  127.  
  128.         // // Remove cart
  129.         // $woocommerce->cart->empty_cart();
  130.  
  131.         // Return thankyou redirect
  132.         return array(
  133.             'result'    => 'success',
  134.             'redirect'  => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('pay'))))
  135.         );
  136.  
  137.     }
  138.  
  139.     function receipt_page( $order )
  140.     {
  141.         echo '<p>'.__('Thank you for your order, click on submit to process Techprocess payment.', 'woocommerce').'</p>';
  142.         echo $this->generate_techprocess_form( $order );
  143.     }
  144.  
  145.     function generate_techprocess_form( $order_id )
  146.     {
  147.         global $woocommerce;
  148.         $order = new WC_Order( $order_id );
  149.  
  150.  
  151.         $dataAll = array(
  152.             'amount'      => $order->get_total(),                                                   //suma de plata
  153.             'curr'        => 'RON',                                                   // moneda de plata
  154.             'invoice_id'  => $order->id,  // numarul comenzii este generat aleator. inlocuiti cuu seria dumneavoastra
  155.             'order_desc'  => "comanda",    //descrierea comenzii
  156.             'email'       => $order->billing_email,                                                          
  157.            
  158.             // va rog sa nu modificati urmatoarele 3 randuri
  159.             'merch_id'    => $this->mid,                                                    // nu modificati
  160.             'timestamp'   => gmdate("YmdHis"),                                        // nu modificati
  161.             'nonce'       => md5(microtime() . mt_rand()),                            //nu modificati
  162.         );
  163.        
  164.         $dataAll['fp_hash'] = strtoupper($this->euplatesc_mac($dataAll, $this->key));
  165.  
  166.         $woocommerce->add_inline_js('
  167.            jQuery("html, body").css("height","100%");
  168.            jQuery("html, body").css("overflow","hidden");
  169.  
  170.            jQuery("body2").block({
  171.  
  172.                    message: "'.__('Iti multumim pentru comanda. Transferring to EuPlatesc.ro gateway', 'woocommerce').'",
  173.                    overlayCSS:
  174.                    {
  175.                        background: "#000",
  176.                        opacity: 0.6
  177.                    },
  178.  
  179.                    css: {
  180.                        padding:        20,
  181.                        textAlign:    "center",
  182.                        color:        "#000",
  183.                        border:      "1px solid #fff",
  184.                        boxShadow: "0px 0px 5px 1px #000",
  185.                        backgroundColor:"#fff",
  186.                        cursor:      "wait",
  187.                        lineHeight:     "32px",
  188.                    }
  189.                });
  190.  
  191.            setTimeout(function(){jQuery("#submit_techprocess_payment_form").click()}, 51000);
  192.        ');
  193.  
  194.         $return='<form action="https://secure.euplatesc.ro/tdsprocess/tranzactd.php" METHOD="POST" name="gateway" target="_self">';
  195.             $return.='<input TYPE="hidden" NAME="email" value="'.$dataAll['email'].'" />';
  196.             $return.='<input TYPE="hidden" NAME="amount" VALUE="'.$dataAll['amount'].'" SIZE="12" MAXLENGTH="12" />';
  197.             $return.='<input TYPE="hidden" NAME="curr" VALUE="'.$dataAll['curr'].'" SIZE="5" MAXLENGTH="3" />';
  198.             $return.='<input TYPE="hidden" NAME="invoice_id" VALUE="'.$dataAll['invoice_id'].'" SIZE="32" MAXLENGTH="32" />';
  199.             $return.='<input TYPE="hidden" NAME="order_desc" VALUE="'.$dataAll['order_desc'].'" SIZE="32" MAXLENGTH="50" />';
  200.             $return.='<input TYPE="hidden" NAME="merch_id" SIZE="15" VALUE="'.$dataAll['merch_id'].'" />';
  201.             $return.='<input TYPE="hidden" NAME="timestamp" SIZE="15" VALUE="'.$dataAll['timestamp'].'" />';
  202.             $return.='<input TYPE="hidden" NAME="nonce" SIZE="35" VALUE="'.$dataAll['nonce'].'" />';
  203.             $return.='<input TYPE="hidden" NAME="fp_hash" SIZE="40" VALUE="'.$dataAll['fp_hash'].'" />';
  204.         $return .='<p><a href="javascript:gateway.submit();" class="txtCheckout">Achita Online</a></p></form>';
  205.         return $return;
  206.     }
  207.  
  208.     /* Output for the order received page.   */
  209.     function thankyou() {
  210.         echo $this->instructions != '' ? wpautop( $this->instructions ) : '';
  211.     }
  212.  
  213.  
  214.  
  215.     //////////////// EU PLATESC FUNCTIONS /////////
  216.     function hmacsha1($key,$data) {
  217.        $blocksize = 64;
  218.        $hashfunc  = 'md5';
  219.        
  220.        if(strlen($key) > $blocksize)
  221.          $key = pack('H*', $hashfunc($key));
  222.        
  223.        $key  = str_pad($key, $blocksize, chr(0x00));
  224.        $ipad = str_repeat(chr(0x36), $blocksize);
  225.        $opad = str_repeat(chr(0x5c), $blocksize);
  226.        
  227.        $hmac = pack('H*', $hashfunc(($key ^ $opad) . pack('H*', $hashfunc(($key ^ $ipad) . $data))));
  228.        return bin2hex($hmac);
  229.  
  230.     }
  231.  
  232.     // ===========================================================================================
  233.     function euplatesc_mac($data, $key)
  234.     {
  235.       $str = NULL;
  236.  
  237.       foreach($data as $d)
  238.       {
  239.         if($d === NULL || strlen($d) == 0)
  240.           $str .= '-'; // valorile nule sunt inlocuite cu -
  241.         else
  242.           $str .= strlen($d) . $d;
  243.       }
  244.          
  245.       // ================================================================
  246.       $key = pack('H*', $key); // convertim codul secret intr-un string binar
  247.       // ================================================================
  248.  
  249.     // echo " $str " ;
  250.  
  251.       return $this->hmacsha1($key, $str);
  252.     }
  253.  
  254.  
  255.  
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment