function woocommerce_atos_automatic_response($atts) { $atos = new woocommerce_atos(); if (isset($_POST['DATA'])) { $transauthorised = false; $data = escapeshellcmd(sanitize_text_field($_POST['DATA'])); $message = sprintf('message=%s', $data); $pathfile = sprintf('pathfile=%s', $atos->pathfile); $path_bin_response = $atos->path_bin_response; $result = exec("{$path_bin_response} {$pathfile} {$message}"); $results = explode('!', $result); $response = array('code' => $results[1], 'error' => $results[2], 'merchantid' => $results[3], 'merchantcountry' => $results[4], 'amount' => $results[5], 'transactionid' => $results[6], 'paymentmeans' => $results[7], 'transmissiondate' => $results[8], 'paymenttime' => $results[9], 'paymentdate' => $results[10], 'responsecode' => $results[11], 'paymentcertificate' => $results[12], 'authorisationid' => $results[13], 'currencycode' => $results[14], 'cardnumber' => $results[15], 'cvvflag' => $results[16], 'cvvresponsecode' => $results[17], 'bankresponsecode' => $results[18], 'complementarycode' => $results[19], 'complementaryinfo' => $results[20], 'returncontext' => $results[21], 'caddie' => $results[22], 'receiptcomplement' => $results[23], 'merchantlanguage' => $results[24], 'language' => $results[25], 'customerid' => $results[26], 'orderid' => $results[27], 'customeremail' => $results[28], 'customeripaddress' => $results[29], 'captureday' => $results[30], 'capturemode' => $results[31], 'data' => $results[32]); $order = new WC_order($response['orderid']); if ($response['responsecode'] == '' && $response['error'] == '') { $atos->msg['class'] = 'error'; $atos->msg['message'] = __('Thank you for shopping with us. However, the transaction has been declined.', 'woocommerce-atos'); } elseif ($response['responsecode'] != 0) { $atos->msg['class'] = 'error'; $atos->msg['message'] = __('Thank you for shopping with us. However, the transaction has been declined.', 'woocommerce-atos'); } else { if ($response['responsecode'] == 00) { $transauthorised = true; $order->update_status('processing'); $order->payment_complete($response['transactionid']); $order->add_order_note(__('Payment accepted by the bank', 'woocommerce-atos')); WC()->cart->empty_cart(); } } if ($transauthorised == false) { $order->update_status('failed'); $order->add_order_note('Failed'); $order->add_order_note($atos->msg['message']); } } else { // end of check post echo __('Precondition failed.', 'woocommerce-atos'); } }
function child_transaction($type, $uid, $order_id, $amount, $reason = '') { global $woocommerce; $order = new WC_order($order_id); //get the uid from order and compare to md5 in the $_GET $post_uid = get_post_meta($order_id, '_uid', true); $check_uid = md5($post_uid); if ($check_uid != $uid) { exit(__('UID is not correct', 'woocommerce-begateway')); } $messages = array('void' => array('not_possible' => __('Wrong order status. Void is not possible.', 'woocommerce-begateway'), 'status' => __('Void status', 'woocommerce-begateway'), 'failed' => __('Void attempt failed', 'woocommerce-begateway'), 'success' => __('Payment voided', 'woocommerce-begateway')), 'capture' => array('not_possible' => __('Wrong order status. Capture is not possible.', 'woocommerce-begateway'), 'status' => __('Capture status', 'woocommerce-begateway'), 'failed' => __('Capture attempt failed', 'woocommerce-begateway'), 'success' => __('Payment captured', 'woocommerce-begateway')), 'refund' => array('not_possible' => __('Wrong order status. Refund is not possible.', 'woocommerce-begateway'), 'status' => __('Refund status', 'woocommerce-begateway'), 'failed' => __('Refund attempt failed', 'woocommerce-begateway'), 'success' => __('Payment refunded', 'woocommerce-begateway'))); //check order status is on hold exit if not if (in_array($type, array('capture', 'void')) && $order->status != 'on-hold') { exit($messages[$type]['not_possible']); } if (in_array($type, array('refund')) && $order->status != 'processing') { exit($messages[$type]['not_possible']); } // now send data to the server $klass = '\\beGateway\\' . ucfirst($type); $transaction = new $klass(); $transaction->setParentUid($post_uid); $transaction->money->setCurrency(get_woocommerce_currency()); $transaction->money->setAmount($amount); if ($type == 'refund') { if (isset($reason) && !empty($reason)) { $transaction->setReason($reason); } else { $transaction->setReason(__('Refunded from Woocommerce', 'woocommerce-begateway')); } } $response = $transaction->submit(); //determine status if success if ($response->isSuccess()) { if ($type == 'capture') { $order->payment_complete(); $order->add_order_note($messages[$type]['success'] . '. UID: ' . $response->getUid()); update_post_meta($order_id, '_uid', $response->getUid()); } elseif ($type == 'void') { $order->update_status('cancelled', $messages[$type]['success'] . '. UID: ' . $response->getUid()); } elseif ($type == 'refund') { $order->update_status('refunded', $messages[$type]['success'] . '. UID: ' . $response->getUid()); } if ('yes' == $this->debug) { $this->log->add('begateway', $messages[$type]['status'] . ': ' . $response->getMessage()); } update_post_meta($order_id, '_bt_admin_message', $messages[$type]['success']); } else { if ('yes' == $this->debug) { $this->log->add('begateway', $messages[$type]['failed'] . ': ' . $response->getMessage()); } update_post_meta($order_id, '_bt_admin_error', $messages[$type]['failed'] . ': ' . $response->getMessage()); } $location = get_post_meta($order_id, '_return_url', true); delete_post_meta($order_id, '_return_url', true); header('Location:' . $location); exit; }