Darek
Участник
Всем привет. Столкнулся с проблемой интеграции Payeer в скрипт.
Поскольку навыков не хватает, пытался написать на основе Perfect Money
Помогите на его основе написать класс для Payeer. Тапками не кидайтесь, сам начал недавно углубляться в эту сферу.
Поскольку навыков не хватает, пытался написать на основе Perfect Money
PHP:
<?php
class perfectmoney extends APayments implements IPayment, IPaymentCallback {
public $pay_name = "Perfect Money";
public $settings = array();
private $amount;
private $inv_id;
private $inv_desc;
public function isCallback() {
if (!isset($_POST['V2_HASH']))
return false;
else
return true;
}
public function process() {
global $sql;
if($this->checkSignature()) {
$inv_id = (integer)$_POST['PAYMENT_ID'];
$res = $sql->fetchOne("SELECT * FROM pay_outcomming WHERE id = $inv_id");
if (!empty($res) and ($_POST['PAYMENT_AMOUNT']==$res['paycost'])) {
if ($res['status']==0) {
$sql->exec("UPDATE pay_outcomming SET status=1 WHERE id=$inv_id");
makeOrder($res);
}
exit("OK" . $inv_id);
}
}
else
exit("Bad signature");
}
public function getFormBalance($amount) {
global $sql, $translator;
$sql->exec("INSERT INTO pay_outcomming(userid, payvariant, paycost, date, status, comments, type)
VALUES('{$_SESSION['ID']}', 'perfectmoney', $amount, NOW(), '0', '".$translator->_('balance_replenishment')."', 'balance')");
$this->inv_id = $sql->lastInsertId();
$this->inv_desc = $translator->_('Deposit_on') . $_SERVER['HTTP_HOST'];
$this->amount = $amount;
$output = $this->constructHtml();
return $output;
}
public function getBuyForm($options) {
global $sql, $translator;
$sql->exec("INSERT INTO pay_outcomming(userid, payvariant, paycost, paycount, date, status, comments, purchase_id, type)
VALUES('{$_SESSION['ID']}', 'perfectmoney', {$options['amount']}, {$options['count']}, NOW(), 0, '{$options['desc']}', {$options['purchase_id']}, '{$options['type']}')");
$this->inv_id = $sql->lastInsertId();
$this->inv_desc = $translator->_('purchase_of_bids');
$this->amount = $options['amount'];
$output = $this->constructHtml();
return $output;
}
protected function constructHtml() {
$form = '
<form name="pay" action="https://perfectmoney.com/api/step1.asp" method="post">
<input type="hidden" name="PAYEE_ACCOUNT" value="'.$this->settings['pmy_account'].'">
<input type="hidden" name="PAYEE_NAME" value="'.$_SERVER['HTTP_HOST'].'">
<input type="hidden" name="PAYMENT_ID" value="'.$this->inv_id.'">
<input type="hidden" name="PAYMENT_AMOUNT" value="'.$this->amount.'">
<input type="hidden" name="PAYMENT_UNITS" value="'.$this->settings['pmy_cur'].'">
<input type="hidden" name="STATUS_URL" value="http://'.$_SERVER['HTTP_HOST'].'/payments/payments-callback.php">
<input type="hidden" name="STATUS_URL_METHOD" value="POST">
<input type="hidden" name="PAYMENT_URL" value="http://'.$_SERVER['HTTP_HOST'].'/article/success.htm">
<input type="hidden" name="PAYMENT_URL_METHOD" value="POST">
<input type="hidden" name="NOPAYMENT_URL" value="http://'.$_SERVER['HTTP_HOST'].'/article/fail.htm">
<input type="hidden" name="NOPAYMENT_URL_METHOD" value="POST">
<input type="hidden" name="SUGGESTED_MEMO" value="'.$this->inv_desc.'" >
<input type="hidden" name="INTERFACE_LANGUAGE" value="ru_RU" >
</form>';
return $form;
}
public function checkSignature() {
return strtoupper(md5(implode(':', array($_POST['PAYMENT_ID'], $_POST['PAYEE_ACCOUNT'], $_POST['PAYMENT_AMOUNT'], $_POST['PAYMENT_UNITS'], $_POST['PAYMENT_BATCH_NUM'], $_POST['PAYER_ACCOUNT'], strtoupper(md5($this->settings['pmy_alterpass'])), $_POST['TIMESTAMPGMT'])))) == strtoupper($_POST['V2_HASH']);
}
public function writelog($title, $data) {
$file = 'perfectmoney.log';
$mode = (file_exists($file) && is_writeable($file)) ? "a" : "w";
$fp = @fopen($file, $mode);
fwrite($fp, date('Y-m-d H:i:s') . ": " . $title . ":\r\n");
if (is_array($data))
fwrite($fp, var_export($data, true) . "\r\n");
else
fwrite($fp, $data . "\r\n");
fwrite($fp, "\r\n");
fclose($fp);
}
}
?>