Support » Plugin: Postepay Gateway per Woocommerce » Doesn't save ppay number. How?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter robertodimarco

    (@robertodimarco)

    i’ve found a solution, here my code :

    <?php
    /*
    Plugin Name: Postepay Getaway per Woocommerce
    Plugin URI: http://plugins.svn.wordpress.org/postepay-woocommerce-gateway/
    Description: Permette la scelta di Postepay come metodo di pagamento, fornendo il mumero di carta al momento del checkout.
    Version: 0.1
    Author: Martino Stenta
    Author URI: http://www.noiza.com
    License: GPL2
    */
    add_action('plugins_loaded', 'woocommerce_ppay_init', 0);
    
    function woocommerce_ppay_init() {
    
    class WC_PPAY extends WC_Payment_Gateway {
    
        public function __construct() {
    		$this->id				= 'ppay';
    		$this->icon 			= apply_filters('woocommerce_bacs_icon', '');
    		$this->has_fields 		= false;
    		$this->method_title     = __( 'Ppay', 'woocommerce' );
    
    		// Load the settings.
    		$this->init_form_fields();
    		$this->init_settings();
    
    		// Define user set variables
    		$this->title 			= $this->settings['title'];
    		$this->description      = $this->settings['description'];
    		$this->ppay_number   	= $this->settings['ppay_number'];
    		$this->ppay_user   		= $this->settings['ppay_user'];
    
    		// Actions
    		add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
    		add_action( 'woocommerce_thankyou_ppay', array( $this, 'thankyou_page' ) );
    
        	// Customer Emails
        	add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 2 );
        } 
    
    	/**
         * Initialise Gateway Settings Form Fields
         */
        function init_form_fields() {
    
        	$this->form_fields = array(
    			'enabled' => array(
    							'title' => __( 'Abilita/Disabilita', 'woocommerce' ),
    							'type' => 'checkbox',
    							'label' => __( 'Abilita Postepay', 'woocommerce' ),
    							'default' => 'yes'
    						),
    			'title' => array(
    							'title' => __( 'Titolo', 'woocommerce' ),
    							'type' => 'text',
    							'description' => __( 'Definisci il titolo del sistema di pagamento.', 'woocommerce' ),
    							'default' => __( 'Postepay', 'woocommerce' )
    						),
    			'description' => array(
    							'title' => __( 'Messaggio personalizzato', 'woocommerce' ),
    							'type' => 'textarea',
    							'description' => __( 'Spiega al cliente come procedere con la ricarica Postepay. Segnala che la merce non sarà inviata fino al ricevimento della ricarica.', 'woocommerce' ),
    							'default' => __('Paga con una ricarica Postepay. Mandaci una mail appena hai fatto il versamento indicando il numero d\'ordine e provvederemo all\'invio della merce.', 'woocommerce')
    						),
    			'ppay_number' => array(
    							'title' => __( 'Numero Postepay', 'woocommerce' ),
    							'type' => 'text',
    							'description' => '',
    							'default' => ''
    						),
    			'ppay_user' => array(
    							'title' => __( 'Intestatario Postepay', 'woocommerce' ),
    							'type' => 'text',
    							'description' => '',
    							'default' => ''
    						),
    
    			);
    
        } // End init_form_fields()
    
    	/**
    	 * Admin Panel Options
    	 * - Options for bits like 'title' and availability on a country-by-country basis
    	 *
    	 * @since 1.0.0
    	 */
    	public function admin_options() {
        	?>
        	<h3><?php _e('Postepay', 'woocommerce'); ?></h3>
        	<p><?php _e('Permetti pagamenti attraverso Postepay', 'woocommerce'); ?></p>
        	<table class="form-table">
        	<?php
        		// Generate the HTML For the settings form.
        		$this->generate_settings_html();
        	?>
    		</table><!--/.form-table-->
        	<?php
        } // End admin_options()
    
        /**
        * There are no payment fields for bacs, but we want to show the description if set.
        **/
        function payment_fields() {
          if ($this->description) echo wpautop(wptexturize($this->description));
        }
    
        function thankyou_page() {
        	if ( $description = $this->get_description() )
            	echo wpautop( wptexturize( wp_kses_post( $description ) ) );
    
    		echo '<h2>' . __( 'Our Details', 'woocommerce' ) . '</h2>';
    		echo '<ul class="order_details ppay_details">';
    
    		$fields = array(
    			'ppay_number'=> __('Numero Postepay', 'woocommerce')
    		);
    		$fields = apply_filters('woocommerce_ppay_fields', array(
    			'ppay_number'=> __('Numero Postepay', 'woocommerce'),
    			'ppay_user'=> __('Intestatario Postepay', 'woocommerce')
    		));
    
    		foreach ($fields as $key=>$value) :
    		    if(!empty($this->$key)) :
    		    	echo '<li class="'.esc_attr($key).'">'.esc_attr( $value ).': <strong>'.wptexturize($this->$key).'</strong></li>';
    		   endif;
    	   endforeach;
    		echo '</ul>';
        }
    
        /**
        * Add text to user email
        **/
        function email_instructions( $order, $sent_to_admin ) {
    
        	if ( $sent_to_admin ) return;
    
        	if ( $order->status !== 'on-hold') return;
    
        	if ( $order->payment_method !== 'ppay') return;
    
    		if ( $description = $this->get_description() )
    			echo wpautop ( wptexturize ( $description ) );
    
    		?><h2><?php _e('Informazioni', 'woocommerce') ?></h2><ul class="order_details ppay_details"><?php
    
    		$fields = apply_filters('woocommerce_ppay_fields', array(
    			'ppay_number'=> __('Numero Postepay', 'woocommerce'),
    			'ppay_user'=> __('Intestatario Postepay', 'woocommerce')
    
    		));
    
    		foreach ($fields as $key=>$value) :
    		    if(!empty($this->$key)) :
    		    	echo '<li class="'.$key.'">'.$value.': <strong>'.wptexturize($this->$key).'</strong></li>';
    		    endif;
    		endforeach;
    
    		?></ul><?php
        }
    
        /**
        * Process the payment and return the result
        **/
        function process_payment( $order_id ) {
        	global $woocommerce;
    
    		$order = new WC_Order( $order_id );
    
    		// Mark as on-hold (we're awaiting the payment)
    		$order->update_status('on-hold', __('In attesa di versamento Postepay', 'woocommerce'));
    
    		// Reduce stock levels
    		$order->reduce_order_stock();
    
    		// Remove cart
    		$woocommerce->cart->empty_cart();
    
    		// Empty awaiting payment session
    		unset($_SESSION['order_awaiting_payment']);
    
    		// 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('thanks'))))
    		);
        }
    
    }
    
    	/**
     	* Add the Gateway to WooCommerce
     	**/
    	function woocommerce_add_ppay_gateway($methods) {
    		$methods[] = 'WC_PPAY';
    		return $methods;
    	}
    
    	add_filter('woocommerce_payment_gateways', 'woocommerce_add_ppay_gateway' );
    }

    Beatboxx

    (@beatboxx)

    Can you tell me how you have solved this? I can’t find any functional difference between our code, but still the values aren’t saved in the backend…

    Thread Starter robertodimarco

    (@robertodimarco)

    Can u post ur code please?

    Great 😀
    It work perfectly, thank you robertodimarco!!!

    Hi, how can send email notification after Postepay payment ?

    Plugin Author Martino Stenta

    (@molokom)

    Hi everybody,
    sorry for the very late reply.

    I did this plugin because I needed and never thought it would interest more then a few people. This is why I uploaded and almost forget it.

    Now I’ve updated the code a bit to work with current release of WooCommerce and WP.
    I also added the field “Intestatario Postepay” as per robertodimarco suggestion.

    I hope it works for you.

    Have a good day,
    m.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Doesn't save ppay number. How?’ is closed to new replies.