Odyssey
hcuTransfer.data
1 <?php
2 
3 /*
4  * File: hcuTransfer.data
5  * Purpose: This script will handle all the interaction with a transfer.
6  * Validate Transfer
7  * Complete Transfer
8  * Create Repeating Transfer when necessary
9  *
10  * NOTE:
11  * The creation of a confirmation code relies on the <cu>tranhdr.processed by to have the following values:
12  * (The first two are literal strings, including the "*" character; the 3rd is the admin users name as it is in the database.)
13  * *sched* - if a scheduled transfer and the background scheduler handled it.
14  * *immed* - If an immediate, internal transfer and the transfer posted right away.
15  * AdminName - The name of the admin user that processed the ach transaction.
16  */
17 
18  // ** SET HOMECU FLAGS
19  $serviceShowInfo = false;
20  $serviceLoadMenu = false;
21  $serviceShowMenu = false;
22  $serviceAllowReadonly = false;
23 
24  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
25  require_once(dirname(__FILE__) . '/../library/hcuService.i');
26 
27  // ** INCLUDE to access shared transfer functions
28  require_once(dirname(__FILE__) . '/../library/hcuTransfer.i');
29 
30  // ** INCLUDE to access scheduled transfer functions
31  require_once(dirname(__FILE__) . '/../library/hcuTransferScheduled.i');
32 
33  // ** INCLUDE to access external/member to member functions
34  require_once(dirname(__FILE__) . '/../library/hcuExternalAccts.i');
35 
36  $retStatusAry = Array(
37  'homecuInfo' => '',
38  'homecuErrors' => Array(),
39  'homecuData' => ''
40  );
41  /*
42  * Returned Errors Structure
43  *
44  * homecuInfo => An informational message to report to the user.
45  *
46  * The existence of Errors is proof of an error, if homecuErrors is NOT found or
47  * empty then success is assumed
48  *
49  * 'homecuErrors' element will contain an array of the following object
50  * 'id' => the element id of the error, this is useful so the client side can
51  * highlight the affected element
52  * 'message' => the error message to be displayed back to the member. For
53  * summary only information, leave the 'id' field blank and
54  * enter the message here
55  *
56  * 'homecuData' element will return information to display for the member.
57  * 'transfer' - this will be an array made up of 'label', 'caption' that
58  * will be used to define the confirmation information for the user
59  * 'repeat' - array of 'label', 'caption', used to success of the message.
60  * the 'label', element maybe be empty, the 'caption' will be set to the
61  * message to be displayed to the member
62  * 'posted' - This will be a text string that lets the user know the transfer was posted
63  * and is awaiting approval.
64  */
65 try {
66  // ** There are different types of transfers
67  // ** First check the refer script -- This will be used to ensure proper usage later
68  // * as errors may be returned differently
69  $parseRefer = parse_url($_SERVER['HTTP_REFERER']);
70  $referScript = basename($parseRefer['path']);
71 
72  if (!in_array($referScript, array('hcuTransfer.prg', 'hcuTransferSchedule.prg'))) {
73  // ** Wrong script calling this data routine
74  throw new Exception ( $MC->msg('Feature Unavailable', HCU_DISPLAY_AS_RAW) );
75  }
76 
77  // ** IMPORT - variables for use in both scripts
78  $inputVars = array();
79  $varOk = array(
80  "form" => array('filter' => FILTER_SANITIZE_STRING),
81  "action" => array('filter' => FILTER_SANITIZE_STRING),
82  "txId" => array('filter' => FILTER_SANITIZE_STRING),
83  "txCode" => array('filter' => FILTER_SANITIZE_STRING),
84  "txFromSuffix" => array('filter' => FILTER_SANITIZE_STRING),
85  "txFromDesc" => array('filter' => FILTER_SANITIZE_STRING),
86  "txFromMember" => array('filter' => FILTER_SANITIZE_STRING),
87  "txToSuffix" => array('filter' => FILTER_SANITIZE_STRING),
88  "txMemAccount" => array('filter' => FILTER_SANITIZE_STRING),
89  "txMemName" => array('filter' => FILTER_SANITIZE_STRING),
90  "txMemType" => array('filter' => FILTER_SANITIZE_STRING),
91  "txToDesc" => array('filter' => FILTER_SANITIZE_STRING),
92  "txToMember" => array('filter' => FILTER_SANITIZE_STRING),
93  "txAmount" => array('filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'options' => array( "flags" => FILTER_FLAG_ALLOW_FRACTION ) ),
94  "txMemo" => array('filter' => FILTER_SANITIZE_STRING, 'options' => array( "flags" => FILTER_FLAG_NO_ENCODE_QUOTES)),
95  "txFrequency" => array('filter' => FILTER_SANITIZE_STRING),
96  "txFrequencyCount" => array('filter' => FILTER_SANITIZE_STRING),
97  "txDateStart" => array('filter' => FILTER_SANITIZE_STRING),
98  "txDateEnd" => array('filter' => FILTER_SANITIZE_STRING),
99  "txDateNext" => array('filter' => FILTER_SANITIZE_STRING),
100  "txStatus" => array('filter' => FILTER_SANITIZE_STRING),
101  "txContinue" => array('filter' => FILTER_SANITIZE_STRING),
102  "paymentComment" => array("filter" => FILTER_SANITIZE_STRING, 'options' => array("flags" => FILTER_FLAG_NO_ENCODE_QUOTES)),
103  "transferFrom" => array("filter" => FILTER_SANITIZE_STRING) // hcuTransferSchedule.prg's equivalent of "txFromSuffix."
104  );
105 
106  HCU_ImportVars( $inputVars, "", $varOk );
107 
108  // these are needed to determine the feature for permissions checking
109  $fromScheduledPage = $referScript == "hcuTransferSchedule.prg";
110  $txFromSuffix = HCU_array_key_value("txFromSuffix", $inputVars);
111  $txFromSuffix = $txFromSuffix === false ? HCU_array_key_value("transferFrom", $inputVars) : $txFromSuffix;
112  $txFromSuffix = $txFromSuffix === false ? "" : trim($txFromSuffix);
113  $sourceParts = explode( "|", $txFromSuffix ); // eg "D|1103|10|0
114  $destParts = isset( $inputVars["txToSuffix"] ) ? explode( "|", $inputVars["txToSuffix"] ) : array();
115  $txFromMember = HCU_array_key_value("txFromMember", $inputVars);
116  $txToMember = HCU_array_key_value("txToMember", $inputVars);
117 
118  $txFromMember = $txFromMember === false ? "" : trim($txFromMember);
119  $txToMember = $txToMember === false ? "" : trim($txToMember);
120 
121  if (HCU_array_key_value("action", $inputVars) === "GetTransferToOptions") {
122 
123  $results = GetTransferToOptions($HB_ENV, $sourceParts, $txFromMember, $fromScheduledPage);
124  $return = array("data" => $results["transferToList"], "info" => "", "errors" => $results["error"]);
125  } else {
126  // check if feature is regular, external, M2M or ACH transfer
127  // The checks for ACHPMT / ACHCOL are required because these transfers
128  // may be viewed and altered on the scheduled tranfer screen.
129  if ( (isset( $sourceParts[0] ) && $sourceParts[0] === "X") ||
130  (isset( $destParts[0] ) && $destParts[0] === "X") ) {
131  $transferFeatureCode = FEATURE_EXTERNAL_TRANSFERS;
132  } else if ( isset( $destParts[0] ) && $destParts[0] === "M" ) {
133  $transferFeatureCode = FEATURE_M2M_TRANSFERS;
134  } else if ( (isset( $sourceParts[0] ) && $sourceParts[0] === "AC") ) {
135  $transferFeatureCode = FEATURE_ACH_COLLECTIONS;
136  } else if ( (isset( $destParts[0] ) && $destParts[0] === "AP") ) {
137  $transferFeatureCode = FEATURE_ACH_PAYMENTS;
138  } else {
139  $transferFeatureCode = FEATURE_TRANSFERS;
140  }
141 
142  // save the feature code for use elsewhere
143  $inputVars["feature_code"] = $transferFeatureCode;
144 
145  /*
146  * ** CHECK USER FEATURE PERMISSIONS **
147  * NOTE: DO NOT AUTO-REDIR. Handle perm error here
148  */
149  if (!PermCheckFeatureScreen($dbh, $HB_ENV, $MC, $transferFeatureCode, 'create', false)) {
150  throw new Exception ( $MC->msg('Rights not set', HCU_DISPLAY_AS_HTML) );
151  }
152 
153 
154  $return = array(
155  "data" => "",
156  "info" => "",
157  "errors" => ""
158  );
159 
160  // ** CHECK - form coming from hcuTransferShedule.prg
161  if (isset( $inputVars['form'] ) && ($inputVars['form'] === "schedule")) {
162  // PerformTransferScheduled does all the transactional work, so we just need to return what it returns
163  $results = PerformTransferScheduled( $HB_ENV, $inputVars, $MC );
164 
165  // results from PerformTransferScheduled are passed straight back to the return structure below
166  $return["data"] = $results["data"];
167  $return["info"] = $results["info"];
168  $return["errors"] = $results["status"]["errors"];
169  } else {
170  // PerformTransfer does all the transactional work, so we just need to return what it returns
171  $results = PerformTransfer( $HB_ENV, $inputVars, $MC );
172 
173  if ($results['status']['code'] === "000") {
174 
175  if ( HCU_array_key_exists( "txn", $results["data"] ) ) {
176  // Return the information to display to the user. Use the Posted date and confirmation regardless if needed confirmation or not.
177  $submitResults = $results["data"]["txn"];
178  $retData = Array(
179  Array("label" => $MC->msg('Date', HCU_DISPLAY_AS_RAW), 'caption' => $submitResults["data_date"]),
180  Array("label" => $MC->msg('Action', HCU_DISPLAY_AS_RAW), 'caption' => $submitResults["data_action"]),
181  Array("label" => $MC->msg('From', HCU_DISPLAY_AS_RAW), 'caption' => $submitResults["data_from"]),
182  Array("label" => $MC->msg('To', HCU_DISPLAY_AS_RAW), 'caption' => $submitResults["data_to"]),
183  Array("label" => $MC->msg('Amount', HCU_DISPLAY_AS_RAW), 'caption' => "$" . mobile_formatnumber($submitResults["data_amount"]), ","),
184  Array("label" => $MC->msg('Confirmation', HCU_DISPLAY_AS_RAW), 'caption' => $submitResults["data_confirm"])
185  );
186 
187  $return["data"]["transfer"] = $retData;
188  }
189 
190  if ( HCU_array_key_exists( "posted", $results["data"] ) ) {
191  $return["data"]["posted"] = $results["data"]["posted"];
192  }
193 
194  if ( HCU_array_key_exists( "repeat", $results["data"] ) ) {
195  $return["data"]["repeat"] = $results["data"]["repeat"];
196  }
197  }
198 
199  // this will pick up any errors
200  $return["errors"] = $results["status"]["errors"];
201  }
202  }
203 
204  $retStatusAry["homecuData"] = $return["data"];
205  $retStatusAry["homecuInfo"] = $return["info"]; // special for this function because could have a partial completion
206  $retStatusAry["homecuErrors"] = $return["errors"];
207 
208 }
209 catch(Exception $ex)
210 {
211  // NOTE: We need to return any data that was set up because the initial transfer may have worked but the recurring schedule failed.
212  $retStatusAry['homecuErrors'] = $ex->getMessage();
213 }
214 
215  header('Content-type: application/json');
216 
217  print HCU_JsonEncode(Array("Results" => Array($retStatusAry)));
218 
219  // NO MORE OUTPUT AFTER THIS POINT!