| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
/**
|
| 4 |
*
|
| 5 |
* @file
|
| 6 |
* The Payment control system for Drupal.
|
| 7 |
* @author: Heshan Wanigasooriya (heshan@heidisoft.com)
|
| 8 |
*
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_menu().
|
| 13 |
*/
|
| 14 |
function paycom_menu() {
|
| 15 |
global $user;
|
| 16 |
$items = array();
|
| 17 |
|
| 18 |
$items['admin/settings/paycom'] = array(
|
| 19 |
'title' => 'Paycom',
|
| 20 |
'page callback' => 'drupal_get_form',
|
| 21 |
'page arguments' => array('paycom_settings'),
|
| 22 |
'access arguments' => array('administer paycom'),
|
| 23 |
'type' => MENU_NORMAL_ITEM,
|
| 24 |
'description' => 'Configure Paycom payment gateway',
|
| 25 |
);
|
| 26 |
|
| 27 |
$items['paycom/postback'] = array(
|
| 28 |
'page callback' => 'paycom_postback',
|
| 29 |
'type' => MENU_CALLBACK,
|
| 30 |
);
|
| 31 |
|
| 32 |
$items['paycom/process'] = array(
|
| 33 |
'page callback' => 'paycom_process_transaction',
|
| 34 |
'type' => MENU_CALLBACK,
|
| 35 |
);
|
| 36 |
|
| 37 |
$items['user/'.$user->uid.'/upgrade'] = array(
|
| 38 |
'title' => 'Upgrade Membership',
|
| 39 |
'page callback' => 'drupal_get_form',
|
| 40 |
'page arguments' => array('paycom_form'),
|
| 41 |
'access arguments' => array('access upgrade page'),
|
| 42 |
'type' => MENU_LOCAL_TASK,
|
| 43 |
);
|
| 44 |
|
| 45 |
$items['upgrade'] = array(
|
| 46 |
'title' => 'Upgrade Membership',
|
| 47 |
'page callback' => 'drupal_get_form',
|
| 48 |
'page arguments' => array('paycom_form'),
|
| 49 |
'access arguments' => array('access upgrade page'),
|
| 50 |
'type' => MENU_CALLBACK,
|
| 51 |
);
|
| 52 |
|
| 53 |
return $items;
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Implementation of hook_help().
|
| 58 |
*/
|
| 59 |
function paycom_help($path, $arg ) {
|
| 60 |
switch ($section) {
|
| 61 |
case 'admin/paycom':
|
| 62 |
return t("This module is intended to help experienced you to set up your web site to connect to Epoch payment gateway using the new FlexPost Interface.<br/>You need to have an account with Paycom in order to use this module. Click <a href=\"http://epoch.com\">here</a> for more information.");
|
| 63 |
}
|
| 64 |
}
|
| 65 |
|
| 66 |
/**
|
| 67 |
* Implementation of hook_settings().
|
| 68 |
*/
|
| 69 |
function paycom_settings() {
|
| 70 |
|
| 71 |
$form['paycom'] = array(
|
| 72 |
'#type' => 'fieldset',
|
| 73 |
'#title' => t('Paycom settings'),
|
| 74 |
'#description' => t('The customer will have this role as long as their Paycom account is in good standing.'),
|
| 75 |
);
|
| 76 |
|
| 77 |
$form['paycom']['paycom_role'] = array(
|
| 78 |
'#type' => 'select',
|
| 79 |
'#title' => t('Role assigned at purchase'),
|
| 80 |
'#default_value' => variable_get('paycom_role', ''),
|
| 81 |
'#options' => user_roles(1),
|
| 82 |
'#description' => t('The customer will have this role as long as their Paycom account is in good standing.'),
|
| 83 |
);
|
| 84 |
|
| 85 |
$form['paycom']['paycom_co_code'] = array(
|
| 86 |
'#type' => 'textfield',
|
| 87 |
'#title' => t('Company Code'),
|
| 88 |
'#default_value' => variable_get('paycom_co_code', ''),
|
| 89 |
'#size' => 10,
|
| 90 |
'#maxlength' => 20,
|
| 91 |
'#description' => t("Three character,unmodifiable alphanumeric company code assigned by Epoch"),
|
| 92 |
'#required' => TRUE,
|
| 93 |
);
|
| 94 |
|
| 95 |
$form['paycom']['paycom_reseller'] = array(
|
| 96 |
'#type' => 'textfield',
|
| 97 |
'#title' => t('Reseller code'),
|
| 98 |
'#default_value' => variable_get('paycom_reseller', 'a'),
|
| 99 |
'#size' => 10,
|
| 100 |
'#maxlength' => 10,
|
| 101 |
'#description' => t("Maximum length 10 characters. To enable EzTrack logic to determine the affiliate (reseller) code, set the reseller parameter to 'eztrack'."),
|
| 102 |
);
|
| 103 |
|
| 104 |
$form['paycom']['paycom_ach'] = array(
|
| 105 |
'#type' => 'checkbox',
|
| 106 |
'#title' => t('ACH'),
|
| 107 |
'#default_value' => variable_get('paycom_ach', ''),
|
| 108 |
'#description' => t('If this field is passed in it will enable online check (ACH) processing. Online check processing is only valid for US.'),
|
| 109 |
);
|
| 110 |
|
| 111 |
$form['paycom']['paycom_processing_url'] = array(
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#title' => t('Paycom processing URL'),
|
| 114 |
'#default_value' => variable_get('paycom_processing_url', 'https://wnu.com/secure/fpost.cgi'),
|
| 115 |
'#size' => 70,
|
| 116 |
'#maxlength' => 180,
|
| 117 |
'#description' => t('URL of the secure payment processing page.'),
|
| 118 |
);
|
| 119 |
|
| 120 |
$form['paycom']['paycom_handle_response'] = array(
|
| 121 |
'#type' => 'checkbox',
|
| 122 |
'#title' => t('Handle Response'),
|
| 123 |
'#default_value' => variable_get('paycom_handle_response', ''),
|
| 124 |
'#description' => t('This field will keep the customer on the FlexPost response page if the transaction is approved.'),
|
| 125 |
);
|
| 126 |
|
| 127 |
$form['paycom']['paycom_response_post'] = array(
|
| 128 |
'#type' => 'checkbox',
|
| 129 |
'#title' => t('Response Post'),
|
| 130 |
'#default_value' => variable_get('paycom_response_post', ''),
|
| 131 |
'#description' => t('If this field is passed in it will enable sending a data post back to the client.'),
|
| 132 |
);
|
| 133 |
|
| 134 |
$form['product'] = array(
|
| 135 |
'#type' => 'fieldset',
|
| 136 |
'#title' => t('Product settings'),
|
| 137 |
'#description' => t('Product id and details of the product.'),
|
| 138 |
);
|
| 139 |
$form['product']['product_packages'] = array(
|
| 140 |
'#type' => 'textfield',
|
| 141 |
'#title' => t('Product Ids ,Price and Duration'),
|
| 142 |
'#default_value' => variable_get('product_packages', ''),
|
| 143 |
'#size' => 100,
|
| 144 |
'#maxlength' => 180,
|
| 145 |
'#description' => t("Please enter product id,Price and the duration for a product, each set should separatd by comma.<br/> Eg: if <b>sfheu32m1ciBYrJ</b> and <b>24$</b> for <b>30</b> days you should enter <b>sfheu32m1ciBYrJ:24:30</b> (each separated by \":\") ."),
|
| 146 |
);
|
| 147 |
|
| 148 |
$form['message'] = array(
|
| 149 |
'#type' => 'fieldset',
|
| 150 |
'#title' => t('Message settings'),
|
| 151 |
);
|
| 152 |
$form['message']['message_content'] = array(
|
| 153 |
'#type' => 'textarea',
|
| 154 |
'#title' => t('Message to member'),
|
| 155 |
'#default_value' => variable_get('message_content', ''),
|
| 156 |
'#description' => t("Please enter message that should be displayed at the upgrade page."),
|
| 157 |
);
|
| 158 |
return system_settings_form($form);
|
| 159 |
}
|
| 160 |
|
| 161 |
/**
|
| 162 |
* Implementation of hook_perm().
|
| 163 |
*/
|
| 164 |
function paycom_perm() {
|
| 165 |
return array('administer paycom', 'access upgrade page');
|
| 166 |
}
|
| 167 |
|
| 168 |
|
| 169 |
function paycom_form_bkp() {
|
| 170 |
global $user;
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
//return $output;
|
| 177 |
}
|
| 178 |
|
| 179 |
|
| 180 |
/**
|
| 181 |
* Implementation of hook_form().
|
| 182 |
*/
|
| 183 |
function paycom_form() {
|
| 184 |
global $user;
|
| 185 |
//print_r($user);
|
| 186 |
$form['#action'] = variable_get('paycom_processing_url', '');
|
| 187 |
//user details ----------------------------
|
| 188 |
$form['user'] = array(
|
| 189 |
'#type' => 'fieldset',
|
| 190 |
'#title' => t('User Details'),
|
| 191 |
'#description' => t('Check your register informations.'),
|
| 192 |
);
|
| 193 |
$form['user']['name'] = array(
|
| 194 |
'#value' => t("<b>User Name</b> : $user->name"),
|
| 195 |
);
|
| 196 |
$form['user']['email'] = array(
|
| 197 |
'#value' => t("<br/><b>Email</b> : $user->mail"),
|
| 198 |
);
|
| 199 |
$accounts = $user->roles;
|
| 200 |
//$sf=',';
|
| 201 |
foreach ($accounts as $value) {
|
| 202 |
$account .= "$value,";
|
| 203 |
//$sf = ",";
|
| 204 |
}
|
| 205 |
$form['user']['account'] = array(
|
| 206 |
'#value' => t("<br/><b>Account Type</b> : $account"),
|
| 207 |
);
|
| 208 |
$status = ($user->status == 1)? "Active":"Not Active";
|
| 209 |
$form['user']['type'] = array(
|
| 210 |
'#value' => t("<br/><b>Status</b> : $status"),
|
| 211 |
);
|
| 212 |
|
| 213 |
//message details ----------------------------
|
| 214 |
$form['msg'] = array(
|
| 215 |
'#type' => 'fieldset',
|
| 216 |
'#title' => t('Message to Member'),
|
| 217 |
);
|
| 218 |
$form['msg']['name'] = array(
|
| 219 |
'#value' => variable_get('message_content', ''),
|
| 220 |
);
|
| 221 |
//hidden fields ------------------------------
|
| 222 |
$form['co_code'] = array(
|
| 223 |
'#type' => 'hidden',
|
| 224 |
'#value' => urlencode(variable_get('paycom_co_code', '')),
|
| 225 |
);
|
| 226 |
|
| 227 |
$form['product_id'] = array(
|
| 228 |
'#type' => 'hidden',
|
| 229 |
'#value' => urlencode($pid),
|
| 230 |
);
|
| 231 |
|
| 232 |
$form['reseller'] = array(
|
| 233 |
'#type' => 'hidden',
|
| 234 |
'#value' => urlencode(variable_get('paycom_reseller', 'a')),
|
| 235 |
);
|
| 236 |
|
| 237 |
$form['email'] = array(
|
| 238 |
'#type' => 'hidden',
|
| 239 |
'#value' => $user->mail,
|
| 240 |
);
|
| 241 |
|
| 242 |
$form['username'] = array(
|
| 243 |
'#type' => 'hidden',
|
| 244 |
'#value' => $user->name,
|
| 245 |
);
|
| 246 |
|
| 247 |
$form['no_userpass'] = array(
|
| 248 |
'#type' => 'hidden',
|
| 249 |
'#value' => TRUE,
|
| 250 |
);
|
| 251 |
|
| 252 |
if (variable_get('paycom_ach', 'false')) {
|
| 253 |
$form['ach_form'] = array(
|
| 254 |
'#type' => 'hidden',
|
| 255 |
'#value' => variable_get('paycom_ach', ''),
|
| 256 |
);
|
| 257 |
}
|
| 258 |
|
| 259 |
if (variable_get('paycom_handle_response', 'false')) {
|
| 260 |
$form['handle_response'] = array(
|
| 261 |
'#type' => 'hidden',
|
| 262 |
'#value' => variable_get('paycom_handle_response', ''),
|
| 263 |
);
|
| 264 |
}
|
| 265 |
|
| 266 |
if (variable_get('paycom_response_post', 'false')) {
|
| 267 |
$form['response_post'] = array(
|
| 268 |
'#type' => 'hidden',
|
| 269 |
'#value' => variable_get('paycom_response_post', ''),
|
| 270 |
);
|
| 271 |
}
|
| 272 |
//payment products--------------------------------------
|
| 273 |
$form['product'] = array(
|
| 274 |
'#type' => 'fieldset',
|
| 275 |
'#title' => t('Pricing Options'),
|
| 276 |
'#description' => t('IMPORTANT: After your signup is completed, please wait minimum 1 minute before trying to log in with your new password. The system needs this time to update all files.'),
|
| 277 |
);
|
| 278 |
$products = variable_get('product_packages', '');
|
| 279 |
$product_array = explode(",", $products);
|
| 280 |
$product_list = array();
|
| 281 |
|
| 282 |
for ($i=0;$i<sizeof($product_array);$i++) {
|
| 283 |
$product_buff = explode(":", $product_array[$i]);
|
| 284 |
if ($product_buff[2]==30) {
|
| 285 |
$moths =1;
|
| 286 |
}
|
| 287 |
else if ($product_buff[2]==60) {
|
| 288 |
$moths =2;
|
| 289 |
}
|
| 290 |
else if ($product_buff[2]==90) {
|
| 291 |
$moths =3;
|
| 292 |
}
|
| 293 |
$product_list[$product_buff[0]] = "Recurring: $$product_buff[1] for every $moths month(s)";
|
| 294 |
}
|
| 295 |
//print_r($product_list);
|
| 296 |
$form['product']['pi_code'] = array(
|
| 297 |
'#type' => 'select',
|
| 298 |
'#title' => t('Pricing options'),
|
| 299 |
'#options' => $product_list,
|
| 300 |
'#description' => t('Select a payment package to be a member and get access to all material.'),
|
| 301 |
);
|
| 302 |
|
| 303 |
|
| 304 |
$form['submit'] = array(
|
| 305 |
'#type' => 'submit',
|
| 306 |
'#value' => t('Secure Signup by credit card'),
|
| 307 |
);
|
| 308 |
|
| 309 |
return $form;
|
| 310 |
}
|
| 311 |
|
| 312 |
/**
|
| 313 |
* handle the paycompost back call().
|
| 314 |
*/
|
| 315 |
function paycom_postback() {
|
| 316 |
/*
|
| 317 |
----- Sample Response Query Strings ----
|
| 318 |
|
| 319 |
ans=[STATUS][APPROVE/DENY CODE][AVS CODE][CVV2CODE][BANK RESPONSE]|[MEMBER ID]&submit_count=[COUNT]&co_code=[COMPANY CODE]&pi_code=[PRODUCT CODE]&
|
| 320 |
ans2=[STATUS][APPROVE/DENY CODE][AVS CODE][CVV2CODE][BANK RESPONSE]|[MEMBER ID]&co_code2=[COMPANY CODE]&pi_code2=[PRODUCT CODE]&
|
| 321 |
ans3=[STATUS][APPROVE/DENY CODE][AVS CODE][CVV2CODE][BANK RESPONSE]|[MEMBER ID]&co_code3=[COMPANY CODE]&pi_code3=[PRODUCT CODE]&[PASS THRU FIELDS]
|
| 322 |
|
| 323 |
*/
|
| 324 |
//$username = $_POST['username'];
|
| 325 |
//$product_id = $_POST['pi_code'];
|
| 326 |
$ans = $_POST['ans'];
|
| 327 |
//watchdog('paycom', t("$ans and user $username and productid $product_id Received", array()), WATCHDOG_NOTICE);
|
| 328 |
|
| 329 |
// we can get the member id by spilitting by "|"
|
| 330 |
$member_id_split = explode("|", $ans);
|
| 331 |
$member_id = $member_id_split[1];
|
| 332 |
$product_id = $_POST['pi_code'];
|
| 333 |
$new_ans = $member_id_split[0];
|
| 334 |
$new_ans_buffer = str_split($new_ans);// split all elements
|
| 335 |
if ($new_ans_buffer[0] == "Y") {
|
| 336 |
if ($username = $_POST['username']) {
|
| 337 |
// change the days by the product id
|
| 338 |
$days =0;
|
| 339 |
$products = variable_get('product_packages', '');
|
| 340 |
$product_array = explode(",", $products);
|
| 341 |
$product_list = array();
|
| 342 |
for ($i=0;$i<sizeof($product_array);$i++) {
|
| 343 |
$product_buff = explode(":", $product_array[$i]);
|
| 344 |
$product_list[$product_buff[0]] = "$product_buff[2]";
|
| 345 |
}
|
| 346 |
$days = $product_list[$product_id];
|
| 347 |
$rid = variable_get('paycom_role', '');
|
| 348 |
|
| 349 |
if ($member = db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s'", $username))) {
|
| 350 |
$values = array('userid' => $member->uid, 'count' => $days, 'unit' => 'D');
|
| 351 |
db_query('INSERT INTO {paycom} (uid, product_id) VALUES (%d, %d )', $member->uid, $product_id);
|
| 352 |
//_upgrade_membership_to_premium($values,0); // Add the entry to the users_roles table
|
| 353 |
db_query("DELETE FROM {users_roles} WHERE uid = %d and rid=%d", $data['userid'], $role_id);
|
| 354 |
// Add the entry to the users_roles table
|
| 355 |
if (!db_fetch_object(db_query("SELECT * FROM {users_roles} WHERE uid = %d AND rid=%d", $data['userid'], $role_id))) {
|
| 356 |
if (db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $data['userid'], $role_id)) {
|
| 357 |
watchdog('Upgrade Member', 'Upgraded user(%user) to an VIP Member.', array('%user' => l($data['userid'], "user/".$data['userid'])));
|
| 358 |
}
|
| 359 |
}
|
| 360 |
watchdog('paycom', 'Upgraded %user to an Upgraded Membership as the result of a successful Paycom Transaction', array('%user' => l($member->name, "user/".$member->uid)));
|
| 361 |
//drupal_set_message("Script was not able to update any records as the email", 'error');
|
| 362 |
}
|
| 363 |
else {
|
| 364 |
watchdog('paycom', 'Script was not able to update any records as the username, %name, was not found in the database.', array('%name' => $username), WATCHDOG_ERROR);
|
| 365 |
//drupal_set_message("Upgraded Membership was success as the result of a successful Paycom Transaction", 'error');
|
| 366 |
}
|
| 367 |
|
| 368 |
}
|
| 369 |
//watchdog('paycom', t('Script was not able to update any records as the email, %email, was not found in the URL.', array('%email' => $email)), WATCHDOG_ERROR);
|
| 370 |
//drupal_set_message("Script was not able to update any records as the email", 'error');
|
| 371 |
|
| 372 |
}
|
| 373 |
else if ($new_ans_buffer[0] == "N") {
|
| 374 |
// to show error messages
|
| 375 |
$error_code = substr($new_ans, 1);
|
| 376 |
$error_msg = _show_paycom_errors($error_code);
|
| 377 |
watchdog('paycom', t("Paycom Error Received $error_msg.", array()), WATCHDOG_ERROR);
|
| 378 |
|
| 379 |
//drupal_set_message($error_msg, 'error');
|
| 380 |
}
|
| 381 |
//parameters should send in a array
|
| 382 |
//userid count - 7 unit - days D
|
| 383 |
/*
|
| 384 |
return $form;
|
| 385 |
*/
|
| 386 |
//$output .= "";
|
| 387 |
//print theme('page', $output);
|
| 388 |
|
| 389 |
}
|
| 390 |
// if the transaction is denied show the error message
|
| 391 |
function _show_paycom_errors($errcode) {
|
| 392 |
$errcode = trim($errcode);
|
| 393 |
switch ($errcode) {
|
| 394 |
case 'MYVSNOTACCEPTED':
|
| 395 |
$msg = 'VISA not accepted : Epoch';
|
| 396 |
break;
|
| 397 |
case 'DECLINEDCVV2':
|
| 398 |
$msg = 'Invalid CVV2:Bank';
|
| 399 |
break;
|
| 400 |
case 'CALLCENTER':
|
| 401 |
$msg = 'Bank Denial';
|
| 402 |
break;
|
| 403 |
case 'DECLINED':
|
| 404 |
$msg = 'Bank Denial';
|
| 405 |
break;
|
| 406 |
case 'DECLINEDINSFUNDS':
|
| 407 |
$msg = 'Bank Denial';
|
| 408 |
break;
|
| 409 |
case 'EXPIRED':
|
| 410 |
$msg = 'Bank Denial';
|
| 411 |
break;
|
| 412 |
case 'INVPIN':
|
| 413 |
$msg = 'Bank Denial';
|
| 414 |
break;
|
| 415 |
case 'MYINVSTARTDATE':
|
| 416 |
$msg = 'Invalid start date:Bank';
|
| 417 |
break;
|
| 418 |
case 'MYAMNOTACCEPTED':
|
| 419 |
$msg = 'AMEX not accepted:Epoth';
|
| 420 |
break;
|
| 421 |
case 'MYCNOTFND':
|
| 422 |
$msg = 'Country not found:Epoth';
|
| 423 |
break;
|
| 424 |
case 'MYSYSERR':
|
| 425 |
$msg = 'System error; need to resubmit:Epoth';
|
| 426 |
break;
|
| 427 |
case 'MYSWNOTACCEPTED':
|
| 428 |
$msg = 'Maestro/Switch/Solo notaccepted:Epoth';
|
| 429 |
break;
|
| 430 |
case 'MYMCNOTACCEPTED':
|
| 431 |
$msg = 'MC not accepted';
|
| 432 |
break;
|
| 433 |
case 'MYINVCARDNUM':
|
| 434 |
$msg = 'Invalid card number';
|
| 435 |
break;
|
| 436 |
case 'MYINVISSUENUM':
|
| 437 |
$msg = 'Invalid issue number';
|
| 438 |
break;
|
| 439 |
case 'MYINVDATE':
|
| 440 |
$msg = 'Invalid start date';
|
| 441 |
break;
|
| 442 |
case 'MYMISSINGDATA':
|
| 443 |
$msg = 'Missing info';
|
| 444 |
break;
|
| 445 |
case 'MYDNVEL':
|
| 446 |
$msg = 'Too many denial attempts';
|
| 447 |
break;
|
| 448 |
case 'INVDATA':
|
| 449 |
$msg = 'Bank Denial';
|
| 450 |
break;
|
| 451 |
case 'MYINVTRANS':
|
| 452 |
$msg = 'Bank Denial';
|
| 453 |
break;
|
| 454 |
case 'MYCOMPVEL':
|
| 455 |
$msg = 'Customer has exceeded spending limits set by the company';
|
| 456 |
break;
|
| 457 |
case 'MYDENIED':
|
| 458 |
$msg = '';
|
| 459 |
break;
|
| 460 |
case 'MYBLOCKEDZIP':
|
| 461 |
$msg = 'Blocked Zip';
|
| 462 |
break;
|
| 463 |
case 'MYCEH':
|
| 464 |
$msg = 'Customer already has a membership to the site.';
|
| 465 |
break;
|
| 466 |
case 'MYRETRY':
|
| 467 |
$msg = 'System problems';
|
| 468 |
break;
|
| 469 |
case 'MYDUPLICATE':
|
| 470 |
$msg = 'Duplicate membership to the same product.';
|
| 471 |
break;
|
| 472 |
case 'MYINVINFO':
|
| 473 |
$msg = 'Invalid info; needs to resubmit';
|
| 474 |
break;
|
| 475 |
case 'MYNEGDB':
|
| 476 |
$msg = 'Customer is in the negative database.';
|
| 477 |
break;
|
| 478 |
case 'MYNOCARDACCEPTED':
|
| 479 |
$msg = 'None of the card types are accepted';
|
| 480 |
break;
|
| 481 |
case 'MYVELDUP':
|
| 482 |
$msg = 'Product Velocity exceeded';
|
| 483 |
break;
|
| 484 |
case 'MYDNFRD':
|
| 485 |
$msg = 'Too many denial attempts';
|
| 486 |
break;
|
| 487 |
}
|
| 488 |
return $msg;
|
| 489 |
}
|
| 490 |
|
| 491 |
/**
|
| 492 |
* Implementation of hook_cron().
|
| 493 |
*/
|
| 494 |
function paycom_cron() {
|
| 495 |
|
| 496 |
$last_ran = variable_get('paycom_last_cron', '');
|
| 497 |
|
| 498 |
// check the cancellations
|
| 499 |
_paycom_check_cancellations($last_ran);
|
| 500 |
|
| 501 |
variable_set('paycom_last_cron', time());
|
| 502 |
|
| 503 |
}
|
| 504 |
|
| 505 |
|
| 506 |
// process transaction
|
| 507 |
function paycom_process_transaction() {
|
| 508 |
if ($email = $_POST['email']) {
|
| 509 |
$rid = variable_get('paycom_role', '');
|
| 510 |
if ($member = db_fetch_object(db_query("SELECT * FROM {users} WHERE email = '%s'", $email))) {
|
| 511 |
// Make sure there is not a duplicate entry in the users_roles table
|
| 512 |
db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $member->uid, $rid);
|
| 513 |
// Add the entry to the users_roles table
|
| 514 |
if (db_query("INSERT INTO {users_roles} ('uid', 'rid') VALUES (%d, %d)", $member->uid, $rid)) {
|
| 515 |
watchdog('paycom', 'Upgraded %user to an Upgraded Membership as the result of a successful Paycom Transaction', array('%user' => l($member->name, "user/".$member->uid)));
|
| 516 |
}
|
| 517 |
}
|
| 518 |
watchdog('paycom', 'Script was not able to update any records as the email, %email, was not found in the database.', array('%email' => $email), WATCHDOG_ERROR);
|
| 519 |
}
|
| 520 |
}
|
| 521 |
/**
|
| 522 |
* check for the expired accounts.
|
| 523 |
*/
|
| 524 |
function _paycom_check_cancellations($last_ran) {
|
| 525 |
|
| 526 |
$sql = db_query("SELECT * FROM {MemberCancelStats} WHERE mcs_canceldate > %d", $last_ran);
|
| 527 |
while ($result = db_fetch_object($sql)) {
|
| 528 |
if ($sql_user = db_fetch_object(db_query("SELECT * FROM {users} WHERE mail = '%s'", $result->mcs_email))) {
|
| 529 |
if (db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $sql_user->uid, variable_get('paycom_role', ''))) {
|
| 530 |
// to delete from the paycom table
|
| 531 |
db_query("DELETE FROM {paycom} WHERE uid = %d" , $sql_user->uid);
|
| 532 |
//to delete from the premium users modules
|
| 533 |
db_query("DELETE FROM {premium_user} WHERE uid = %d", $sql_user->uid);
|
| 534 |
watchdog('paycom', '%user lost their Upgraded Membership role due to a Paycom cancellation.', array('%user' => l($sql_user->name, "user/{$sql_user->uid}/edit")));
|
| 535 |
}
|
| 536 |
}
|
| 537 |
}
|
| 538 |
}
|
| 539 |
|
| 540 |
|
| 541 |
function paycom_country_conversion($country) {
|
| 542 |
$list = array(
|
| 543 |
"Andorra" => "ad",
|
| 544 |
"United Arab Emirates" => "ae",
|
| 545 |
"Afghanistan"=>"af",
|
| 546 |
"Antigua and Barbuda"=>"ag",
|
| 547 |
"Anguilla"=>"ai",
|
| 548 |
"Albania"=>"al",
|
| 549 |
"Armenia"=>"am",
|
| 550 |
"Netherlands Antilles"=>"an",
|
| 551 |
"Angola"=>"ao",
|
| 552 |
"Antarctica"=>"aq",
|
| 553 |
"Argentina"=>"ar",
|
| 554 |
"American Samoa"=>"as",
|
| 555 |
"Austria"=>"at",
|
| 556 |
"Australia"=>"au",
|
| 557 |
"Aruba"=>"aw",
|
| 558 |
"Aland Islands"=>"ax",
|
| 559 |
"Azerbaijan"=>"az",
|
| 560 |
"Bosnia and Herzegovina"=>"ba",
|
| 561 |
"Barbados"=>"bb",
|
| 562 |
"Bangladesh"=>"bd",
|
| 563 |
"Belgium"=>"be",
|
| 564 |
"Burkina Faso"=>"bf",
|
| 565 |
"Bulgaria"=>"bg",
|
| 566 |
"Bahrain"=>"bh",
|
| 567 |
"Burundi"=>"bi",
|
| 568 |
"Benin"=>"bj",
|
| 569 |
"Bermuda"=>"bm",
|
| 570 |
"Brunei Darussalam"=>"bn",
|
| 571 |
"Bolivia"=>"bo",
|
| 572 |
"Brazil"=>"br",
|
| 573 |
"Bahamas"=>"bs",
|
| 574 |
"Bhutan"=>"bt",
|
| 575 |
"Bouvet Island"=>"bv",
|
| 576 |
"Botswana"=>"bw",
|
| 577 |
"Belarus"=>"by",
|
| 578 |
"Belize"=>"bz",
|
| 579 |
"Canada"=>"ca",
|
| 580 |
"Cocos (Keeling) Islands"=>"cc",
|
| 581 |
"Democratic Republic of the Congo (formerly Zaire)"=>"cd",
|
| 582 |
"Central African Republic"=>"cf",
|
| 583 |
"Congo (Republic of the Congo)"=>"cg",
|
| 584 |
"Switzerland (Confoederatio Helvetica)"=>"ch",
|
| 585 |
"Cote d\'Ivoire (Ivory Coast)"=>"ci",
|
| 586 |
"Cook Islands"=>"ck",
|
| 587 |
"Chile"=>"cl",
|
| 588 |
"Cameroon"=>"cm",
|
| 589 |
"China"=>"cn",
|
| 590 |
"Colombia"=>"co",
|
| 591 |
"Costa Rica"=>"cr",
|
| 592 |
"Serbia and Montenegro"=>"cs",
|
| 593 |
"Cuba"=>"cu",
|
| 594 |
"Cape Verde"=>"cv",
|
| 595 |
"Christmas Island"=>"cx",
|
| 596 |
"Cyprus"=>"cy",
|
| 597 |
"Czech Republic"=>"cz",
|
| 598 |
"Germany (Deutschland)"=>"de",
|
| 599 |
"Djibouti"=>"dj",
|
| 600 |
"Denmark"=>"dk",
|
| 601 |
"Dominica"=>"dm",
|
| 602 |
"Dominican Republic"=>"do",
|
| 603 |
"Algeria"=>"dz",
|
| 604 |
"Ecuador"=>"ec",
|
| 605 |
"Estonia"=>"ee",
|
| 606 |
"Egypt"=>"eg",
|
| 607 |
"Western Sahara (formerly Spanish Sahara)"=>"eh",
|
| 608 |
"Eritrea"=>"er",
|
| 609 |
"Spain (Espana)"=>"es",
|
| 610 |
"Ethiopia"=>"et",
|
| 611 |
"Finland"=>"fi",
|
| 612 |
"Fiji"=>"fj",
|
| 613 |
"Falkland Islands"=>"fk",
|
| 614 |
"Federated States of Micronesia"=>"fm",
|
| 615 |
"Faroe Islands"=>"fo",
|
| 616 |
"France"=>"fr",
|
| 617 |
"Gabon"=>"ga",
|
| 618 |
"Ghana"=>"gd",
|
| 619 |
"Georgia"=>"ge",
|
| 620 |
"French Guiana"=>"gf",
|
| 621 |
"Gibraltar"=>"gi",
|
| 622 |
"Greenland"=>"gl",
|
| 623 |
"Gambia"=>"gm",
|
| 624 |
"Guinea"=>"gn",
|
| 625 |
"Guadeloupe"=>"gp",
|
| 626 |
"Equatorial Guinea"=>"gq",
|
| 627 |
"Greece"=>"gr",
|
| 628 |
"South Georgia and the South Sandwich Islands"=>"gs",
|
| 629 |
"Guatemala"=>"gt",
|
| 630 |
"Guam"=>"gu",
|
| 631 |
"Guinea-Bissau"=>"gw",
|
| 632 |
"Guyana"=>"gy",
|
| 633 |
"Hong Kong"=>"hk",
|
| 634 |
"Heard Island and McDonald Islands"=>"hm",
|
| 635 |
"Honduras"=>"hn",
|
| 636 |
"Croatia (Hrvatska)"=>"hr",
|
| 637 |
"Haiti"=>"ht",
|
| 638 |
"Hungary"=>"hu",
|
| 639 |
"Indonesia"=>"id",
|
| 640 |
"Ireland"=>"ie",
|
| 641 |
"Israel"=>"il",
|
| 642 |
"India"=>"in",
|
| 643 |
"British Indian Ocean Territory (including Diego Garcia)"=>"io",
|
| 644 |
"Iraq"=>"iq",
|
| 645 |
"Iran"=>"ir",
|
| 646 |
"Iceland"=>"is",
|
| 647 |
"Italy"=>"it",
|
| 648 |
"Jamaica"=>"jm",
|
| 649 |
"Jordan"=>"jo",
|
| 650 |
"Japan"=>"jp",
|
| 651 |
"Kenya"=>"ke",
|
| 652 |
"Kyrgyzstan"=>"kg",
|
| 653 |
"Cambodia"=>"kh",
|
| 654 |
"Kiribati"=>"ki",
|
| 655 |
"Comoros"=>"km",
|
| 656 |
"Saint Kitts and Nevis"=>"kn",
|
| 657 |
"North Korea"=>"kp",
|
| 658 |
"South Korea"=>"kr",
|
| 659 |
"Kuwait"=>"kw",
|
| 660 |
"Cayman Islands"=>"ky",
|
| 661 |
"Kazakhstan"=>"kz",
|
| 662 |
"Laos"=>"la",
|
| 663 |
"Lebanon"=>"lb",
|
| 664 |
"Saint Lucia"=>"lc",
|
| 665 |
"Liechtenstein"=>"li",
|
| 666 |
"Sri Lanka"=>"lk",
|
| 667 |
"Liberia"=>"lr",
|
| 668 |
"Lesotho"=>"ls",
|
| 669 |
"Lithuania"=>"lt",
|
| 670 |
"Luxembourg"=>"lu",
|
| 671 |
"Latvia"=>"lv",
|
| 672 |
"Libya"=>"ly",
|
| 673 |
"Morocco"=>"ma",
|
| 674 |
"Monaco"=>"mc",
|
| 675 |
"Moldova"=>"md",
|
| 676 |
"Madagascar"=>"mg",
|
| 677 |
"Marshall Islands"=>"mh",
|
| 678 |
"Former Yugoslav Republic of Macedonia"=>"mk",
|
| 679 |
"Mali"=>"ml",
|
| 680 |
"Myanmar (Burma)"=>"mm",
|
| 681 |
"Mongolia"=>"mn",
|
| 682 |
"Macao (Macau)"=>"mo",
|
| 683 |
"Northern Mariana Islands"=>"mp",
|
| 684 |
"Martinique"=>"mq",
|
| 685 |
"Mauritania"=>"mr",
|
| 686 |
"Montserrat"=>"ms",
|
| 687 |
"Malta"=>"mt",
|
| 688 |
"Mauritius"=>"mu",
|
| 689 |
"Maldives"=>"mv",
|
| 690 |
"Malawi"=>"mw",
|
| 691 |
"Mexico"=>"mx",
|
| 692 |
"Malaysia"=>"my",
|
| 693 |
"Mozambique"=>"mz",
|
| 694 |
"Namibia"=>"na",
|
| 695 |
"New Caledonia"=>"nc",
|
| 696 |
"Niger"=>"ne",
|
| 697 |
"Norfolk Island"=>"nf",
|
| 698 |
"Nigeria"=>"ng",
|
| 699 |
"Nicaragua"=>"ni",
|
| 700 |
"Netherlands"=>"nl",
|
| 701 |
"Norway"=>"no",
|
| 702 |
"Nepal"=>"np",
|
| 703 |
"Nauru"=>"nr",
|
| 704 |
"Niue"=>"nu",
|
| 705 |
"New Zealand"=>"nz",
|
| 706 |
"Oman"=>"om",
|
| 707 |
"Panama"=>"pa",
|
| 708 |
"Peru"=>"pe",
|
| 709 |
"French Polynesia"=>"pf",
|
| 710 |
"Papua New Guinea"=>"pg",
|
| 711 |
"Philippines"=>"ph",
|
| 712 |
"Pakistan"=>"pk",
|
| 713 |
"Poland"=>"pl",
|
| 714 |
"Saint-Pierre and Miquelon"=>"pm",
|
| 715 |
"Pitcairn Islands"=>"pn",
|
| 716 |
"Puerto Rico"=>"pr",
|
| 717 |
"Palestinian Territories (West Bank and Gaza Strip)"=>"ps",
|
| 718 |
"Portugal"=>"pt",
|
| 719 |
"Palau"=>"pw",
|
| 720 |
"Paraguay"=>"py",
|
| 721 |
"Qatar"=>"qa",
|
| 722 |
"Reunion"=>"re",
|
| 723 |
"Romania"=>"ro",
|
| 724 |
"Russia"=>"ru",
|
| 725 |
"Rwanda"=>"rw",
|
| 726 |
"Saudi Arabia"=>"sa",
|
| 727 |
"Solomon Islands"=>"sb",
|
| 728 |
"Seychelles"=>"sc",
|
| 729 |
"Sudan"=>"sd",
|
| 730 |
"Sweden"=>"se",
|
| 731 |
"Singapore"=>"sg",
|
| 732 |
"Saint Helena"=>"sh",
|
| 733 |
"Slovenia"=>"si",
|
| 734 |
"Svalbard and Jan Mayen Islands"=>"sj",
|
| 735 |
"Slovakia"=>"sk",
|
| 736 |
"Sierra Leone"=>"sl",
|
| 737 |
"San Marino"=>"sm",
|
| 738 |
"Senegal"=>"sn",
|
| 739 |
"Somalia"=>"so",
|
| 740 |
"Suriname"=>"sr",
|
| 741 |
"Sao Tome and Principe"=>"st",
|
| 742 |
"El Salvador"=>"sv",
|
| 743 |
"Syria"=>"sy",
|
| 744 |
"Swaziland"=>"sz",
|
| 745 |
"Turks and Caicos Islands"=>"tc",
|
| 746 |
"Chad (Tchad)"=>"td",
|
| 747 |
"French Southern Territories"=>"tf",
|
| 748 |
"Togo"=>"tg",
|
| 749 |
"Thailand"=>"th",
|
| 750 |
"Tajikistan"=>"tj",
|
| 751 |
"Tokelau"=>"tk",
|
| 752 |
"Timor-Leste (East Timor)"=>"tl",
|
| 753 |
"Turkmenistan"=>"tm",
|
| 754 |
"Tunisia"=>"tn",
|
| 755 |
"Tonga"=>"to",
|
| 756 |
"Turkey"=>"tr",
|
| 757 |
"Trinidad and Tobago"=>"tt",
|
| 758 |
"Tuvalu"=>"tv",
|
| 759 |
"Taiwan"=>"tw",
|
| 760 |
"Tanzania"=>"tz",
|
| 761 |
"Ukraine"=>"ua",
|
| 762 |
"Uganda"=>"ug",
|
| 763 |
"United Kingdom"=>"uk",
|
| 764 |
"United States Minor Outlying Islands"=>"um",
|
| 765 |
"United States"=>"us",
|
| 766 |
"Uruguay"=>"uy",
|
| 767 |
"Uzbekistan"=>"uz",
|
| 768 |
"Vatican City"=>"va",
|
| 769 |
"Saint Vincent and the Grenadines"=>"vc",
|
| 770 |
"Venezuela"=>"ve",
|
| 771 |
"British Virgin Islands"=>"vg",
|
| 772 |
"U.S. Virgin Islands"=>"vi",
|
| 773 |
"Vietnam"=>"vn",
|
| 774 |
"Vanuatu"=>"vu",
|
| 775 |
"Wallis and Futuna"=>"wf",
|
| 776 |
"Samoa"=>"ws",
|
| 777 |
"Yemen"=>"ye",
|
| 778 |
"Mayotte"=>"yt",
|
| 779 |
"South Africa"=>"za",
|
| 780 |
"Zambia"=>"zm",
|
| 781 |
"Zimbabwe"=>"zw"
|
| 782 |
);
|
| 783 |
|
| 784 |
return $list[$country];
|
| 785 |
}
|