Odyssey
rdcTZtest.i
1 <?php
2 
3 function Deposit_Responder($response, $respHTTP, $respCURL, $vendorinfo, $parms) {
4  # returns:
5  # assume we are going to succeed...
6  $return['status']['response'] = 'true';
7  $return['status']['message'] = 'Success';
8  $return['status']['code'] = '000';
9 
10  try {
11 
12  # $vendorinfo populated by function parameter
13  // set up as if from curdc_read
14  // note! already json_decoded
15  // $depo = curdc_read($dbh, $parms);
16  // $vendorinfo = $depo['data']['vendorinfo'];
17 
18  $rdcresult = PostItem_Responder($response, $respHTTP, $respCURL);
19 
20  if (HCU_array_key_value('response', $rdcresult['status']) == 'false' ||
21  !HCU_array_key_value('WasSuccessful',$rdcresult['data']) ) {
22  if ($rdcresult['status']['response'] == 'false') {
23  # HTTP error or Curl error or empty response
24  $vendorinfo['Message'] = "PostItem failed {$rdcresult['status']['message']}";
25  $errorcode = $rdcresult['status']['code'];
26  }
27  if (!$rdcresult['data']['WasSuccessful']) {
28  # rejected at TranzCap
29  $vendorinfo['Message'] = $rdcresult['data']['ErrorMessage'] . ' Deposit Cannot be processed as submitted';
30  $errorcode = 241;
31  }
32  $parms['rdcstatus'] = 'R';
33  $vendorinfo['Vendortime'] = time();
34  $vendorinfo['DepositStatus'] = "Failed";
35  $vendorinfo['DepositTime'] = date('YmdHis');
36 
37  // # update vendorinfo here
38  // $depostat = curdc_setvinfo($dbh, array('Cu' => $parms['Cu'], 'depositid' => $parms['depositid'],
39  // 'rdcstatus' => $parms['rdcstatus'], 'vendorinfo' => json_encode($vendorinfo)));
40  // if ($depostat['status']['response'] == 'false') {
41  // throw new Exception('HomeCU Update Vendorinfo Failed', 240);
42  // }
43 
44  $return['data'] = $rdcresult['data'];
45  $return['data']['depositid'] = $parms['depositid'];
46  $return['data']['rdcstatus'] = $parms['rdcstatus'];
47 
48  throw new Exception($vendorinfo['Message'], $errorcode);
49 
50  } else {
51  $parms['rdcstatus'] = 'C';
52  $vendorinfo['Vendortime'] = time();
53  $vendorinfo['DepositStatus'] = "Accepted";
54  $vendorinfo['DepositTime'] = date('YmdHis');
55  $vendorinfo['Message'] = 'Accepted';
56  $vendorinfo['Review'] = '';
57  $vendorinfo['TransactionReceiptNumber'] = "{$rdcresult['data']['BatchID']}-{$rdcresult['data']['ItemID']}";
58  $vendorinfo['TransactionDateTime'] = date('c');
59 
60  $return['status']['response'] = 'true';
61  $return['status']['message'] = 'TranzCapture Deposit Complete';
62  # this returns everything from Ensenta, but that will be a problem if we add other vendors
63  # pick a list of stuff to return and be consistent for everyone?
64  $return['data'] = $rdcresult['data'];
65  $return['data']['depositid'] = $parms['depositid'];
66  $return['data']['rdcstatus'] = $parms['rdcstatus'];
67  # use the Ensenta names for values the apps look for --
68  $return['data']['TransactionReceiptNumber'] = "{$rdcresult['data']['BatchID']}-{$rdcresult['data']['ItemID']}";
69  $return['data']['TransactionDateTime'] = date('c');
70  $return['data']['MaskedAccountholderNumber'] = $vendorinfo['accounts'][$acctid]['suffix'];
71 
72  $hcumessage = "Your deposit request for account {$vendorinfo['accounts'][$acctid]['suffix']} has been received";
73  if (HCU_array_key_value('SentToReview', $rdcresult['data']) == 'true') {
74  $hcumessage .= " pending review";
75  }
76  $hcumessage .= ". Your confirmation number is '{$rdcresult['data']['BatchID']}-{$rdcresult['data']['ItemID']}'. ";
77  if (HCU_array_key_value('depSuccessMsg',$parms)) {
78  $hcumessage .= convertMicrosoftCharacters($parms['depSuccessMsg']);
79  } else {
80  $hcumessage .= "Please save this number and refer to it if you need to contact the credit union regarding this transaction. ";
81  }
82 
83  $return['data']['HCUReceiptMessage'] = $hcumessage;
84  }
85  } catch (Exception $e) {
86  $return['status']['response'] = 'false';
87  $return['status']['code'] = $e->getCode();
88  $return['status']['message'] = "(" . $e->getLine() . ") " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8', FALSE);
89  }
90 
91  return $return;
92  }
93 
94 function PostItem_Responder($response, $respHTTP, $respCURL) {
95  try {
96 
97  $tzSaid = [];
98 
99  $tzSaid = EmbCurl_Responder($response, $respHTTP, $respCURL);
100  if (HCU_array_key_value('error', $tzSaid)) {
101  # look for errors, otherwise decode and save the token
102  throw new Exception("Error " . HCU_array_key_value('message', $tzSaid), 999);
103  }
104  // when WasSuccessful is false, don't throw error, just return with messages intact
105  // so we can reject cleanly in calling function
106  // if (!$tzSaid['WasSuccessful']) {
107  // # look for errors, otherwise decode and save the token
108  // throw new Exception("{$tzSaid['ErrorMessage']},999");
109  // }
110 
111  $return['status']['response'] = 'true';
112  $return['status']['message'] = 'Success';
113  $return['data'] = $tzSaid;
114  } catch (Exception $e) {
115  $return['status']['response'] = 'false';
116  $return['status']['message'] = $e->getMessage();
117  $return['status']['code'] = $e->getCode();
118  $return['data'] = $tzSaid;
119  }
120  return $return;
121  }
122 
123 
124 function EmbCurl_Responder($response, $respHTTP, $respCURL)
125  {
126 
127  $respERR = '';
128  $respArr = '';
129  // $response = 'test string here';
130  // $respHTTP = 'test code here';
131  // $respCURL = 'test code here';
132 
133  if ($respCURL) {
134  $respERR = "HCUERROR: Connection Failed cURL $respCURL";
135  $respArr = array("error" => "hcuC{$respCURL}", "message" => "$respERR");
136  } elseif ($respHTTP > 400 && $respHTTP < 600) {
137  # HTTP Response 4xx client error or 5xx server error
138  $respArr = json_decode($response, true);
139  $respERR = "HCUERROR: Connection Failed HTTP $respHTTP " . $respArr['Message'];
140  $respArr = array("error" => "hcuH{$respHTTP}", "message" => "$respERR");
141  } elseif (!isset($response) || $response == '') {
142  if ($respHTTP == 204) {
143  # HTTP 204 No Content w/o response = 'Everything OK but no data'
144  $respArr = array();
145  } else {
146  $respArr = array("error" => "hcuE", "message" => "Empty Response");
147  }
148  } else {
149  $respArr = json_decode($response, TRUE);
150  if (is_null($respArr)) {
151  $respArr = array("error" => "tzE", "message" => "Invalid Response");
152  }
153  if (!empty($respArr['Message'])) {
154  $respArr = array("error" => "tzE", "message" => $respArr['Message']);
155  }
156  # tranzAddMobileUser returning system-level config error from TranzCap
157  # with an extra layer in the response array -- this will catch it...
158  if (isset($respArr[0]) && !empty($respArr[0]['Message'])) {
159  $respArr = array("error" => "tzE", "message" => $respArr[0]['Message']);
160  }
161  }
162  return $respArr;
163  }
164 ?>