function onTP_Processpayment($data, $vars = array()) { $isValid = true; $error = array(); $error['code'] = ''; $error['desc'] = ''; if (!empty($data['payment_type']) && $data['payment_type'] == "recurring") { $response = plgpaymentAuthorizenet::onTP_Processpayment_recurring($data); return $response; } $authnet_values = array("login" => $this->login_id, "tran_key" => $this->tran_key, "version" => "3.1", "delim_char" => "|", "delim_data" => "TRUE", "type" => "AUTH_CAPTURE", "method" => "CC", "relay_response" => "FALSE", "card_num" => $data['cardnum'], "card_code" => $data['cardcvv'], "exp_date" => $data['cardexp'], "description" => "", "amount" => $data['amount'], "first_name" => $data['cardfname'], "last_name" => $data['cardlname'], "address" => $data['cardaddress1'], "city" => $data['cardcity'], "state" => $data['cardstate'], "zip" => $data['cardzip'], "country" => $data['cardcountry'], "cust_id" => $data['user_id'], "email" => $data['email'], "invoice_num" => $vars->order_id, "description" => $vars->item_name); require_once 'authorizenet/lib/AuthorizeNet.php'; $sale = new AuthorizeNetAIM($this->login_id, $this->tran_key); //Check sandbox or live $plgPaymentAuthorizenetHelper = new plgPaymentAuthorizenetHelper(); $sandbox = $plgPaymentAuthorizenetHelper->isSandboxEnabled(); $sale->setSandbox($sandbox); $sale->setFields($authnet_values); $allresp = $sale->authorizeAndCapture(); if ($allresp->approved) { //echo "Sale successful!"; } else { $error['desc'] = $allresp->error_message; } //print_r($allresp);die; //3.compare response order id and send order id in notify URL $res_orderid = ''; $res_orderid = $data['order_id']; if ($isValid) { if (!empty($vars) && $res_orderid != $vars->order_id) { $isValid = false; $error['desc'] .= " ORDER_MISMATCH" . "Invalid ORDERID; notify order_is " . $vars->order_id . ", and response " . $res_orderid; } } // amount check if ($isValid) { if (!empty($vars)) { // Check that the amount is correct $order_amount = (double) $vars->amount; $retrunamount = (double) $allresp->amount; $epsilon = 0.01; if ($order_amount - $retrunamount > $epsilon) { $allresp[0] = 'ERROR'; // change response status to ERROR FOR AMOUNT ONLY $isValid = false; $error['desc'] .= "ORDER_AMOUNT_MISTMATCH - order amount= " . $order_amount . ' response order amount = ' . $retrunamount; } } } // TRANSLET PAYMENT RESPONSE $payment_status = $this->translateResponse($allresp->response_code); $transaction_id = $allresp->transaction_id; $result = array('transaction_id' => $transaction_id, 'order_id' => $data['order_id'], 'status' => $payment_status, 'total_paid_amt' => $allresp->amount, 'raw_data' => $allresp, 'error' => $error, 'return' => $data['return']); return $result; }
function onTP_Processpayment($data) { if (isset($data['payment_type']) && $data['payment_type'] == "recurring") { $response = plgpaymentAuthorizenet::onTP_Processpayment_recurring($data); return $response; } $error = array(); $action_url = plgPaymentAuthorizenetHelper::buildAuthorizenetUrl(); $authnet_values = array("x_login" => $this->login_id, "x_tran_key" => $this->tran_key, "x_version" => "3.1", "x_delim_char" => "|", "x_delim_data" => "TRUE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_relay_response" => "FALSE", "x_card_num" => $data['cardnum'], "x_card_code" => $data['cardcvv'], "x_exp_date" => $data['cardexp'], "x_description" => "", "x_amount" => $data['amount'], "x_first_name" => $data['cardfname'], "x_last_name" => $data['cardlname'], "x_address" => $data['cardaddress1'], "x_city" => $data['cardcity'], "x_state" => $data['cardstate'], "x_zip" => $data['cardzip'], "x_country" => $data['cardcountry'], "x_cust_id" => $data['user_id'], "x_email" => $data['email'], "x_order_id" => $data['order_id']); $fields = ""; foreach ($authnet_values as $key => $value) { $fields .= "{$key}=" . urlencode($value) . "&"; } //call to curl $ch = curl_init($action_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& ")); $resp = curl_exec($ch); //execute post and get results curl_close($ch); $allresp = explode('|', $resp); //call to curl $payment_status = $this->translateResponse($allresp[0]); $error['code'] = $allresp[0]; $error['desc'] = $allresp[3]; $transaction_id = $allresp[6]; $result = array('transaction_id' => $transaction_id, 'order_id' => $data['order_id'], 'status' => $payment_status, 'total_paid_amt' => $allresp[9], 'raw_data' => $resp, 'error' => $error, 'return' => $data['return']); return $result; }