Odyssey
PAYVERIS_API.i
1 <?php
2 
3 
4 define( "MP_PV_ERROR_CODE", "5010" );
5 
6 
7 function bpAuth($parms) {
8  try {
9  $return=array('status'=>array('response'=>'true','code'=>'000','message'=>'success'));
10 
11  if ($parms['pilot'] == 1) {
12  $parms['serviceurl'] = $parms['piloturl'];
13  } else {
14  $parms['serviceurl'] = $parms['produrl'];
15  }
16 
17  $parms['Token']=time();
18 
19  $reqdata = PV_getUserProfile($parms); # how to know if member is authorized
20  if ($reqdata['status']['response'] != 'true') {
21  throw new Exception($reqdata['status']['message']);
22  }
23  # format valid response array
24  $return['data']['Token']=time();
25  $return['data']['BillpayId']=$parms['BillpayId'];
26  $output['MoblPayName']= (trim($parms['MoblPayName']) == '' ? htmlentities('Pay Bills') : htmlentities($parms['MoblPayName']));
27  $return['data']['DateModel']=$parms['datemodel'];
28  $return['data']['Extras']=htmlentities($parms['ExtraOptions']);
29 
30  } catch (Exception $e) {
31  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage(),'code'=>'999'),'data'=>array('Token'=>'0'));
32  }
33  return $return;
34 }
35 
36 function bpHist($parms) {
37  try {
38  $return=array('status'=>array('response'=>'true','message'=>'success'));
39  if ($parms['pilot'] == 1) {
40  $parms['serviceurl'] = $parms['piloturl'];
41  } else {
42  $parms['serviceurl'] = $parms['produrl'];
43  }
44  $parms['Token']=$parms['passwith']['Token'];
45  $reqdata = pscuGetRecentPayments($parms); # get payment history
46 
47  if ($reqdata['status']['response'] != 'true') {
48  throw new Exception($reqdata['status']['message']);
49  }
50  # format valid response array
51  $return['data'][]=$item;
52 
53  # sort if needed
54  if (is_array($return['data'])) {
55  usort($return['data'], "histSort");
56  }
57 
58  } catch (Exception $e) {
59  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
60  }
61  return $return;
62 }
63 
64 function bpSched($parms) {
65  try {
66  $return=array('status'=>array('response'=>'true','message'=>'success'));
67  if ($parms['pilot'] == 1) {
68  $parms['serviceurl'] = $parms['piloturl'];
69  } else {
70  $parms['serviceurl'] = $parms['produrl'];
71  }
72 
73  $parms['Token']=$parms['passwith']['Token'];
74  $reqdata = pscuGetScheduledPayments($parms); # show scheduled payments
75  if ($reqdata['status']['response'] != 'true') {
76  throw new Exception($reqdata['status']['message']);
77  }
78 
79  # format valid response array
80 
81  $return['data'][]=$item;
82 
83  # sort if needed
84  if (is_array($return['data'])) {
85  usort($return['data'], "schedSort");
86  }
87 
88  } catch (Exception $e) {
89  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
90  }
91  return $return;
92 }
93 
94 function bpSourceAccts($parms) {
95  try {
96  $return=array('status'=>array('response'=>'true','message'=>'success'));
97  if ($parms['pilot'] == 1) {
98  $parms['serviceurl'] = $parms['piloturl'];
99  } else {
100  $parms['serviceurl'] = $parms['produrl'];
101  }
102 
103  $parms['Token']=$parms['passwith']['Token'];
104  $reqdata = pscuBankAccounts($parms); # get source accounts
105  if ($reqdata['status']['response'] != 'true') {
106  throw new Exception($reqdata['status']['message']);
107  }
108  $hasAtLeastOneAccount = false;
109  // make sure we have a name for the account
110  if ( strlen( $item["Name"] ) == 0 &&
111  strlen( $item["FromId"] ) > 0 ) {
112  $parts = explode( "|", $item["FromId"] );
113  $item["Name"] = $parts[0];
114  }
115 
116  $return['data'][]=$item;
117 
118  if ( !$hasAtLeastOneAccount ) {
119  throw new Exception("No source accounts received from vendor.");
120  }
121  } catch (Exception $e) {
122  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
123  }
124  return $return;
125 }
126 
127 function bpDestAccts($parms) {
128  try {
129  $return=array('status'=>array('response'=>'true','message'=>'success'));
130  if ($parms['pilot'] == 1) {
131  $parms['serviceurl'] = $parms['piloturl'];
132  } else {
133  $parms['serviceurl'] = $parms['produrl'];
134  }
135 
136  $parms['Token']=$parms['passwith']['Token'];
137  $reqdata = pscuGetPayees($parms); # get destination accounts
138  if ($reqdata['status']['response'] != 'true') {
139  throw new Exception($reqdata['status']['message']);
140  }
141  $hasAtLeastOneAccount = false;
142  $return['data'][]=$item;
143 
144  if ( !$hasAtLeastOneAccount ) {
145  throw new Exception("No destination accounts received from vendor.");
146  }
147  } catch (Exception $e) {
148  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
149  }
150  return $return;
151 }
152 
153 function bpPmtAdd($parms) {
154  try {
155  $return=array('status'=>array('response'=>'true','message'=>'success'));
156  if ($parms['pilot'] == 1) {
157  $parms['serviceurl'] = $parms['piloturl'];
158  } else {
159  $parms['serviceurl'] = $parms['produrl'];
160  }
161  list($acctno,$accttype,$rt) = explode("|",$parms['passwith']['FromId']);
162  $parms['Token']=$parms['passwith']['Token'];
163  $parms['PayeeId'] = $parms['passwith']['ToId'];
164  $parms['AcctNo'] = $acctno;
165  $parms['AcctType'] = $accttype;
166  $parms['rt'] = $rt;
167  $parms['PayDate'] = $parms['passwith']['Date'];
168  $parms['Amount'] = $parms['passwith']['Amount'];
169  $parms['DelMethod'] = 'REGULAR_PAYMENT'; # allow rush if available?
170 
171  $reqdata = pscuAddPayment($parms); # submit payment
172  if ($reqdata['status']['response'] != 'true') {
173  throw new Exception($reqdata['status']['message']);
174  }
175 
176  $return['data']['Confirmation']=$reqdata['data']['confirmationNumber'];
177  $return['data']['TransactionId']=$reqdata['data']['transactionID'];
178  $return['data']['EstimatedArrival']='';
179 
180  } catch (Exception $e) {
181  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
182  }
183  return $return;
184 }
185 
186 function bpTrnAdd($parms) {
187  try {
188  $return=array('status'=>array('response'=>'true','message'=>'success'),'data'=>array());
189  # if no Transfer functionality - just return error
190  throw new Exception('Feature Unavailable');
191  } catch (Exception $e) {
192  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
193  }
194  return $return;
195 }
196 
197 function bpPmtEdit($parms) {
198  try {
199  $return=array('status'=>array('response'=>'true','message'=>'success'));
200  if ($parms['pilot'] == 1) {
201  $parms['serviceurl'] = $parms['piloturl'];
202  } else {
203  $parms['serviceurl'] = $parms['produrl'];
204  }
205 
206  list($acctno,$accttype,$rt) = explode("|",$parms['passwith']['FromId']);
207  $parms['Token']=$parms['passwith']['Token'];
208  $parms['txnID'] = $parms['passwith']['TxnId'];
209  $parms['PayeeId'] = $parms['passwith']['ToId'];
210  $parms['AcctNo'] = $acctno;
211  $parms['AcctType'] = $accttype;
212  $parms['rt'] = $rt;
213  $parms['PayDate'] = $parms['passwith']['Date'];
214  $parms['Amount'] = $parms['passwith']['Amount'];
215  # PSCU mobile doesn't support rush payments
216  $parms['DelMethod'] = 'REGULAR_PAYMENT';
217 
218  $reqdata = pscuEditPayment($parms); # update payment
219  if ($reqdata['status']['response'] != 'true') {
220  throw new Exception($reqdata['status']['message']);
221  }
222 
223  $return['data']['Confirmation']=$reqdata['data']['confirmationNumber'];
224  $return['data']['TransactionId']=$reqdata['data']['transactionID'];
225  $return['data']['EstimatedArrival']='';
226 
227 
228  } catch (Exception $e) {
229  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
230  }
231  return $return;
232 }
233 
234 function bpPmtStop($parms) {
235  try {
236  $return=array('status'=>array('response'=>'true','message'=>'success'));
237  if ($parms['pilot'] == 1) {
238  $parms['serviceurl'] = $parms['piloturl'];
239  } else {
240  $parms['serviceurl'] = $parms['produrl'];
241  }
242 
243  $parms['Token']=$parms['passwith']['Token'];
244  $parms['txnID'] = $parms['passwith']['TxnId'];
245 
246 
247  $reqdata = pscuCancelPayment($parms); # cancel payment
248  if ($reqdata['status']['response'] != 'true') {
249  throw new Exception($reqdata['status']['message']);
250  }
251  $return['data']['StopResult']=1;
252 
253  } catch (Exception $e) {
254  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
255  }
256  return $return;
257 }
258 
259 function bpGetPaymentDates($parms) {
260  try {
261  $return=array('status'=>array('response'=>'true','message'=>'success'));
262 
263  if ($parms['pilot'] == 1) {
264  $parms['serviceurl'] = $parms['piloturl'];
265  } else {
266  $parms['serviceurl'] = $parms['produrl'];
267  }
268 
269  $parms['Token']=$parms['passwith']['Token'];
270 
271  $reqdata = pscuGetPayees($parms); # get business dates
272  if ($reqdata['status']['response'] != 'true') {
273  throw new Exception($reqdata['status']['message']);
274  }
275  # format calendar
276 
277  $datelist=array();
278  # test $firstpay to make sure it is a date?
279  $defaultTZ=date_default_timezone_get(); # so we can put it back
280  date_default_timezone_set('UTC');
281  $now=time();
282  if($now > strtotime( $cutoff )) {
283  $Start = strtotime( $nextpay );
284  } else {
285  $Start = strtotime( $firstpay );
286  }
287  # if Start is false (strtotime failed) use current time
288  $Start = ($Start ? $Start : $now);
289  $End = $Start + (90 * 24 * 60 * 60);
290  $holidays = ListHolidays(date('Y',$Start),date('Y',$End));
291  for ($i=$Start; $i<=$End; $i+=86400) {
292  $i=GetNextBusiness($i);
293  $item=array();
294  $idate = gmdate('Y-m-d',$i);
295  if (!in_array($idate,$holidays)) {
296  $item['Proc'] = gmdate('Y-m-d',$i);
297  if (strtoupper($parms['datemodel']) == 'DUE') {
298  $item['Due'] = gmdate('Y-m-d',GetNextBusiness($i+($lead*86400)));
299  }
300 
301  $datelist[]=$item;
302  }
303  }
304 
305  date_default_timezone_set($defaultTZ);
306 
307  $return['data']['EarliestPay'] = $firstpay;
308  $return['data']['NextPay'] = $nextpay;
309  $return['data']['Cutoff'] = $cutoff;
310  $return['data']['LeadDays'] = $lead;
311  # build RushOptions list like this:
312 // $return['data']['RushOptions'][]=array('Display'=>'Overnight','Value'=>'OVERNIGHT_CHECK','Price'=>'14.95');
313  $return['data']['RushOptions']=array();
314  $return['data']['PaymentDates']=$datelist;
315  } catch (Exception $e) {
316  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
317  }
318  return $return;
319 }
320 
321 function bpGetTerms($parms) {
322  try {
323  # PayVeris has no Get Terms functionality - just return empty success
324  $return=array('status'=>array('response'=>'true','message'=>'success'),'data'=>array('Terms'=>''));
325  } catch (Exception $e) {
326  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
327  }
328  return $return;
329 }
330 
331 function bpGetRushOptions($parms) {
332  try {
333  # PayVeris has no Rush Options functionality - just return empty success
334  $return=array('status'=>array('response'=>'true','message'=>'success'),'data'=>array());
335  } catch (Exception $e) {
336  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
337  }
338  return $return;
339 }
340 
341 function bpAcceptTerms($parms) {
342  try {
343  # PayVeris has no Accept Terms functionality - just return empty success
344  $return=array('status'=>array('response'=>'true','message'=>'success'),'data'=>array());
345  } catch (Exception $e) {
346  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
347  }
348  return $return;
349 }
350 
351 function bpGetFeatureList($parms) {
352  try {
353  # Need to decide what the data looks like here -- string list of available features
354  # maybe something out of trusteddetail (which comes to this function in $parms)
355  # to allow customizing by cu
356  $return=array('status'=>array('response'=>'true','message'=>'success'),'data'=>array('featurelist'=>"Payment|History|Scheduled"));
357  } catch (Exception $e) {
358  $return=array('status'=>array('response'=>'false','message'=>$e->getMessage()),'code'=>MP_PV_ERROR_CODE,'data'=>array());
359  }
360  return $return;
361 }
362 function schedSort($a, $b)
363 {
364  $atime = strtotime($a['Date']);
365  $btime = strtotime($b['Date']);
366  if ($atime == $btime) {
367  if ($a['ToName'] == $b['ToName']) {
368  return 0;
369  }
370  return ($a['ToName'] < $b['ToName']) ? -1 : 1;
371  }
372  return ($atime < $btime) ? -1 : 1;
373 }
374 
375 function histSort($a, $b) {
376  $atime = strtotime($a['Date']);
377  $btime = strtotime($b['Date']);
378  if ($atime == $btime) {
379  if ($a['ToName'] == $b['ToName']) {
380  return 0;
381  }
382  return ($a['ToName'] < $b['ToName']) ? -1 : 1;
383  }
384  return ($atime > $btime) ? -1 : 1;
385 }
386 
387 function PV_createUserSession($parms) {
388 # uses: $parms['APIKey']
389 # $parms['APIVersion']
390 # $parms['ClientCode']
391 # $parms['clientid']
392 # $parms['BillpayId']
393 # $parms['MIR']
394 //
395 
396  try {
397  if (!isset($parms['passwith']['Cu']) ||
398  !isset($parms['APIKey']) ||
399  !isset($parms['serviceurl']) ||
400  !isset($parms['APIVersion']) ||
401  !isset($parms['ClientCode']) ||
402  !isset($parms['passwith']['BillpayId']) ||
403  !count($parms['passwith']['Accounts'])) {
404  throw new Exception("Missing Parameters");
405  }
406  list($msec, $sec) = explode(" ", microtime());
407  $floatsec = sprintf("%03d", (float) $msec * 1000);
408  $RequestID = (gmdate("YmdHis")) . $floatsec;
409 // $parms['MIR']["class"] = 'B';
410 // $parms['MIR']["firstname"] = '.';
411  $pvCustomerType = ( in_array($parms['MIR']["class"], array('B','T') ) ? 'Business' : 'Personal');
412 
413  $soapString = '<?xml version="1.0" encoding="utf-8"?>';
414  $soapString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cus=\"http://www.payveris.com/api/schema/CustomerServices\" xmlns:com=\"http://www.payveris.com/api/schema/CommonTypes\">";
415  $soapString .= "\n<soapenv:Header/>";
416  $soapString .= "\n<soapenv:Body>";
417  $soapString .= "<cus:CreateUserSessionRequest>
418  <com:Version>{$parms['APIVersion']}</com:Version>
419  <com:APIKey>{$parms['APIKey']}</com:APIKey>
420  <com:ClientCode>{$parms['ClientCode']}</com:ClientCode>
421  <com:RequestId>$RequestID</com:RequestId>
422  <cus:CustomerProfile CustomerCode=\"{$parms['passwith']['BillpayId']}\" UserCode=\"{$parms['passwith']['BillpayId']}\">
423  <com:CustomerType>{$pvCustomerType}</com:CustomerType>
424  <com:Prefix></com:Prefix>
425  <com:FirstName>{$parms['MIR']["firstname"]}</com:FirstName>
426  <com:MiddleInitial></com:MiddleInitial>
427  <com:LastName>{$parms['MIR']["lastname"]}</com:LastName>
428  <com:Suffix></com:Suffix>
429  <com:EmailAddress>{$parms['MIR']['email']}</com:EmailAddress>
430  <com:UserRole>{$pvCustomerType}</com:UserRole>\n";
431  if (isset($parms['MIR']["homephone"])) {
432  $soapString .= "<com:Phone>
433  <com:NumberType>Personal</com:NumberType>
434  <com:AreaCode>{$parms['MIR']["homephone"]['Area']}</com:AreaCode>
435  <com:Prefix>{$parms['MIR']["homephone"]['Pre']}</com:Prefix>
436  <com:Number>{$parms['MIR']["homephone"]['Num']}</com:Number>
437  </com:Phone>\n";
438  }
439  if (isset($parms['MIR']["cellphone"])) {
440  $soapString .= "<com:Phone>
441  <com:NumberType>Cellular</com:NumberType>
442  <com:AreaCode>{$parms['MIR']["cellphone"]['Area']}</com:AreaCode>
443  <com:Prefix>{$parms['MIR']["cellphone"]['Pre']}</com:Prefix>
444  <com:Number>{$parms['MIR']["cellphone"]['Num']}</com:Number>
445  </com:Phone>\n";
446  }
447  if (isset($parms['MIR']["workphone"])) {
448  $soapString .= "<com:Phone>
449  <com:NumberType>Business</com:NumberType>
450  <com:AreaCode>{$parms['MIR']["workphone"]['Area']}</com:AreaCode>
451  <com:Prefix>{$parms['MIR']["workphone"]['Pre']}</com:Prefix>
452  <com:Number>{$parms['MIR']["workphone"]['Num']}</com:Number>
453  </com:Phone>\n";
454  }
455  $soapString .= "<com:Address>
456  <com:AddressLine1>{$parms['MIR']['address1']}</com:AddressLine1>\n";
457  if (isset($parms['MIR']['Address2'])) {
458  $soapString .= "<com:AddressLine2>{$parms['MIR']['address2']}</com:AddressLine2>\n";
459  }
460  $soapString .= "<com:City>{$parms['MIR']['city']}</com:City>
461  <com:StateCode>{$parms['MIR']['state']}</com:StateCode>
462  <com:ZipCode>{$parms['MIR']['zip']}</com:ZipCode>
463  <com:Country>{$parms['MIR']['cc']}</com:Country>
464  </com:Address>\n";
465  if ($pvCustomerType == 'Business') {
466  # documentation does not show Address as part of Business profile,
467  # but connection fails without it
468  $soapString .= "<com:Business>
469  <com:BusinessName>{$parms['MIR']["lastname"]}</com:BusinessName>
470  <com:EmailAddress>{$parms['MIR']['email']}</com:EmailAddress>
471  <com:Address>
472  <com:AddressLine1>{$parms['MIR']['address1']}</com:AddressLine1>\n";
473  if (isset($parms['MIR']['Address2'])) {
474  $soapString .= "<com:AddressLine2>{$parms['MIR']['address2']}</com:AddressLine2>\n";
475  }
476  $soapString .= "<com:City>{$parms['MIR']['city']}</com:City>
477  <com:StateCode>{$parms['MIR']['state']}</com:StateCode>
478  <com:ZipCode>{$parms['MIR']['zip']}</com:ZipCode>
479  <com:Country>{$parms['MIR']['cc']}</com:Country>
480  </com:Address>
481  </com:Business>\n";
482  }
483  $soapString .= "<com:Accounts>\n";
484  if (is_array($parms['passwith']['Accounts'])) {
485  foreach ($parms['passwith']['Accounts'] as $acctkey => $acct) {
486  if (is_array($acct)) {
487 
488  if( isset( $parms['SendCoreSpecific'] ) && $parms['SendCoreSpecific'] ) {
489  $csatTag = "<com:CoreSpecificAccountType>{$acct['corespecific']}</com:CoreSpecificAccountType>";
490  } else {
491  $csatTag = '';
492  }
493 
494  $soapString .= "<com:Account AccountCode=\"$acctkey\" PayBillsFrom=\"{$acct['paybillsfrom']}\" PrimaryBillPaymentAccount=\"false\" TransferFrom=\"{$acct['transferfrom']}\" TransferTo=\"{$acct['transferto']}\">
495  <com:RoutingNumber>{$parms['passwith']['rt']}</com:RoutingNumber>
496  <com:AccountNumber>{$acct['micraccount']}</com:AccountNumber>
497  <com:Description>" . htmlspecialchars($acct['description'], ENT_QUOTES, 'UTF-8', FALSE) . "</com:Description>
498  <com:Type>{$acct['depositdesc']}</com:Type>
499  <com:Balance>{$acct['acctbalance']}</com:Balance>
500  <com:BalanceAsOfDate>{$acct['acctbalasof']}</com:BalanceAsOfDate>
501  " . $csatTag . "
502  <com:AccountStatus>Active</com:AccountStatus>
503  <com:AccessRole>Full</com:AccessRole>
504  </com:Account>\n";
505  }
506  }
507  }
508  $soapString .= "</com:Accounts>
509  <com:Status>Active</com:Status>
510  </cus:CustomerProfile>
511  <cus:SessionValidForMinutes>30</cus:SessionValidForMinutes>
512  <cus:UnreadMessageCount>0</cus:UnreadMessageCount>
513  </cus:CreateUserSessionRequest>
514  </soapenv:Body>
515 </soapenv:Envelope>\n";
516 
517  $reqHeaders = array();
518  $reqHeaders[] = "Content-Type: text/xml; charset=utf-8";
519  $reqHeaders[] = 'SOAPAction: ""';
520 
521  $response = PV_embcurl("{$parms['serviceurl']}/CustomerServices", $soapString, $reqHeaders);
522 
523  if (empty($response)) {
524  throw new Exception("Empty Response");
525  }
526  if (is_array($response) && isset($response['curl_errno'])) {
527  throw new Exception("Curl Error {$response['curl_errno']} {$response['curl_error']}");
528  }
529  # call parse function to format response array
530  $xmlreturn = PV_GetXMLItem($response, 'ArtifactId', 'http://www.payveris.com/api/schema/CustomerServices');
531  if (!is_array($xmlreturn)) {
532  throw new Exception("Invalid XML Response" );
533  }
534  if ( isset( $xmlreturn['faultcode'] ) && $xmlreturn['faultcode'] ) {
535  throw new Exception("PV Fault {$xmlreturn['faultcode']} {$xmlreturn['faultstring']}");
536  }
537  $return["status"]["response"] = 'true';
538  $return["status"]["code"] = '000';
539  $return["status"]["message"] = 'Success';
540  $return["data"]['ArtifactId'] = $xmlreturn[0];
541 
542  $return["request"] = $soapString;
543  $return["raw"] = $response;
544  } catch (Exception $e) {
545  $return["status"]["response"] = 'false';
546  $return["status"]["message"] = $e->getMessage();
547  }
548  if ( $parms["logging"] == "enabled" ) {
549  $logParms = $parms["environment"]; // get the environment info passed in
550  $logParms["token"] = $return["data"]['ArtifactId']; // the id used across all communications in session
551  $logParms["txnId"] = time(); // the id for this transaction
552  $logParms["logPoint"] = "CreateUserSessionRequest"; // this action in a readable form
553  $logParms["request"] = "{$logParms['platform']} : userIP {$logParms['userIP']} userAgent {$logParms['userAgent']} \n$soapString"; // the request
554  $logParms["reply"] = $response; // the response
555  LogSSOActivity( $logParms );
556  }
557 
558  return $return;
559 }
560 function PV_getUserProfile($parms) {
561 # uses: $parms['APIKey']
562 # $parms['APIVersion']
563 # $parms['ClientCode']
564 # $parms['clientid']
565 # $parms['BillpayId']
566 # $parms['MIR']
567 //
568 
569  try {
570  if (!isset($parms['APIKey']) ||
571  !isset($parms['serviceurl']) ||
572  !isset($parms['APIVersion']) ||
573  !isset($parms['ClientCode']) ||
574  !isset($parms['passwith']['BillpayId'])) {
575  throw new Exception("Missing Parameters");
576  }
577  list($msec, $sec) = explode(" ", microtime());
578  $floatsec = sprintf("%03d", (float) $msec * 1000);
579  $RequestID = (gmdate("YmdHis")) . $floatsec;
580 
581  $soapString = '<?xml version="1.0" encoding="utf-8"?>';
582  $soapString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cus=\"http://www.payveris.com/api/schema/CustomerServices\" xmlns:com=\"http://www.payveris.com/api/schema/CommonTypes\">";
583  $soapString .= "\n<soapenv:Header/>";
584  $soapString .= "\n<soapenv:Body>";
585  $soapString .= "<cus:GetUserProfileRequest>
586  <com:Version>{$parms['APIVersion']}</com:Version>
587  <com:APIKey>{$parms['APIKey']}</com:APIKey>
588  <com:ClientCode>{$parms['ClientCode']}</com:ClientCode>
589  <com:RequestId>$RequestID</com:RequestId>
590  <com:UserCode>{$parms['passwith']['BillpayId']}</com:UserCode>
591  </cus:GetUserProfileRequest>
592  </soapenv:Body>
593 </soapenv:Envelope>\n";
594 
595  $reqHeaders = array();
596  $reqHeaders[] = "Content-Type: text/xml; charset=utf-8";
597  $reqHeaders[] = 'SOAPAction: ""';
598 
599  $response = PV_embcurl("{$parms['serviceurl']}/CustomerServices", $soapString, $reqHeaders);
600 
601  if (empty($response)) {
602  throw new Exception("Empty Response");
603  }
604  if (is_array($response) && isset($response['curl_errno'])) {
605  throw new Exception("Curl Error {$response['curl_errno']} {$response['curl_error']}");
606  }
607  # call parse function to format response array
608  $xmlreturn = PV_GetXMLResponse($response, 'CustomerProfile', 'http://www.payveris.com/api/schema/CustomerServices');
609  if (!is_array($xmlreturn)) {
610  throw new Exception("Invalid XML Response");
611  }
612  if ($xmlreturn['faultcode']) {
613  throw new Exception("PV Fault {$xmlreturn['faultcode']} {$xmlreturn['faultstring']}");
614  }
615  $return["status"]["response"] = 'true';
616  $return["status"]["code"] = '000';
617  $return["status"]["message"] = 'Success';
618  $return["data"]['ArtifactId'] = $xmlreturn[0];
619 
620 // $return[request] = $soapString;
621 // $return[raw] = $response;
622  } catch (Exception $e) {
623  $return["status"]["response"] = 'false';
624  $return["status"]["message"] = $e->getMessage();
625  }
626  return $return;
627 }
628 function PV_getPaymentAccounts($parms) {
629 # uses: $parms['APIKey']
630 # $parms['APIVersion']
631 # $parms['ClientCode']
632 # $parms['clientid']
633 # $parms['BillpayId']
634 # $parms['MIR']
635 //
636 
637  try {
638  if (!isset($parms['APIKey']) ||
639  !isset($parms['serviceurl']) ||
640  !isset($parms['APIVersion']) ||
641  !isset($parms['ClientCode']) ||
642  !isset($parms['passwith']['BillpayId'])) {
643  throw new Exception("Missing Parameters");
644  }
645  list($msec, $sec) = explode(" ", microtime());
646  $floatsec = sprintf("%03d", (float) $msec * 1000);
647  $RequestID = (gmdate("YmdHis")) . $floatsec;
648  $parms['passwith']['BillpayId'] = '0000000223';
649  $soapString = '<?xml version="1.0" encoding="utf-8"?>';
650  $soapString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cus=\"http://www.payveris.com/api/schema/CustomerServices\" xmlns:com=\"http://www.payveris.com/api/schema/CommonTypes\">";
651  $soapString .= "\n<soapenv:Header/>";
652  $soapString .= "\n<soapenv:Body>";
653  $soapString .= "<pay:GetUserPaymentAccountsRequest>
654  <com:Version>{$parms['APIVersion']}</com:Version>
655  <com:APIKey>{$parms['APIKey']}</com:APIKey>
656  <com:ClientCode>{$parms['ClientCode']}</com:ClientCode>
657  <com:RequestId>$RequestID</com:RequestId>
658  <com:UserCode>{$parms['passwith']['BillpayId']}</com:UserCode>
659  </pay:GetUserPaymentAccountsRequest>
660  </soapenv:Body>
661 </soapenv:Envelope>\n";
662 
663  $reqHeaders = array();
664  $reqHeaders[] = "Content-Type: text/xml; charset=utf-8";
665  $reqHeaders[] = 'SOAPAction: ""';
666 
667  $response = PV_embcurl("{$parms['serviceurl']}/PaymentServices", $soapString, $reqHeaders);
668 
669  if (empty($response)) {
670  throw new Exception("Empty Response");
671  }
672  if (is_array($response) && isset($response['curl_errno'])) {
673  throw new Exception("Curl Error {$response['curl_errno']} {$response['curl_error']}");
674  }
675  # call parse function to format response array
676  $xmlreturn = PV_GetXMLResponse($response, 'Accounts', 'http://www.payveris.com/api/schema/PaymentServices');
677  if (!is_array($xmlreturn)) {
678  throw new Exception("Invalid XML Response");
679  }
680  if ($xmlreturn['faultcode']) {
681  throw new Exception("PV Fault {$xmlreturn['faultcode']} {$xmlreturn['faultstring']}");
682  }
683  $return["status"]["response"] = 'true';
684  $return["status"]["code"] = '000';
685  $return["status"]["message"] = 'Success';
686  $return["data"] = $xmlreturn[0];
687 
688 // $return[request] = $soapString;
689 // $return[raw] = $response;
690  } catch (Exception $e) {
691  $return["status"]["response"] = 'false';
692  $return["status"]["message"] = $e->getMessage();
693  }
694  return $return;
695 }
696 
697 function PV_GetXMLItem($pvXML, $pvCONT, $pvNS) {
698  try {
699  $xml = simplexml_load_string($pvXML,"SimpleXMLElement",LIBXML_NOWARNING);
700  if (!is_object($xml)) {
701  throw new Exception("Invalid XML");
702  }
703 
704  $xml->registerXPathNamespace('s', "http://schemas.xmlsoap.org/soap/envelope/");
705  $errorresponse = $xml->xpath("//s:Fault");
706  if(is_array($errorresponse) && count($errorresponse)) {
707  $resp_arr = array('faultcode' => $errorresponse[0]->faultcode,
708  'faultstring' => $errorresponse[0]->faultstring);
709  } else {
710 
711 // $tfile = fopen ("/tmp/pv_rawxml","a");
712 // $dstamp = date("Ymd h:i:s");
713 // fwrite($tfile, "($dstamp) $pvCONT:\n$pvXML\n");
714 // fwrite($tfile, "result with '//bill:$pvCONT' : " . print_r($dataresponse,true));
715 // fwrite($tfile, "resp_arr: " . print_r($resp_arr,true));
716 // fclose ($tfile);
717 
718  $xml->registerXPathNamespace('bill', $pvNS);
719  $dataresponse = $xml->xpath("//bill:$pvCONT");
720 // $resp_arr=array("$pvCONT" => $dataresponse[0][0]->__toString() );
721 // $item = $dataresponse[0]->__toString();
722  if (!is_object($dataresponse[0])) {
723  throw new Exception("Invalid Response Object");
724  }
725  $resp_arr = array($dataresponse[0]->__toString());
726  }
727 
728  } catch (Exception $e) {
729  $resp_arr = false;
730  }
731  return $resp_arr;
732 }
733 function PV_GetXMLResponse($pvXML, $pvCONT, $pvNS) {
734  try {
735  $xml = simplexml_load_string($pvXML,"SimpleXMLElement",LIBXML_NOWARNING);
736  if (!is_object($xml)) {
737  throw new Exception("Invalid XML");
738  }
739 
740  $xml->registerXPathNamespace('s', "http://schemas.xmlsoap.org/soap/envelope/");
741  $errorresponse = $xml->xpath("//s:Fault");
742  if(is_array($errorresponse) && count($errorresponse)) {
743  $resp_arr = array('faultcode' => $errorresponse[0]->faultcode,
744  'faultstring' => $errorresponse[0]->faultstring);
745  } else {
746  $xml->registerXPathNamespace('bill', $pvNS);
747  $dataresponse = $xml->xpath("//bill:$pvCONT");
748  $resp_arr = objectToArray($dataresponse[0]);
749  }
750 // $tfile = fopen ("/tmp/pv_rawxml","a");
751 // $dstamp = date("Ymd h:i:s");
752 // fwrite($tfile, "($dstamp) $pvCONT:\n$pvXML\n");
753 // fwrite($tfile, "result with '//bill:$pvCONT' : " . print_r($dataresponse,true));
754 // fwrite($tfile, "resp_arr: " . print_r($resp_arr,true));
755 // fclose ($tfile);
756 
757 // $resp_arr = array();
758 // foreach ($dataresponse as $key => $details) {
759 // foreach ($details as $dkey => $dd) {
760 // $resp_arr[$key][$dkey] = (string) ($dd);
761 // }
762 // }
763 
764  } catch (Exception $e) {
765  $resp_arr = false;
766  }
767  return $resp_arr;
768 }
769 
770 function objectToArray( $object )
771  {
772  if( !is_object( $object ) && !is_array( $object ) )
773  {
774  return $object;
775  }
776  if( is_object( $object ) )
777  {
778  $object = get_object_vars( $object );
779  }
780  return array_map( 'objectToArray', $object );
781  }
782 
783 
784 function PV_embcurl($reqURL, $reqSoap, $reqHeaders, $reqOpts = array()) {
785  # reqURL is the service url
786  # reqSoap is the soap string to pass
787  # reqHeaders is an array of headers to be sent
788  # reqOpts is an array of curlopts
789 
790 
791  $curlopts = array(
792  CURLOPT_RETURNTRANSFER => 1,
793  CURLOPT_SSL_VERIFYPEER => 0,
794  CURLOPT_SSL_VERIFYHOST => 0,
795  CURLOPT_HEADER => 0,
796  CURLOPT_POST => 1,
797  CURLOPT_POSTFIELDS => "$reqSoap",
798  CURLOPT_URL => "$reqURL");
799 
800  $ch = @curl_init();
801  @curl_setopt_array($ch, $curlopts);
802  if (count($reqOpts)) {
803  @curl_setopt_array($ch, $reqOpts);
804  }
805  @curl_setopt($ch, CURLOPT_HTTPHEADER, $reqHeaders);
806  $response = @curl_exec($ch);
807 
808  if (curl_errno($ch)) {
809  $response = array('Curl_errno' => curl_errno($ch), 'Curl_error' => curl_error($ch));
810  }
811  @curl_close($ch);
812  return $response;
813 }
814 
815 function ListHolidays($Start, $End) {
816 //================================================= ================
817 //This function programmatically determines Federal Holidays landing
818 // between the given start and end YY
819 // adapted from code Written by Jana Bauer,
820 // which was adapted from code obtained at
821 //http://www.tek-tips.com/faqs.cfm?fid=6003
822 //================================================= ================
823 
824  $holidays = array();
825  for ($i = $Start; $i <= $End; $i++) {
826  for ($m = 1; $m <= 12; $m++) {
827  switch ($m) {
828  case 3:
829  case 4:
830  case 6:
831  case 8:
832 // No holidays in these months
833  break;
834 
835  case 1:
836  // New Year's Day 1/1 or Following Monday
837  $dtHoliday = mktime(12, 0, 0, 1, 1, $i);
838 // $holidays[] = date('Y-m-d',GetNearestWeekday($dtHoliday));
839  $holidays[] = date('Y-m-d',$dtHoliday);
840  // MLK Day 3rd Monday in January
841  $dow = idate('w', $dtHoliday);
842  # find first Monday
843  switch ($dow) {
844  case 0: #Sunday
845  $dtHoliday += 86400;
846  break;
847  case 1: #already Monday
848  break;
849  case 2:
850  $dtHoliday += (86400 * 6);
851  break;
852  case 3:
853  $dtHoliday += (86400 * 5);
854  break;
855  case 4:
856  $dtHoliday += (86400 * 4);
857  break;
858  case 5:
859  $dtHoliday += (86400 * 3);
860  break;
861  case 6:
862  $dtHoliday += (86400 * 2);
863  break;
864  }
865  $dtHoliday += (86400 * 14); # add 2 weeks to get 3rd Monday
866  $holidays[] = date('Y-m-d',$dtHoliday);
867  break;
868 
869  case 2:
870  // President's Day 3rd Monday in February
871  $dtHoliday = mktime(12, 0, 0, 2, 1, $i);
872  $dow = idate('w', $dtHoliday);
873  # find first Monday
874  switch ($dow) {
875  case 0: #Sunday
876  $dtHoliday += 86400;
877  break;
878  case 1: #already Monday
879  break;
880  case 2:
881  $dtHoliday += (86400 * 6);
882  break;
883  case 3:
884  $dtHoliday += (86400 * 5);
885  break;
886  case 4:
887  $dtHoliday += (86400 * 4);
888  break;
889  case 5:
890  $dtHoliday += (86400 * 3);
891  break;
892  case 6:
893  $dtHoliday += (86400 * 2);
894  break;
895  }
896  $dtHoliday += (86400 * 14); # add 2 weeks to get 3rd Monday
897  $holidays[] = date('Y-m-d',$dtHoliday);
898  break;
899 
900  case 5:
901  // Memorial Day Last Monday in May
902  $dtHoliday = mktime(12, 0, 0, 5, 31, $i);
903  $dow = idate('w', $dtHoliday);
904  # find last day & back up
905  switch ($dow) {
906  case 0: #Sunday
907  $dtHoliday -= (86400 * 6);
908  break;
909  case 1: #already Monday
910  break;
911  case 2:
912  $dtHoliday -= 86400;
913  break;
914  case 3:
915  $dtHoliday -= (86400 * 2);
916  break;
917  case 4:
918  $dtHoliday -= (86400 * 3);
919  break;
920  case 5:
921  $dtHoliday -= (86400 * 4);
922  break;
923  case 6:
924  $dtHoliday -= (86400 * 5);
925  break;
926  }
927  $holidays[] = date('Y-m-d',$dtHoliday);
928  break;
929 
930  case 7:
931  // Independence Day 7/4 or Following Monday
932  $dtHoliday = mktime(12, 0, 0, 7, 4, $i);
933 // $holidays[] = date('Y-m-d',GetNearestWeekday($dtHoliday));
934  $holidays[] = date('Y-m-d',$dtHoliday);
935 
936  break;
937 
938  case 9:
939  // Labor Day 1st Monday in September
940  $dtHoliday = mktime(12, 0, 0, 9, 1, $i);
941  $dow = idate('w', $dtHoliday);
942  # find first Monday
943  switch ($dow) {
944  case 0: #Sunday
945  $dtHoliday += 86400;
946  break;
947  case 1: #already Monday
948  break;
949  case 2:
950  $dtHoliday += (86400 * 6);
951  break;
952  case 3:
953  $dtHoliday += (86400 * 5);
954  break;
955  case 4:
956  $dtHoliday += (86400 * 4);
957  break;
958  case 5:
959  $dtHoliday += (86400 * 3);
960  break;
961  case 6:
962  $dtHoliday += (86400 * 2);
963  break;
964  }
965  $holidays[] = date('Y-m-d',$dtHoliday);
966  break;
967 
968  case 10:
969  // Columbus Day 2nd Monday in October
970  $dtHoliday = mktime(12, 0, 0, 10, 1, $i);
971  $dow = idate('w', $dtHoliday);
972  # find first Monday
973  switch ($dow) {
974  case 0: #Sunday
975  $dtHoliday += 86400;
976  break;
977  case 1: #already Monday
978  break;
979  case 2:
980  $dtHoliday += (86400 * 6);
981  break;
982  case 3:
983  $dtHoliday += (86400 * 5);
984  break;
985  case 4:
986  $dtHoliday += (86400 * 4);
987  break;
988  case 5:
989  $dtHoliday += (86400 * 3);
990  break;
991  case 6:
992  $dtHoliday += (86400 * 2);
993  break;
994  }
995  $dtHoliday += (86400 * 7); # add 1 week to get 2nd Monday
996  $holidays[] = date('Y-m-d',$dtHoliday);
997  break;
998 
999  case 11:
1000  // Veteran's Day 11/11 or Following Monday
1001  $dtHoliday = mktime(12, 0, 0, 11, 11, $i);
1002 // $holidays[] = date('Y-m-d',GetNearestWeekday($dtHoliday));
1003  $holidays[] = date('Y-m-d',$dtHoliday);
1004 
1005  // Thanksgiving Day 4th Thursday in November
1006  $dtHoliday = mktime(12, 0, 0, 11, 1, $i);
1007  $dow = idate('w', $dtHoliday);
1008  # find first Thursday
1009  switch ($dow) {
1010  case 0: #Sunday
1011  $dtHoliday += (86400 * 4);
1012  break;
1013  case 1: #Monday
1014  $dtHoliday += (86400 * 3);
1015  break;
1016  case 2:
1017  $dtHoliday += (86400 * 2);
1018  break;
1019  case 3:
1020  $dtHoliday += 86400;
1021  break;
1022  case 4:
1023  break;
1024  case 5:
1025  $dtHoliday += (86400 * 6);
1026  break;
1027  case 6:
1028  $dtHoliday += (86400 * 5);
1029  break;
1030  }
1031  $dtHoliday += (86400 * 21); # add 3 weeks to get 4th Thursday
1032  $holidays[] = date('Y-m-d',$dtHoliday);
1033  break;
1034 
1035  case 12:
1036  // Christmas Day 12/25 or Following Monday
1037  $dtHoliday = mktime(12, 0, 0, 12, 25, $i);
1038 // $holidays[] = date('Y-m-d',GetNearestWeekday($dtHoliday));
1039  $holidays[] = date('Y-m-d',$dtHoliday);
1040 
1041  break;
1042  }
1043  }
1044  }
1045 
1046  return $holidays;
1047 }
1048 
1049 //------------------------------------------------------------------------------------------------------------
1050 Function GetNearestWeekday($dtTimeStamp) {
1051 // Not currently called - if holiday falls on weekend leave it be
1052 //Note Sunday = 0, Saturday = 6
1053  $intWeekday = idate('w', $dtTimeStamp);
1054  switch ($intWeekday) {
1055  case 0: #Sunday - move forward to Monday
1056  $dtTimeStamp += 86400;
1057  break;
1058  case 6: #Saturday - move back to Friday
1059  $dtTimeStamp -= 86400;
1060  break;
1061  case 1: # Monday - Friday - do nothing
1062  case 2:
1063  case 3:
1064  case 4:
1065  case 5:
1066  default:
1067  break;
1068  }
1069  return $dtTimeStamp;
1070 }
1071 
1072 Function GetNextBusiness($dtTimeStamp) {
1073 // Not currently called - if holiday falls on weekend leave it be
1074 //Note Sunday = 0, Saturday = 6
1075  $intWeekday = idate('w', $dtTimeStamp);
1076  switch ($intWeekday) {
1077  case 0: #Sunday - move forward to Monday
1078  $dtTimeStamp += 86400;
1079  break;
1080  case 6: #Saturday - move forward to Monday
1081  $dtTimeStamp += (86400*2);
1082  break;
1083  case 1: # Monday - Friday - do nothing
1084  case 2:
1085  case 3:
1086  case 4:
1087  case 5:
1088  default:
1089  break;
1090  }
1091  return $dtTimeStamp;
1092 }
1093 function PV_getHCUAccts($dbh, $parms) {
1094  $AcctList=array();
1095 
1096  if (!isset($parms['passwith']['Cu']) || !isset($parms['passwith']['Cn'])) {
1097  $AcctList["status"]["response"] = 'false';
1098  $AcctList["status"]["code"] = '910';
1099  $AcctList["status"]["message"] = 'Missing PV Account Parameters' . print_r($parms,true); # PV_getHCUAccts missing Cu/Cn
1100 
1101  return ($AcctList);
1102 
1103  }
1104 
1105  $Cu = $parms['passwith']['Cu'];
1106  $Cn = $parms['passwith']['Cn'];
1107  $showavailable = $parms['passwith']['showavailable'];
1108  $showbal = ($showavailable ? 'available' : 'amount ');
1109  $dataasof = ((bool)strtotime($parms['passwith']['lastupdate']) ? date('Y-m-d', strtotime($parms['passwith']['lastupdate'])) : date('Y-m-d'));
1110  $PV_AcctsWhere = $parms['getAcctsWhere'];
1111  $PV_AcctsAs = (isset($parms['AccountNumberAs']) ? $parms['AccountNumberAs'] : "trim(micraccount)");
1112  $PV_csatAs = (isset($parms['CoreSpecificAs']) ? $parms['CoreSpecificAs'] : "trim(accounttype)");
1113  $PV_PayBillsFrom = (isset($parms['PayBillsFrom']) ? $parms['PayBillsFrom'] : "'true'");
1114  $PV_TransferFrom = (isset($parms['TransferFrom']) ? $parms['TransferFrom'] : "'true'");
1115  $PV_TransferTo = (isset($parms['TransferTo']) ? $parms['TransferTo'] : "'true'");
1116  $PV_SendJoint = (HCU_array_key_value('sendjoint', $parms) ? '' : " and accounttype not like '%@%' ");
1117 // [PayBillsFrom] => case when deposittype='Y' and trim(micraccount) <> '' then 'true' else 'false' end as paybillsfrom
1118 // [getAcctsWhere] => (deposittype='Y' and trim(micraccount) <> '') or deposittype in ('S','N')
1119 // [TransferFrom] => upper('true')
1120 // [TransferTo] => upper('true')
1121  $accts = array();
1122 #
1123  $sql = "select trim(accountnumber) as accountnumber,
1124  trim(accounttype) as accounttype,
1125  certnumber,
1126  deposittype,
1127  case when deposittype = 'Y' then 'Checking' else 'Savings' end as depositdesc,
1128  $showbal as acctbalance,
1129  $PV_PayBillsFrom as paybillsfrom,
1130  $PV_TransferFrom as transferfrom,
1131  $PV_TransferTo as transferto,
1132  trim(description) as description,
1133  $PV_AcctsAs as micraccount,
1134  $PV_csatAs as corespecific
1135  from ${Cu}accountbalance
1136  where accountnumber='$Cn' and deposittype in ('Y','S','N') $PV_SendJoint ";
1137  if (isset($PV_AcctsWhere)) $sql .= " and $PV_AcctsWhere ";
1138 
1139 # Run the sql and see if we got anything
1140 
1141  $sthdp = db_query($sql, $dbh);
1142 
1143  if (db_num_rows($sthdp)) {
1144  $checkingCount=0;
1145  for ($row = 0; $drow = db_fetch_array($sthdp, $row); $row++) {
1146  if ($drow['deposittype'] == 'Y') {
1147  $checkingCount++;
1148  }
1149  // ** BEFORE it's used, encode the description with UTF-8 Encoding.
1150  // * setting it here eliminates the need to set it each time it's called in this loop
1151  $drow['description'] = utf8_encode($drow['description']);
1152 
1153  $accounttype = $drow['accounttype'];
1154  $cert = $drow['certnumber'];
1155  $micraccount = $drow['micraccount'];
1156  if (strpos($accounttype, "@")) {
1157  $trust = 'joint';
1158  } else {
1159  $trust = 'primary';
1160  }
1161  if (trim($micraccount) == '') {
1162  $sqlmicr = "select trim(o.micraccount) as omicr
1163  from cuovermicr o join cuadmin a on o.cu = a.cu
1164  where o.cu='$Cu' and o.accountnumber='$Cn'
1165  and o.accounttype='$accounttype' and o.rt=a.rt
1166  order by o.startcheck desc limit 1";
1167  $sthmicr = db_query($sqlmicr, $dbh);
1168  if (db_num_rows($sthmicr) == 1) {
1169  list ($micraccount) = db_fetch_row($sthmicr, 0);
1170  $drow['micraccount'] = $micraccount;
1171  }
1172  }
1173 // $accts["dp"][query]=$sql;
1174 // $accts[parms]=$parms;
1175  $accts["dp"]["D|$Cn|$accounttype|$cert"]["accounttype"] = $drow['accounttype'];
1176  $accts["dp"]["D|$Cn|$accounttype|$cert"]["certnumber"] = $drow['certnumber'];
1177  $accts["dp"]["D|$Cn|$accounttype|$cert"]["depositdesc"] = $drow['depositdesc'];
1178  $accts["dp"]["D|$Cn|$accounttype|$cert"]["description"] = $drow['description'];
1179  $accts["dp"]["D|$Cn|$accounttype|$cert"]["acctbalance"] = sprintf("%.2f",$drow['acctbalance']);
1180  $accts["dp"]["D|$Cn|$accounttype|$cert"]["acctbalasof"] = $dataasof;
1181  $accts["dp"]["D|$Cn|$accounttype|$cert"]["micraccount"] = $drow['micraccount'];
1182  $accts["dp"]["D|$Cn|$accounttype|$cert"]["corespecific"] = $drow['corespecific'];
1183  $accts["dp"]["D|$Cn|$accounttype|$cert"]["trust"] = "$trust";
1184  $accts["dp"]["D|$Cn|$accounttype|$cert"]["paybillsfrom"] = $drow['paybillsfrom'];
1185  $accts["dp"]["D|$Cn|$accounttype|$cert"]["transferfrom"] = $drow['transferfrom'];
1186  $accts["dp"]["D|$Cn|$accounttype|$cert"]["transferto"] = $drow['transferto'];
1187  $accts["dp"]["D|$Cn|$accounttype|$cert"]["displaydesc"] =
1188  ($cert == 0 ? "{$drow['description']} - $accounttype" : "{$drow['description']} # $cert - $accounttype");
1189  }
1190  }
1191  if (isset($accts['dp']) && sizeof($accts['dp'])) {
1192  $accts["status"]["code"] = '000';
1193  $accts["status"]["severity"] = 'SUCCESS';
1194  $accts["status"]["CheckingAccounts"] = $checkingCount;
1195  } else {
1196  # error, no rows
1197  $accts["status"]["code"] = '999';
1198  $accts["status"]["severity"] = 'ERROR';
1199  $accts["status"]["errors"][] = 'No Accounts Available';
1200 // $accts["status"][sql] = $sql;
1201 // $accts["status"][sqlmicr] = $sqlmicr;
1202  }
1203  if ( $parms["logging"] == "enabled" ) {
1204  $logParms = $parms["environment"]; // get the environment info passed in
1205  $logParms["token"] = ''; // the id used across all communications in session
1206  $logParms["txnId"] = time(); // the id for this transaction
1207  $logParms["logPoint"] = "PV_getHCUAccts"; // this action in a readable form
1208  $logParms["request"] = "{$logParms['platform']} : userIP {$logParms['userIP']} userAgent {$logParms['userAgent']} \n$sql"; // the request
1209  $logParms["reply"] = print_r($accts,true); // the response
1210  LogSSOActivity( $logParms );
1211  }
1212  return ($accts);
1213 }
1214 function PV_populateMIR($MIR, $Ml, $reqMIR, $datefmt = 'Y-m-d', $phones = 'flat', $noEmpty = false) {
1215  try {
1216 /*
1217 //$mirFields = Array(
1218 // "accountnumber",
1219 // "firstname",
1220 // "middlename",
1221 // "lastname",
1222 // "email",
1223 // "homephone",
1224 // "workphone",
1225 // "cellphone",
1226 // "fax",
1227 // "ssn",
1228 // "address1",
1229 // "address2",
1230 // "city",
1231 // "state",
1232 // "zip",
1233 // "cc",
1234 // "dob",
1235 // "class"
1236 // );
1237  *
1238  */
1239  /* strip slashes and dashes and non-digits from phone numbers
1240  * and zip code and tax id; rearrange DOB into mmddyyyy
1241  * then check to see if we have enough valid data to
1242  * satisfy the request
1243  */
1244  if ($phones == 'flat') {
1245  $MIR['phone'] = preg_replace('/\D/', '', $MIR['homephone']);
1246  if (trim($MIR['phone']) == '') {
1247  $MIR['phone'] = preg_replace('/\D/', '', $MIR['cellphone']);
1248  }
1249  if (trim($MIR['phone']) == '') {
1250  $MIR['phone'] = preg_replace('/\D/', '', $MIR['workphone']);
1251  }
1252  } elseif ($phones == 'split') {
1253  $MIR['homephone'] = preg_replace('/\D/', '', $MIR['homephone']);
1254  switch (strlen($MIR['homephone'])) {
1255  case 10:
1256  $MIR['homephone'] = array('Area' => substr($MIR['homephone'], 0, 3),
1257  'Pre' => substr($MIR['homephone'], 3, 3),
1258  'Num' => substr($MIR['homephone'], 6, 4));
1259  break;
1260  # PV requires 10 digits -- don't allow 7
1261 // case 7:
1262 // $MIR['homephone'] = array('pre' => substr($MIR['homephone'], 3, 3),
1263 // 'num' => substr($MIR['homephone'], 6, 4));
1264 // break;
1265  default:
1266  unset($MIR['homephone']);
1267  break;
1268  }
1269  $MIR['cellphone'] = preg_replace('/\D/', '', $MIR['cellphone']);
1270  switch (strlen($MIR['cellphone'])) {
1271  case 10:
1272  $MIR['cellphone'] = array('Area' => substr($MIR['cellphone'], 0, 3),
1273  'Pre' => substr($MIR['cellphone'], 3, 3),
1274  'Num' => substr($MIR['cellphone'], 6, 4));
1275  break;
1276  # PV requires 10 digits -- don't allow 7
1277 // case 7:
1278 // $MIR['cellphone'] = array('pre' => substr($MIR['cellphone'], 3, 3),
1279 // 'num' => substr($MIR['cellphone'], 6, 4));
1280 // break;
1281  default:
1282  unset($MIR['cellphone']);
1283  break;
1284  }
1285  $MIR['workphone'] = preg_replace('/\D/', '', $MIR['workphone']);
1286  switch (strlen($MIR['workphone'])) {
1287  case 10:
1288  $MIR['workphone'] = array('Area' => substr($MIR['workphone'], 0, 3),
1289  'Pre' => substr($MIR['workphone'], 3, 3),
1290  'Num' => substr($MIR['workphone'], 6, 4));
1291  break;
1292  # PV requires 10 digits -- don't allow 7
1293 // case 7:
1294 // $MIR['workphone'] = array('pre' => substr($MIR['workphone'], 3, 3),
1295 // 'num' => substr($MIR['workphone'], 6, 4));
1296 // break;
1297  default:
1298  unset($MIR['workphone']);
1299  break;
1300  }
1301  }
1302 
1303 
1304  if (strtotime($MIR['dob'])) {
1305  $MIR['dob'] = date($datefmt, strtotime($MIR['dob']));
1306  } else {
1307  $MIR['dob'] = '';
1308  }
1309 
1310  $rmlist = array(' ', '-');
1311  $MIR['ssn'] = str_replace($rmlist, '', $MIR['ssn']);
1312 
1313  $MIR['zip'] = str_replace($rmlist, '', $MIR['zip']);
1314  if (strlen($MIR['zip']) < 5) {
1315  unset($MIR['zip']);
1316  }
1317 
1318  $rmlist = array("#", "&", "/", "%", ",", ":", "=", "?", "'");
1319 
1320  $EMAIL = (empty($MIR['email']) ? $Ml : $MIR['email']);
1321  $MIR['email'] = str_replace($rmlist, "", $EMAIL);
1322  $MIR['firstname'] = str_replace($rmlist, "", $MIR['firstname']);
1323  $MIR['middlename'] = str_replace($rmlist, "", $MIR['middlename']);
1324  $MIR['lastname'] = str_replace($rmlist, "", $MIR['lastname']);
1325  $MIR['address1'] = str_replace($rmlist, "", $MIR['address1']);
1326  $MIR['address2'] = str_replace($rmlist, "", $MIR['address2']);
1327  $MIR['city'] = str_replace($rmlist, "", $MIR['city']);
1328  $MIR['state'] = str_replace($rmlist, "", $MIR['state']);
1329  $MIR['accountnumber'] = str_replace($rmlist, "", $MIR['accountnumber']);
1330  # default country code to US. Assume CU will specify for other countries
1331  if (trim($MIR['cc']) == '') {
1332  $MIR['cc'] = 'US';
1333  }
1334 
1335  $MIR['class'] = str_replace($rmlist, "", $MIR['class']);
1336  if (trim($MIR['class']) == '') {
1337  $MIR['class'] = 'P'; # default to personal account
1338  }
1339  # Jan 2018 Payveris requires firstname / lastname even for business. So if this is a business
1340  # account and the first name is empty, fill it with a dot so we can connect
1341  if (empty($MIR['firstname']) && in_array ( $MIR['class'] , array ('B','T') ) ) {
1342  $MIR['firstname'] = '.';
1343  }
1344 
1345 
1346  if ($noEmpty) {
1347  if (trim($MIR['email']) == false) {
1348  unset($MIR['email']);
1349  }
1350  if (trim($MIR['firstname']) == false) {
1351  unset($MIR['firstname']);
1352  }
1353  if (trim($MIR['middlename']) == false) {
1354  unset($MIR['middlename']);
1355  }
1356  if (trim($MIR['lastname']) == false) {
1357  unset($MIR['lastname']);
1358  }
1359  if (trim($MIR['address1']) == false) {
1360  unset($MIR['address1']);
1361  }
1362  if (trim($MIR['address2']) == false) {
1363  unset($MIR['address2']);
1364  }
1365  if (trim($MIR['city']) == false) {
1366  unset($MIR['city']);
1367  }
1368  if (trim($MIR['state']) == false) {
1369  unset($MIR['state']);
1370  }
1371  if (trim($MIR['accountnumber']) == false) {
1372  unset($MIR['accountnumber']);
1373  }
1374  if (trim($MIR['dob']) == false) {
1375  unset($MIR['dob']);
1376  }
1377  if (trim($MIR['zip']) == false) {
1378  unset($MIR['zip']);
1379  }
1380  }
1381 
1382  $missing = array_diff_key($reqMIR, $MIR);
1383  if (sizeof($missing)) {
1384 // throw new Exception("Incomplete Member Info (" . join(", ",array_keys($missing)) . ") mir gets " . print_r($MIR,true));
1385  throw new Exception("Incomplete Member Info (" . join(", ", array_keys($missing)) . ")");
1386  }
1387  $return['status']['response'] = true;
1388  $return['status']['message'] = 'Success';
1389  $return['data'] = $MIR;
1390  } catch (Exception $e) {
1391  $return['status']['response'] = false;
1392  $return['status']['message'] = $e->getMessage();
1393 // $return['status']['message'] = "(" . $e->getline() . ") " . $e->getMessage();
1394  $return['data'] = array();
1395  }
1396  return $return;
1397 }
1398 
1399 ?>