-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjibimo.php
170 lines (159 loc) · 7.45 KB
/
jibimo.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/*
- Author : Hamidreza shooshtari
- Module Designed For The : jibimo.com
- Mail : Hamidrezashoshtari84@gamil.com
*/
use WHMCS\Database\Capsule;
if(isset($_REQUEST['invoiceId']) && is_numeric($_REQUEST['invoiceId'])){
require_once __DIR__ . '/../../init.php';
require_once __DIR__ . '/../../includes/gatewayfunctions.php';
require_once __DIR__ . '/../../includes/invoicefunctions.php';
$gatewayParams = getGatewayVariables('jibimo');
if(isset($_REQUEST['trx'], $_REQUEST['hash'], $_REQUEST['callback'])){
$invoice = Capsule::table('tblinvoices')->where('id', $_REQUEST['invoiceId'])->where('status', 'Unpaid')->first();
if(!$invoice){
die("Invoice not found");
}
$client = Capsule::table('tblclients')->where('id', $_SESSION['uid'])->first();
$client_number = "+98".str_replace(array('-', '(', ')', '.', ',', '+', ' '),null,substr($client->phonenumber,3,15));
$response = jibimo_request('https://api.jibimo.com/v2/ipg/verify', [
'trx' => $_GET['trx']
]);
if(isset($response['status'])){
if($response['status'] == 1){
if ($response['mobile_number'] == $client_number) {
$amount = $response['amount'] / ($gatewayParams['currencyType'] == 'IRT' ? 10 : 1);
$hash = sha1($invoice->id . $response['amount'] . ($gatewayParams['testMode'] == 'on' ? 'test' : $gatewayParams['apiToken']));
if ($_REQUEST['hash'] == $hash) {
logTransaction($gatewayParams['name'], $_REQUEST, 'Success');
addInvoicePayment(
$invoice->id,
$response['tracking_id'],
$amount,
$response['date'],
'jibimo'
);
} else {
logTransaction($gatewayParams['name'], array(
'Code' => 'Invalid Amount',
'Message' => 'رقم تراكنش با رقم پرداخت شده مطابقت ندارد',
'Transaction' => $response['tracking_id'],
'Invoice' => $invoice->id,
'Amount' => $amount,
), 'Failure');
}
}
} else {
logTransaction($gatewayParams['name'], array(
'Code' => isset($response['state_code']) ? $response['state_code'] : 'Verify',
'Message' => isset($response['errorMessage']) ? $response['errorMessage'] : 'در ارتباط با وب سرویس api.jibimo.com خطایی رخ داده است',
'Transaction' => $response['transId'],
'Invoice' => $invoice->id,
), 'Failure');
}
header('Location: ' . $gatewayParams['systemurl'] . '/viewinvoice.php?id=' . $invoice->id);
}
} else if(isset($_SESSION['uid'])){
$invoice = Capsule::table('tblinvoices')->where('id', $_REQUEST['invoiceId'])->where('status', 'Unpaid')->where('userid', $_SESSION['uid'])->first();
if(!$invoice){
die("Invoice not found");
}
$client = Capsule::table('tblclients')->where('id', $_SESSION['uid'])->first();
$client_number = "+98".str_replace(array('-', '(', ')', '.', ',', '+', ' '),null,substr($client->phonenumber,3,15));
$hash = sha1($invoice->id . ($invoice->total * ($gatewayParams['currencyType'] == 'IRT' ? 10 : 1)) . ($gatewayParams['testMode'] == 'on' ? 'test' : $gatewayParams['apiToken']));
if($gatewayParams['testMode'] == 'on'){ $mobile_number = true; }else{ $mobile_number = false; }
$response = jibimo_request('https://api.jibimo.com/v2/ipg/request', [
'amount' => intval($invoice->total * ($gatewayParams['currencyType'] == 'IRT' ? 10 : 1)),
'return_url' => $gatewayParams['systemurl'] . '/modules/gateways/jibimo.php?invoiceId=' . $invoice->id . '&callback=1&hash=' . $hash,
'mobile_number' => $client_number,
'check_national_code' => $mobile_number,
]);
print_r($response);
echo "<br>".$client_number."<br>";
if($response !== false){
if(isset($response['trx'])){
header("Location: {$response['link']}");
} else {
$text = 'اتصال به درگاه پرداخت ناموفق بود.';
$text .= '<br />';
$text .= 'متن خطا: %s';
echo sprintf($text, $response['errors']['token']);
}
} else {
echo 'اتصال به درگاه امکان پذیر نیست.';
}
}
return;
}
if (!defined('WHMCS')) {
die('This file cannot be accessed directly');
}
function jibimo_request($url, $params)
{
global $gatewayParams;
$header = [
'Content-Type: application/json',
'Accept: application/json',
'API-KEY: ' . $gatewayParams['apiToken'],
];
$handler = curl_init();
curl_setopt($handler, CURLOPT_HTTPHEADER, $header);
curl_setopt($handler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($handler, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($handler, CURLOPT_URL, $url);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, True);
curl_setopt($handler, CURLOPT_POST, True);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handler, CURLOPT_VERBOSE, true);
$result = curl_exec($handler);
$info = curl_getinfo($handler);
if (!$result) {
return false;
}
return json_decode($result, true);
}
function jibimo_MetaData()
{
return array(
'DisplayName' => 'ماژول پرداخت آنلاین api.jibimo.com برای WHMCS',
'APIVersion' => '1.0',
);
}
function jibimo_config()
{
return array(
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'جیبیمو',
),
'currencyType' => array(
'FriendlyName' => 'نوع ارز',
'Type' => 'dropdown',
'Options' => array(
'IRR' => 'ریال',
'IRT' => 'تومان',
),
),
'apiToken' => array(
'FriendlyName' => 'کد API',
'Type' => 'text',
'Size' => '255',
'Default' => '',
'Description' => 'کد api دریافتی از سایت api.jibimo.com',
),
'testMode' => array(
'FriendlyName' => 'برسی شماره موبایل',
'Type' => 'yesno',
'Description' => 'برای فعال کردن همخوانی شماره موبایل و حساب تیک بزنید',
),
);
}
function jibimo_link($params)
{
$htmlOutput = '<form method="GET" action="modules/gateways/jibimo.php">';
$htmlOutput .= '<input type="hidden" name="invoiceId" value="' . $params['invoiceid'] .'">';
$htmlOutput .= '<input type="submit" value="' . $params['langpaynow'] . '" />';
$htmlOutput .= '</form>';
return $htmlOutput;
}