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
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,71 @@ try {
}
```

### Mass payment (withdraw) integration using UnitPay API

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

/**
* Mass payment integration
*
* @link https://help.unitpay.ru/article/62-masspayment
* @link https://help.unitpay.money/article/62-masspayment
*/

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

// Project Data
$domain = 'unitpay.money'; // Your working domain: unitpay.money or unitpay.ru
$projectId = 1;
$partnerSecretKey = '9e977d0c0e1bc8f5cc9775a8cc8744f1'; // Available in profile settings
$login = 'mail@example.com';
$transactionId = sha1($login . $projectId . time());

// Payment info
$orderSum = 900;
$purse = '+79000000000';
$paymentType = 'mc';
$orderDesc = 'Payment for item "'.$itemName.'"';
$orderCurrency = 'RUB';

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

/**
* 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('massPayment', [
'sum' => $orderSum,
'purse' => $purse,
'login' => $login,
'transactionId' => $transactionId,
'paymentType' => $paymentType,
'projectId' => $projectId,
]);

// If need user redirect on Payment Gate
if (isset($response->result)) {
// success result
$statusResponse = $unitpay->api('massPaymentStatus', [
'login' => $login,
'transactionId' => $transactionId
]);
echo 'Mass payment status: ' . $statusResponse->result->status;
} elseif (isset($response->error->message)) {
$error = $response->error->message;
print 'Error: '.$error;
}
```

## Installation

### Install composer package
Expand Down
15 changes: 12 additions & 3 deletions UnitPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ public function getPrice()
class UnitPay
{
private $supportedCurrencies = array('EUR','UAH', 'BYR', 'USD','RUB');
private $supportedUnitpayMethods = array('initPayment', 'getPayment');
private $supportedUnitpayMethods = array(
'initPayment',
'getPayment',
'getCommissions',
'massPayment',
'massPaymentStatus',
);
private $requiredUnitpayMethodsParams = array(
'initPayment' => array('desc', 'account', 'sum'),
'getPayment' => array('paymentId')
'getPayment' => array('paymentId'),
'getCommissions' => array('projectId', 'login'),
'massPayment' => array('login', 'purse', 'transactionId', 'sum', 'paymentType'),
'massPaymentStatus' => array('login', 'transactionId'),
);
private $supportedPartnerMethods = array('check', 'pay', 'error');
private $supportedUnitpayIp = array(
Expand Down Expand Up @@ -344,4 +353,4 @@ public function getErrorHandlerResponse($message)
)
));
}
}
}