<?php 
/**
* Входящий платеж
*/

if (isset($_POST['ik_co_id'])) {
  
  $set_paytype = $payment->getSettings('interkassa');
  
  $checkPOST = array(
                  'id' => $_POST['ik_pm_no'], 
                  'service' => $_POST['ik_x_service'], 
                  'service_id' => $_POST['ik_x_service_id'], 
                  'wmr' => round($_POST['ik_am'], 2), 
                  'array' => serialize($_POST),
                  'paytype' => 'interkassa',
                  'method' => 'INTERKASSA',
                  'resp' => 'YES',
                  );
                  
  if ($request === 'result' && $_POST['ik_inv_st'] === 'success') 
  {
    foreach ($_POST as $k => $v) {
      if (strpos($k, 'ik_') === 0) {
        $data[$k] = $v;
      }
    }

    unset($data['ik_sign']);
    ksort($data, SORT_STRING);
    array_push($data, $set_paytype['PAYMENT']['SECRET_KEY']);
    $common_string = implode(':', $data);
    
    $hash = base64_encode(md5($common_string, true));

    if ($hash === $_POST['ik_sign']) {
      $pay_result = 'result';
    }  
  }
  
  else {
    $pay_result = ($_POST['ik_inv_st'] == 'success' ? 'success' : 'fail');
  }
}