1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282:
<?php
class PHPShopPayment extends PHPShopObj {
var $debug = false;
function __construct($objID) {
$this->objID = $objID;
$this->order = array('order' => 'num');
$this->objBase = $GLOBALS['SysValue']['base']['payment_systems'];
parent::__construct();
}
function getName() {
return parent::getParam("name");
}
function getPath() {
return parent::getParam("path");
}
function getId() {
return parent::getParam("id");
}
}
class PHPShopPaymentArray extends PHPShopArray {
function __construct($sql = false) {
$this->objSQL = $sql;
$this->order = array('order' => 'num');
$this->objBase = $GLOBALS['SysValue']['base']['payment_systems'];
parent::__construct('id', "name", 'path', 'enabled', 'yur_data_flag', 'icon');
}
}
class PHPShopPaymentResult {
var $debug = false;
var $log = false;
function __construct() {
global $_classPath;
$this->log_file = dirname(__FILE__) . $_classPath . 'payment/paymentlog.log';
$this->updateorder();
}
function __call($name, $arguments) {
if ($name == __CLASS__) {
self::__construct();
}
}
function option() {
$this->payment_name = 'Liqpay';
include_once(dirname(__FILE__) . '/../hook/mod_option.hook.php');
$this->option = new PHPShopLiqpayArray();
}
function check() {
$xml = base64_decode($_REQUEST['operation_xml']);
$this->result_var = readDatabase($xml, 'response', false);
if ($this->result_var['status'] == 'success') {
$this->out_summ = $this->result_var['amount'];
$this->inv_id = $this->true_num($this->result_var['order_id']);
$this->crc = $_REQUEST['signature'];
$this->my_crc = base64_encode(sha1($this->option['merchant_sign'] . $_REQUEST['operation_xml'] . $this->option['merchant_sign'], 1));
return true;
}
}
function done() {
echo "OK" . $this->inv_id . "\n";
$this->log();
}
function error($type = 1) {
if ($type == 1)
echo "bad order num\n";
else
echo "bad sign\n";
$this->log();
}
function set_order_status_101() {
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['order_status']);
$PHPShopOrm->debug = $this->debug;
$data = $PHPShopOrm->select(array('id'), array('id' => '=101'), false, array('limit' => 1));
if (!is_array($data)) {
$PHPShopOrm->clean();
$PHPShopOrm->insert(array('id_new' => 101, 'name_new' => '', 'color_new' => '#ccff00'));
}
return 101;
}
function ofd($data) {
global $_classPath, $PHPShopModules, $PHPShopSystem;
$ofd = $PHPShopSystem->getParam('ofd');
if (empty($ofd))
$ofd = 'atol';
if (!empty($PHPShopModules->ModValue['base'][$ofd])) {
include_once($_classPath . 'modules/' . substr($ofd, 0, 15) . '/api.php');
if (function_exists('OFDStart')) {
OFDStart($data);
}
}
}
function updateorder() {
if ($this->check()) {
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['orders']);
$PHPShopOrm->debug = $this->debug;
$orderUid = $this->true_num($this->inv_id);
$row = $PHPShopOrm->select(array('*'), array('uid' => "='" . $orderUid . "'"), false, array('limit' => 1));
if (!empty($row['uid'])) {
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['payment']);
$PHPShopOrm->insert(array('uid_new' => $this->inv_id, 'name_new' => $this->payment_name,
'sum_new' => $this->out_summ, 'datas_new' => time()));
$this->setOrderPaid($orderUid);
$this->done();
$this->ofd($row);
}
else
$this->error();
}
else
$this->error(2);
}
function log() {
if (empty($this->log))
return '';
if (!empty($this->inv_id)) {
$content = "
" . $this->payment_name . " Payment Start ------------------
date=" . date("F j, Y, g:i a") . "
out_summ=" . $this->out_summ . "
inv_id=" . $this->inv_id . "
crc=" . $this->crc . "
my_crc=" . $this->my_crc . "
REQUEST_URI=" . $_SERVER['REQUEST_URI'] . "
IP=" . $_SERVER['REMOTE_ADDR'] . "
" . $this->payment_name . " Payment End --------------------
";
} else {
if (is_array($_REQUEST))
foreach ($_REQUEST as $k => $v) {
$content.=$k . '=' . $v . '
';
}
$content.= "
" . $this->payment_name . " Payment Start ------------------
" . $content . "
" . $this->payment_name . " Payment End --------------------
";
}
PHPShopFile::chmod($this->log_file, false);
PHPShopFile::write($this->log_file, $content, 'a+', true);
}
function true_num($uid) {
$last_num = substr($uid, -$GLOBALS['SysValue']['my']['order_prefix_format']);
$total = strlen($uid);
$first_num = substr($uid, 0, ($total - $GLOBALS['SysValue']['my']['order_prefix_format']));
return $first_num . "-" . $last_num;
}
public function setOrderPaid($orderUid)
{
$PHPShopOrm = new PHPShopOrm($GLOBALS['SysValue']['base']['orders']);
$PHPShopOrm->debug = $this->debug;
$PHPShopOrm->update(
array('statusi_new' => $this->set_order_status_101(), 'paid_new' => 1),
array('uid' => '="' . $orderUid . '"')
);
}
}
?>