27 define(
"M2M_SIGNIFICANT_LEN", 5 );
39 function ManageExternalAccount( $pHBEnv, $pInputVars ) {
40 $retStatusAry = Array(
41 'status' => Array(
'code'=>
'000',
'errors' => Array()),
50 $dbh = $pHBEnv[
"dbh"];
53 $action = $pInputVars[
"action"];
57 $aryValidate = EXT_ValidateInputs( $pHBEnv, $dbh, $pInputVars, $MC );
59 if ( !$aryValidate || ($aryValidate[
"code"] !==
"000") ) {
61 if ( is_array( $aryValidate[
"errors"] ) ) {
62 for ( $e = 0; $e < count( $aryValidate[
"errors"] ); $e++ ) {
63 $aryErrors[] = $aryValidate[
"errors"][$e];
66 $aryErrors[] = $aryValidate[
"errors"];
69 throw new Exception (HCU_JsonEncode($aryErrors));
74 $pInputVars[
"display_name"] = ConvertFromUTF8( $pInputVars[
"display_name"] );
77 $return = EXT_AddAccount( $dbh, $pHBEnv, $pInputVars, $MC );
78 if ( $return[
"code"] !==
"000" ) {
79 if ( is_array( $return[
"errors"] ) ) {
80 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
81 $aryErrors[] = $return[
"errors"][$e];
84 $aryErrors[] = $return[
"errors"];
87 throw new Exception (HCU_JsonEncode($aryErrors));
91 $retStatusAry[
"info"][] = $MC->msg(
'EXT Account Added', HCU_DISPLAY_AS_RAW);
96 $pInputVars[
"ext_acct_id"] = $return[
"data"][
"id"];
97 $return = EXT_StartAccountVerify( $dbh, $pHBEnv, $pInputVars, $MC );
98 if ( $return[
"code"] !==
"000" ) {
99 if ( is_array( $return[
"errors"] ) ) {
100 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
101 $aryErrors[] = $return[
"errors"][$e];
104 $aryErrors[] = $return[
"errors"];
107 throw new Exception (HCU_JsonEncode($aryErrors));
111 $retStatusAry[
"info"][] = $MC->msg(
'EXT Account verify started', HCU_DISPLAY_AS_RAW);
114 $return = EXT_GetAccounts( $dbh, $pHBEnv );
115 if ( $return[
"code"] !==
"000" ) {
116 if ( is_array( $return[
"errors"] ) ) {
117 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
118 $aryErrors[] = $return[
"errors"][$e];
121 $aryErrors[] = $return[
"errors"];
124 throw new Exception (HCU_JsonEncode($aryErrors));
128 $retStatusAry[
"data"] = $return[
"data"];
131 case "add_m2m_account":
133 $aryValidate = EXT_ValidateM2MInputs( $pHBEnv, $dbh, $pInputVars, $MC );
135 if ( !$aryValidate || ($aryValidate[
"code"] !==
"000") ) {
137 if ( is_array( $aryValidate[
"errors"] ) ) {
138 for ( $e = 0; $e < count( $aryValidate[
"errors"] ); $e++ ) {
139 $aryErrors[] = $aryValidate[
"errors"][$e];
142 $aryErrors[] = $aryValidate[
"errors"];
145 throw new Exception (HCU_JsonEncode($aryErrors));
150 $pInputVars[
"display_name"] = ConvertFromUTF8( $pInputVars[
"display_name"] );
153 $return = EXT_AddM2MAccount( $dbh, $pHBEnv, $pInputVars, $MC );
154 if ( $return[
"code"] !==
"000" ) {
155 if ( is_array( $return[
"errors"] ) ) {
156 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
157 $aryErrors[] = $return[
"errors"][$e];
160 $aryErrors[] = $return[
"errors"];
163 throw new Exception (HCU_JsonEncode($aryErrors));
167 $retStatusAry[
"info"][] = $MC->msg(
'Member Account Added', HCU_DISPLAY_AS_RAW);
171 $return = EXT_GetM2MAccounts( $dbh, $pHBEnv );
172 if ( $return[
"code"] !==
"000" ) {
173 if ( is_array( $return[
"errors"] ) ) {
174 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
175 $aryErrors[] = $return[
"errors"][$e];
178 $aryErrors[] = $return[
"errors"];
181 throw new Exception (HCU_JsonEncode($aryErrors));
185 $retStatusAry[
"data"] = $return[
"data"];
188 case "update_account":
191 $pInputVars[
"display_name"] = ConvertFromUTF8( $pInputVars[
"display_name"] );
194 $return = EXT_UpdateAccount( $dbh, $pHBEnv, $pInputVars, $MC );
195 if ( $return[
"code"] !==
"000" ) {
196 if ( is_array( $return[
"errors"] ) ) {
197 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
198 $aryErrors[] = $return[
"errors"][$e];
201 $aryErrors[] = $return[
"errors"];
204 throw new Exception (HCU_JsonEncode($aryErrors));
208 $retStatusAry[
"info"][] = $MC->msg(
'EXT Account Updated', HCU_DISPLAY_AS_RAW);
211 $retStatusAry[
"data"] = $return[
"data"];
214 case "validate_account":
218 $return = EXT_ValidateAccount( $dbh, $pHBEnv, $pInputVars, $MC );
219 if ( $return[
"code"] !==
"000" ) {
220 if ( is_array( $return[
"errors"] ) ) {
221 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
222 $aryErrors[] = $return[
"errors"][$e];
225 $aryErrors[] = $return[
"errors"];
228 throw new Exception (HCU_JsonEncode($aryErrors));
232 if ( isset( $return[
"status"] ) && $return[
"status"] ==
"a" ) {
233 $retStatusAry[
"info"][] = $MC->msg(
'EXT Account Validated', HCU_DISPLAY_AS_RAW);
237 $retStatusAry[
"data"] = $return[
"data"];
240 case "delete_account":
242 $return = EXT_DeleteAccount( $dbh, $pHBEnv, $pInputVars, $MC );
243 if ( $return[
"code"] !==
"000" ) {
244 if ( is_array( $return[
"errors"] ) ) {
245 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
246 $aryErrors[] = $return[
"errors"][$e];
249 $aryErrors[] = $return[
"errors"];
252 throw new Exception (HCU_JsonEncode($aryErrors));
256 $retStatusAry[
"info"][] = $MC->msg(
'EXT Account Deleted', HCU_DISPLAY_AS_RAW);
261 $retStatusAry[
"data"] = $pInputVars[
"id"];
266 $return = EXT_GetAccounts( $dbh, $pHBEnv );
267 if ( $return[
"code"] !==
"000" ) {
268 $aryErrors[] = $MC->msg(
'EXT Error getting accounts', HCU_DISPLAY_AS_RAW);
270 if ( is_array( $return[
"errors"] ) ) {
271 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
272 $aryErrors[] = $return[
"errors"][$e];
275 $aryErrors[] = $return[
"errors"];
278 throw new Exception (HCU_JsonEncode($aryErrors));
282 $retStatusAry[
"data"] = $return[
"data"];
284 case "get_m2m_accounts":
286 $return = EXT_GetM2MAccounts( $dbh, $pHBEnv );
287 if ( $return[
"code"] !==
"000" ) {
288 $aryErrors[] = $MC->msg(
'EXT Error getting accounts', HCU_DISPLAY_AS_RAW);
290 if ( is_array( $return[
"errors"] ) ) {
291 for ( $e = 0; $e < count( $return[
"errors"] ); $e++ ) {
292 $aryErrors[] = $return[
"errors"][$e];
295 $aryErrors[] = $return[
"errors"];
298 throw new Exception (HCU_JsonEncode($aryErrors));
302 $retStatusAry[
"data"] = $return[
"data"];
305 $aryErrors[] =
"Unexpected action: {$pInputVars["action
"]}";
306 throw new Exception (HCU_JsonEncode($aryErrors));
310 }
catch( Exception $ex ) {
312 $retStatusAry[
"status"][
"errors"] = HCU_JsonDecode( $ex->getMessage() );
313 $retStatusAry[
"status"][
"code"] =
"999";
317 if ( $retStatusAry[
"status"][
"errors"] != array() ) {
318 $retStatusAry[
"status"][
"code"] =
"999";
321 return $retStatusAry;
325 function Check_ExternalTransfersEnabled( $pDbh, $pHBEnv ) {
327 }
catch (Exception $ex) {
328 $logInfo = array(
"message" => $ex->getMessage(),
"code" => $ex->getCode() );
329 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
336 function Check_M2MTransfersEnabled( $pDbh, $pHBEnv ) {
338 }
catch (Exception $ex) {
339 $logInfo = array(
"message" => $ex->getMessage(),
"code" => $ex->getCode() );
340 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
347 function Get_ExternalTransferStatusLookup( $pMC ) {
348 return array (
"0" => $pMC->msg(
"EXT Pending confirmation" ),
349 "p" => $pMC->msg(
"EXT Pending verification" ),
350 "a" => $pMC->msg(
"Active" ),
351 "l" => $pMC->msg(
"EXT Locked" ),
352 "i" => $pMC->msg(
"Inactive" ) );
363 function EXT_GetAccounts( $pDbh, $pHBEnv ) {
365 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
366 $pMC = $pHBEnv[
'MC'];
371 FROM {$pHBEnv["Cu
"]}extaccount ea 372 WHERE ea.user_id = {$pHBEnv["Uid
"]} 374 ORDER BY lower( display_name ), status, id 376 $rs = db_query( $SQL, $pDbh );
378 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1133" );
385 $mask= GetMask($pDbh, $pHBEnv[
"Cu"]);
386 $mask= $mask[
"code"] != 0 ? array(
"start" => -2) : $mask[
"data"];
388 while ( $extRow = db_fetch_array( $rs, $row++ ) ) {
389 $displayName = trim( $extRow[
"display_name"] );
391 $remoteInfo = HCU_JsonDecode( $extRow[
"remote_info"]);
393 $nameOnAccount = $remoteInfo[
"rdfi"][
"name"];
396 $status = trim( $extRow[
"status"] );
397 if ( $status ==
'p' ) {
398 $keep = array(
"rdfi" => $remoteInfo[
"rdfi"] );
401 $myDateTime =
new DateTime( date(
"m/d/y g:ia", $remoteInfo[
"verify"][
"pending_date"] ) );
402 $myDateTime->setTimezone(
new DateTimeZone( $pHBEnv[
"tz"] ) );
404 $keep[
"verify"] = array(
"pending_date" => $myDateTime->format(
"m/d/y g:ia" ),
405 "tries" => $remoteInfo[
"verify"][
"tries"] );
406 $returnRemoteInfo = HCU_JsonEncode( $keep );
409 $returnRemoteInfo = $extRow[
"remote_info"];
414 $saveRow = array(
"id" => $extRow[
"id"],
415 "user_id" => $extRow[
"user_id"],
416 "display_name" => $displayName,
417 "name_on_account" => $nameOnAccount,
419 "remote_info" => $returnRemoteInfo,
420 "remoteAccount" => $remoteInfo[
"rdfi"][
"routing"] .
" / " . ApplyMask($remoteInfo[
"rdfi"][
"account"], $mask));
422 $return[] = $saveRow;
425 $returnData[
"data"] = $return;
426 }
catch (Exception $ex) {
427 $logInfo = array(
"message" => $ex->getMessage(),
"code" => $ex->getCode() );
428 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
430 $returnData[
"code"] =
"999";
445 function EXT_GetM2MAccounts( $pDbh, $pHBEnv ) {
447 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
448 $pMC = $pHBEnv[
'MC'];
453 FROM {$pHBEnv["Cu
"]}extaccount ea 454 WHERE ea.user_id = {$pHBEnv["Uid
"]} 456 ORDER BY lower( display_name ), status, id 458 $rs = db_query( $SQL, $pDbh );
460 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1134" );
467 $mask= GetMask($pDbh, $pHBEnv[
"Cu"]);
468 $mask= $mask[
"code"] != 0 ? array(
"start" => -2) : $mask[
"data"];
470 while ( $extRow = db_fetch_array( $rs, $row++ ) ) {
471 $displayName = trim( $extRow[
"display_name"] );
473 $remoteInfo = HCU_JsonDecode( $extRow[
"remote_info"]);
475 $status = trim( $extRow[
"status"] );
476 $returnRemoteInfo = $extRow[
"remote_info"];
478 $saveRow = array(
"id" => $extRow[
"id"],
479 "user_id" => $extRow[
"user_id"],
480 "display_name" => $displayName,
482 "remote_info" => $returnRemoteInfo,
483 "remoteAccount" => ApplyMask($remoteInfo[
"rdfi"][
"account"], $mask));
485 $return[] = $saveRow;
488 $returnData[
"data"] = $return;
489 }
catch (Exception $ex) {
490 $logInfo = array(
"message" => $ex->getMessage(),
"code" => $ex->getCode() );
491 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
493 $returnData[
"code"] =
"999";
508 function EXT_ValidateInputs( $pHBEnv, $pDbh, $pInputVars, $pMC ) {
510 $aryReturnErrors = array();
511 $retACHValidate = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
515 if ( strlen( trim( $pInputVars[
"display_name"] ) ) == 0 ) {
516 $aryReturnErrors = $pMC->msg(
"ACH Validation Name", HCU_DISPLAY_AS_HTML) .
" 1119";
520 $testDisplay = prep_save( html_entity_decode( $pInputVars[
"display_name"], ENT_QUOTES ), 20 );
521 $sql =
"SELECT count(*) 522 FROM {$pHBEnv["Cu
"]}extaccount 523 WHERE user_id = {$pHBEnv["Uid
"]} 524 AND lower( display_name ) = lower( '{$testDisplay}' ) 527 $rs = db_query( $sql, $pDbh );
529 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1135" );
532 $countRow = db_fetch_array( $rs, 0 );
533 if ( $countRow[0] > 0 ) {
534 $aryReturnErrors = $pMC->msg(
"ACH Unique display name required", HCU_DISPLAY_AS_HTML) .
" 1125";
537 if ( trim( $pInputVars[
"dfi_routing"] ) ==
"" ||
538 !ctype_digit( trim( $pInputVars[
"dfi_routing"] ) ) ||
539 strlen( trim( $pInputVars[
"dfi_routing"] ) ) != 9 ) {
540 $aryReturnErrors[] = $pMC->msg(
"ACH Validation DFI Routing") .
" 1122";
543 if ( trim( $pInputVars[
"dfi_account"] ) ==
"" ) {
544 $aryReturnErrors[] = $pMC->msg(
"ACH Validation DFI Account") .
" 1121";
547 if ( !(trim( $pInputVars[
"dfi_account_type"] ) == ACCOUNT_TYPE_CHECKING ||
548 trim( $pInputVars[
"dfi_account_type"] ) == ACCOUNT_TYPE_SAVINGS )) {
549 $aryReturnErrors[] = $pMC->msg(
"ACH Validation DFI Type") .
" 1120";
551 }
catch (Exception $ex) {
552 $message = $ex->getMessage();
554 $aryReturnErrors[] = $message;
557 if ( count( $aryReturnErrors ) > 0 ) {
559 $retACHValidate[
'code'] =
'999';
560 $retACHValidate[
"errors"] = $aryReturnErrors;
563 return $retACHValidate;
574 function EXT_ValidateM2MInputs( $pHBEnv, $pDbh, $pInputVars, $pMC ) {
576 $aryReturnErrors = array();
577 $retACHValidate = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
581 if ( strlen( trim( $pInputVars[
"display_name"] ) ) == 0 ) {
582 $aryReturnErrors = $pMC->msg(
"ACH Validation Name", HCU_DISPLAY_AS_HTML) .
" 1127";
586 $testDisplay = prep_save( html_entity_decode( $pInputVars[
"display_name"], ENT_QUOTES ), 20 );
587 $sql =
"SELECT count(*) 588 FROM {$pHBEnv["Cu
"]}extaccount 589 WHERE user_id = {$pHBEnv["Uid
"]} 590 AND lower( display_name ) = lower( '{$testDisplay}' ) 593 $rs = db_query( $sql, $pDbh );
595 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1136" );
598 $countRow = db_fetch_array( $rs, 0 );
599 if ( $countRow[0] > 0 ) {
600 $aryReturnErrors = $pMC->msg(
"ACH Unique display name required", HCU_DISPLAY_AS_HTML) .
" 1128";
603 if ( trim( $pInputVars[
"dfi_account"] ) ==
"" ) {
604 $aryReturnErrors[] = $pMC->msg(
"ACH Validation DFI Account") .
" 1129";
607 if ( !(trim( $pInputVars[
"dfi_account_type"] ) == ACCOUNT_TYPE_CHECKING ||
608 trim( $pInputVars[
"dfi_account_type"] ) == ACCOUNT_TYPE_SAVINGS )) {
609 $aryReturnErrors[] = $pMC->msg(
"ACH Validation DFI Type") .
" 1131";
611 }
catch (Exception $ex) {
612 $message = $ex->getMessage();
614 $aryReturnErrors[] = $message;
617 if ( count( $aryReturnErrors ) > 0 ) {
619 $retACHValidate[
'code'] =
'999';
620 $retACHValidate[
"errors"] = $aryReturnErrors;
623 return $retACHValidate;
636 function EXT_AddAccount( $pDbh, $pHBEnv, $pInputVars, $pMC ) {
638 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
644 $displayName = prep_save( html_entity_decode( $pInputVars[
"display_name"], ENT_QUOTES ), 20 );
645 $nameOnAccount = prep_save( html_entity_decode( $pInputVars[
"name_on_account"], ENT_QUOTES ) );
648 $remoteInfo = array(
"rdfi" => array(
"routing" => $pInputVars[
"dfi_routing"],
649 "account" => $pInputVars[
"dfi_account"],
650 "type" => $pInputVars[
"dfi_account_type"],
651 "name" => $nameOnAccount ) );
653 $remoteInfoStr = HCU_JsonEncode( $remoteInfo );
655 $sql =
"INSERT INTO {$pHBEnv["Cu
"]}extaccount (user_id, type, display_name, status, remote_info) 656 VALUES ({$pHBEnv["Uid
"]}, 'EXT', '$displayName', '0', '$remoteInfoStr') 659 $extRs = db_query( $sql, $pDbh );
662 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1101" );
666 list($extId) = db_fetch_array($extRs, 0);
669 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1102" );
673 $returnData[
"data"][
"id"] = $extId;
675 }
catch (Exception $ex) {
677 $message = $ex->getMessage();
678 $code = $ex->getCode();
680 $logInfo = array(
"message" => $message,
"code" => $code );
681 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
683 $returnData[
"code"] =
"999";
684 $returnData[
"errors"][] = $message;
700 function EXT_AddM2MAccount( $pDbh, $pHBEnv, $pInputVars, $pMC ) {
702 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
706 if ( _ConfirmM2MAccount( $pHBEnv, $pInputVars ) ==
false ) {
707 throw new Exception( $pMC->msg(
"M2M Account Not Found", HCU_DISPLAY_AS_HTML) .
" 1130" );
713 $displayName = prep_save( html_entity_decode( $pInputVars[
"display_name"], ENT_QUOTES ), 20 );
714 $nameOnAccount = prep_save( html_entity_decode( $pInputVars[
"name_on_account"], ENT_QUOTES ) );
717 $remoteInfo = array(
"rdfi" => array(
"account" => $pInputVars[
"dfi_account"],
718 "type" => $pInputVars[
"dfi_account_type"],
719 "name" => $nameOnAccount ),
720 "verify" => array(
"verified" => time() ) );
722 $remoteInfoStr = HCU_JsonEncode( $remoteInfo );
724 $sql =
"INSERT INTO {$pHBEnv["Cu
"]}extaccount (user_id, type, display_name, status, remote_info) 725 VALUES ({$pHBEnv["Uid
"]}, 'M2M', '$displayName', 'a', '$remoteInfoStr') 728 $extRs = db_query( $sql, $pDbh );
731 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1101" );
735 list($extId) = db_fetch_array($extRs, 0);
738 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1102" );
742 $returnData[
"data"][
"id"] = $extId;
744 }
catch (Exception $ex) {
746 $message = $ex->getMessage();
747 $code = $ex->getCode();
749 $logInfo = array(
"message" => $message,
"code" => $code );
750 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
752 $returnData[
"code"] =
"999";
753 $returnData[
"errors"][] = $message;
769 function _ConfirmM2MAccount( $pEnv, $pInputVars ) {
774 if ($pEnv[
'live'] == 0) {
775 throw new Exception( $pMC->msg(
"Option not set", HCU_DISPLAY_AS_HTML) .
" 1144" );
778 $mbrRequest = array(
"type" => PACKET_REQUEST_MIR,
779 "member" => $pInputVars[
"dfi_account"] );
780 $memberInfo = GetMemberInfo( $pEnv, $mbrRequest );
782 if ( $memberInfo[
"code"] ===
"000" ) {
783 if ( isset( $memberInfo[
"data"][
"lastname"] ) ) {
786 $testCompare = substr( $pInputVars[
"name_on_account"], 0, M2M_SIGNIFICANT_LEN );
787 $compareLen = strlen( $testCompare );
788 $compareExact = $compareLen < M2M_SIGNIFICANT_LEN;
790 $actualName = substr( trim( $memberInfo[
"data"][
"lastname"] ), 0, M2M_SIGNIFICANT_LEN );
792 if ( $compareExact ) {
794 $isValid = strcasecmp( $actualName, $testCompare ) == 0 && strlen( trim( $memberInfo[
"data"][
"lastname"]) ) == $compareLen;
796 $isValid = strcasecmp( $actualName, $testCompare ) == 0;
816 function EXT_UpdateAccount( $pDbh, $pHBEnv, $pInputVars, $pMC ) {
818 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
822 $testDisplay = prep_save( html_entity_decode( $pInputVars[
"display_name"], ENT_QUOTES ), 20 );
823 $sql =
"SELECT count(*) 824 FROM {$pHBEnv["Cu
"]}extaccount 825 WHERE user_id = {$pHBEnv["Uid
"]} 826 AND lower( display_name ) = lower( '{$testDisplay}' ) 827 AND id <> {$pInputVars["id"]} 830 $rs = db_query( $sql, $pDbh );
832 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1137" );
835 $countRow = db_fetch_array( $rs, 0 );
836 if ( $countRow[0] > 0 ) {
837 throw new Exception( $pMC->msg(
"ACH Unique display name required", HCU_DISPLAY_AS_HTML) .
" 1126" );
842 FROM {$pHBEnv["Cu
"]}extaccount ea 843 WHERE ea.id = {$pInputVars["id"]} 846 $rs = db_query( $sql, $pDbh );
848 $extRow = db_fetch_array( $rs, 0 );
850 if ( $extRow[
"id"] == 0 ) {
851 throw new Exception( $pMC->msg(
"EXT Acct Status Error", HCU_DISPLAY_AS_HTML) .
" 1103" );
859 if ( $extRow[
"type"] ==
"EXT" ) {
860 $remoteInfo = HCU_JsonDecode( $extRow[
"remote_info"]);
862 if ( $remoteInfo[
"rdfi"][
"name"] != $pInputVars[
"name_on_account"] ) {
863 $returnNameOnAccount = html_entity_decode( $pInputVars[
"name_on_account"], ENT_QUOTES );
864 $remoteInfo[
"rdfi"][
"name"] = prep_save( $returnNameOnAccount );
865 $updateRemoteInfo = HCU_JsonEncode( $remoteInfo );
869 if ( strlen( $sqlUpdate ) > 0 ) {
873 $sqlUpdate .=
"remote_info = '$updateRemoteInfo' ";
875 $returnNameOnAccount = $remoteInfo[
"rdfi"][
"name"];
879 if ( $extRow[
"display_name"] != $pInputVars[
"display_name"] ) {
880 $returnDisplayName = html_entity_decode( $pInputVars[
"display_name"], ENT_QUOTES );
881 $displayName = prep_save( $returnDisplayName, 20 );
884 if ( strlen( $sqlUpdate ) > 0 ) {
888 $sqlUpdate .=
"display_name = '$displayName' ";
891 $returnDisplayName = $extRow[
"display_name"];
895 $sql =
"UPDATE {$pHBEnv["Cu
"]}extaccount SET $sqlUpdate WHERE id = {$pInputVars["id"]}";
897 $extRs = db_query( $sql, $pDbh );
900 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1104" );
904 if ( $extRow[
"type"] ==
"EXT" ) {
906 $returnData[
"data"] = array(
"id" => $pInputVars[
"id"],
907 "name_on_account" => $returnNameOnAccount,
908 "display_name" => $returnDisplayName
911 $returnData[
"data"] = array(
"id" => $pInputVars[
"id"],
912 "display_name" => $returnDisplayName
915 }
catch (Exception $ex) {
917 $message = $ex->getMessage();
918 $code = $ex->getCode();
920 $logInfo = array(
"message" => $message,
"code" => $code );
921 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
923 $returnData[
"code"] =
"999";
924 $returnData[
"errors"][] = $message;
940 function EXT_ValidateAccount( $pDbh, $pHBEnv, $pInputVars, $pMC ) {
942 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
945 if ( $pInputVars[
"id"] == 0 ) {
946 throw new Exception( $pMC->msg(
"EXT Acct Status Error", HCU_DISPLAY_AS_HTML) .
" 1105" );
949 $sql =
"SELECT * FROM {$pHBEnv["Cu
"]}extaccount WHERE id = {$pInputVars["id"]}";
951 $extRs = db_query( $sql, $pDbh );
953 $extRow = db_fetch_array( $extRs, 0 );
955 if ( $extRow[
"id"] == 0 || ($extRow[
"status"] !=
"p" && $extRow[
"status"] !=
"l") ) {
956 throw new Exception( $pMC->msg(
"EXT Acct Status Error", HCU_DISPLAY_AS_HTML) .
" 1106" );
960 $remoteInfo = HCU_JsonDecode( $extRow[
"remote_info"]);
962 if ( !isset( $remoteInfo[
"verify"] ) || ($remoteInfo[
"verify"][
"micro1"] <= 0) || ($remoteInfo[
"verify"][
"micro2"] <= 0) ) {
963 throw new Exception( $pMC->msg(
"EXT Acct Status Error", HCU_DISPLAY_AS_HTML) .
" 1107" );
967 if ( $remoteInfo[
"verify"][
"tries"] <= 0 || $extRow[
"status"] ==
"l" ) {
968 throw new Exception( $pMC->msg(
"EXT Retry Attempt", HCU_DISPLAY_AS_HTML) .
" 1108" );
972 $savedMicro1 = $remoteInfo[
"verify"][
"micro1"];
973 $savedMicro2 = $remoteInfo[
"verify"][
"micro2"];
976 $failedValidation =
true;
977 if ( $pInputVars[
"micro1"] < $pInputVars[
"micro2"] ) {
978 if ( ( $savedMicro1 == $pInputVars[
"micro1"] ) &&
979 ( $savedMicro2 == $pInputVars[
"micro2"] ) ) {
980 $failedValidation =
false;
983 if ( ( $savedMicro1 == $pInputVars[
"micro2"] ) &&
984 ( $savedMicro2 == $pInputVars[
"micro1"] ) ) {
985 $failedValidation =
false;
989 if ( $failedValidation ) {
991 $remoteInfo[
"verify"][
"tries"] -= 1;
992 $remoteInfoStr = prep_save( HCU_JsonEncode( $remoteInfo ) );
994 $returnStatus = $remoteInfo[
"verify"][
"tries"] <= 0 ?
"l" : $extRow[
"status"];
997 if ( $returnStatus ==
"l" ) {
998 $returnMessage = $pMC->msg(
"EXT Retry Attempt", HCU_DISPLAY_AS_HTML) .
" 1123";
1000 $returnMessage = $pMC->msg(
"EXT Acct validation fail", HCU_DISPLAY_AS_HTML) .
" 1124";
1004 $returnStatus =
"a";
1006 date_default_timezone_set(
"UTC");
1007 $remoteInfo[
"verify"] = array(
"verified" => time() );
1008 $remoteInfoStr = prep_save( HCU_JsonEncode( $remoteInfo ) );
1011 $returnMessage = $pMC->msg(
"EXT Acct validation success", HCU_DISPLAY_AS_HTML);
1014 $sql =
"UPDATE {$pHBEnv["Cu
"]}extaccount SET remote_info = '$remoteInfoStr', status = '$returnStatus' 1015 WHERE id = {$extRow["id"]}; ";
1017 $rs = db_query( $sql, $pDbh );
1021 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1109" );
1025 $returnData[
"data"] = array(
"id" => $pInputVars[
"id"],
1026 "status" => $returnStatus,
1027 "tries" => HCU_array_key_value(
"tries", $remoteInfo[
"verify"] ),
1028 "message" => $returnMessage
1030 }
catch (Exception $ex) {
1032 $message = $ex->getMessage();
1033 $code = $ex->getCode();
1035 $logInfo = array(
"message" => $message,
"code" => $code );
1036 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
1038 $returnData[
"code"] =
"999";
1039 $returnData[
"errors"][] = $message;
1055 function EXT_DeleteAccount( $pDbh, $pHBEnv, $pInputVars, $pMC ) {
1057 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
1060 if ( $pInputVars[
"id"] == 0 ) {
1061 throw new Exception( $pMC->msg(
"EXT Acct Status Error", HCU_DISPLAY_AS_HTML) .
" 1110" );
1067 SELECT * FROM cu_scheduledtxn WHERE cu = '{$pHBEnv['Cu']}' AND txn_data::json->'txn'->>'from'='{$pInputVars["id"]}' 1069 SELECT * FROM cu_scheduledtxn WHERE cu = '{$pHBEnv['Cu']}' AND txn_data::json->'txn'->>'to'='{$pInputVars["id"]}'";
1070 $txnRs = db_query( $sql, $pDbh );
1072 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1140" );
1074 $txnData = db_fetch_all($txnRs);
1078 if (!empty($txnData) && count($txnData) > 0) {
1079 throw new Exception($pMC->msg(
"EXT Error Delete Accounts Scheduled", HCU_DISPLAY_AS_HTML) .
"1141");
1105 SELECT * FROM {$pHBEnv['Cu']}transhdr h 1106 LEFT JOIN {$pHBEnv['Cu']}transdtl d ON h.id = d.transhdr_id 1107 WHERE h.feature_code='TRNEXT' 1108 AND h.approved_status is NULL 1109 OR (h.approved_status=10 AND h.processed_status is NULL) 1111 CASE WHEN h.transactioncode='1P' OR h.transactioncode='1W' 1112 THEN d.transdata::json->'acct_dest'->'remote_entity'->>'entry_id'='{$pInputVars['id']}' 1113 ELSE d.transdata::json->'acct_source'->'remote_entity'->>'entry_id'='{$pInputVars['id']}' 1115 $txnRs = db_query( $sql, $pDbh );
1117 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1142" );
1119 $txnData = db_fetch_all($txnRs);
1123 if (!empty($txnData) && count($txnData) > 0) {
1124 throw new Exception($pMC->msg(
"EXT Error Delete Accounts", HCU_DISPLAY_AS_HTML) .
" 1143");
1127 $sql =
"DELETE FROM {$pHBEnv["Cu
"]}extaccount WHERE id = {$pInputVars["id"]}";
1128 $extRs = db_query( $sql, $pDbh );
1130 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1111" );
1132 }
catch (Exception $ex) {
1134 $message = $ex->getMessage();
1135 $code = $ex->getCode();
1137 $logInfo = array(
"message" => $message,
"code" => $code );
1138 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
1140 $returnData[
"code"] =
"999";
1141 $returnData[
"errors"][] = $message;
1157 function EXT_StartAccountVerify( $pDbh, $pHBEnv, $pInputVars, $pMC ) {
1159 $returnData = array(
"code" =>
"000",
"errors" => array(),
"data" => array() );
1163 $sql =
"SELECT settings::json->>'offsetting' AS offsetting, 1164 settings::json->>'cutoff' AS cutoff 1166 WHERE cu = '{$pHBEnv["Cu
"]}'";
1167 $sqlRs = db_query( $sql, $pDbh );
1169 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1131" );
1172 $adminData = db_fetch_assoc( $sqlRs );
1174 $offsetMicroFlag = $adminData[
'offsetting'] ===
"null" ? 0 : $adminData[
'offsetting'];
1175 $achCutoffTime = $adminData[
'cutoff'] ===
"null" ? 0 : $adminData[
'cutoff'];
1179 FROM {$pHBEnv["Cu
"]}extaccount ea 1180 WHERE ea.id = {$pInputVars["ext_acct_id
"]} 1183 $rs = db_query( $sql, $pDbh );
1185 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1132" );
1188 $extRow = db_fetch_array( $rs, 0 );
1190 if ( $extRow[
"id"] == 0 || $extRow[
"status"] !=
"0" ) {
1191 throw new Exception( $pMC->msg(
"EXT Acct Status Error", HCU_DISPLAY_AS_HTML) .
" 1112" );
1195 $remoteInfo = HCU_JsonDecode( $extRow[
"remote_info"]);
1198 $microOne = rand( 10, 70 );
1199 $microTwo = rand( 10, 70 );
1201 $microOneSubmit = round( $microOne / 100, 2 );
1202 $microTwoSubmit = round( $microTwo / 100, 2 );
1203 $microSumSubmit = round( ($microOneSubmit + $microTwoSubmit), 2 );
1206 if ( $microOne < $microTwo ) {
1207 $microSave1 = $microOne;
1208 $microSave2 = $microTwo;
1210 $microSave1 = $microTwo;
1211 $microSave2 = $microOne;
1214 date_default_timezone_set(
"UTC");
1215 $remoteInfo[
"verify"] = array(
"micro1" => $microSave1,
1216 "micro2" => $microSave2,
1218 "pending_date" => time() );
1220 $remoteInfoStr = prep_save( HCU_JsonEncode( $remoteInfo ) );
1222 $sql =
"BEGIN TRANSACTION";
1223 $rs = db_query( $sql, $pDbh );
1225 $sql =
"UPDATE {$pHBEnv["Cu
"]}extaccount SET remote_info = '$remoteInfoStr', status = 'p' 1226 WHERE id = {$extRow["id"]}; ";
1228 $rs = db_query( $sql, $pDbh );
1230 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1138" );
1237 $effDate = date(
"Y-m-d" );
1238 $featureCode = FEATURE_EXTERNAL_TRANSFERS;
1240 $sql =
"INSERT INTO {$pHBEnv["Cu
"]}transhdr (feature_code, effective_date, 1241 posted_by, posted_date, approved_by, approved_date, approved_status, 1242 transactioncode, memo) 1243 VALUES ('{$featureCode}', '{$effDate}', 1244 {$pHBEnv["Uid
"]}, now(), {$pHBEnv["Uid
"]}, now(), 10, 1245 '$transCode', 'External Account Activate' ) 1248 $hdrRs = db_query( $sql, $pDbh );
1251 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1113" );
1255 list($headerId) = db_fetch_array($hdrRs, 0);
1258 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1114" );
1262 $achData = array(
"rdfi" => array(
"rdfi_routing" => $remoteInfo[
"rdfi"][
"routing"],
1263 "rdfi_account" => $remoteInfo[
"rdfi"][
"account"],
1264 "rdfi_account_type" => $remoteInfo[
"rdfi"][
"type"],
1265 "rdfi_txn_type" =>
"CR",
1267 "remote_entity" => array(
"name" => $remoteInfo[
"rdfi"][
"name"],
1268 "entry_id" => $extRow[
"id"],
1269 "display_name" => $extRow[
"display_name"] ) );
1272 $transData = array(
"acct_source" =>
"micro",
"acct_dest" => $achData );
1274 $jsonTransData = prep_save( HCU_JsonEncode( $transData ) );
1277 $referenceId = $pHBEnv[
"Uid"];
1281 $sql =
"INSERT INTO {$pHBEnv["Cu
"]}transdtl (transhdr_id, reference_id, amount, email_notify, transdata) 1282 VALUES ($headerId, $referenceId, $microOneSubmit, 0, '$jsonTransData');";
1283 $sql .=
"INSERT INTO {$pHBEnv["Cu
"]}transdtl (transhdr_id, reference_id, amount, email_notify, transdata) 1284 VALUES ($headerId, $referenceId, $microTwoSubmit, 0, '$jsonTransData')";
1286 $dtlRs = db_query( $sql, $pDbh );
1289 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1115" );
1293 if ( $offsetMicroFlag ) {
1297 $sql =
"INSERT INTO {$pHBEnv["Cu
"]}transhdr (feature_code, effective_date, 1298 posted_by, posted_date, approved_by, approved_date, approved_status, 1299 transactioncode, memo) 1300 VALUES ('{$featureCode}', '{$effDate}', 1301 {$pHBEnv["Uid
"]}, now(), {$pHBEnv["Uid
"]}, now(), 10, 1302 '$transCode', 'Ext Acct Activate Offset' ) 1305 $hdrRs = db_query( $sql, $pDbh );
1308 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1116" );
1312 list($headerId) = db_fetch_array($hdrRs, 0);
1315 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1117" );
1319 $achData[
"rdfi"][
"rdfi_txn_type"] =
"DB";
1320 $transData = array(
"acct_source" => $achData,
"acct_dest" =>
"micro" );
1322 $jsonTransData = prep_save( HCU_JsonEncode( $transData ) );
1325 $sql =
"INSERT INTO {$pHBEnv["Cu
"]}transdtl (transhdr_id, reference_id, amount, email_notify, transdata) 1326 VALUES ($headerId, $referenceId, $microSumSubmit, 0, '$jsonTransData')";
1328 $dtlRs = db_query( $sql, $pDbh );
1331 throw new Exception( $pMC->msg(
"ACH Query Error", HCU_DISPLAY_AS_HTML) .
" 1118" );
1336 $sql =
"COMMIT TRANSACTION";
1337 $achRs = db_query( $sql, $pDbh );
1341 }
catch (Exception $ex) {
1343 $message = $ex->getMessage();
1344 $code = $ex->getCode();
1347 $sql =
"ROLLBACK TRANSACTION";
1348 db_query( $sql, $pDbh );
1350 $logInfo = array(
"message" => $message,
"code" => $code );
1351 $pHBEnv[
"SYSENV"][
"logger"]->error( HCU_JsonEncode( $logInfo ) );
1353 $returnData[
"code"] =
"999";
1354 $returnData[
"errors"][] = $message;