-
Notifications
You must be signed in to change notification settings - Fork 15
/
simpledonate.php
316 lines (288 loc) · 11.2 KB
/
simpledonate.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
require_once 'simpledonate.civix.php';
/**
* Implementation of hook_civicrm_config
*/
function simpledonate_civicrm_config(&$config) {
_simpledonate_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_xmlMenu
*
* @param $files array(string)
*/
function simpledonate_civicrm_xmlMenu(&$files) {
_simpledonate_civix_civicrm_xmlMenu($files);
}
function simpledonate_civicrm_navigationMenu(&$navMenu) {
$pages = array(
'admin_page' => array(
'label' => 'Simple Donation Pages',
'name' => 'Simple Donation Pages',
'url' => 'civicrm/simple/donation/pages?reset=1',
'permission'=> 'access CiviContribute',
'parent' => array('Contributions'),
'operator' => 'AND',
'separator' => NULL,
'active' => 1
),
'settings_page' => array(
'label' => 'Simple Donate Configuration',
'name' => 'Simple Donate Configuration',
'url' => 'civicrm/simple/donation/configuration?reset=1',
//'url' => 'civicrm/admin/contribute/simpledonate',
//'permission'=> 'access CiviContribute',
'permission' => 'access CiviContribute,administer CiviCRM',
'parent' => array('Administer','CiviContribute'),
'operator' => 'AND',
'separator' => NULL,
'active' => 1
),
);
foreach($pages as $item) {
// Check that our item doesn't already exist
if (empty($item['url'])) {
$menu_item_search = array('name' => $item['name']);
} else {
$menu_item_search = array('url' => $item['url']);
}
$menu_items = array();
CRM_Core_BAO_Navigation::retrieve($menu_item_search, $menu_items);
if (empty($menu_items)) {
$path = implode('/',$item['parent']);
unset($item['parent']);
_simpledonate_civix_insert_navigation_menu($navMenu, $path, $item);
}
}
}
/**
* Implementation of hook_civicrm_install
*/
function simpledonate_civicrm_install() {
return _simpledonate_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_uninstall
*/
function simpledonate_civicrm_uninstall() {
$query = "DELETE FROM civicrm_navigation WHERE name in ('Simple Donate','Simple Donate Configuration')";
CRM_Core_DAO::executeQuery($query);
return _simpledonate_civix_civicrm_uninstall();
}
/**
* Implementation of hook_civicrm_enable
*/
function simpledonate_civicrm_enable() {
$sql = "UPDATE civicrm_navigation SET is_active=1 WHERE name IN ('Simple Donate Configuration', 'Simple Donate', 'Test Donation', 'Live Donation')";
CRM_Core_DAO::executeQuery($sql);
return _simpledonate_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_disable
*/
function simpledonate_civicrm_disable() {
$sql = "UPDATE civicrm_navigation SET is_active=0 WHERE name IN ('Simple Donate Configuration', 'Simple Donate', 'Test Donation', 'Live Donation')";
CRM_Core_DAO::executeQuery($sql);
return _simpledonate_civix_civicrm_disable();
}
/**
* Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*/
function simpledonate_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _simpledonate_civix_civicrm_upgrade($op, $queue);
}
/**
* Implementation of hook_civicrm_managed
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*/
function simpledonate_civicrm_managed(&$entities) {
return _simpledonate_civix_civicrm_managed($entities);
}
/**
* Implementation of hook_civicrm_caseTypes
*
* Generate a list of case-types
*
* Note: This hook only runs in CiviCRM 4.4+.
*/
function simpledonate_civicrm_caseTypes(&$caseTypes) {
_simpledonate_civix_civicrm_caseTypes($caseTypes);
}
/**
* Implementation of hook_civicrm_alterSettingsFolders
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
*/
function simpledonate_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
_simpledonate_civix_civicrm_alterSettingsFolders($metaDataFolders);
}
function simpledonate_civicrm_pageRun(&$page) {
$session = CRM_Core_Session::singleton();
$pageName = $page->getVar('_name');
if ($pageName == 'Civi\Angular\Page\Main' && $page->urlPath[1] == 'simple') {
//Get all contribution page detils and session details to be used in js
$settingVal = CRM_SimpleDonate_Page_SimpleDonationPage::getSimpleDonateSetting();
$settingVal['donatePageID'] = $session->get('pageId');
$session = CRM_Core_Session::singleton();
$tempID = CRM_Utils_Request::retrieve('cid', 'Positive');
//check if this is a checksum authentication
$userChecksum = CRM_Utils_Request::retrieve('cs', 'String');
if ($userChecksum) {
//check for anonymous user.
$validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($tempID, $userChecksum);
if ($validUser) {
$contactID = $tempID;
}
} else {
$contactID = $session->get('userID');
}
if ($settingVal['donatePageID']) {
$extends = CRM_Core_Component::getComponentID('CiviContribute');
$priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $settingVal['donatePageID'], $extends);
$priceField = civicrm_api3('PriceField', 'get', array("price_set_id" => $priceSetID));
//Check for is_quick_config
$isQuickConfig = civicrm_api3('PriceSet', 'getvalue', array(
'id' => $priceSetID,
'return' => "is_quick_config",
));
//Check for Other amount
$otherAmount = FALSE;
foreach($priceField['values'] as $key => $value) {
if ($value['name'] == 'other_amount') {
$otherAmount = TRUE;
}
else {
$priceFieldVal = civicrm_api3('PriceFieldValue', 'get', array('return' => "amount, title, name, is_default","price_field_id"=> $value['id'], 'is_active' => 1));
$priceList = $priceFieldVal['values'];
$htmlPriceList[$value['html_type']] = $priceFieldVal['values'];
}
}
//Get donation page details
$donateConfig = $donatePage = civicrm_api3('ContributionPage', 'getsingle', array(
'id' => $settingVal['donatePageID'],
));
CRM_Utils_System::setTitle($donateConfig['title']); // Set the page title
$currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $donatePage['currency'], 'symbol', 'name');
// Check for test or live donation
if (!empty($page->urlPath[2]) && $page->urlPath[2] === 'test') {
$test = 'test';
}
else {
$test = 'live';
}
//Get donation page details
$donateConfig = $donatePage = civicrm_api3('ContributionPage', 'getsingle', array(
'id' => $settingVal['donatePageID'],
));
CRM_Utils_System::setTitle($donateConfig['title']); // Set the page title
$currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $donatePage['currency'], 'symbol', 'name');
$paymentProcessors = simpledonate_civicrm_get_payment_processors($donatePage['payment_processor'], $test, $donateConfig);
//set Country and State value
$config = CRM_Core_Config::singleton();
$defaultContactCountry = $config->defaultContactCountry;
$stateProvince = array_flip(CRM_Core_PseudoConstant::stateProvinceForCountry($defaultContactCountry));
$countryList = CRM_Core_PseudoConstant::country();
$stateList = array();
foreach($countryList as $key => $val) {
$stateList[$key] = CRM_Core_PseudoConstant::stateProvinceForCountry($key);
}
CRM_Core_Resources::singleton()->addSetting(array(
'simpledonate' => array(
'sessionContact' => $contactID,
'priceSetID' => $priceSetID,
'ziptasticEnable' => $settingVal['ziptasticEnable'],
'countryList' => CRM_Core_PseudoConstant::country(),
'stateList' => $stateList,
'country' => $defaultContactCountry,
'allStates' => $stateProvince,
'currency' => $currencySymbol,
'config' => $donateConfig,
'paymentProcessor' => $paymentProcessors,
'priceList' => empty($priceList) ? NULL : $priceList,
'otherAmount' => $otherAmount,
'isTest' => ($test == 'test') ? 1 : 0,
'htmlPriceList' => empty($priceList) ? NULL :$htmlPriceList,
'isQuickConfig' => $isQuickConfig,
'donatePageId' => $settingVal['donatePageID'],
),
));
//Include bootstrap and custom css files to affect this angular page only
CRM_Core_Resources::singleton()->addStyleFile('com.webaccessglobal.simpledonate', 'css/bootstrap.min.css', 103, 'page-header');
CRM_Core_Resources::singleton()->addStyleFile('com.webaccessglobal.simpledonate', 'css/simpledonate.css', 100, 'page-body');
CRM_Core_Resources::singleton()->addScriptFile('com.webaccessglobal.simpledonate', 'js/libs/bootstrap.min.js', 100, 'html-header');
}
if ($contactID) {
$id = array('id' => $contactID);
$result = civicrm_api3('Contact', 'getSingle', $id);
CRM_Core_Resources::singleton()->addSetting(array(
'simpledonateVal' => $result,
));
}
}
}
/**
* @param $angularModule
*/
function simpledonate_civicrm_angularModules(&$angularModule) {
$angularModule['simpledonate'] = array(
'ext' => 'com.webaccessglobal.simpledonate',
'js' => array(
'js/simpledonate.js',
'js/libs/parsley.min.js',
'js/libs/jquery.ziptastic.js',
'js/libs/modernizr.js',
//'js/libs/jquery.inputmask.js',
'js/libs/jquery.inputmask.bundle.min.js',
//'js/libs/jquery.inputmaskDate.extensions.js',
)
);
}
/**
* Get live and/or test payment processor based on live paymentProcessorId.
* Fixes bugs in civicrm getPayment function.
*
* Passing test to getPayment will always return NULL to CiviCRM bug.
*
* PaymentProcessor Ids via the Donate Page Config are always live.
*
* Deal with getting the test processor during transaction processing.
*
* @param $paymentProcessorIds
* @param $mode
* @param $donateConfig
*/
function simpledonate_civicrm_get_payment_processors($paymentProcessorIDs, $mode, $donateConfig) {
//Get payment processor details
if (!$paymentProcessorIDs) {
CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
}
if (is_array($paymentProcessorIDs)) {
$payments = array( );
foreach ($paymentProcessorIDs as $paymentProcessorID) {
$payment = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID);
$payments[$payment['id']] = $payment;
}
asort($payments);
$paymentProcessors = $payments;
}
else {
$paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorIDs);
$paymentProcessors[$paymentProcessor['id']] = $paymentProcessor;
$paymentProcessors[$paymentProcessor['id']]['hide'] = $donateConfig['is_pay_later'] ? FALSE : TRUE;
}
//Only use paymentProcessors of billing_mode type FORM
foreach ($paymentProcessors as $id => $payment) {
if ($payment['billing_mode'] != CRM_Core_Payment::BILLING_MODE_FORM) {
unset ($paymentProcessors[$id]);
}
}
return $paymentProcessors;
}