Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * WC wcCpg1 Gateway Class.
- * Built the wcCpg1 method.
- */
- class WC_Custom_Payment_Gateway_1 extends WC_Payment_Gateway {
- /**
- * Constructor for the gateway.
- *
- * @return void
- */
- public function __construct() {
- global $woocommerce;
- $this->id = 'wcCpg1';
- $this->icon = apply_filters( 'woocommerce_wcCpg1_icon', '' );
- $this->has_fields = false;
- $this->method_title = __( 'Custom Payment Gateways 1', 'wcwcCpg1' );
- $this->mid = "44840979312";
- $this->key = "D78AA8E43636C5B40CAAC5FA12E74EEFC17C3C9F";
- // Load the form fields.
- $this->init_form_fields();
- // Load the settings.
- $this->init_settings();
- // Define user set variables.
- $this->title = $this->settings['title'];
- $this->description = $this->settings['description'];
- $this->instructions = $this->get_option( 'instructions' );
- $this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
- $this->responseurl = $this->get_option('responseurl');
- // Actions.
- if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) )
- add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
- else
- add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
- add_action('woocommerce_receipt_wcCpg1', array(&$this, 'receipt_page'));
- }
- /* Admin Panel Options.*/
- function admin_options() {
- ?>
- <h3><?php _e('Custom Payment Gateways 1','wcwcCpg1'); ?></h3>
- <table class="form-table">
- <?php $this->generate_settings_html(); ?>
- </table> <?php
- }
- /* Initialise Gateway Settings Form Fields. */
- public function init_form_fields() {
- global $woocommerce;
- $shipping_methods = array();
- if ( is_admin() )
- foreach ( $woocommerce->shipping->load_shipping_methods() as $method ) {
- $shipping_methods[ $method->id ] = $method->get_title();
- }
- $this->form_fields = array(
- 'enabled' => array(
- 'title' => __( 'Enable/Disable', 'wcwcCpg1' ),
- 'type' => 'checkbox',
- 'label' => __( 'Enable Custom Payment Gateways 1', 'wcwcCpg1' ),
- 'default' => 'no'
- ),
- 'title' => array(
- 'title' => __( 'Title', 'wcwcCpg1' ),
- 'type' => 'text',
- 'description' => __( 'This controls the title which the user sees during checkout.', 'wcwcCpg1' ),
- 'desc_tip' => true,
- 'default' => __( 'Custom Payment Gateways 1', 'wcwcCpg1' )
- ),
- 'description' => array(
- 'title' => __( 'Description', 'wcwcCpg1' ),
- 'type' => 'textarea',
- 'description' => __( 'This controls the description which the user sees during checkout.', 'wcwcCpg1' ),
- 'default' => __( 'Desctiptions for Custom Payment Gateways 1.', 'wcwcCpg1' )
- ),
- 'instructions' => array(
- 'title' => __( 'Instructions', 'wcwcCpg1' ),
- 'type' => 'textarea',
- 'description' => __( 'Instructions that will be added to the thank you page.', 'wcwcCpg1' ),
- 'default' => __( 'Instructions for Custom Payment Gateways 1.', 'wcwcCpg1' )
- ),
- 'responseurl' => array(
- 'title' => __( 'Response URL', 'woocommerce' ),
- 'type' => 'textarea',
- 'description' => __( 'This is the URL which needs to be configured into the Merchant Administration Console - Response URL', 'woocommerce' ),
- 'default' => __(home_url() . "/?wc-api=WC_techprocess" , 'woocommerce')
- ),
- 'enable_for_methods' => array(
- 'title' => __( 'Enable for shipping methods', 'wcwcCpg1' ),
- 'type' => 'multiselect',
- 'class' => 'chosen_select',
- 'css' => 'width: 450px;',
- 'default' => '',
- 'description' => __( 'If wcCpg1 is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'wcwcCpg1' ),
- 'options' => $shipping_methods,
- 'desc_tip' => true,
- )
- );
- }
- /* Process the payment and return the result. */
- function process_payment ($order_id) {
- global $woocommerce;
- $order = new WC_Order( $order_id );
- // // Mark as on-hold
- // $order->update_status('on-hold', __( 'Your order wont be shipped until the funds have cleared in our account.', 'woocommerce' ));
- // // Reduce stock levels
- // $order->reduce_order_stock();
- // // Remove cart
- // $woocommerce->cart->empty_cart();
- // Return thankyou redirect
- return array(
- 'result' => 'success',
- 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('pay'))))
- );
- }
- function receipt_page( $order )
- {
- echo '<p>'.__('Thank you for your order, click on submit to process Techprocess payment.', 'woocommerce').'</p>';
- echo $this->generate_techprocess_form( $order );
- }
- function generate_techprocess_form( $order_id )
- {
- global $woocommerce;
- $order = new WC_Order( $order_id );
- $dataAll = array(
- 'amount' => $order->get_total(), //suma de plata
- 'curr' => 'RON', // moneda de plata
- 'invoice_id' => $order->id, // numarul comenzii este generat aleator. inlocuiti cuu seria dumneavoastra
- 'order_desc' => "comanda", //descrierea comenzii
- 'email' => $order->billing_email,
- // va rog sa nu modificati urmatoarele 3 randuri
- 'merch_id' => $this->mid, // nu modificati
- 'timestamp' => gmdate("YmdHis"), // nu modificati
- 'nonce' => md5(microtime() . mt_rand()), //nu modificati
- );
- $dataAll['fp_hash'] = strtoupper($this->euplatesc_mac($dataAll, $this->key));
- $woocommerce->add_inline_js('
- jQuery("html, body").css("height","100%");
- jQuery("html, body").css("overflow","hidden");
- jQuery("body2").block({
- message: "'.__('Iti multumim pentru comanda. Transferring to EuPlatesc.ro gateway', 'woocommerce').'",
- overlayCSS:
- {
- background: "#000",
- opacity: 0.6
- },
- css: {
- padding: 20,
- textAlign: "center",
- color: "#000",
- border: "1px solid #fff",
- boxShadow: "0px 0px 5px 1px #000",
- backgroundColor:"#fff",
- cursor: "wait",
- lineHeight: "32px",
- }
- });
- setTimeout(function(){jQuery("#submit_techprocess_payment_form").click()}, 51000);
- ');
- $return='<form action="https://secure.euplatesc.ro/tdsprocess/tranzactd.php" METHOD="POST" name="gateway" target="_self">';
- $return.='<input TYPE="hidden" NAME="email" value="'.$dataAll['email'].'" />';
- $return.='<input TYPE="hidden" NAME="amount" VALUE="'.$dataAll['amount'].'" SIZE="12" MAXLENGTH="12" />';
- $return.='<input TYPE="hidden" NAME="curr" VALUE="'.$dataAll['curr'].'" SIZE="5" MAXLENGTH="3" />';
- $return.='<input TYPE="hidden" NAME="invoice_id" VALUE="'.$dataAll['invoice_id'].'" SIZE="32" MAXLENGTH="32" />';
- $return.='<input TYPE="hidden" NAME="order_desc" VALUE="'.$dataAll['order_desc'].'" SIZE="32" MAXLENGTH="50" />';
- $return.='<input TYPE="hidden" NAME="merch_id" SIZE="15" VALUE="'.$dataAll['merch_id'].'" />';
- $return.='<input TYPE="hidden" NAME="timestamp" SIZE="15" VALUE="'.$dataAll['timestamp'].'" />';
- $return.='<input TYPE="hidden" NAME="nonce" SIZE="35" VALUE="'.$dataAll['nonce'].'" />';
- $return.='<input TYPE="hidden" NAME="fp_hash" SIZE="40" VALUE="'.$dataAll['fp_hash'].'" />';
- $return .='<p><a href="javascript:gateway.submit();" class="txtCheckout">Achita Online</a></p></form>';
- return $return;
- }
- /* Output for the order received page. */
- function thankyou() {
- echo $this->instructions != '' ? wpautop( $this->instructions ) : '';
- }
- //////////////// EU PLATESC FUNCTIONS /////////
- function hmacsha1($key,$data) {
- $blocksize = 64;
- $hashfunc = 'md5';
- if(strlen($key) > $blocksize)
- $key = pack('H*', $hashfunc($key));
- $key = str_pad($key, $blocksize, chr(0x00));
- $ipad = str_repeat(chr(0x36), $blocksize);
- $opad = str_repeat(chr(0x5c), $blocksize);
- $hmac = pack('H*', $hashfunc(($key ^ $opad) . pack('H*', $hashfunc(($key ^ $ipad) . $data))));
- return bin2hex($hmac);
- }
- // ===========================================================================================
- function euplatesc_mac($data, $key)
- {
- $str = NULL;
- foreach($data as $d)
- {
- if($d === NULL || strlen($d) == 0)
- $str .= '-'; // valorile nule sunt inlocuite cu -
- else
- $str .= strlen($d) . $d;
- }
- // ================================================================
- $key = pack('H*', $key); // convertim codul secret intr-un string binar
- // ================================================================
- // echo " $str " ;
- return $this->hmacsha1($key, $str);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment