Commit 2d63d6b8 authored by bulinat's avatar bulinat
Browse files

fix branch structure

parent 37b8dbf5
Loading
Loading
Loading
Loading

images/logo.gif

deleted100644 → 0
−1.36 KiB
Loading image diff...

uc_rbkmoney.info

deleted100644 → 0
+0 −7
Original line number Diff line number Diff line
; $Id$
name = RBK Money
description = Provide RBK Money payment gateway
dependencies[] = uc_payment
package = "Ubercart - payment"
core = 6.x
project = "uc_rbkmoney"
 No newline at end of file

uc_rbkmoney.module

deleted100644 → 0
+0 −306
Original line number Diff line number Diff line
<?php

/**
 * Implementation of hook_perm().
 */
function uc_rbkmoney_perm() {
  return array('administer uc_rbkmoney');
}

/**
 * Implementation of hook_menu().
 */
function uc_rbkmoney_menu() {
  $items['admin/store/settings/uc_rbkmoney'] = array(
    'title' => 'RBK Money',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('uc_rbkmoney_setup'),
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['uc_rbkmoney/response'] = array(
    'title' => 'Internal Data',
    'page callback' => 'uc_rbkmoney_done_payment',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['uc_rbkmoney/success'] = array(
    'title' => 'Internal Data',
    'page callback' => 'uc_rbkmoney_payment_end',
    'page arguments' => array('success'),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['uc_rbkmoney/fail'] = array(
    'title' => 'Internal Data',
    'page callback' => 'uc_rbkmoney_payment_end',
    'page arguments' => array('fail'),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Callback for settings page
 */
function uc_rbkmoney_setup() {
  global $base_url;
  $form['responseURL'] = array(
    '#value' => t('Response URL: ') . $base_url . '/uc_rbkmoney/response',
    '#suffix' => '<div class="description">' . t("For insertion into \"Payment notification URL\" field on <a target=_blank href=\"http://www.rbkmoney.ru\">RBK Money</a> settings page") . '</div>',
  );
  $form['actionURL'] = array(
    '#type' => 'textfield',
    '#title' => t('Payment form action URL'),
    '#default_value' => variable_get('uc_rbkmoney_actionURL', 'https://rbkmoney.ru/acceptpurchase.aspx'),
    '#description' => t("Default: \"https://rbkmoney.ru/acceptpurchase.aspx\""),
    '#required' => TRUE,
  );
  $form['eshopId'] = array(
    '#type' => 'textfield',
    '#title' => t('Site ID'),
    '#default_value' => variable_get('uc_rbkmoney_eshopId', ''),
    '#description' => t("Merchant ID of your site"),
    '#required' => TRUE,
  );
  $form['recipientCurrency'] = array(
    '#type' => 'select',
    '#title' => t('Payments currency'),
    '#options' => array('RUR' => 'RUR', 'USD' => 'USD', 'EUR' => 'EUR', 'UAH' => 'UAH'),
    '#default_value' => variable_get('uc_rbkmoney_recipientCurrency', 'RUR'),
    '#description' => t("Please, select payments currency"),
    '#required' => TRUE,
  );
  $form['secretKey'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret key'),
    '#default_value' => variable_get('uc_rbkmoney_secretKey', ''),
    '#description' => t("Secret key, entered on <a target=_blank href=\"http://www.rbkmoney.ru\">RBK Money</a> settings page"),
    '#required' => TRUE,
  );
  $form['log'] = array(
    '#type' => 'radios',
    '#title' => t('Save RBK Money\'s server responses in <a href="/admin/reports/dblog">system log</a>'),
    '#options' => array('on' => t('Yes'), 'off' => t('No')),
    '#default_value' => variable_get('uc_rbkmoney_log', 'on'),
  );
  $form['preference'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Advanced options of protocol')
  );
  $form['preference']['method'] = array(
    '#type' => 'select',
    '#title' => t('Prefered payment method'),
    '#options' => array(
      'all' => t('All (default)'),
      'inner' => t('RBK Money wallet'),
      'bankCard' => t('Visa/MasterCard bank card'),
      'exchangers' => t('E-payment systems'),
      'prepaidcard' => t('RBK Money prepaid card'),
      'transfers' => t('Money transfer systems'),
      'terminals' => t('Cash-in kiosks'),
      'iFree' => 'SMS',
      'bank' => t('Bank transfer'),
      'postRus' => t('Russian Post'),
      'atm' => t('ATMs'),
      'yandex' => t('Yandex'),
      'ibank' => t('Internert banking'),
      'euroset' => t('Euroset')
    ),
    '#default_value' => variable_get('uc_rbkmoney_preference', 'all'),
    '#description' => t("Default payment method. Allow to skip payment selection page"),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save changes'),
  );
  return $form;
}

/**
 * Submit setup form
 */
function uc_rbkmoney_setup_submit($form, &$form_state) {
  variable_set('uc_rbkmoney_actionURL', trim($form_state['values']['actionURL']));
  variable_set('uc_rbkmoney_eshopId', trim($form_state['values']['eshopId']));
  variable_set('uc_rbkmoney_recipientCurrency', $form_state['values']['recipientCurrency']);
  variable_set('uc_rbkmoney_secretKey', $form_state['values']['secretKey']);
  variable_set('uc_rbkmoney_log', $form_state['values']['log']);
  variable_set('uc_rbkmoney_preference', $form_state['values']['method']);
  drupal_set_message(t('Settings have been saved'), $type = 'status');
}

/**
 * Implementation of hook_payment_method().
 */
function uc_rbkmoney_payment_method() {
  $path = base_path() . drupal_get_path('module', 'uc_rbkmoney');
  $title = t('RBK Money') . '<br /><img src="' . $path . '/images/logo.gif" style="position: relative; left: 2.5em;">';
  $methods[] = array(
    'id' => 'rbkmoney',
    'name' => t('RBK Money'),
    'title' => $title,
    'desc' => t('RBK Money'),
    'weight' => 1,
    'callback' => 'uc_payment_method_rbkmoney',
    'checkout' => TRUE,
    'no_gateway' => TRUE,
  );
  return $methods;
}

/**
 * Callback for rbkmoney payment method settings.
 */
function uc_payment_method_rbkmoney($op, &$arg1) {
  switch ($op) {
    case 'cart-details':
      return;
    case 'settings':
      return;
  }
}

/**
 * Implementation of hook_form_alter().
 */
function uc_rbkmoney_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'uc_cart_checkout_review_form' && ($order_id = intval($_SESSION['cart_order'])) > 0) {
    $order = uc_order_load($order_id);
    if ($order->payment_method == 'rbkmoney') {
      unset($form['submit']);
      $form['#prefix'] = '<table><tr><td>';
      $form['#suffix'] = '</td><td>' . drupal_get_form('uc_rbkmoney_submit_form', $order) . '</td></tr></table>';
    }
  }
}

/**
 * Payment request form
 */
function uc_rbkmoney_submit_form($form_state, $order) {
  global $base_url;
  $desc = '';
  foreach ($order->products as $value) {
    if (!empty($desc)) {
      $desc .= ', ';
    }
    $desc .= $value->qty . '&times; ' . $value->title;
  }
  // Prevent more than 255 symbols of order description
  if (strlen($desc) > 255) {
    $desc = t('Order №') . $order->order_id;
  }

  $form['eshopId'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('uc_rbkmoney_eshopId', ''),
  );
  $form['orderId'] = array(
    '#type' => 'hidden',
    '#value' => $order->order_id,
  );
  $form['serviceName'] = array(
    '#type' => 'hidden',
    '#value' => $desc,
  );
  $form['recipientAmount'] = array(
    '#type' => 'hidden',
    '#value' => $order->order_total,
  );
  $form['recipientCurrency'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('uc_rbkmoney_recipientCurrency', ''),
  );
  $form['successUrl'] = array(
    '#type' => 'hidden',
    '#value' => $base_url . '/uc_rbkmoney/success',
  );
  $form['failUrl'] = array(
    '#type' => 'hidden',
    '#value' => $base_url . '/uc_rbkmoney/fail',
  );
  $pref = variable_get('uc_rbkmoney_preference', '');
  if ($pref != 'all') {
    $form['preference'] = array(
      '#type' => 'hidden',
      '#value' => $pref,
    );
  }
  $form['#action'] = variable_get('uc_rbkmoney_actionURL', '');
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Place your order'),
  );
  return $form;
}

/**
 * Callback for RBK Money system response
 */
function uc_rbkmoney_done_payment() {
  drupal_set_header('Content-type: text/html; charset=iso-8859-1');

  if (variable_get('uc_rbkmoney_log', '') == 'on') {
    $log = '<pre>' . var_export($GLOBALS['_POST'], TRUE) . '</pre>';
    watchdog('uc_rbkmoney', $log);
  }

  $response['eshopId'] = $GLOBALS['_POST']['eshopId'];
  $response['orderId'] = $GLOBALS['_POST']['orderId'];
  $response['serviceName'] = $GLOBALS['_POST']['serviceName'];
  $response['eshopAccount'] = $GLOBALS['_POST']['eshopAccount'];
  $response['recipientAmount'] = $GLOBALS['_POST']['recipientAmount'];
  $response['recipientCurrency'] = $GLOBALS['_POST']['recipientCurrency'];
  $response['paymentStatus'] = $GLOBALS['_POST']['paymentStatus'];
  $response['userName'] = $GLOBALS['_POST']['userName'];
  $response['userEmail'] = $GLOBALS['_POST']['userEmail'];
  $response['paymentData'] = $GLOBALS['_POST']['paymentData'];
  $response['hash'] = $GLOBALS['_POST']['hash'];

  if (!empty($response['hash'])) {
    $crc = md5($response['eshopId'] . '::' . $response['orderId'] . '::' . $response['serviceName'] . '::' . $response['eshopAccount'] . '::' . $response['recipientAmount'] . '::' . $response['recipientCurrency'] . '::' . $response['paymentStatus'] . '::' . $response['userName'] . '::' . $response['userEmail'] . '::' . $response['paymentData'] . '::' . variable_get('uc_rbkmoney_secretKey', ''));
    $order = uc_order_load($response['orderId']);

    if ($response['hash'] == $crc) {
      switch ($response['paymentStatus']) {
        case "3" :
          uc_order_update_status($response['orderId'], 'processing');
          uc_order_comment_save($response['orderId'], $order->uid, t('RBK Money: processing'), $type = 'admin', $status = 1, $notify = FALSE);
          break;
        case "5" :
          uc_payment_enter($response['orderId'], 'RBK Money', $response['recipientAmount'], $order->uid, NULL, NULL);
          uc_cart_complete_sale($order);
          uc_order_comment_save($response['orderId'], $order->uid, t('RBK Money: payment successful'), $type = 'admin', $status = 1, $notify = FALSE);
          break;
      }
    } elseif ($response['hash'] !== $crc) {
      uc_order_update_status($response['orderId'], 'canceled');
      uc_order_comment_save($response['orderId'], $order->uid, t('MD5 checksum fail, order canceled'), $type = 'admin', $status = 1, $notify = FALSE);
      watchdog('uc_rbkmoney', t('MD5 checksum fail, order canceled'));
    }
  }
}

/**
 * Callback redirect from RBK Money site
 */
function uc_rbkmoney_payment_end($arg) {
  switch ($arg) {
    case "success" :
      if (isset($_SESSION['cart_order'])) {
        $_SESSION['do_complete'] = TRUE;
        drupal_goto('cart/checkout/complete');
      }
      break;
    case "fail" :
      unset($_SESSION['cart_order']);
      drupal_set_message(t("Your payment has been declined."));
      drupal_goto('cart');
      break;
  }
  return;
}
 No newline at end of file