public function process_payment($order_id) { error_reporting(0); $order = $this->api->getOrderByID($order_id); $this->load_config(); $sandbox = true; if ($this->m_config['AUTHORIZENET_SANDBOX']) { $sandbox = false; } $amount = $order->gross * 100; $currency = $order->currency; $cardnumber = str_replace(" ", "", $_POST['credit_card_number']); $cardname = $_POST['credit_card_name']; $cardtype = $_POST['credit_card_type']; $cvnnumber = $_POST['credit_card_cvn']; $expdate = $_POST['credit_card_exp_month'] . $_POST['credit_card_exp_year']; // API credentials only need to be defined once define("AUTHORIZENET_API_LOGIN_ID", $this->m_config['AUTHORIZENET_API_LOGIN_ID']); define("AUTHORIZENET_TRANSACTION_KEY", $this->m_config['AUTHORIZENET_TRANSACTION_KEY']); define("AUTHORIZENET_SANDBOX", $sandbox); $sale = new AuthorizeNetAIM(); $sale->amount = $amount; $sale->card_num = $cardnumber; $sale->exp_date = $expdate; if ($this->m_config['transaction_method'] == 'authorization') { $response = $sale->authorizeOnly(); } elseif ($this->m_config['transaction_method'] == 'capture') { $response = $sale->authorizeAndCapture(); } if ($response->approved) { $order->paid(); echo "<h2>Your payment was successfully processed. Thank you!</h2>"; echo "Success! Transaction ID:" . $response->transaction_id; } else { echo "<h2>Your card was declined.</h2>"; } }
$sale->description = $_POST['description']; $query = "select * from coupons_coupons where coupon_id='{$couponid}'"; $resultset = mysql_query($query); while ($row = mysql_fetch_array($resultset)) { $DESC = html_entity_decode($row['coupon_name'], ENT_QUOTES); $total_payable_amount = $row["coupon_value"]; if (ctype_digit($total_payable_amount)) { $total_payable_amount = $total_payable_amount; } else { $total_payable_amount = number_format($total_payable_amount, 2, ',', ''); $total_payable_amount = explode(',', $total_payable_amount); $total_payable_amount = $total_payable_amount[0] . '.' . $total_payable_amount[1]; } } $amount = $total_payable_amount * $L_QTY0 - $_SESSION['deductable_ref_amt']; $response = $sale->authorizeOnly(); if ($response->approved) { $transaction_id = $response->transaction_id; $responseheader = array('Order Status' => $response->response_reason_text, 'Invoice Number' => $response->invoice_number, 'Authorization Code' => $response->authorization_code, 'Credit card' => $response->card_type, 'Billing Address' => $response->address); $TYPE = $_POST['pay_mod_id']; $REFERRAL_AMOUNT = $_SESSION['deductable_ref_amt']; require_once $_SERVER['DOCUMENT_ROOT'] . "/system/includes/dboperations.php"; $sql = "insert into transaction_details (PAYERID,COUPONID,TIMESTAMP,CORRELATIONID,ACK,FIRSTNAME,LASTNAME,TRANSACTIONID,TRANSACTIONTYPE,PAYMENTTYPE,ORDERTIME,AMT,PAYMENTSTATUS,REASONCODE,L_QTY0,USERID,EMAIL,TYPE,CAPTURED,REFERRAL_AMOUNT) values ('{$response->customer_id}','{$couponid}',now(),'{$response->authorization_code}','{$response->response_reason_text}','{$response->first_name}','{$response->last_name}','{$response->transaction_id}','{$response->transaction_type}','{$response->method}',now(),'{$response->amount}','{$response->response_reason_text}','{$response->response_reason_code}','{$qty}','{$userid}','{$response->email_address}','{$TYPE}','0','{$REFERRAL_AMOUNT}')"; $result = mysql_query($sql); $txnid = mysql_insert_id(); $_SESSION['txn_id'] = $txnid; check_deal_status($couponid); $cid = $couponid; $_SESSION['COUPONID'] = $couponid; $deal_quantity = $_SESSION['deal_quantity'] = $qty; $txn_amt = $response->amount;
public function testAdvancedAIM() { $auth = new AuthorizeNetAIM(); $auth->amount = "45.00"; // Use eCheck: $auth->setECheck('121042882', '123456789123', 'CHECKING', 'Bank of Earth', 'Jane Doe', 'WEB'); // Set multiple line items: $auth->addLineItem('item1', 'Golf tees', 'Blue tees', '2', '5.00', 'N'); $auth->addLineItem('item2', 'Golf shirt', 'XL', '1', '40.00', 'N'); // Set Invoice Number: $auth->invoice_num = time(); // Set a Merchant Defined Field: $auth->setCustomField("entrance_source", "Search Engine"); // Authorize Only: $response = $auth->authorizeOnly(); $this->assertTrue($response->approved); if ($response->approved) { $auth_code = $response->transaction_id; // Now capture: $capture = new AuthorizeNetAIM(); $capture_response = $capture->priorAuthCapture($auth_code); $this->assertTrue($capture_response->approved); // Now void: $void = new AuthorizeNetAIM(); $void_response = $void->void($capture_response->transaction_id); $this->assertTrue($void_response->approved); } }
public function process_payment($order_id) { global $woocommerce; $wc_order = new WC_Order($order_id); $cardtype = $this->get_card_type(sanitize_text_field(str_replace(' ', '', $_POST['authorizenet-card-number']))); if (!in_array($cardtype, $this->authorizenet_cardtypes)) { wc_add_notice('Merchant do not support accepting in ' . $cardtype, $notice_type = 'error'); return array('result' => 'success', 'redirect' => WC()->cart->get_checkout_url()); die; } $card_num = sanitize_text_field(str_replace(' ', '', $_POST['authorizenet-card-number'])); $exp_date = explode("/", sanitize_text_field($_POST['authorizenet-card-expiry'])); $exp_month = str_replace(' ', '', $exp_date[0]); $exp_year = str_replace(' ', '', $exp_date[1]); if (strlen($exp_year) == 2) { $exp_year += 2000; } $cvc = sanitize_text_field($_POST['authorizenet-card-cvc']); $sale = new AuthorizeNetAIM(); $sale->amount = $wc_order->order_total; $sale->card_num = $card_num; $sale->exp_date = $exp_year . '/' . $exp_month; $sale->card_code = $cvc; $customer = (object) array(); $customer->first_name = $wc_order->billing_first_name; $customer->last_name = $wc_order->billing_last_name; $customer->company = $wc_order->billing_company; $customer->address = $wc_order->billing_address_1 . ' ' . $wc_order->billing_address_2; $customer->city = $wc_order->billing_city; $customer->state = $wc_order->billing_state; $customer->zip = $wc_order->billing_postcode; $customer->country = $wc_order->billing_country; $customer->phone = $wc_order->billing_phone; $customer->email = $wc_order->billing_email; $customer->cust_id = $wc_order->user_id; $customer->invoice_num = $wc_order->get_order_number(); $customer->description = get_bloginfo('blogname') . ' Order #' . $wc_order->get_order_number(); $customer->ship_to_first_name = $wc_order->shipping_first_name; $customer->ship_to_last_name = $wc_order->shipping_last_name; $customer->ship_to_company = $wc_order->shipping_company; $customer->ship_to_address = $wc_order->shipping_address_1 . ' ' . $wc_order->shipping_address_2; $customer->ship_to_city = $wc_order->shipping_city; $customer->ship_to_state = $wc_order->shipping_state; $customer->ship_to_zip = $wc_order->shipping_postcode; $customer->ship_to_country = $wc_order->shipping_country; $customer->delim_char = '|'; $customer->encap_char = ''; $customer->customer_ip = $this->get_client_ip(); $customer->tax = $wc_order->get_total_tax(); $customer->freight = $wc_order->get_total_shipping(); $customer->header_email_receipt = 'Order Receipt ' . get_bloginfo('blogname'); $customer->footer_email_receipt = 'Thank you for Using ' . get_bloginfo('blogname'); $sale->setFields($customer); if ('yes' == AUTHORIZENET_TRANSACTION_MODE) { $response = $sale->authorizeOnly(); } else { $response = $sale->authorizeAndCapture(); } if ($response) { if (1 == $response->approved || 4 == $response->approved) { $wc_order->add_order_note(__($response->response_reason_text . 'on' . date("d-m-Y h:i:s e") . 'with Transaction ID = ' . $response->transaction_id . ' using ' . strtoupper($response->transaction_type) . ' and authorization code ' . $response->authorization_code, 'woocommerce')); $wc_order->payment_complete($response->transaction_id); WC()->cart->empty_cart(); $transactionmetas = array('approved' => $response->approved, 'declined' => $response->declined, 'error' => $response->error, 'held' => $response->held, 'response_code' => $response->response_code, 'response_subcode' => $response->response_subcode, 'response_reason_code' => $response->response_reason_code, 'authorization_code' => $response->authorization_code, 'card_type' => $response->card_type, 'transaction_type' => $response->transaction_type, 'account_number' => $response->account_number, 'cavv_response' => $response->cavv_response, 'card_code_response' => $response->card_code_response); add_post_meta($order_id, '_' . $order_id . '_' . $response->transaction_id . '_metas', $transactionmetas); if (1 == $response->approved && "auth_capture" == $response->transaction_type) { add_post_meta($order_id, '_authorizenet_charge_status', 'charge_auth_captured'); } if (1 == $response->approved && "auth_only" == $response->transaction_type) { add_post_meta($order_id, '_authorizenet_charge_status', 'charge_auth_only'); } return array('result' => 'success', 'redirect' => $this->get_return_url($wc_order)); } else { $wc_order->add_order_note(__($response->response_reason_text . '---' . $response->error_message . ' on' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($response->transaction_type), 'woocommerce')); wc_add_notice($response->response_reason_text, $notice_type = 'error'); } } else { $wc_order->add_order_note(__($response->response_reason_text . '---' . $response->error_message . ' on' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($response->transaction_type), 'woocommerce')); wc_add_notice($response->response_reason_text, $notice_type = 'error'); } }
$aim->card_code = $cc_cvv; // Set the customer's information: $aim->first_name = $cc_first_name; $aim->last_name = $cc_last_name; $aim->address = $cc_address; $aim->state = $cc_state; $aim->city = $cc_city; $aim->zip = $cc_zip; $aim->email = $_SESSION['email']; // $aim->addLineItem(); // $aim->setCustomField('thing', 'value'); // $aim->phone; // $aim->tax // $aim->freight // $aim->description $response = $aim->authorizeOnly(); // Add slashes to two text values: $reason = addslashes($response->response_reason_text); $full_response = addslashes($response->response); // Record the transaction: $r = mysqli_query($dbc, "CALL add_transaction({$order_id}, '{$response->transaction_type}', {$order_total}, {$response->response_code}, '{$reason}', {$response->transaction_id}, '{$full_response}')"); // Upon success, redirect: if ($response->approved) { // Add the transaction info to the session: $_SESSION['response_code'] = $response->response_code; // Redirect to the next page: $location = 'https://' . BASE_URL . 'final.php'; header("Location: {$location}"); exit; } else { // Do different things based upon the response:
} else { $pageURL .= $_SERVER["SERVER_NAME"]; } $user =& JFactory::getUser(); $site =& JFactory::getDocument(); $site->setTitle(JText::_('CHECK_OUT_BUTTON')); $cart = $this->cart; foreach ($cart->getAll() as $cartItem) { $item = $cartItem; } if (isset($_POST['x_process'])) { $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $_POST['x_amount'], 'card_num' => $_POST['x_card_num'], 'exp_date' => $_POST['x_exp_month'] . "/" . $_POST['x_exp_year'], 'first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name'], 'email' => $_POST['x_email'], 'card_code' => $_POST['x_card_code'], 'invoice_num' => $_POST['x_invoice_num'], 'description' => $_POST['x_description'], 'type' => $_POST['x_type'])); if ($_POST['x_type'] == "AUTH_ONLY") { $response = $transaction->authorizeOnly(); } elseif ($_POST['x_type'] == "AUTH_CAPTURE") { $response = $transaction->authorizeAndCapture(); } else { echo "<span style=\"color: red;\">There is an error when making the transaction, please contact Administrator!</span><br/>"; } if ($response->approved) { JFactory::getSession()->set('cart', null); ?> <form name="paymentForm" method="post" action="<?php echo JURI::base() . "index.php?option=com_enmasse&controller=payment&task=notifyUrl&payClass=authorizenet"; ?> " id="checkout_form"> <input type="hidden" type="text" name="approved" value="true"/> <input type="hidden" type="text" name="authorization_code" value="<?php
public function test_payment() { if (!ci()->cart->contents()) { notice('Your cart is empty.', 'error'); echo "<script>document.location.href='/order-online/'</script>"; exit; } $card_num = ci()->input->post('card_number'); $em = ci()->input->post('exp_month'); $ey = ci()->input->post('exp_year'); $store_id = ci()->input->post('store'); $this->set_gateway_data($store_id); require_once APPPATH . 'libraries/anet/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(ci()->system_settings['api_login_id'], ci()->system_settings['transaction_key']); $transaction->setSandbox((bool) ci()->system_settings['api_mode']); $transaction->setFields(array('amount' => $this->_get_grand_total(), 'card_num' => $card_num, 'exp_date' => "{$em}{$ey}")); $response = $transaction->authorizeOnly(); if ($response->approved) { ci()->session->set_userdata('authorization_code', $response->authorization_code); echo '<script>showStep()</script>'; exit; } echo $response->response_reason_text; exit; }
/** * Validates the provided credit card data by posting a temporary $1.00 authorization charge. * * @param array $data The credit card data to use to verify. * * @return bool */ public function auth(array $data) { $authorize_aim = new AuthorizeNetAIM(); $authorize_aim->amount = 1.0; $authorize_aim->card_num = $data['number']; $authorize_aim->exp_date = $data['expiration_month'] . '/' . $data['expiration_year']; $authorize_aim->allow_partial_auth = true; $response = $authorize_aim->authorizeOnly(); if ($response->approved == true) { return true; } Log::error('Authorize.net auth transaction failed.'); return false; }