F
F
First Name2016-12-24 12:09:42
PHP
First Name, 2016-12-24 12:09:42

Is it easier to write a payment system from scratch or change it?

Good day to all.
I decided to connect the free-kassa electronic payment system to the store, but there is no plugin for woocommerce, there is only for e-commerce. And then the choice arose:
1. Transfer the store to e-commerce, since there are only three products and it won’t take much time
2. Write by yourself for the store (Knowledge of php only Basics)
3. Remake the plugin code for e-commerce under woocommerce
Please help me with the choice.
Thanks in advance for your replies.
*Plugin itself*

<?php
$nzshpcrt_gateways[$num] = array(
  'name' => __( 'Free-kassa.ru', 'wpsc' ),
  'internalname' => ( 'freekassa'),
  'function' => ( 'gateway_freekassa'),
  'form' => ( 'form_freekassa'),
  'submit_function' => ( 'submit_freekassa'),
  'display_name' => __( 'Free-kassa.ru', 'wpsc' ),
  'payment_type' =>  ( 'freekassa_checkout')
);

function form_freekassa() {
  $output = "
  <tr>
    <td>" . __( 'Merchant ID', 'wpsc' ) . "</td>
    <td><input type='text' size='40' value ='".get_option('freekassa_merchant_id')."' name='freekassa_merchant_id' /></td>
  </tr>
  <tr>
    <td>" . __( 'Секретное слово 1', 'wpsc' ) . "</td>
    <td><input type='text' size='40' value ='".get_option('freekassa_secret_1')."' name='freekassa_secret_1' /></td>
  </tr>
  <tr>
    <td>" . __( 'Секретное слово 2', 'wpsc' ) . "</td>
    <td><input type='text' size='40' value ='".get_option('freekassa_secret_2')."' name='freekassa_secret_2' /></td>
  </tr>";
  return $output;
}

function submit_freekassa(){
  if($_POST['freekassa_merchant_id'] != null)
  {
    update_option('freekassa_merchant_id',$_POST['freekassa_merchant_id']);
  }
  if($_POST['freekassa_secret_1'] != null) 
  {
    update_option('freekassa_secret_1',$_POST['freekassa_secret_1']);
  }
  if($_POST['freekassa_secret_2'] != null) 
  {
    update_option('freekassa_secret_2',$_POST['freekassa_secret_2']);
  }
  return true;
}

function gateway_freekassa($seperator, $sessionid){
  global $wpdb, $wpsc_cart;
  
  $purchase_log = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= ".$sessionid." LIMIT 1", ARRAY_A);
  $merchant_id = get_option('freekassa_merchant_id');
  $secret_1 = get_option('freekassa_secret_1');
  $order_id=$purchase_log[0]['id'];
  $out_amount= number_format($wpsc_cart->total_price,2);
  $my_signature = md5($merchant_id.":".$out_amount.":".$secret_1.":".$order_id);
  $post_variables = Array(
    "m" => $merchant_id,
    "oa" => $out_amount,
    "s" => $my_signature,
    "o" => $order_id
  );
  $url = 'http://www.free-kassa.ru/merchant/cash.php'; 

  $html = '<form action="' . "" . $url . '" method="get" name="freekassa_form" >';
  $html.= '<input type="image" name="submit" alt="Free-kassa.ru" />';
  foreach ($post_variables as $name => $value) {
    $html.= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';
  }
  $html.= '</form>';
  $html.= ' <script type="text/javascript">';
  $html.= ' document.freekassa_form.submit();';
  $html.= ' </script>';
  echo $html;
}

function nzshpcrt_freekassa_result() {
  global $wpdb;	
  unset($_SESSION['WpscGatewayErrorMessage']);

  if ($_REQUEST['freekassa']=='result') 
  {
    $purchase_log = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`= ".$_REQUEST['MERCHANT_ORDER_ID']." LIMIT 1", ARRAY_A);
    $need_amount=$purchase_log[0]['totalprice'];
    $merchant_id = get_option('freekassa_merchant_id');
    $secret_2 = get_option('freekassa_secret_2');
    $order_id=$_REQUEST['MERCHANT_ORDER_ID'];
    $signature=$_REQUEST['SIGN'];
    $out_amount=$_REQUEST['AMOUNT'];
    $my_signature = md5($merchant_id.":".$out_amount.":".$secret_2.":".$order_id);
    $sessionid=$purchase_log[0]['sessionid'];

    if ($my_signature == $signature AND $need_amount == $out_amount ) 
    {
      $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('processed' => 3), array('id' => $order_id), array('%d', '%s'), array('%d'));
    } else {
      $transaction_url_with_sessionid = add_query_arg( 'sessionid', $sessionid, get_option( 'checkout_url' ) );
      $_SESSION['WpscGatewayErrorMessage'] = __('Ошибка в цифровой подписи');
      wp_redirect( $transaction_url_with_sessionid); exit;
    }
  }
  if ($_REQUEST['freekassa']=='success')
  {
    $purchase_log = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`= ".$_REQUEST['MERCHANT_ORDER_ID']." LIMIT 1", ARRAY_A);
    $sessionid=$purchase_log[0]['sessionid'];
    $transaction_url_with_sessionid = add_query_arg( 'sessionid', $sessionid, get_option( 'transact_url' ) );
    wp_redirect( $transaction_url_with_sessionid); exit;
  }
  if ($_REQUEST['freekassa']=='cancel')
  {
    $purchase_log = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `id`= ".$_REQUEST['MERCHANT_ORDER_ID']." LIMIT 1", ARRAY_A);
    $sessionid=$purchase_log[0]['sessionid'];
    $_SESSION['WpscGatewayErrorMessage'] = __('Ошибка при проведении оплаты.');
    $transaction_url_with_sessionid = add_query_arg( 'sessionid', $sessionid, get_option( 'checkout_url' ) );
    wp_redirect( $transaction_url_with_sessionid); exit;
  }

}
add_action('wp_loaded', 'nzshpcrt_freekassa_result');

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Volf, 2016-12-24
@Wolfnsex

Write yourself for the store (Knowledge of php only Basics)

As far as I understand, knowledge in the field of writing and working plugins "e-commerce" and "woocommerce", at best, is similar to what was voiced in the quote above? Then I think the choice is clear. These are still payments / money, I would not put such experiments in a similar area.
Well, or, just decide for yourself what is cheaper for you. "Move the store" to (under) what is already there, or hire a specialist who would do a quality job of writing / altering such plugins for you, or learn PHP and the plugin system at a level sufficient for such tasks.

P
Pretor DH, 2016-12-24
@PretorDH

Translate to e-commerce...
With basic knowledge of PHP, don't take on rewriting, it will take weeks of time. Even finishing will take more time. If there were 1000 products, then maybe yes, but it would probably be easier to convert the database.
PS But if you are a perfectionist, then all these arguments are useless. Go as you wish.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question