public function process(&$payment, $action) { if (!$this->validate_billing_information($payment)) { wp_redirect(esc_url_raw($payment->get_checkout_url())); die; } if ('pending' != $payment->get_status()) { die; } $payment->clear_errors(); if (!class_exists('AuthorizeNetAIM')) { require_once WPBDP_PATH . 'vendors/anet_php_sdk/AuthorizeNet.php'; } if ($payment->has_item_type('recurring_fee')) { // TODO: round fees not within 7-365 days (or make non-recurring). return $this->process_recurring($payment); } $data = $payment->get_data('billing-information'); $aim = new AuthorizeNetAIM(wpbdp_get_option('authorize-net-login-id'), wpbdp_get_option('authorize-net-transaction-key')); if (wpbdp_get_option('payments-test-mode')) { $aim->setSandbox(true); } else { $aim->setSandbox(false); } // Order info. $aim->setFields(array('amount' => $payment->get_total(), 'description' => $payment->get_short_description(), 'invoice_num' => $payment->get_id())); // Card info. $aim->setFields(array('card_num' => $data['cc_number'], 'exp_date' => $data['cc_exp_month'] . substr($data['cc_exp_year'], 0, 2), 'card_code' => $data['cc_cvc'])); // Billing addres info. $aim->setFields(array('first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'address' => $data['address_line1'], 'city' => $data['address_city'], 'state' => $data['address_state'], 'country' => $data['address_country'], 'zip' => $data['zipcode'])); // TODO: maybe add zip, phone, email and cust_id $aim->setCustomField('payment_id', $payment->get_id()); $aim->setCustomField('listing_id', $payment->get_listing_id()); $response = $aim->authorizeAndCapture(); if ($response->approved) { $payment->set_status(WPBDP_Payment::STATUS_COMPLETED, WPBDP_Payment::HANDLER_GATEWAY); } elseif ($response->error) { $payment->set_data('validation-errors', array(sprintf(_x('The payment gateway didn\'t accept your credit card or billing information. The following reason was given: "%s".', 'authorize-net', 'WPBDM'), '(' . $response->response_reason_code . ') ' . rtrim($response->response_reason_text, '.')))); } elseif ($response->held) { $payment->add_error(sprintf(_x('Your payment is being held for review by the payment gateway. The following reason was given: "%s".', 'authorize-net', 'WPBDM'), '(' . $response->response_reason_code . ') ' . rtrim($response->response_reason_text, '.'))); } else { $payment->add_error(sprintf(_x('Payment was rejected. The following reason was given: "%s".', 'authorize-net', 'WPBDM'), '(' . $response->response_reason_code . ') ' . rtrim($response->response_reason_text, '.'))); $payment->set_status(WPBDP_Payment::STATUS_REJECTED, WPBDP_Payment::HANDLER_GATEWAY); } $payment->save(); wp_redirect(esc_url_raw($payment->get_redirect_url())); die; }
public function processTransaction($data) { $log = Logger::getInstance(); $log->LogDebug("process transaction authorize - "); //creditCard,$order,$customer $customer = (object) array(); $customer->first_name = $data->reservationData->userData->first_name; $customer->last_name = $data->reservationData->userData->last_name; $customer->address = $data->reservationData->userData->address; $customer->city = $data->reservationData->userData->city; $customer->state = $data->reservationData->userData->state_name; $customer->country = $data->reservationData->userData->country; $customer->email = $data->reservationData->userData->email; $order = array('description' => JText::_('LNG_ORDER_DESC') . ' ' . $data->reservationData->hotel->hotel_name . '(' . $data->reservationData->userData->start_date . '-' . $data->reservationData->userData->end_date . ')', 'invoice_num' => $data->confirmation_id); $result = new stdClass(); $result->card_name = JRequest::getVar("card_name", null); $result->card_number = JRequest::getVar("card_number", null); $result->card_expiration_year = JRequest::getVar("card_expiration_year", null); $result->card_expiration_month = JRequest::getVar("card_expiration_month", null); $result->card_security_code = JRequest::getVar("card_security_code", null); $result->amount = $data->cost > 0 ? $data->cost : $data->total; $creditCard = array('exp_date' => $result->card_expiration_month . "" . substr($result->card_expiration_year, -2), 'card_num' => $result->card_number, 'amount' => $result->amount); $sale = new AuthorizeNetAIM($this->AUTHORIZENET_API_LOGIN_ID, $this->AUTHORIZENET_TRANSACTION_KEY); if ($this->AUTHORIZENET_SANDBOX == 'false') { $sale->setSandbox(false); } else { $sale->setSandbox(true); } $sale->setFields($creditCard); $sale->setFields($order); $sale->setFields($customer); $response = $sale->authorizeAndCapture(); $log->LogDebug("process response authorize - " . serialize($response)); if (isset($response->approved) && $response->approved == 1) { $result->status = PAYMENT_SUCCESS; $result->payment_status = PAYMENT_STATUS_PAID; } else { $result->status = PAYMENT_ERROR; $result->payment_status = PAYMENT_STATUS_FAILURE; $result->error_message = $response->error_message; } $result->transaction_id = 0; $result->payment_date = date("Y-m-d"); $result->response_code = $response->approved; $result->confirmation_id = $data->confirmation_id; $result->processor_type = $this->type; return $result; }
public function _process($params) { $transaction = new AuthorizeNetAIM($this->settings['api_login_id'], $this->settings['transaction_key']); $transaction->amount = $params['amount']; $transaction->card_num = $params['card_no']; $transaction->exp_date = $params['exp_month'] . $params['exp_year']; $transaction->card_code = $params['csc']; $transaction->invoice_num = $params['reference']; $transaction->customer_ip = $this->CI->input->ip_address(); $transaction->setSandbox((bool) $this->settings['test_mode']); // set extra billing details if we have them if (isset($params['card_name'])) { $names = explode(' ', $params['card_name'], 2); $transaction->first_name = $names[0]; $transaction->last_name = isset($names[1]) ? $names[1] : ''; } if (isset($params['address']) and isset($params['address2'])) { $params['address'] = trim($params['address'] . " \n" . $params['address2']); } foreach (array('company' => 'company', 'address' => 'address', 'city' => 'city', 'state' => 'region', 'zip' => 'postcode', 'country' => 'country', 'phone' => 'phone', 'email' => 'email') as $key => $field) { if (isset($params[$field])) { $transaction->{$key} = $params[$field]; } } $response = $transaction->authorizeAndCapture(); if ($response->approved) { return new Merchant_response('authorized', $response->response_reason_text, $response->transaction_id, (double) $response->amount); } elseif ($response->declined) { return new Merchant_response('declined', $response->response_reason_text); } else { return new Merchant_response('failed', $response->response_reason_text); } }
public function processTransaction($data) { //creditCard,$order,$customer $customer = (object) array(); $customer->first_name = "George"; $customer->last_name = "Bara"; $this->amount = $data->amount; $this->itemName = $data->service . " " . $data->description; $this->itemNumber = $data->id; $order = array('description' => $data->service . " " . $data->description, 'invoice_num' => $data->id); $result = new stdClass(); $result->card_name = JRequest::getVar("card_name", null); $result->card_number = JRequest::getVar("card_number", null); $result->card_expiration_year = JRequest::getVar("card_expiration_year", null); $result->card_expiration_month = JRequest::getVar("card_expiration_month", null); $result->card_security_code = JRequest::getVar("card_security_code", null); $result->amount = $data->amount; $creditCard = array('exp_date' => $result->card_expiration_month . "" . substr($result->card_expiration_year, -2), 'card_num' => $result->card_number, 'amount' => $result->amount); $authorize = new AuthorizeNetAIM($this->apiLoginId, $this->transactionKey); if ($this->mode == "test") { $authorize->setSandbox(true); } else { $authorize->setSandbox(false); } $authorize->setFields($creditCard); $authorize->setFields($order); $authorize->setFields($customer); $response = $authorize->authorizeAndCapture(); dump($response); if (isset($response->approved) && $response->approved == 1) { $result->status = PAYMENT_SUCCESS; $result->payment_status = PAYMENT_STATUS_PAID; } else { $result->status = PAYMENT_ERROR; $result->payment_status = PAYMENT_STATUS_FAILURE; $result->error_message = $response->error_message; } $result->transaction_id = $response->transaction_id; $result->payment_date = date("Y-m-d"); $result->response_code = $response->approved; $result->order_id = $data->id; $result->processor_type = $this->type; return $result; }
/** * Payment process and create subscription * @author Gaurav */ public function process() { $this->layout = false; /*$request = new AuthorizeNetTD; $transactionId = "2234120548"; $response = $request->getTransactionDetails($transactionId); pr($response); exit; echo $response->xml->transaction->transactionStatus; exit;*/ $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $this->request->data['BusinessOwner']['memberShipPrice'], 'card_num' => $this->request->data['BusinessOwner']['CC_Number'], 'exp_date' => $this->request->data['BusinessOwner']['expiration'], 'card_code' => $this->request->data['BusinessOwner']['cvv'])); $response = $transaction->authorizeAndCapture(); //pr($response);exit; if (isset($response->declined) && $response->declined == "1") { $errMsg = $response->response_reason_text; $errMsg .= "Please try again later."; $this->Session->setFlash(__($errMsg), 'flash_bad'); $this->redirect(array('controller' => 'users', 'action' => 'payment')); } if (isset($response->error) && $response->error == "1") { $errMsg = $response->response_reason_text; $errMsg .= "Please try again later."; $this->Session->setFlash(__($errMsg), 'flash_bad'); $this->redirect(array('controller' => 'users', 'action' => 'payment')); } if (isset($response->approved) && $response->approved == "1") { /* * ***********Create Subscription****************** */ /* $subscription = new AuthorizeNet_Subscription; $subscription->name = 'Api Subscription'; $subscription->intervalLength = "1"; $subscription->intervalUnit = "months"; $subscription->startDate = date('Y-m-d',time()); $subscription->totalOccurrences = "999"; $subscription->amount = '50'; $subscription->creditCardCardNumber = $this->request->data['BusinessOwner']['CC_Number']; $subscription->creditCardExpirationDate = $this->request->data['BusinessOwner']['expiration']; $subscription->creditCardCardCode = $this->request->data['BusinessOwner']['cvv']; $subscription->billToFirstName = 'A3'; $subscription->billToLastName = 'Logics'; $request = new AuthorizeNetARB; $response = $request->createSubscription($subscription); $subscription_id = $response->getSubscriptionId(); */ $errMsg = "Payment Successful"; $this->Session->setFlash(__($errMsg), 'flash_good'); /* * ***********Create Subscripton******************* */ $this->redirect(array('controller' => 'users', 'action' => 'payment')); } }
public function _process($params) { $transaction = new AuthorizeNetAIM($this->settings['api_login_id'], $this->settings['transaction_key']); $transaction->amount = $params['amount']; $transaction->card_num = $params['card_no']; $transaction->exp_date = $params['exp_month'] . $params['exp_year']; $transaction->card_code = $params['csc']; $transaction->invoice_num = $params['reference']; $transaction->setSandbox((bool) $this->settings['test_mode']); $response = $transaction->authorizeAndCapture(); if ($response->approved) { return new Merchant_response('authorized', $response->response_reason_text, $response->transaction_id, (double) $response->amount); } elseif ($response->declined) { return new Merchant_response('declined', $response->response_reason_text); } else { return new Merchant_response('failed', $response->response_reason_text); } }
function authorizepayment($REQUEST) { if (!checkCreditCard($REQUEST['x_card_num'], $REQUEST['card_type'], $ccerror, $ccerrortext)) { $_SESSION['donate_msg'] = 'Please enter a valid credit card number.'; return false; } else { $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $REQUEST['amount'], 'card_num' => $REQUEST['x_card_num'], 'exp_date' => $REQUEST['exp_month'] . '/' . $REQUEST['exp_year'], 'first_name' => $REQUEST['first_name'], 'last_name' => $REQUEST['last_name'], 'address' => $REQUEST['address'], 'city' => $REQUEST['city'], 'state' => $REQUEST['state'], 'country' => $REQUEST['country'], 'zip' => $REQUEST['zip'], 'email' => $REQUEST['email'])); $transaction->setCustomField("Donation Form", $REQUEST["form_id"]); $transaction->setCustomField("Donation Type", $REQUEST["donation_type"]); $transaction->addLineItem("Donation", "Donation to '" . get_bloginfo("name") . "'", "Donation to '" . get_bloginfo("name") . "' using the form: " . $REQUEST["form_id"], 1, $REQUEST['amount'], false); $response = $transaction->authorizeAndCapture(); if ($response->approved) { $_SESSION['donate_msg'] = $response->response_reason_text; return true; } else { $_SESSION['donate_msg'] = $response->response_reason_text; return false; } } }
/** * Get the AuthorizeNetAIM object and set up basic parameters * @return AuthorizeNetAIM */ function get_api() { if (!class_exists('AuthorizeNetAIM')) { require_once 'anet_php_sdk/AuthorizeNet.php'; } //Basic Credentials $sale = new AuthorizeNetAIM(get_option('em_' . $this->gateway . '_api_user'), get_option('em_' . $this->gateway . '_api_key')); if (get_option('em_' . $this->gateway . '_mode') == 'live') { $sale->setSandbox(false); } else { $sale->setSandbox(true); } return $sale; }
public function executeProcessSale() { $this->setLayout(false); $this->result = false; $request = $this->getRequest(); $request->setParameter('x_exp_date', $this->getRequestParameter("exp_month") . "/" . $this->getRequestParameter("exp_year")); $request->setParameter("exp_month", ""); $request->setParameter("exp_year", ""); if ($this->getRequestParameter("submitted")) { if (array_key_exists("cart", $_SESSION)) { $products = array(); foreach ($_SESSION["cart"] as $item) { $doc = Document::getDocumentInstance($item); if ($doc) { $cnt = $_SESSION["num"][$item]; if (!$cnt) { $cnt = 1; } $price = $doc->getPrice(); $price = $price * $cnt; echo "price:" . $price . "<br>"; $totalPrice += $price; } } $totalPrice += round($totalPrice * (UtilsHelper::Settings("taxes") / 100), 2); } require_once sfConfig::get('sf_web_dir') . '/anet_php_sdk/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $totalPrice, 'card_num' => $this->getRequestParameter('x_card_num'), 'exp_date' => $this->getRequestParameter('x_exp_date'), 'first_name' => $this->getRequestParameter('x_first_name'), 'last_name' => $this->getRequestParameter('x_last_name'), 'address' => $this->getRequestParameter('x_address'), 'email' => $this->getRequestParameter('x_email'), 'city' => $this->getRequestParameter('x_city'), 'state' => $this->getRequestParameter('x_state'), 'country' => $this->getRequestParameter('x_country'), 'zip' => $this->getRequestParameter('x_zip'), 'email' => $this->getRequestParameter('x_email'), 'card_code' => $this->getRequestParameter('x_card_code'))); $transaction->setCustomFields(array('products' => $this->getRequestParameter('x_delivery_address'))); $response = $transaction->authorizeAndCapture(); $this->response = $response; if (!$this->getRequestParameter('terms')) { $request->setError('errterms', "Please accept the terms of use"); UtilsHelper::setFlashMsg('', UtilsHelper::MSG_ERROR); } else { if ($response->approved) { $this->result = "success"; $this->transaction_id = $response->transaction_id; $message = "\n\t\t\t\t\tYou successfully ordered products from SubcommPools.com<br>\n\t\t\t\t\t<br>Date:" . date('l jS \\of F Y h:i:s A') . "<br>\n\t\t\t\t\t<br>Transaction number:" . $response->transaction_id . "<br>\n\t\t\t\t\t<br>Name: " . $this->getRequestParameter('x_first_name') . " " . $this->getRequestParameter('x_last_name') . "<br>\n\t\t\t\t\t<br>-------------------<br><br>"; foreach ($_SESSION["cart"] as $item) { $doc = Document::getDocumentInstance($item); if ($doc) { $itemCnt = $_SESSION["num"][$item]; if (!$itemCnt) { $itemCnt = 1; } $itemPrice = $doc->getPrice(); $itemPrice = $itemPrice * $cnt; $message .= $doc->getLabel() . ", Quantity: " . $itemCnt . ", \$" . $itemPrice . "<br>"; } } $message .= "<br>Total+Tax: \$" . $totalPrice . "<br>\n\t\t\t\t\t<br>Thank you for your purchase."; UtilsHelper::sendEmail($this->getRequestParameter('x_email'), $message, "SubcommPools Purchase", UtilsHelper::Settings("main_email"), "SubcommPools", UtilsHelper::Settings("main_email")); $_SESSION["cart"] = null; $_SESSION["num"] = null; } else { $this->response_text = $response->response_reason_text; //var_dump($response); $request->setError('errsubmit', $response->response_reason_text); UtilsHelper::setFlashMsg('', UtilsHelper::MSG_ERROR); //$this->result = $response->response_reason_text; //header('Location: error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text); } } } }
private static function get_aim($local_api_settings = array()) { self::include_api(); $api_settings = self::get_api_settings($local_api_settings); $is_sandbox = $api_settings['mode'] == "test"; $aim = new AuthorizeNetAIM($api_settings['login_id'], $api_settings['transaction_key']); $aim->setSandbox($is_sandbox); return $aim; }
public function PaymentCreditGift() { $excludeArr = array('creditvalue', 'cardType', 'email', 'cardNumber', 'CCExpDay', 'CCExpMnth', 'creditCardIdentifier', 'total_price', 'CreditSubmit'); $dataArr = array(); $condition = array('id' => $this->checkLogin('U')); $this->checkout_model->commonInsertUpdate(USERS, 'update', $excludeArr, $dataArr, $condition); //User ID $loginUserId = $this->checkLogin('U'); if ($this->input->post('creditvalue') == 'authorize') { $Auth_Details = unserialize(API_LOGINID); $Auth_Setting_Details = unserialize($Auth_Details['settings']); error_reporting(-1); define("AUTHORIZENET_API_LOGIN_ID", $Auth_Setting_Details['Login_ID']); // Add your API LOGIN ID define("AUTHORIZENET_TRANSACTION_KEY", $Auth_Setting_Details['Transaction_Key']); // Add your API transaction key define("API_MODE", $Auth_Setting_Details['mode']); if (API_MODE == 'sandbox') { define("AUTHORIZENET_SANDBOX", true); // Set to false to test against production } else { define("AUTHORIZENET_SANDBOX", false); } define("TEST_REQUEST", "FALSE"); require_once './authorize/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $this->input->post('total_price'), 'card_num' => $this->input->post('cardNumber'), 'exp_date' => $this->input->post('CCExpDay') . '/' . $this->input->post('CCExpMnth'), 'first_name' => $this->input->post('full_name'), 'last_name' => '', 'address' => $this->input->post('address'), 'city' => $this->input->post('city'), 'state' => $this->input->post('state'), 'country' => $this->input->post('country'), 'phone' => $this->input->post('phone_no'), 'email' => $this->input->post('email'), 'card_code' => $this->input->post('creditCardIdentifier'))); $response = $transaction->authorizeAndCapture(); if ($response->approved) { //$moveShoppingDataToPayment = $this->ibrandshopping_model->moveShoppingDataToPayment(); redirect('order/giftsuccess/' . $loginUserId . '/' . $response->transaction_id); } else { //redirect('site/shopcart/cancel?failmsg='.$response->response_reason_text); redirect('order/failure/' . $response->response_reason_text); } } else { if ($this->input->post('creditvalue') == 'paypaldodirect') { $PaypalDodirect = unserialize($this->data['paypal_credit_card_settings']['settings']); $dodirects = array('Sandbox' => $PaypalDodirect['mode'], 'APIUsername' => $PaypalDodirect['Paypal_API_Username'], 'APIPassword' => $PaypalDodirect['paypal_api_password'], 'APISignature' => $PaypalDodirect['paypal_api_Signature'], 'APISubject' => '', 'APIVersion' => '85.0'); // Show Errors if ($dodirects['Sandbox']) { error_reporting(E_ALL); ini_set('display_errors', '1'); } $this->load->library('Paypal_pro', $dodirects); $DPFields = array('paymentaction' => '', 'ipaddress' => $this->input->ip_address(), 'returnfmfdetails' => '1'); $CCDetails = array('creditcardtype' => $this->input->post('cardType'), 'acct' => $this->input->post('cardNumber'), 'expdate' => $this->input->post('CCExpDay') . $this->input->post('CCExpMnth'), 'cvv2' => $this->input->post('creditCardIdentifier'), 'startdate' => '', 'issuenumber' => ''); $PayerInfo = array('email' => $this->input->post('email'), 'payerid' => '', 'payerstatus' => '', 'business' => ''); $PayerName = array('salutation' => 'Mr.', 'firstname' => $this->input->post('full_name'), 'middlename' => '', 'lastname' => '', 'suffix' => ''); //'x_amount' => , // 'x_email' => $this->input->post('email'), $BillingAddress = array('street' => $this->input->post('address'), 'street2' => '', 'city' => $this->input->post('city'), 'state' => $this->input->post('state'), 'countrycode' => $this->input->post('country'), 'zip' => $this->input->post('postal_code'), 'phonenum' => $this->input->post('phone_no')); $ShippingAddress = array('shiptoname' => $this->input->post('full_name'), 'shiptostreet' => $this->input->post('address'), 'shiptostreet2' => $this->input->post('address2'), 'shiptocity' => $this->input->post('city'), 'shiptostate' => $this->input->post('state'), 'shiptozip' => $this->input->post('postal_code'), 'shiptocountry' => $this->input->post('country'), 'shiptophonenum' => $this->input->post('phone_no')); $PaymentDetails = array('amt' => $this->input->post('total_price'), 'currencycode' => $this->data['currencyType'], 'itemamt' => '', 'shippingamt' => '', 'insuranceamt' => '', 'shipdiscamt' => '', 'handlingamt' => '', 'taxamt' => '', 'desc' => '', 'custom' => '', 'invnum' => '', 'buttonsource' => '', 'notifyurl' => '', 'recurring' => ''); // For order items you populate a nested array with multiple $Item arrays. // Normally you'll be looping through cart items to populate the $Item array // Then push it into the $OrderItems array at the end of each loop for an entire // collection of all items in $OrderItems. $OrderItems = array(); $Item = array('l_name' => '', 'l_desc' => '', 'l_amt' => '', 'l_number' => '', 'l_qty' => '', 'l_taxamt' => '', 'l_ebayitemnumber' => '', 'l_ebayitemauctiontxnid' => '', 'l_ebayitemorderid' => ''); array_push($OrderItems, $Item); $Secure3D = array('authstatus3d' => '', 'mpivendor3ds' => '', 'cavv' => '', 'eci3ds' => '', 'xid' => ''); $PayPalRequestData = array('DPFields' => $DPFields, 'CCDetails' => $CCDetails, 'PayerInfo' => $PayerInfo, 'PayerName' => $PayerName, 'BillingAddress' => $BillingAddress, 'ShippingAddress' => $ShippingAddress, 'PaymentDetails' => $PaymentDetails, 'OrderItems' => $OrderItems, 'Secure3D' => $Secure3D); $PayPalResult = $this->paypal_pro->DoDirectPayment($PayPalRequestData); $lastFeatureInsertId = $this->session->userdata('randomNo'); if (!$this->paypal_pro->APICallSuccessful($PayPalResult['ACK'])) { $errors = array('Errors' => $PayPalResult['ERRORS']); //$this->load->view('paypal_error',$errors); $newerrors = $errors['Errors'][0]['L_LONGMESSAGE']; redirect('order/failure/' . $newerrors); } else { // Successful call. Load view or whatever you need to do here. redirect('order/success/' . $loginUserId . '/' . $lastFeatureInsertId . '/' . $PayPalResult['TRANSACTIONID']); } } } }
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; }
public static function doTransaction($type, $transactionData = array()) { $request = new AuthorizeNetCIM(); $requestAim = new AuthorizeNetAIM(); Log::write(__METHOD__ . ' sandbox ' . (int) SANDBOX_MODE); $request->setSandbox(SANDBOX_MODE); $transaction = new AuthorizeNetTransaction(); $libAnetResponse = new Lib_Anet_Response(); switch ($type) { case self::$TRANS_AUTHONLY: $amount = $customer_profile_id = $payment_profile_id = $invoice_id = null; extract($transactionData, EXTR_OVERWRITE); Log::write(__METHOD__ . ' cp :' . $customer_profile_id . ' pp :' . $payment_profile_id . ' inv :' . $invoice_id . ' amt :' . $amount); $cps = Lib_Anet::getCardProfiles($customer_profile_id); $transaction->amount = $amount; $transaction->customerProfileId = $customer_profile_id; $transaction->customerPaymentProfileId = $payment_profile_id; $transaction->order->invoiceNumber = $invoice_id; $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHONLY, $transaction); // $request->createCustomerProfileTransaction($transactionType, $transaction); if ($response->isOk()) { Log::write(__METHOD__ . ' ok'); $transactionResponse = $response->getTransactionResponse(); $libAnetResponse->state = true; $libAnetResponse->transaction_id = $transactionResponse->transaction_id; $libAnetResponse->authorization_code = $transactionResponse->authorization_code; $libAnetResponse->message = $transactionResponse->response_reason_text; $libAnetResponse->text = $response->getMessageText(); $libAnetResponse->code = $response->getMessageCode(); $libAnetResponse->last_digit = trim(str_replace('X', '', $transactionResponse->account_number)); } if ($response->isError()) { Log::write(__METHOD__ . ' err'); $libAnetResponse->state = false; $libAnetResponse->text = $response->getMessageText(); $libAnetResponse->code = $response->getMessageCode(); } Log::write(__METHOD__ . ' ' . $response->getMessageCode() . ' ' . $response->getMessageText()); Log::write(__METHOD__ . ' ' . json_encode($libAnetResponse)); if ($libAnetResponse->text == 'A duplicate transaction has been submitted.') { $libAnetResponse->text = 'Try again in 2 minutes'; } return $libAnetResponse; break; case self::$TRANS_PRIORAUTHCAPTURE: $transaction_id = $amount = null; extract($transactionData, EXTR_OVERWRITE); $transaction->transId = $transaction_id; $transaction->amount = $amount; $response = $request->createCustomerProfileTransaction(self::$TRANS_PRIORAUTHCAPTURE, $transaction); if ($response->isOk()) { $transactionResponse = $response->getTransactionResponse(); $libAnetResponse->state = true; $libAnetResponse->transaction_id = $transactionResponse->transaction_id; $libAnetResponse->authorization_code = $transactionResponse->authorization_code; $libAnetResponse->message = $transactionResponse->response_reason_text; $libAnetResponse->text = $response->getMessageText(); $libAnetResponse->code = $response->getMessageCode(); } if ($response->isError()) { $libAnetResponse->state = false; /*$returnResponse->message = $transactionResponse->response_reason_text;*/ $libAnetResponse->text = $response->getMessageText(); $libAnetResponse->code = $response->getMessageCode(); } return $libAnetResponse; break; case self::$TRANS_AUTHCAPTURE: $amount = $customer_profile_id = $payment_profile_id = null; extract($transactionData, EXTR_OVERWRITE); $transaction->amount = $amount; $transaction->customerProfileId = $customer_profile_id; $transaction->customerPaymentProfileId = $payment_profile_id; $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHCAPTURE, $transaction); if ($response->isOk()) { $transactionResponse = $response->getTransactionResponse(); $libAnetResponse->state = true; $libAnetResponse->transaction_id = $transactionResponse->transaction_id; $libAnetResponse->authorization_code = $transactionResponse->authorization_code; $libAnetResponse->message = $transactionResponse->response_reason_text; $libAnetResponse->text = $response->getMessageText(); $libAnetResponse->code = $response->getMessageCode(); $libAnetResponse->last_digit = trim(str_replace('X', '', $transactionResponse->account_number)); } if ($response->isError()) { $libAnetResponse->state = false; $libAnetResponse->text = $response->getMessageText(); $libAnetResponse->code = $response->getMessageCode(); } return $libAnetResponse; break; case self::$TRANS_CREDIT: $amount = $customerProfileId = $paymentProfileId = null; $transaction->amount = $transactionData->amount; $requestAim->setSandbox(SANDBOX_MODE); $response = $requestAim->credit($transactionData->id, $transactionData->amount, $transactionData->lfor); return true; if (!$response->error) { return true; } else { throw new Exception($response->response_reason_text, 512); } break; case self::$TRANS_VOID: $amount = $customer_profile_id = $payment_profile_id = $invoice_id = null; extract($transactionData, EXTR_OVERWRITE); $transaction->amount = $amount; $transaction->customerProfileId = $customer_profile_id; $transaction->customerPaymentProfileId = $payment_profile_id; $transaction->order->invoiceNumber = $invoice_id; $response = $request->createCustomerProfileTransaction(self::$TRANS_AUTHONLY, $transaction); break; } }
/** *function to reactivate the account *@author Priti Kabra */ public function reactivate($regType = NULL, $refId = NULL) { $userId = $this->Encryption->decode($this->Session->read('Auth.Front.id')); $userData = $this->User->find('first', array('conditions' => array('User.id' => $userId))); $this->set(compact('userData')); if ($this->request->is('post')) { $this->loadModel('Coupon'); $this->loadModel('Transaction'); $this->loadModel('Subscription'); //Check Coupon Code if (!empty($this->request->data['BusinessOwner']['code'])) { $couponCheck = $this->checkCouponCode($this->request->data['BusinessOwner']['code']); if (isset($couponCheck['error'])) { $checkCouponError = 1; $this->User->validationErrors['couponcheck'] = $couponCheck['error']; $this->request->data = $this->request->data; } else { $this->request->data['BusinessOwner']['memberShipPrice'] = $couponCheck['newMembershipPrice']; } } else { $this->request->data['BusinessOwner']['memberShipPrice'] = Configure::read('PLANPRICE'); } $this->request->data['BusinessOwner']['expiration'] = $this->request->data['BusinessOwner']['expiration_month']['month'] . '/' . $this->request->data['BusinessOwner']['expiration_year']['year']; if (!isset($checkCouponError)) { //PAYMENT $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $this->request->data['BusinessOwner']['memberShipPrice'], 'card_num' => $this->request->data['BusinessOwner']['CC_Number'], 'exp_date' => $this->request->data['BusinessOwner']['expiration'], 'card_code' => $this->request->data['BusinessOwner']['cvv'])); $response = $transaction->authorizeAndCapture(); if (isset($response->declined) && $response->declined == "1") { $errMsg = $response->response_reason_text; $this->Session->setFlash(__($errMsg), 'Front/flash_bad'); $this->__unsetData(); } else { if (isset($response->error) && $response->error == "1") { $errMsg = $response->response_reason_text; $this->Session->setFlash(__($errMsg), 'Front/flash_bad'); $this->__unsetData(); } else { if (isset($response->approved) && $response->approved == "1") { $userDataUpdate['deactivated_by_user'] = 0; $userDataUpdate['reactivate'] = 1; $this->User->id = $userId; if ($this->User->save($userDataUpdate)) { if ($regType != NULL && $refId != NULL) { $decrypted = $this->Encryption->decode($refId); $inviteData = $this->InvitePartner->find('first', array('conditions' => array('id' => $decrypted))); if ($this->request->data['User']['user_email'] == $inviteData['InvitePartner']['invitee_email']) { $data = array('InvitePartner.referral_amount' => 'InvitePartner.referral_amount + 5', 'InvitePartner.status' => "'active'", 'invitee_userid' => $this->User->id); $this->InvitePartner->updateAll($data, array('id' => $decrypted)); } } $transactions['user_id'] = $userId; $transactions['transaction_id'] = $response->transaction_id; $transactions['status'] = 1; $transactions['amount_paid'] = $this->request->data['BusinessOwner']['memberShipPrice']; $transactions['credit_card_number'] = $this->Encryption->encode(substr($this->request->data['BusinessOwner']['CC_Number'], -4, 4)); $this->Transaction->save($transactions); $txId = $this->Transaction->getLastInsertID(); //Create Subscription $this->request->data['Subscription']['transaction_id'] = $response->transaction_id; $this->createSubscription($this->request->data, $userId); //Update Purchase date $this->Transaction->id = $txId; $this->Transaction->save(array('purchase_date' => $this->Common->getCurrentActiveDate($userId))); //delete goals //$this->GroupGoals->resetUserGoals($userId); $this->Session->write('UID', $this->Encryption->encode($this->User->id)); $this->Session->write('countryInfo', $this->request->data['BusinessOwner']['country_id']); $this->Session->write('zipInfo', $this->request->data['BusinessOwner']['zipcode']); //Create Subscripton ends $this->redirect(array('controller' => 'groups', 'action' => 'group-selection')); } else { foreach ($this->User->validationErrors as $key => $value) { $err[] = $value[0]; } $this->Session->setFlash(__($err), 'Front/flash_bad'); $this->__unsetData(); } } else { foreach ($this->BusinessOwner->validationErrors as $key => $value) { $err[] = $value[0]; } $this->Session->setFlash(__($err[0]), 'Front/flash_bad'); $this->__unsetData(); } } } } else { $this->Session->setFlash(__($this->User->validationErrors['couponcheck']), 'Front/flash_bad'); $this->__unsetData(); $this->request->data = $this->request->data; } } }
public function external_hook($hook) { switch ($hook) { case 'pay': // result is retured via ajax and displayed on the page. $invoice_id = isset($_REQUEST['invoice_id']) ? $_REQUEST['invoice_id'] : false; $invoice_payment_id = isset($_REQUEST['invoice_payment_id']) ? $_REQUEST['invoice_payment_id'] : false; if ($invoice_id && $invoice_payment_id) { $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); $invoice_data = module_invoice::get_invoice($invoice_id); if ($invoice_payment_data && $invoice_data && $invoice_id == $invoice_data['invoice_id'] && $invoice_payment_data['invoice_id'] == $invoice_data['invoice_id']) { $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $description = _l('Payment for invoice %s', $invoice_data['name']); require_once 'includes/plugin_paymethod_authorize/anet_php_1.1.8/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(module_config::c('payment_method_authorize_api_login_id', ''), module_config::c('payment_method_authorize_transaction_key', '')); $transaction->setSandbox(module_config::c('payment_method_authorize_sandbox', 0)); $transaction->VERIFY_PEER = module_config::c('payment_method_authorize_ssl_verify', 1); $transaction->amount = $invoice_payment_data['amount']; // USD ONLY foreach (array("address", "allow_partial_auth", "amount", "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name", "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name", "card_code", "card_num", "cardholder_authentication_value", "city", "company", "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description", "duplicate_window", "duty", "echeck_type", "email", "email_customer", "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt", "freight", "header_email_receipt", "invoice_num", "last_name", "line_item", "login", "method", "phone", "po_num", "recurring_billing", "relay_response", "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country", "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip", "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key", "trans_id", "type", "version", "zip") as $possible_value) { if (isset($_POST[$possible_value])) { $transaction->setField($possible_value, $_POST[$possible_value]); } } $transaction->setField('card_num', isset($_POST['number']) ? $_POST['number'] : ''); $transaction->setField('exp_date', $_POST['month'] . '/' . $_POST['year']); $transaction->setField('card_code', $_POST['cvv']); //$transaction->card_num = isset($_POST['number']) ? $_POST['number'] : ''; //$transaction->exp_date = $_POST['month'].'/'.$_POST['year']; //$transaction->card_code = $_POST['cvv']; $response = $transaction->authorizeAndCapture(); if ($response->approved) { // echo "<h1>Success! The test credit card has been charged!</h1>"; // echo "Transaction ID: " . $response->transaction_id; update_insert("invoice_payment_id", $invoice_payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'))); module_paymethod_stripe::add_payment_data($invoice_payment_id, 'log', "Successfully paid: " . var_export($response, true)); module_invoice::save_invoice($invoice_id, array()); // success! // redirect to receipt page. redirect_browser(module_invoice::link_receipt($invoice_payment_id)); } else { echo isset($response->error_message) ? $response->error_message : (isset($response->response_reason_text) ? $response->response_reason_text : var_export($response, true)); } exit; } } echo 'Error paying via Authorize'; exit; } }
public function testInvalidCredentials() { if (MERCHANT_LIVE_API_LOGIN_ID) { // Post a response to live server using invalid credentials. $sale = new AuthorizeNetAIM('a', 'a'); $sale->setSandbox(false); $sale->setFields(array('amount' => rand(1, 1000), 'card_num' => '6011000000000012', 'exp_date' => '0415')); $response = $sale->authorizeAndCapture(); $this->assertTrue($response->error); $this->assertEquals("13", $response->response_reason_code); } }
/** * Authorize.net Payments * * @param $purchase_data */ public function give_process_authorize_net_payment($purchase_data) { if (!isset($_POST['card_number']) || $_POST['card_number'] == '') { give_set_error('empty_card', __('You must enter a card number', 'give')); } if (!isset($_POST['card_name']) || $_POST['card_name'] == '') { give_set_error('empty_card_name', __('You must enter the name on your card', 'give')); } if (!isset($_POST['card_exp_month']) || $_POST['card_exp_month'] == '') { give_set_error('empty_month', __('You must enter an expiration month', 'give')); } if (!isset($_POST['card_exp_year']) || $_POST['card_exp_year'] == '') { give_set_error('empty_year', __('You must enter an expiration year', 'give')); } if (!isset($_POST['card_cvc']) || $_POST['card_cvc'] == '' || strlen($_POST['card_cvc']) < 3) { give_set_error('empty_cvc', __('You must enter a valid CVC', 'give')); } $errors = give_get_errors(); //No errors: Continue with payment processing if (!$errors) { //Include Authorize SDK require_once GIVE_AUTHORIZE_PLUGIN_DIR . '/includes/anet_php_sdk/AuthorizeNet.php'; if (!give_is_test_mode()) { //LIVE: $authorize_api_login = give_get_option('give_api_login'); $authorize_trans_key = give_get_option('give_transaction_key'); } else { //SANDBOX $authorize_api_login = give_get_option('give_authorize_sandbox_api_login'); $authorize_trans_key = give_get_option('give_authorize_sandbox_transaction_key'); } //Check for credentials entered if (empty($authorize_api_login) || empty($authorize_trans_key)) { give_set_error('error_id_here', __('Error: Missing API Login or Transaction key. Please enter them in the plugin settings.', 'give-authorize')); return; } //Proceed with Authorize AIM $transaction = new AuthorizeNetAIM($authorize_api_login, $authorize_trans_key); $transaction->VERIFY_PEER = false; //Sandbox or not? if (give_is_test_mode()) { $transaction->setSandbox(true); } else { $transaction->setSandbox(false); } $card_info = $purchase_data['card_info']; $card_names = explode(' ', $card_info['card_name']); $first_name = isset($card_names[0]) ? $card_names[0] : $purchase_data['user_info']['first_name']; if (!empty($card_names[1])) { unset($card_names[0]); $last_name = implode(' ', $card_names); } else { $last_name = $purchase_data['user_info']['last_name']; } $transaction->amount = $purchase_data['price']; $transaction->card_num = strip_tags(trim($card_info['card_number'])); $transaction->card_code = strip_tags(trim($card_info['card_cvc'])); $transaction->exp_date = strip_tags(trim($card_info['card_exp_month'])) . '/' . strip_tags(trim($card_info['card_exp_year'])); $transaction->description = give_get_purchase_summary($purchase_data); $transaction->first_name = $first_name; $transaction->last_name = $last_name; $transaction->address = $card_info['card_address'] . ' ' . $card_info['card_address_2']; $transaction->city = $card_info['card_city']; $transaction->country = $card_info['card_country']; $transaction->state = $card_info['card_state']; $transaction->zip = $card_info['card_zip']; $transaction->customer_ip = give_get_ip(); $transaction->email = $purchase_data['user_email']; $transaction->invoice_num = $purchase_data['purchase_key']; try { $response = $transaction->authorizeAndCapture(); if ($response->approved) { $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), 'price_id' => isset($purchase_data['post_data']['give-price-id']) ? intval($purchase_data['post_data']['give-price-id']) : '', 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'authorizenet'); $payment = give_insert_payment($payment_data); if ($payment) { give_update_payment_status($payment, 'publish'); give_send_to_success_page(); } else { give_set_error('authorize_error', __('Error: your payment could not be recorded. Please try again', 'give')); give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } } else { if (isset($response->response_reason_text)) { $error = $response->response_reason_text; } elseif (isset($response->error_message)) { $error = $response->error_message; } else { $error = ''; } if (strpos(strtolower($error), 'the credit card number is invalid') !== false) { give_set_error('invalid_card', __('Your card number is invalid', 'give')); } elseif (strpos(strtolower($error), 'this transaction has been declined') !== false) { give_set_error('invalid_card', __('Your card has been declined', 'give')); } elseif (isset($response->response_reason_text)) { give_set_error('api_error', $response->response_reason_text); } elseif (isset($response->error_message)) { give_set_error('api_error', $response->error_message); } else { give_set_error('api_error', sprintf(__('An error occurred. Error data: %s', 'give'), print_r($response, true))); } give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } } catch (AuthorizeNetException $e) { give_set_error('request_error', $e->getMessage()); give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } } else { give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']); } }
public function do_payment($post_arr = '') { $error = array(); $allergies_content = ''; $post = $post_arr ? $post_arr : ci()->input->post(NULL, TRUE); extract($post); if (!$card_number) { $error[] = 'Please provide your card number.'; } if (!$exp_year and !$exp_month) { $error[] = 'Please provide your card\'s expiry date.'; } if (!$first_name) { $error[] = 'Please provide your billing first name'; } if (!$last_name) { $error[] = 'Please provide your billing last name'; } if (!$x_email) { $error[] = 'Please provide your billing email'; } if (!$x_address) { $error[] = 'Please provide your billing address'; } if (!$x_phone) { $error[] = 'Please provide your billing phone number'; } if (!$region) { $error[] = 'Please provide your billing state'; } if (!$x_city) { $error[] = 'Please provide your billing city'; } if (!$x_zip) { $error[] = 'Please provide your billing ZIP code'; } if (!@$alergy) { $error[] = 'Please answer if you have alergy'; } if (!($order_data = ci()->session->userdata('order'))) { $error[] = 'Wrong order'; } if (!($this->_authorization_code = ci()->session->userdata('authorization_code'))) { $error[] = 'Wrong transaction'; } if (@$login_type == 'register') { include_once APPPATH . 'controllers/users/login.php'; $_POST['username'] = $_POST['email']; $users = new Login(); $order['member_id'] = $users->registration(true); } elseif ($session = ci()->session->userdata('user')) { $order['member_id'] = ci()->get_user_session_data('member_id'); } if ($shipping_same_as_billing == 'n') { if (!$delivery_first_name) { $error[] = 'Please provide your delivery first name'; } if (!$delivery_last_name) { $error[] = 'Please provide your delivery last name'; } if (!$delivery_email) { $error[] = 'Please provide your delivery email'; } if (!$delivery_address) { $error[] = 'Please provide your delivery address'; } if (!$delivery_phone) { $error[] = 'Please provide your delivery phone number'; } if (!$store_region) { $error[] = 'Please provide your delivery state'; } if (!$delivery_city) { $error[] = 'Please provide your delivery city'; } if (!$delivery_zip) { $error[] = 'Please provide your delivery ZIP code'; } $order_data['shipping_name'] = $delivery_first_name . " " . $delivery_last_name; $order_data['shipping_email'] = $delivery_email; $order_data['shipping_address1'] = $delivery_address; $order_data['shipping_region'] = implode(', ', array(ci()->taxes_model->get_state($region), $x_city)); $order_data['shipping_phone'] = $delivery_phone; $order_data['shipping_postcode'] = $delivery_zip; } else { $order_data['shipping_name'] = $first_name . " " . $last_name; $order_data['shipping_email'] = $x_email; $order_data['shipping_address1'] = $x_address; $order_data['shipping_region'] = implode(', ', array(ci()->taxes_model->get_state($region), $x_city)); $order_data['shipping_phone'] = $x_phone; $order_data['shipping_postcode'] = $x_zip; } $exp_date = "{$exp_month}/{$exp_year}"; if (!isset($post['delivery_type'])) { $error[] = 'You can\'t order some of products in your state'; } else { $order_data['delivery_type'] = $post['delivery_type']; } foreach (ci()->cart->contents() as $k => $v) { $items_names[] = ($v['option']['opt'] ? $v['option']['product_options']->description[$v['option']['opt']] : '') . ' ' . $v['option']['product_title']; } if (!$error) { $this->set_gateway_data(@$store); 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']); // we add shipping data $order_data['order_shipping_tax'] = $this->_getshipping($store_region); $order_data['order_tax'] = $this->getdelivery($x_zip, isset($deliver_option), 1); $order_data['order_total'] = $this->_get_grand_total(); // coupon check if ($coupon = ci()->session->userdata('coupon')) { $coupon_check = ci()->coupons_model->coupon_valid(@$coupon['coupon_code'], ci()->session->userdata('member_id')); if ($coupon_check['status'] == 'ok') { $order_data['order_total'] -= $coupon['amount']; $order_data['coupon_code'] = $coupon['coupon_code']; } } $transaction->amount = $order_data['order_total']; $transaction->auth_code = $this->_authorization_code; $order_data['billing_name'] = $first_name . " " . $last_name; $order_data['order_email'] = $x_email; $order_data['billing_address1'] = $x_address; $order_data['billing_region'] = implode(', ', array(ci()->taxes_model->get_state($region), $x_city)); $order_data['state_id'] = $region; $order_data['store_state_id'] = $store_region; $order_data['billing_phone'] = $x_phone; $order_data['billing_postcode'] = $x_zip; $order_data['notes'] = $notes; $order_data['alergy'] = $alergy; $order_data['client_allergies'] = @$allergies_content; $order_data['start_date'] = $delivery_date; $order_data['store_id'] = @$store; if (@$ready_time) { foreach ($ready_time as $stamp => $time) { $order_data['start_date'] = date("m/d/Y", $stamp); $ready_time_arr[] = "for " . date("m/d/Y", $stamp) . " on {$time}"; } $order_data['ready_time'] = implode("<br>", $ready_time_arr); } $order_data['order_hash'] = md5(rand(333333, 7777777) . mktime()); $order_data['items_names'] = implode(',', $items_names); $transaction->card_num = $card_number; $transaction->exp_date = $exp_date; $response = $transaction->captureOnly(); if ($response->approved) { $order_data['order_paid_date'] = mktime(); $order_data['order_status'] = 'Paid & Pending Processing'; $order_data['transaction_id'] = $response->transaction_id; if (isset($order_data['order_id'])) { unset($order_data['order_id']); } $order_data['order_id'] = $this->_model->save($order_data); foreach ($order_data['items'] as $k => $v) { $v['order_id'] = $order_data['order_id']; ci()->order_items_model->save($v); } ci()->session->unset_userdata('order'); if ($coupon) { ci()->coupons_model->use_coupon($coupon['coupon_code'], ci()->user_session_data['member_id']); ci()->session->unset_userdata('coupon'); } notice('Thank you for your order! You will receive an email confirmation shortly.'); $order_data['stores'] = ci()->stores_model->get_stores($store_region, 'Open'); $this->_send_email($order_data); // send admin email if (isset(ci()->system_settings['admin_email'])) { $this->_send_email($order_data, ci()->system_settings['admin_email']); } ci()->cart->destroy(); echo "<script> document.location.href='http://'+window.location.host+'/users/orders/view_order?hash={$order_data['order_hash']}&cart_empty=true'</script>"; exit; } else { echo $response->response_reason_text; } exit; } else { if (!$post_arr) { echo implode('<br>- ', $error); exit; } else { return $error; } } }
private function get_aim($local_api_settings = array()) { $this->include_api(); if (!empty($local_api_settings)) { $api_settings = array('login_id' => rgar($local_api_settings, 'overrideLogin'), 'transaction_key' => rgar($local_api_settings, 'overrideKey'), 'mode' => rgar($local_api_settings, 'overrideMode')); } else { $api_settings = $this->get_api_settings($local_api_settings); } $is_sandbox = $api_settings['mode'] == 'test'; if ($is_sandbox) { $this->log_debug(__METHOD__ . '(): In test mode. Using the Authorize.net Sandbox.'); } $aim = new AuthorizeNetAIM($api_settings['login_id'], $api_settings['transaction_key']); $aim->setSandbox($is_sandbox); return $aim; }
if ($res['promo_price'] > 0) { $amount_to_pay = $res['promo_price']; } $amount_to_pay = is_numeric($amount_to_pay) ? normalPrettyPrice($amount_to_pay) : ''; $amount_to_pay = unPrettyPrice($amount_to_pay); $payment_description .= isset($res['title']) ? $res['title'] : ''; /*dump($amount_to_pay); dump($payment_description);*/ if (isset($_POST['x_card_num'])) { define("AUTHORIZENET_API_LOGIN_ID", $autho_api_id); define("AUTHORIZENET_TRANSACTION_KEY", $autho_key); define("AUTHORIZENET_SANDBOX", $mode_autho == "sandbox" ? true : false); //define("TEST_REQUEST", $mode_autho=="sandbox"?"FALSE":"TRUE"); require_once 'anet_php_sdk/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $params = array('description' => $payment_description, 'amount' => $amount_to_pay, 'card_num' => $_POST['x_card_num'], 'exp_date' => $_POST['expiration_month'] . "/" . $_POST['expiration_yr'], 'first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name'], 'address' => $_POST['x_address'], 'city' => $_POST['x_city'], 'state' => $_POST['x_state'], 'country' => $_POST['x_country'], 'zip' => $_POST['x_zip'], 'card_code' => $_POST['cvv']); $transaction->setFields($params); $response = $transaction->authorizeAndCapture(); if ($response->approved) { $resp_transaction = $response->transaction_id; $params = array('merchant_id' => Yii::app()->functions->getMerchantID(), 'sms_package_id' => $package_id, 'payment_type' => $payment_code, 'package_price' => $amount_to_pay, 'sms_limit' => isset($res['sms_limit']) ? $res['sms_limit'] : '', 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'payment_gateway_response' => json_encode($response), 'status' => "paid", 'payment_reference' => $resp_transaction); if ($db_ext->insertData("{{sms_package_trans}}", $params)) { header('Location: ' . Yii::app()->request->baseUrl . "/merchant/smsReceipt/id/" . Yii::app()->db->getLastInsertID()); } else { $error = Yii::t("default", "ERROR: Cannot insert record."); } } else { $error = $response->response_reason_text; } }
/** * Initializes and returns AuthorizeNetAIM object. * * @since 3.5 * * @access protected * @staticvar AuthorizeNetAIM $aim The instance of AuthorizeNetAIM class. * * @param boolean $refresh Determines whether we need to refresh $aim object or not. * @param boolean $pre_fill Determines whether we need to pre fill AIM object with posted data or not. * * @return AuthorizeNetAIM The instance of AuthorizeNetAIM class. */ protected function _get_aim($refresh = false, $pre_fill = true) { static $aim = null; if (!$refresh && !is_null($aim)) { return $aim; } require_once MEMBERSHIP_ABSPATH . '/classes/Authorize.net/AuthorizeNet.php'; // merchant information $login_id = $this->_get_option('api_user'); $transaction_key = $this->_get_option('api_key'); $mode = $this->_get_option('mode', self::MODE_SANDBOX); // create new AIM $aim = new AuthorizeNetAIM($login_id, $transaction_key); $aim->setSandbox($mode != self::MODE_LIVE); if (defined('MEMBERSHIP_AUTHORIZE_LOGFILE')) { $aim->setLogFile(MEMBERSHIP_AUTHORIZE_LOGFILE); } if ($pre_fill) { // card information $aim->card_num = preg_replace('/\\D/', '', filter_input(INPUT_POST, 'card_num')); $aim->card_code = trim(filter_input(INPUT_POST, 'card_code')); $aim->exp_date = sprintf('%02d/%02d', filter_input(INPUT_POST, 'exp_month', FILTER_VALIDATE_INT), substr(filter_input(INPUT_POST, 'exp_year', FILTER_VALIDATE_INT), -2)); $aim->duplicate_window = MINUTE_IN_SECONDS; // customer information $aim->cust_id = $this->_member->ID; $aim->customer_ip = self::_get_remote_ip(); $aim->email = $this->_member->user_email; // billing information $aim->first_name = substr(trim(filter_input(INPUT_POST, 'first_name')), 0, 50); $aim->last_name = substr(trim(filter_input(INPUT_POST, 'last_name')), 0, 50); $aim->company = substr(trim(filter_input(INPUT_POST, 'company')), 0, 50); $aim->address = substr(trim(filter_input(INPUT_POST, 'address')), 0, 60); $aim->city = substr(trim(filter_input(INPUT_POST, 'city')), 0, 40); $aim->state = substr(trim(filter_input(INPUT_POST, 'state')), 0, 40); $aim->zip = substr(trim(filter_input(INPUT_POST, 'zip')), 0, 20); $aim->country = substr(trim(filter_input(INPUT_POST, 'country')), 0, 60); $aim->phone = substr(trim(filter_input(INPUT_POST, 'phone')), 0, 25); $aim->fax = substr(trim(filter_input(INPUT_POST, 'fax')), 0, 25); } return $aim; }