Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
vendor/
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":1071:{a:2:{s:7:"defects";a:2:{s:23:"APITest::testApiSuccess";i:4;s:30:"UnitPayAPITest::testApiSuccess";i:4;}s:5:"times";a:18:{s:38:"UnitPayTest::testSuccessCreateInstance";d:0.039;s:35:"UnitPayTest::testFailCreateInstance";d:0.01;s:42:"UnitPayTest::testSuccessGetSignatureEquals";d:0.004;s:44:"UnitPayTest::testSuccessFormEqualsWithSecret";d:0.001;s:47:"UnitPayTest::testSuccessFormEqualsWithoutSecret";d:0.001;s:37:"UnitPayTest::testApiUnsupportedMethod";d:0.002;s:27:"UnitPayTest::testApiSuccess";d:0.87;s:29:"UnitPayTest::testRealIPGetter";d:0.001;s:39:"UnitPayTest::testHandlerFailEmptyMethod";d:0.004;s:39:"UnitPayTest::testHandlerFailEmptyParams";d:0.001;s:45:"UnitPayTest::testHandlerFailUnsupportedMethod";d:0.001;s:42:"UnitPayTest::testHandlerFailWrongSignature";d:0.001;s:42:"UnitPayTest::testHandlerFailWrongIpAddress";d:0.003;s:31:"UnitPayTest::testHandlerSuccess";d:0.001;s:33:"APITest::testApiUnsupportedMethod";d:0.044;s:23:"APITest::testApiSuccess";d:0.002;s:40:"UnitPayAPITest::testApiUnsupportedMethod";d:0.043;s:30:"UnitPayAPITest::testApiSuccess";d:1.371;}}}
188 changes: 1 addition & 187 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,197 +1,11 @@
# UnitPay PHP-SDK
Php sdk for [UnitPay.ru ](https://unitpay.ru) and [UnitPay.money ](https://unitpay.money)
Php sdk for [UnitPay.ru](https://unitpay.ru) and [UnitPay.money](https://unitpay.money)

Documentation https://help.unitpay.ru and https://help.unitpay.money

## Examples ##
These are just some quick examples. Check out the samples in [`/sample`](https://github.com/unitpay/php-sdk/blob/master/sample).

### Payment integration using UnitPay Form
```php
<?php
include ('../UnitPay.php');

// Project Data
$domain = 'unitpay.money'; // Your working domain: unitpay.money or unitpay.ru
$secretKey = '9e977d0c0e1bc8f5cc9775a8cc8744f1';
$publicId = '15155-ae12d';

// My item Info
$itemName = 'Iphone 6 Skin Cover';

// My Order Data
$orderId = 'a183f94-1434-1e44';
$orderSum = 900;
$orderDesc = 'Payment for item "' . $itemName . '"';
$orderCurrency = 'RUB';

$unitPay = new UnitPay($domain, $secretKey);

$unitPay
->setBackUrl('http://domain.com')
->setCustomerEmail('customer@domain.com')
->setCustomerPhone('79001235555')
->setCashItems(array(
new CashItem($itemName, 1, $orderSum)
));

$redirectUrl = $unitPay->form(
$publicId,
$orderSum,
$orderId,
$orderDesc,
$orderCurrency
);

header("Location: " . $redirectUrl);
```

### Payment integration using UnitPay Api

```php
<?php

header('Content-Type: text/html; charset=UTF-8');

/**
* API integration
*
* @link https://help.unitpay.ru/article/32-creating-payment-via-api
* @link https://help.unitpay.money/article/32-creating-payment-via-api
*/

include ('../UnitPay.php');

// Project Data
$domain = 'unitpay.money'; // Your working domain: unitpay.money or unitpay.ru
$projectId = 1;
$secretKey = '9e977d0c0e1bc8f5cc9775a8cc8744f1';

// My item Info
$itemName = 'Iphone 6 Skin Cover';

// My Order Data
$orderId = 'a183f94-1434-1e44';
$orderSum = 900;
$orderDesc = 'Payment for item "'.$itemName.'"';
$orderCurrency = 'RUB';

$unitPay = new UnitPay($domain, $secretKey);

/**
* Base params: account, desc, sum, currency, projectId, paymentType
* Additional params:
* Qiwi, Mc:
* phone
* alfaClick:
* clientId
*
* @link https://help.unitpay.ru/article/32-creating-payment-via-api
* @link https://help.unitpay.money/article/32-creating-payment-via-api
*/
$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);

// If without redirect (invoice)
} elseif (isset($response->result->type)
&& $response->result->type == 'invoice') {
// Url on receipt page in Unitpay
$receiptUrl = $response->result->receiptUrl;
// Payment ID in Unitpay (you can save it)
$paymentId = $response->result->paymentId;
// Invoice Id in Payment Gate (you can save it)
$invoiceId = $response->result->invoiceId;
// User redirect
header("Location: " . $receiptUrl);

// If error during api request
} elseif (isset($response->error->message)) {
$error = $response->error->message;
print 'Error: '.$error;
}
```

### Handler sample

```php
<?php

/**
* Demo handler for your projects
*
*/
include ('../UnitPay.php');

// Project Data
$domain = 'unitpay.money'; // Your working domain: unitpay.money or unitpay.ru
$projectId = 1;
$secretKey = '9e977d0c0e1bc8f5cc9775a8cc8744f1';

// My item Info
$itemName = 'Iphone 6 Skin Cover';

// My Order Data
$orderId = 'a183f94-1434-1e44';
$orderSum = 900;
$orderDesc = 'Payment for item "' . $itemName . '"';
$orderCurrency = 'RUB';

$unitPay = new UnitPay($domain, $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':
echo $unitPay->getSuccessHandlerResponse('Check Success. Ready to pay.');
break;
// Method Pay means that the money received
case 'pay':
// Please complete order
echo $unitPay->getSuccessHandlerResponse('Pay Success');
break;
// Method Error means that an error has occurred.
case 'error':
// Please log error text.
echo $unitPay->getSuccessHandlerResponse('Error logged');
break;
}
// Oops! Something went wrong.
} catch (Exception $e) {
echo $unitPay->getErrorHandlerResponse($e->getMessage());
}
```

## Installation

### Install composer package
Expand Down
Loading