-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathinitPaymentApi.php
More file actions
62 lines (54 loc) · 1.72 KB
/
Copy pathinitPaymentApi.php
File metadata and controls
62 lines (54 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?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('../vendor/autoload.php');
$unitPay = new unitpay\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);
// 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;
}