wordpress - WooCommerce Custom Payment Gateway -


i trying make custom gateway plugin merchant account got stuck , don't know how continue.

now, here done far:

<?php  /*   plugin name: paysecure.ro payment gateway   plugin uri: http://www.paysecure.ro   description: allows use paysecure.ro payment gateway woocommerce plugin.   version: 0.0.1   author: andrei raileanu  */  if ( ! defined( 'abspath' ) ) exit; // exit if accessed directly  add_action('plugins_loaded', 'woocommerce_paysecure', 0);  function woocommerce_paysecure(){     if (!class_exists('wc_payment_gateway'))         return; // if wc payment gateway class not available, nothing     if(class_exists('wc_paysecure'))         return;      class wc_gateway_paysecure extends wc_payment_gateway{         public function __construct(){              $plugin_dir = plugin_dir_url(__file__);              global $woocommerce;              $this->id = 'paysecure';             $this->icon = apply_filters('woocommerce_paysecure_icon', ''.$plugin_dir.'paysecure.png');             $this->has_fields = true;              // load settings             $this->init_form_fields();             $this->init_settings();              // define user set variables             $this->title = "credit/debit card";              $this->description = "you redirected paysecure.ro complete purchase.";             $this->cui = "xxxxxxxxx";             $this->encryption_key = "xxxxxxxxx";             $this->currency = "usd";              // logs             if ($this->debug == 'yes'){                 $this->log = $woocommerce->logger();             }              // actions             add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));              // save options             add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );              // payment listener/api hook             add_action('woocommerce_api_wc_' . $this->id, array($this, 'check_ipn_response'));          }          function init_form_fields()             {                 $this->form_fields = array(                     'enabled' => array(                         'title' => __( 'enable/disable', 'woocommerce' ),                         'type' => 'checkbox',                         'label' => __( 'enable paysecure', 'woocommerce' ),                         'default' => 'yes'                     )                 );         }          public function admin_options() {              ?>             <h3><?php _e( 'paysecure', 'woocommerce' ); ?></h3>             <p><?php _e( 'paysecure payment gateway', 'woocommerce' ); ?></p>              <table class="form-table">                     <?php $this->generate_settings_html(); ?>               </table>               <?php         }          function payment_fields() {             $plugin_dir = plugin_dir_url(__file__);             // description of payment method settings             if ($this->description) { ?>                 <p><?php                 echo $this->description; ?>                 </p><?php             } ?>  <?php         }          function process_payment( $order_id ) {             global $woocommerce;              $order = new wc_order($order_id);              // need these fields             //$this->notify_url;         //$order->get_total();             //$order->get_order_number();             //$order->billing_first_name;              //$order->billing_email;          }      }      function add_paysecure_gateway($methods){         $methods[] = 'wc_gateway_paysecure';         return $methods;     }      add_filter('woocommerce_payment_gateways', 'add_paysecure_gateway');  } 

here php instructions merchant account provider:

<?php   require_once('./functions.php');   $key = 'this encryption key';   $data = array( 'cui' => 'this cui code', 'amount' => '200', 'currency' => 'usd', 'order' =>  '12313', 'desc' => ps_clean('short description'), 'pentru' => 'email address', 'trtype' => 0,                               'backref' => 'http://www.site.ro/test.php', 'timestamp'=>time()    

);

 echo '<form action="https://paysecure.ro/order/cgi-bin/" method="post" >';    foreach ($data $l => $v ) echo '<input size="55" readonly type="text" name="'.$l.'" value="'.$v.'" /> : <label for="'.$l.'">'.$l.'</label><br>';     echo '<input size="55" type="text" name="p_sign" readonly value="'.calculatesign($data,$key).'" /><br>' ; //se calculeaza p_sign - ul , encriptarea datelor  ?> <input type="submit" /> </form> 

can me rest of code?

1st mistake noticed made, $this->id must in lowercase. 'paysecure' not gonna work here come time api hook.

// payment listener/api hook add_action('woocommerce_api_wc_' . $this->id, array($this, 'check_ipn_response')); 

change instead:

// payment listener/api hook add_action('woocommerce_api_wc_paysecure', array($this, 'check_ipn_response')); 

2nd mistake forgot create function check_ipn_response()

   // handles callbacks received payment backend. give url payment processing comapny ipn response url:     // usage:  http://myurl.com/?wc-api=wc_gateway_paysecure       function check_ipn_response() {          $http_contents  = file_get_contents("php://input");         $json = json_decode($http_contents, true);         $order = new wc_order($json['custom']);                  if ($callback_json['status'] == 'transaction approved')                  {             $order->payment_complete();  //this ensure stock reductions made, , status changed correct value.             $order->add_order_note( __( 'kiwipay transaction approved.', 'kiwipay' ) );                 }                    else                 {                         $order->update_status('failed');                         $order->add_order_note('kiwipay status received - ' . $callback_json['status']);     }                   //references:                 //http://docs.woothemes.com/document/payment-gateway-api/                 //https://github.com/paymium/woocommerce/blob/master/checkout.php                 //https://github.com/tubiz/voguepay-woocommerce-payment-gateway/blob/master/voguepay-woocommerce-payment-gateway.php                   /*                 {                 "id":1863,                 "amount":1750,                 "status":"transaction approved",                 "created":1434198776,                 "reference":"2626", //this order number $order->get_order_number()                 "name":"hamishtest test",                 "email":"hamish@tst.xom",                 "address":{"street":"my rd","region":"n/a","city":"tauranga","zip":"3175","country":"nz"},                 "test":true,                 "price":"17.50",                 "custom":"6589"   //this wc order_id passed during process_payment paymen processor.                 }                 */ 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -