Всем доброго времени суток.
Решил подключить к магазину электронную платежку free-kassa,но для woocommerce плагина нет,есть только для e-commerce.И тут встал выбор:
1.Перевести магазин на e-commerce,так как всего три товара и много времени это не займет
2.Написать самомум под магазин(Знания php только Азы)
3.Переделать код плагина для e-commerce под woocommerce
Прошу помочь с выбором.
Заранее благодарю за ответы.
*Сам плагин*
<?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');