Example #1
0
<?php

/**
 * Payment form
 *
 * @link http://help.unitpay.ru/article/31-creating-payment-from-payment-form
 */
require_once './orderInfo.php';
require_once '../UnitPay.php';
$unitPay = new UnitPay($secretKey);
$redirectUrl = $unitPay->form($publicId, $orderSum, $orderId, $orderDesc, $orderCurrency);
header("Location: " . $redirectUrl);
Example #2
0
<?php

//error_reporting(0);
include 'config.php';
include 'lib/UnitPayModel.php';
include 'lib/UnitPay.php';
class UnitPayEvent
{
    public function check($params)
    {
        $unitPayModel = UnitPayModel::getInstance();
        if ($unitPayModel->getAccountByName($params['account'])) {
            return true;
        }
        return 'Character not found';
    }
    public function pay($params)
    {
        $unitPayModel = UnitPayModel::getInstance();
        $countItems = floor($params['sum'] / Config::ITEM_PRICE);
        $unitPayModel->donateForAccount($params['account'], $countItems);
    }
}
$payment = new UnitPay(new UnitPayEvent());
echo $payment->getResult();
Example #3
0
<?php

/**
 *  Demo handler for your projects
 *
 * @link http://help.unitpay.ru/article/35-confirmation-payment
 */
require_once './orderInfo.php';
require_once '../UnitPay.php';
$unitPay = new UnitPay($secretKey);
try {
    // Validate request (check ip address, signature and etc)
    $unitPay->checkHandlerRequest();
    list($method, $params) = array($_GET['method'], $_GET['params']);
    // Very important! Validate request with your order data, before complete order
    if ($params['orderSum'] != $orderSum || $params['orderCurrency'] != $orderCurrency || $params['account'] != $orderId || $params['projectId'] != $projectId) {
        // logging data and throw exception
        throw new InvalidArgumentException('Order validation Error!');
    }
    switch ($method) {
        // Just check order (check server status, check order in DB and etc)
        case 'check':
            print $unitPay->getSuccessHandlerResponse('Check Success. Ready to pay.');
            break;
            // Method Pay means that the money received
        // Method Pay means that the money received
        case 'pay':
            // Please complete order
            print $unitPay->getSuccessHandlerResponse('Pay Success');
            break;
            // Method Error means that an error has occurred.
Example #4
0
<?php

header('Content-Type: text/html; charset=UTF-8');
/**
 * API integration
 *
 * @link http://help.unitpay.ru/article/32-creating-payment-via-api
 */
require_once './orderInfo.php';
require_once '../UnitPay.php';
$unitPay = new UnitPay($secretKey);
/**
 * Base params: account, desc, sum, currency, projectId, paymentType
 * Additional params:
 *  Qiwi, Mc:
 *      phone
 * alfaClick:
 *      clientId
 *
 * @link http://help.unitpay.ru/article/32-creating-payment-via-api
 * @link http://help.unitpay.ru/article/36-codes-payment-systems
 */
$response = $unitPay->api('initPayment', ['account' => $orderId, 'desc' => $orderDesc, 'sum' => $orderSum, 'paymentType' => 'yandex', 'currency' => $orderCurrency, 'projectId' => $projectId]);
// If need user redirect on Payment Gate
if (isset($response->result->type) && $response->result->type == 'redirect') {
    // Url on PaymentGate
    $redirectUrl = $response->result->redirectUrl;
    // Payment ID in Unitpay (you can save it)
    $paymentId = $response->result->paymentId;
    // User redirect
    header("Location: " . $redirectUrl);
Example #5
0
<?php

header('Content-Type: text/html; charset=UTF-8');
/**
 * Payment info
 *
 * @link http://help.unitpay.ru/article/58-get-payment
 */
require_once './orderInfo.php';
require_once '../UnitPay.php';
$unitPay = new UnitPay($secretKey);
$response = $unitPay->api('getPayment', ['paymentId' => 3403575]);
// If need user redirect on Payment Gate
if (isset($response->result)) {
    // Payment Info
    $paymentInfo = $response->result;
    var_dump($paymentInfo);
    // If error during api request
} elseif (isset($response->error->message)) {
    $error = $response->error->message;
    print 'Error: ' . $error;
}
Example #6
0
        $orderSum = $params['orderSum'];
        $date = $params['date'];
        $paymentType = $params['paymentType'];
        $orderCurrency = $params['orderCurrency'];
        // $errorMessage = $params['errorMessage'];
        $unitPay = new ParseObject("UnitPay");
        $unitPay->set('sum', $sum);
        $unitPay->set('profit', $profit);
        $unitPay->set('unitpayId', $unitpayId);
        $unitPay->set('account', $account);
        $unitPay->set('paymentType', $paymentType);
        $unitPay->set('orderSum', $orderSum);
        $unitPay->set('date', $date);
        $unitPay->set('paymentType', $paymentType);
        $unitPay->set('orderCurrency', $orderCurrency);
        // $unitPay->set('errorMessage', $errorMessage);
        try {
            $unitPay->save();
            // $parseId = $unitPay->getObjectId();
            return $this->getResponseSuccess('PAY is successful');
        } catch (ParseException $ex) {
            return $this->getResponseError('pay error');
        }
    }
}
$unitPay = new UnitPay();
echo $unitPay->getResult($_GET);
// CHECK
// account date operator orderCurrency orderSum paymentType phone profit projectId sign sum unitpayId
// PAY
// account date operator orderCurrency orderSum paymentType phone profit projectId sign sum unitpayId