/
tiki-payment.php
212 lines (183 loc) · 6.3 KB
/
tiki-payment.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: tiki-payment.php 51201 2014-05-09 16:53:50Z lphuberdeau $
// Data sent by the IPN must be left unharmed
if ( isset( $_GET['ipn'] ) ) {
$ipn_data = $_POST;
}
$inputConfiguration = array(
array(
'staticKeyFilters' => array(
'amount' => 'text',
'manual_amount' => 'text',
'description' => 'text',
'request' => 'alpha',
'payable' => 'digits',
'offset_outstanding' => 'digits',
'offset_overdue' => 'digits',
'offset_past' => 'digits',
'offset_canceled' => 'digits',
'invoice' => 'digits',
'cancel' => 'digits',
'note' => 'striptags',
'detail' => 'wikicontent',
'cclite_payment_amount' => 'text', // params for cart module
'tiki_credit_amount' => 'text',
'tiki_credit_pay' => 'text',
'tiki_credit_type' => 'text',
'checkout' => 'text',
'update' => 'word',
'daconfirm' => 'word', // ticketlib
'ticket' => 'word',
'returnurl' => 'url',
),
'staticKeyFiltersForArrays' => array('cart' => 'digits',), // params for cart module
'catchAllUnset' => null,
)
);
require_once 'tiki-setup.php';
require_once 'lib/categories/categlib.php';
require_once 'lib/payment/paymentlib.php';
$access->check_feature('payment_feature');
$auto_query_args = array(
'offset_outstanding',
'offset_overdue',
'offset_past',
'offset_canceled',
);
if ( isset($_POST['tiki_credit_pay'])
&& isset($_POST['tiki_credit_amount'])
&& isset($_POST['tiki_credit_type'])
&& isset($_POST['invoice'])
) {
require_once 'lib/payment/creditspaylib.php';
$userpaycredits = new UserPayCredits;
$userpaycredits->payAmount($_POST['tiki_credit_type'], $_POST['tiki_credit_amount'], $_POST['invoice']);
}
if ( isset($ipn_data) ) {
$access->check_feature('payment_paypal_ipn');
require_once 'lib/payment/paypallib.php';
$invoice = $paypallib->get_invoice($ipn_data);
if (!is_numeric($invoice) || $invoice < 1) {
echo 'Payment response was not correctly formatted'; // goes back to PayPal server - for debugging mainly
exit;
}
$info = $paymentlib->get_payment($invoice);
// Important to check with paypal first
if (isset($info) && $paypallib->is_valid($ipn_data, $info)) {
$amount = $paypallib->get_amount($ipn_data);
$paymentlib->enter_payment($invoice, $amount, 'paypal', $ipn_data);
} else {
echo 'Payment '.$invoice.' was not verified'; // goes back to PayPal server
exit;
}
exit;
}
if ($prefs['payment_system'] == 'israelpost' && isset($_GET['invoice']) && $jitGet->OKauthentication->word()) {
$gateway = $paymentlib->gateway('israelpost');
// Return URL - check payment right away through APIs
$id = $_GET['invoice'];
$verified = $gateway->check_payment($id, $jitGet, $jitPost);
if ($verified) {
$access->redirect('tiki-payment.php?invoice=' . $id, tra('Payment has been confirmed.'));
} else {
$access->redirect('tiki-payment.php?invoice=' . $id, tra('Payment confirmation has not been received yet.'));
}
}
if ( isset( $_POST['manual_amount'], $_POST['invoice'] ) && preg_match('/^\d+(\.\d{2})?$/', $_POST['manual_amount']) ) {
$objectperms = Perms::get('payment', $_REQUEST['invoice']);
if ( $objectperms->payment_manual ) {
$paymentlib->enter_payment(
$_POST['invoice'],
$_POST['manual_amount'],
'user',
array(
'user' => $user,
'note' => $_POST['note'],
)
);
if (isset($_POST['returnurl'])) {
header('Location: ' . $_POST['returnurl']);
exit;
}
$access->redirect('tiki-payment.php?invoice=' . $_POST['invoice'], tra('Manual payment entered.'));
} else {
$access->redirect('tiki-payment.php?invoice=' . $_POST['invoice'], tra('You do not have permission to enter payment.'));
}
}
if ( isset($_POST['request']) && $globalperms->request_payment ) {
// Create new payment request
if ( ! empty($_POST['description']) && preg_match('/^\d+(\.\d{2})?$/', $_POST['amount']) && $_POST['payable'] > 0 ) {
$id = $paymentlib->request_payment($_POST['description'], $_POST['amount'], (int) $_POST['payable'], $_POST['detail']);
if ( $prefs['feature_categories'] == 'y' ) {
$cat_objid = $id;
$cat_type = 'payment';
$cat_desc = $_POST['description'];
$cat_name = $_POST['description'];
$cat_href = 'tiki-payment.php?invoice=' . $id;
require 'categorize.php';
}
$access->redirect('tiki-payment.php?invoice=' . $id, tra('New payment requested.'));
}
}
if ( isset($_REQUEST['cancel']) ) {
$objectperms = Perms::get('payment', $_REQUEST['cancel']);
$info = $paymentlib->get_payment($_REQUEST['cancel']);
if ( $objectperms->payment_admin || $info['user'] == $user ) {
$access->check_authenticity(tr('Cancel payment %0?', $_REQUEST['cancel']));
$paymentlib->cancel_payment($_REQUEST['cancel']);
$access->redirect('tiki-payment.php?invoice=' . $_REQUEST['cancel'], tra('Payment canceled.'));
}
}
// Obtain information
/**
* @param $type
*/
function fetch_payment_list($type)
{
global $paymentlib, $globalperms, $user, $prefs, $smarty;
$offsetKey = 'offset_' . $type;
$method = 'get_' . $type;
$offset = isset($_REQUEST[$offsetKey]) ? intval($_REQUEST[$offsetKey]) : 0;
$max = intval($prefs['maxRecords']);
$forUser = '';
if (!$globalperms->payment_admin
&& (
($type == 'outstanding' || $type == 'overdue')
&& $prefs['payment_user_only_his_own'] == 'y'
|| $type != 'outstanding'
&& $type != 'overdue'
&& $prefs['payment_user_only_his_own_past'] == 'y'
)
) {
$forUser = $user;
}
$data = $paymentlib->$method($offset, $max, $forUser);
$data['offset'] = $offset;
$data['offset_arg'] = "offset_$type";
$data['max'] = $max;
$smarty->assign($type, $data);
}
if ( $prefs['feature_categories'] == 'y' && $globalperms->payment_request ) {
$cat_type = 'payment';
$cat_objid = '';
$cat_object_exists = false;
$smarty->assign('section', 'payment');
require 'categorize_list.php';
}
if ( isset($_REQUEST['invoice']) ) {
$smarty->assign('invoice', $_REQUEST['invoice']);
}
fetch_payment_list('outstanding');
fetch_payment_list('overdue');
fetch_payment_list('past');
fetch_payment_list('canceled');
fetch_payment_list('authorized');
$smarty->assign('mid', 'tiki-payment.tpl');
$smarty->display('tiki.tpl');