Example #1
0
 function updateBill($param)
 {
     global $modx;
     // checking SignOn
     if (!$this->checkSign($param)) {
         //if not Signed
         $resp_code = 1000;
     } else {
         //get data from MS2 about this transaction
         if ($order = $modx->getObject('msOrder', $param->txn)) {
             //get order data from qiwi
             $rc = $this->checkAccount($this->login, $this->password, $param->txn);
             // $modx->log(modX::LOG_LEVEL_ERROR,'Payment resp:'.$rc->user.' '.$rc->amount. ' '.$rc->date.' '.$rc->lifetime.' '.$rc->status);
             //creating handler to Qiwi
             /* @var msPaymentInterface|Qiwi $handler */
             $handler = new Qiwi($modx->newObject('msOrder'));
             //matching qiwi data and MS2 data for anti fraud (spoof amount in txn)
             if ($rc->amount == $order->get('cost')) {
                 //all check complete, status is real, go to verify Qiwi status
                 //if param status in update is 60 and in qiwi status is 60 -its true payment
                 if ($param->status == 60 && $rc->status == 60) {
                     // Successfully payment
                     // get order  ($param->txn), marking as payd
                     //  $modx->log(modX::LOG_LEVEL_ERROR,'[miniShop2] Payment OK txn:'.$param->txn. 'status:'.$param->status);
                     $params = array('status' => '60');
                     /* @var msPaymentInterface|Qiwi $handler */
                     $handler->receive($order, $params);
                     $resp_code = 0;
                     //success payment
                 } else {
                     if ($param->status >= 100 and $rc->status >= 100) {
                         // canceled
                         // get order  ($param->txn), mark as canceled
                         $params = array('status' => '100');
                         $handler->receive($order, $params);
                         $resp_code = -2;
                         //canceled
                     } else {
                         if ($param->status >= 50 && $param->status < 60) {
                             // under processing
                             $resp_code = -3;
                         } else {
                             if ($param->status != $rc->status) {
                                 // status from input service != status in qiwi
                                 $resp_code = -7;
                             } else {
                                 // unknown state
                                 $resp_code = -4;
                             }
                         }
                     }
                 }
                 //end of logic for statuses
             } else {
                 //when amount count mismatch
                 $resp_code = -5;
                 $modx->log(modX::LOG_LEVEL_ERROR, '[miniShop2] Payment failed, txn:' . $param->txn . '$param->status:' . $param->status . ' rc->satus:' . $rc->status . ' order->cost:' . $order->get('cost') . ' $rc->amount:' . $rc->amount . ' fraud matching failed!');
             }
         } else {
             //transaction not found in MS2
             $resp_code = -6;
             $modx->log(modX::LOG_LEVEL_ERROR, '[miniShop2] Could not retrieve order by Qiwi payment with id ' . $param->txn . ' because ID is not found in system.');
         }
     }
     //logic end
     if ($resp_code != 0) {
         $modx->log(modX::LOG_LEVEL_ERROR, '[miniShop2] Failed payment ' . $param->txt . ' Local resp_code: ' . $resp_code . ' Server status:' . $rc->status);
     }
     /** @var qiwiResponse $to_srv_responce */
     $to_srv_responce = new qiwiResponse();
     $to_srv_responce->updateBillResult = 0;
     //send 0 (we process payment) to Qiwi permanently
     return $to_srv_responce;
 }
Example #2
0
<?php

require 'qiwi.class.php';
$Qiwi = new Qiwi();
// Создаем экземпляр класса
// CОЗДАНИЕ СЧЕТА
$bill_id = rand(10000000, 99999999);
$create_result = $Qiwi->create('79001234567', 100, date('Y-m-d', strtotime(date('Y-m-d') . " + 1 DAY")) . "T00:00:00", $bill_id, 'Тестовая оплата');
if ($bill_create->result_code !== 0) {
    echo 'Ошибка в создании счета';
} else {
    echo 'Счет выставлен';
}
// ПЕРЕАДРЕСАЦИЯ НА СТРАНИЦУ ОПЛАТЫ
$Qiwi->redir($bill_id, 'http://' . $_SERVER['SERVER_NAME'] . '/success_url', 'http://' . $_SERVER['SERVER_NAME'] . '/fail_url');
// ПОЛУЧЕНИЕ ИНФОРМАЦИИ О СЧЕТЕ
$info_result = $Qiwi->info($bill_id);
if ($info_result->result_code !== 0) {
    echo 'Ошибка в получении информации о счете';
} else {
    echo 'Статус счета: ' . $info_result->bill->status;
}
// ОТМЕНА СЧЕТА
$reject_result = $Qiwi->reject($bill_id);
if ($reject_result->bill->status === 'rejected') {
    echo 'Не удалось отменить счет';
} else {
    echo 'Счет отменен';
}
Example #3
0
if (!isset($modx)) {
    define('MODX_API_MODE', true);
    require dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/index.php';
    $modx->getService('error', 'error.modError');
    $modx->setLogLevel(modX::LOG_LEVEL_ERROR);
}
$modx->error->message = null;
/* @var miniShop2 $miniShop2 */
$miniShop2 = $modx->getService('minishop2');
$miniShop2->loadCustomClasses('payment');
if (!class_exists('Qiwi')) {
    exit('Error: could not load payment class "Qiwi".');
}
/* @var msPaymentInterface|Qiwi $handler */
$handler = new Qiwi($modx->newObject('msOrder'));
$config = $handler->config;
switch ($_GET['action']) {
    //generate Qiwi request and redirect to Qiwi
    case 'continue':
        if (!empty($_GET['msorder'])) {
            if ($order = $modx->getObject('msOrder', $_GET['msorder'])) {
                $response = $handler->send($order);
                $modx->sendRedirect($response);
            }
        }
        break;
    case 'result':
        //Going to qiwi.class to processing payment
        $handler->request();
        break;