Odyssey
hcuMRDC.data
1 <?php
2 /*
3  * File: hcuMRDC.data
4  * Purpose: Handle the CRUD portion of the Mobile Deposits. When returning the requested data
5  * do it in a JSON format, for the client to display accordingly.
6  *
7  *
8  * Call this script with the following parameters
9  * rdc_type - what the client side is requesting.
10  *
11  * Types:
12  *
13  * Returns JSON OBJECT.
14  */
15 
16  // ** SET SCRIPT LEVEL VARIABLES
17  $serviceShowInfo = true;
18  $serviceLoadMenu = true;
19  $serviceShowMenu = true;
20  $serviceLiveCheck = true;
21  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
22  require_once(dirname(__FILE__) . '/../library/hcuService.i');
23 
24  require_once(dirname(__FILE__) . '/../library/rdcCommon.i');
25  require_once(dirname(__FILE__) . '/../../shared/library/cutrusted.i');
26 
27  PermCheckFeatureScreen($dbh, $HB_ENV, $MC, FEATURE_BASIC);
28 
29  $aryInfo = array();
30  $aryResult = array();
31 
32 try {
33  // ** IMPORT FORM VALUES
34  $inputVars = array();
35  $varOk = array(
36  "rdc_token" => array('filter' => FILTER_SANITIZE_STRING),
37  "rdc_type" => array('filter' => FILTER_SANITIZE_STRING),
38  "depositid" => array('filter' => FILTER_SANITIZE_STRING),
39  "toid" => array('filter' => FILTER_SANITIZE_STRING),
40  "fromid" => array('filter' => FILTER_SANITIZE_STRING),
41  "amount" => array('filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'options' => array( "flags" => FILTER_FLAG_ALLOW_FRACTION ) )
42  );
43 
44  HCU_ImportVars( $inputVars, "", $varOk );
45 
46  header('Content-Type: application/json');
47 
48  $iPayparms_ary = Array();
49 
50  if ( strpos( $inputVars['rdc_token'], "=" ) !== false ||
51  strpos( $inputVars['rdc_token'], "+" ) !== false ) {
52  // already decoded
53  $decodedToken = $inputVars['rdc_token'];
54  $encodedToken = urlencode( $inputVars['rdc_token'] );
55  } else {
56  $encodedToken = $inputVars['rdc_token'];
57  $decodedToken = urldecode( $inputVars['rdc_token'] );
58  }
59  $commonString = hcu_decrypturl( $decodedToken, $HB_ENV['2factorkey']);
60 
61  parse_str( $commonString, $commonParms );
62 
63  $rdcAccount = $commonParms["rdcAccount"];
64  $rdcVendorKey = isset( $commonParms["rdcVendor"] ) ? $commonParms["rdcVendor"] : "";
65  $rdcDepositId = isset( $commonParms["rdcDepositId"] ) ? $commonParms["rdcDepositId"] : 0;
66 
67  switch ( strtolower($inputVars['rdc_type']) ) {
68  case "accounts":
69  $rdcParams = array();
70  $rdcParams["DEPOSITID"] = $rdcDepositId;
71  $rdcParams["RDC_ACTION"] = "AUTH";
72  $rdcParams["MBRACCT"]= $rdcAccount;
73 
74  // Get a token; once we get it we can keep using it so don't lose it.
75  $rdcResultAry = HandleRDCRequest($HB_ENV, $rdcParams);
76 
77  if ($rdcResultAry['STATUS']['CODE'] != '000') {
78  // just the one error message and code
79  $errorMessage = "{$rdcResultAry["STATUS"]["MESSAGE"]} ({$rdcResultAry["STATUS"]["code"]})";
80  throw new Exception( $errorMessage );
81  }
82 
83  if ( is_array($rdcResultAry["RDC_RESPONSE"]["ACCOUNTS"]) ) {
84  // return the account information
85  $accounts = $rdcResultAry["RDC_RESPONSE"]["ACCOUNTS"];
86  $returnData = array();
87  for ( $i = 0; $i < count( $accounts); $i++ ) {
88  $displayName = $accounts[$i]["ACCT"]["DISPLAYDESC"];
89  $acctId = $accounts[$i]["ACCT"]["ACCTID"];
90  $returnData[] = array( "Name" => $displayName, "FromId" => $acctId );
91  }
92  } else {
93  // return error that no accounts found
94  throw new Exception ( $MC->msg("EXT No Accounts", HCU_DISPLAY_AS_HTML) );
95  }
96 
97 
98  // extract the account info
99  $aryResult = $returnData;
100  break;
101  case "history":
102  $rdcParams = array();
103  $rdcParams["DEPOSITID"] = $rdcDepositId;
104  $rdcParams["RDC_ACTION"] = "INFO";
105  $rdcParams["MBRACCT"] = $rdcAccount;
106 
107  // Get a token; once we get it we can keep using it so don't lose it.
108  $rdcResultAry = HandleRDCRequest($HB_ENV, $rdcParams);
109 
110  if ($rdcResultAry['STATUS']['CODE'] != '000') {
111  $errorMessage = "{$rdcResultAry["STATUS"]["MESSAGE"]} ({$rdcResultAry["STATUS"]["CODE"]})";
112 
113  throw new Exception (json_encode($aryErrors));
114  }
115 
116  // need to set up for the Kendo DataSource to handle
117  $aryResult = array();
118  for ( $i = 0; $i < count( $rdcResultAry["RDC_RESPONSE"]["DEPOSITS"] ); $i++ ) {
119  $oneDeposit = $rdcResultAry["RDC_RESPONSE"]["DEPOSITS"][$i]["DEPOSIT"];
120 
121  $aryResult[] = array( "depositId" => $oneDeposit["DEPOSITID"],
122  "acctId" => $oneDeposit["ACCTID"],
123  "amount" => $oneDeposit["AMOUNT"],
124  "amountDisplay" => $oneDeposit["AMOUNTDISPLAY"],
125  "hcuStatus" => $oneDeposit["HCUSTATUS"],
126  "rdcStatus" => $oneDeposit["RDCSTATUS"],
127  "lastUpdate" => date( "m/d/Y h:ia", strtotime($oneDeposit["LASTUPDATE"]) ),
128  "status" => $oneDeposit["STATUS"] );
129  }
130 
131  break;
132  case "deposit":
133  $rdcParams = array();
134  $rdcParams["DEPOSITID"] = $rdcDepositId;
135  $rdcParams["RDC_ACTION"] = "DEPOSIT";
136  $rdcParams["MBRACCT"]= $rdcAccount; // this is the member account
137  $rdcParams['ACCTID'] = $inputVars['toid']; // this is the selected deposit sub-account
138  $rdcParams['AMOUNT'] = $inputVars['amount'] * 100; // amount is expected to be without decimals
139 
140  // Get a token; once we get it we can keep using it so don't lose it.
141  $rdcResultAry = HandleRDCRequest($HB_ENV, $rdcParams);
142 
143  if ($rdcResultAry['STATUS']['CODE'] != '000') {
144  // just the one error message and code
145  $errorMessage = "{$rdcResultAry["STATUS"]["MESSAGE"]} ({$rdcResultAry["STATUS"]["CODE"]})";
146  throw new Exception( $errorMessage );
147  }
148 
149  // need to handle different scenarios based on the return code in /RDC_RESPONSE/RDCSTATUS;
150  // not all plugins will return all choices
151  // "B" = blocked - show user the risks and let them decide
152  // "R" = rejected - user cannot continue without changing something
153  // "F" = fixable - use should be able to change something and try again (usually the amount)
154  // "C" = complete - Yay! It worked
155 
156  // Build up the message based on the status; the client will allow re-submit or cancel for
157  // the ones that can be re-submitted (the logic is similar to Android DepositMainActivity)
158 
159  // every status except "C" will get any messages to show the user ("C" get the HCURECEIPTMESSAGE)
160  $displayMessage = "";
161  if ( $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"] != "C" ) {
162  if ( HCU_array_key_exists( "RISKS", $rdcResultAry["RDC_RESPONSE"] ) &&
163  count( $rdcResultAry["RDC_RESPONSE"]["RISKS"] ) > 0 ) {
164  // get the list of messages to display
165  $messageList = array();
166  for ( $i = 0; $i < count( $rdcResultAry["RDC_RESPONSE"]["RISKS"] ); $i++ ) {
167  $messageList[] = "<p>{$rdcResultAry["RDC_RESPONSE"]["RISKS"][$i]["MSGTEXT"]}</p>";
168  }
169 
170  $displayMessage = implode("", $messageList);
171  }
172 
173  if ( HCU_array_key_exists( "RESPONSECODE", $rdcResultAry["RDC_RESPONSE"] ) &&
174  strlen( $rdcResultAry["RDC_RESPONSE"]["RESPONSECODE"] ) > 0 ) {
175  $displayMessage .= "<p>" . $MC->msg("Response code", HCU_DISPLAY_AS_HTML) . ": {$rdcResultAry["RDC_RESPONSE"]["RESPONSECODE"]}</p>";
176  }
177  }
178 
179  if ( $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"] == "C" ) {
180  // success
181  $aryResult["status"] = $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"];
182  $aryResult["title"] = $MC->msg("Deposit Submitted", HCU_DISPLAY_AS_HTML); // deposit submitted
183 
184  // add the "funds available" to the display message
185  if ( strlen( $rdcResultAry["RDC_RESPONSE"]["FUNDSAVAILABLE"] ) > 0 ) {
186  $displayMessage .= "<p>{$rdcResultAry["RDC_RESPONSE"]["FUNDSAVAILABLE"]}</p>";
187  }
188 
189  if ( strlen( $rdcResultAry["RDC_RESPONSE"]["HCURECEIPTMESSAGE"] ) > 0 ) {
190  $displayMessage .= "<p>{$rdcResultAry["RDC_RESPONSE"]["HCURECEIPTMESSAGE"]}</p>";
191  }
192 
193  $aryResult["message"] = $displayMessage;
194  } else if ( $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"] == "B" ||
195  $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"] == "R" ||
196  $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"] == "F" ) {
197  // "B" and "F" are fixable but user could opt not to
198  $aryResult["status"] = $rdcResultAry["RDC_RESPONSE"]["RDCSTATUS"];
199  $aryResult["title"] = $MC->msg("Attention", HCU_DISPLAY_AS_HTML); // attention - might be fixable
200 
201  $aryResult["message"] = $displayMessage;
202  } else {
203  // unexpected - should not get except by accident
204  $aryResult["status"] = "";
205  $aryResult["title"] = $MC->msg("Unexpected error", HCU_DISPLAY_AS_HTML); // unexpected error
206 
207  $aryResult["message"] = $displayMessage;
208  }
209 
210  break;
211  default:
212  // error
213  throw new Exception ( $MC->msg("ACH Unknown Action", HCU_DISPLAY_AS_HTML) );
214  }
215 
216 }
217 catch(Exception $ex)
218 {
219  //Return error message
220  $aryReply["homecuErrors"] = $ex->getMessage();
221 
222  // if returning error, not replying with data
223  $aryResult = array();
224 
225  // if returning error, not returning status
226  $aryInfo = array();
227 }
228 
229  if ( count( $aryInfo ) ) {
230  $aryReply["homecuInfo"] = $aryInfo;
231  }
232 
233  if ( count( $aryResult ) ) {
234  $aryReply["homecuData"] = $aryResult;
235  //$aryReply = $aryResult;
236  }
237 
238  print json_encode($aryReply);