|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class mun extends Controller { |
|
4
|
|
|
|
|
5
|
|
|
public function __construct() { |
|
6
|
|
|
$this->load_library('auth_lib', 'auth'); |
|
7
|
|
|
$this->auth->force_authentication(); |
|
|
|
|
|
|
8
|
|
|
$this->load_model('contest_model', 'model'); |
|
9
|
|
|
load_helper('validations'); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
private function get_mun_payment_url($nick, $phone, $team_size, $needs_accomodation) { |
|
13
|
|
|
global $payment_cfg; |
|
14
|
|
|
|
|
15
|
|
|
$proxy = 'http://proxy.iiit.ac.in:8080'; |
|
16
|
|
|
$user_details = $this->auth->get_user_details(); |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
$name = $user_details['name']; |
|
19
|
|
|
$email = $user_details['mail']; |
|
20
|
|
|
|
|
21
|
|
|
$url = $payment_cfg['mun']['api_url']; |
|
22
|
|
|
$api_headers = $payment_cfg['mun']['api_headers']; |
|
23
|
|
|
$purpose = $payment_cfg['mun']['purpose']; |
|
24
|
|
|
$amount = $payment_cfg['mun']['amount'] * $team_size; |
|
25
|
|
|
if ($needs_accomodation) |
|
26
|
|
|
$amount = $amount + $payment_cfg['mun']['accomodation_amount'] * $team_size; |
|
27
|
|
|
$redirect_url = $payment_cfg['mun']['redirect_url']; |
|
28
|
|
|
$webhook = $payment_cfg['mun']['webhook']; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$ch = curl_init(); |
|
31
|
|
|
|
|
32
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
33
|
|
|
curl_setopt($ch, CURLOPT_PROXY, $proxy); |
|
34
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false); |
|
35
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
36
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
37
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $api_headers); |
|
38
|
|
|
$payload = array( |
|
39
|
|
|
'purpose' => $purpose, |
|
40
|
|
|
'amount' => $amount, |
|
41
|
|
|
'phone' => $phone, |
|
42
|
|
|
'buyer_name' => $name, |
|
43
|
|
|
'redirect_url' => base_url() . $redirect_url, |
|
44
|
|
|
//'webhook' => base_url() . $webhook, |
|
45
|
|
|
'email' => $email, |
|
46
|
|
|
'allow_repeated_payments' => false |
|
47
|
|
|
); |
|
48
|
|
|
curl_setopt($ch, CURLOPT_POST, true); |
|
49
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload)); |
|
50
|
|
|
$response = curl_exec($ch); |
|
51
|
|
|
curl_close($ch); |
|
52
|
|
|
|
|
53
|
|
|
$response_array = json_decode($response, true); |
|
54
|
|
|
return $response_array['payment_request']['longurl']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function register() { |
|
58
|
|
|
$user_nick = $this->auth->get_user(); |
|
|
|
|
|
|
59
|
|
|
global $payment_cfg; |
|
60
|
|
|
$user_details = $this->model->is_registered_for_mun($user_nick); |
|
|
|
|
|
|
61
|
|
|
$errors = []; |
|
62
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$user_details) { |
|
63
|
|
|
required_post_params(['contact_number', 'institute', 'team_size'], $errors); |
|
64
|
|
View Code Duplication |
if (!empty($_POST['contact_number']) && !is_valid_phone_number($_POST['contact_number']) ) { |
|
|
|
|
|
|
65
|
|
|
$errors['contact_number'] = 'Please enter a valid phone number'; |
|
66
|
|
|
} |
|
67
|
|
|
if (!ctype_digit($_POST['team_size'])) { |
|
68
|
|
|
$errors['team_size'] = 'Please enter a number'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$team_size = intval($_POST['team_size']); |
|
72
|
|
|
$needs_accomodation = (int) (isset($_POST['needs_accomodation']) && $_POST['needs_accomodation'] == 'yes'); |
|
73
|
|
|
|
|
74
|
|
|
if (!$errors) { |
|
75
|
|
|
$user_details = [ |
|
76
|
|
|
'nick' => $user_nick, |
|
77
|
|
|
'contact_number' => $_POST['contact_number'], |
|
78
|
|
|
'institute' => $_POST['institute'], |
|
79
|
|
|
'team_size' => $team_size, |
|
80
|
|
|
'needs_accomodation' => $needs_accomodation, |
|
81
|
|
|
]; |
|
82
|
|
|
if ($this->model->register_for_mun($user_details)) { |
|
83
|
|
|
$redirect_url = $this->get_mun_payment_url($user_nick, $_POST['contact_number'], $team_size, $needs_accomodation); |
|
84
|
|
|
$this->load_library('http_lib', 'http'); |
|
85
|
|
|
$this->http->redirect( $redirect_url ); |
|
|
|
|
|
|
86
|
|
|
} else { |
|
87
|
|
|
$errors['common'] = __('Some unexpected error occurred'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
$this->load_view('skeleton_template/header', [ |
|
92
|
|
|
'title' => __('Register').' · '.__('MUN'), |
|
93
|
|
|
'is_authenticated' => true, |
|
94
|
|
|
'user_nick' => $user_nick, |
|
95
|
|
|
]); |
|
96
|
|
|
|
|
97
|
|
|
$this->load_view('contest/mun', [ |
|
98
|
|
|
'user_nick' => $user_nick, |
|
99
|
|
|
'user_details' => $user_details, |
|
100
|
|
|
'errors' => $errors |
|
101
|
|
|
]); |
|
102
|
|
|
$this->load_view('skeleton_template/footer'); |
|
103
|
|
|
$this->load_view('skeleton_template/buttons_hide'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
View Code Duplication |
public function pay_again() { |
|
|
|
|
|
|
107
|
|
|
$user_nick = $this->auth->get_user(); |
|
|
|
|
|
|
108
|
|
|
global $payment_cfg; |
|
109
|
|
|
$user_details = $this->model->is_registered_for_mun($user_nick); |
|
|
|
|
|
|
110
|
|
|
if ($user_details && $user_details['payment_status'] != 'success') { |
|
111
|
|
|
$redirect_url = $this->get_mun_payment_url($user_nick, $user_details['contact_number'], |
|
112
|
|
|
$user_details['team_size'], $user_details['needs_accomodation']); |
|
113
|
|
|
$this->load_library('http_lib', 'http'); |
|
114
|
|
|
$this->http->redirect($redirect_url); |
|
|
|
|
|
|
115
|
|
|
} else { |
|
116
|
|
|
$this->load_library('http_lib', 'http'); |
|
117
|
|
|
$this->http->redirect(base_url() . "talks-and-workshops/mun/register/"); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
View Code Duplication |
public function success() { |
|
|
|
|
|
|
122
|
|
|
$this->load_library('http_lib', 'http'); |
|
123
|
|
|
if (!isset($_GET['payment_id'])) { |
|
124
|
|
|
$this->http->response_code( 400 ); |
|
|
|
|
|
|
125
|
|
|
exit(); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
global $payment_cfg; |
|
128
|
|
|
$proxy = 'http://proxy.iiit.ac.in:8080'; |
|
129
|
|
|
|
|
130
|
|
|
$nick = $this->auth->get_user(); |
|
|
|
|
|
|
131
|
|
|
$id = urlencode($_GET['payment_request_id']); |
|
132
|
|
|
$payment_id = urlencode($_GET['payment_id']); |
|
133
|
|
|
$url = $payment_cfg['mun']['api_url'] . $id . '/' . $payment_id . '/'; |
|
134
|
|
|
$api_headers = $payment_cfg['mun']['api_headers']; |
|
135
|
|
|
|
|
136
|
|
|
$ch = curl_init(); |
|
137
|
|
|
|
|
138
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
139
|
|
|
curl_setopt($ch, CURLOPT_PROXY, $proxy); |
|
140
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false); |
|
141
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
142
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
143
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $api_headers); |
|
144
|
|
|
$response = curl_exec($ch); |
|
145
|
|
|
curl_close($ch); |
|
146
|
|
|
$response_array = json_decode($response, true); |
|
147
|
|
|
|
|
148
|
|
|
if (@$response_array['success']) { |
|
149
|
|
|
$status = $response_array['payment_request']['payment']['status']; |
|
150
|
|
|
$payment_id = $_GET['payment_id']; |
|
151
|
|
|
$payment_data = $response; |
|
152
|
|
|
$this->model->mun_payment_success($payment_id, $nick, $status == 'Credit' ? 'success' : 'failed', $payment_data); |
|
|
|
|
|
|
153
|
|
|
} else { |
|
154
|
|
|
if ( is_array( $response_array ) ) { |
|
155
|
|
|
$this->model->mun_dump_data('unknown', 'callback', json_encode( [ '$_GET' => $_GET, 'response' => $response_array ] )); |
|
156
|
|
|
} else { |
|
157
|
|
|
$this->model->mun_dump_data('unknown', 'callback', json_encode($_GET)); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
$this->http->redirect(base_url() . "talks-and-workshops/mun/register/"); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
View Code Duplication |
public function webhook() { |
|
|
|
|
|
|
164
|
|
|
global $payment_cfg; |
|
165
|
|
|
|
|
166
|
|
|
if (isset($_POST['custom_fields'][$nick_field])) { |
|
|
|
|
|
|
167
|
|
|
$nick = $_POST['custom_fields'][$nick_field]['value']; |
|
168
|
|
|
$this->model->mun_dump_data($nick, 'webhook', json_encode($_POST)); |
|
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|