This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaylith_bank.php
146 lines (125 loc) · 4.26 KB
/
paylith_bank.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
if (! defined('WHMCS')) {
die('This file cannot be accessed directly');
}
function paylith_bank_config()
{
return [
'FriendlyName' => [
'Type' => 'System',
'Value' => 'Paylith - Havale / EFT'
],
'paylithBankApiKey' => [
'FriendlyName' => 'Mağaza Parola (API Key)',
'Type' => 'text',
'Size' => '25',
'Description' => 'Paylith.com üzerinde kayıtlı olan mağazanın parolası.',
],
'paylithBankApiSecret' => [
'FriendlyName' => 'Mağaza Gizli Anahtar (API Secret)',
'Type' => 'text',
'Size' => '25',
'Description' => 'Paylith.com üzerinde kayıtlı olan mağazanın gizli anahtarı.',
],
];
}
function paylith_bank_link($params)
{
$clientDetails = $params['clientdetails'];
$paylithApiKey = $params['paylithBankApiKey'];
$paylithApiSecret = $params['paylithBankApiSecret'];
$paylithGatewayToken = paylithBankGenerateHash(
$paylithApiKey,
$paylithApiSecret,
$params['invoiceid'],
$clientDetails['userid'],
$clientDetails['email'],
paylithBankGetIpAddress(),
);
$postFields = [
'apiKey' => $paylithApiKey,
'token' => $paylithGatewayToken,
'conversationId' => (string) $params['invoiceid'],
'userId' => $clientDetails['userid'],
'userEmail' => $clientDetails['email'],
'userIpAddress' => paylithBankGetIpAddress(),
'productApi' => true,
'productData' => [
'name' => $params['description'],
'amount' => $params['amount'] * 100,
'paymentChannels' => [2],
],
];
$response = paylithBankSendRequest($postFields);
$response = json_decode($response);
return '
<!-- Paylith Bank Transfer -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/izimodal-1.6.0@1.6.1/css/iziModal.min.css">
<script src="https://cdn.jsdelivr.net/npm/izimodal-1.6.0@1.6.1/js/iziModal.min.js"></script>
<button id="openPaylithModal" class="btn btn-success" type="button">'.$params['langpaynow'].'</button>
<script>
$("#paylithModal").iziModal({
iframe: true,
iframeURL: "'.$response->paymentLink.'",
title: "Paylith Ortak Ödeme Sayfası",
iframeHeight: 800,
width: 950,
headerColor: "linear-gradient(-45deg,#b486ff,#7200ff 60%,#7200ff 99%)",
});
$(document).on("click", "#openPaylithModal", function (e) {
e.preventDefault();
console.log("triggered btn");
$("#paylithModal").iziModal("open");
});
</script>
<!-- /Paylith Bank Transfer -->
';
}
function paylithBankGetIpAddress()
{
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
if (strstr($ip, ',')) {
$tmp = explode(',', $ip);
$ip = trim($tmp[0]);
}
} else {
$ip = getenv("REMOTE_ADDR");
}
return $ip;
}
function paylithBankGenerateHash(
string $apiKey,
string $apiSecret,
string $conversationId,
string $userId,
string $userEmail,
string $userIpAddress
) {
$hashStr = [
'apiKey' => $apiKey,
'conversationId' => $conversationId,
'userEmail' => $userEmail,
'userId' => $userId,
'userIpAddress' => $userIpAddress,
];
$hash = hash_hmac('sha256', implode('|', $hashStr) . $apiSecret, $apiKey);
return hash_hmac('md5', $hash, $apiKey);
}
function paylithBankSendRequest(array $payload)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.paylith.com/v1/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
curl_setopt($ch, CURLOPT_SSLVERSION, 6); // Force TLSv1.2
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}