/** * Reimplementation of vmPaymentPlugin::plgVmOnConfirmedOrder() * * @link http://www.authorize.net/support/AIM_guide.pdf * Credit Cards Test Numbers * Visa Test Account 4007000000027 * Amex Test Account 370000000000002 * Master Card Test Account 6011000000000012 * Discover Test Account 5424000000000015 * @author Valerie Isaksen */ function plgVmConfirmedOrder(VirtueMartCart $cart, $order) { if (!($this->_currentMethod = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return FALSE; } $this->setInConfirmOrder($cart); $usrBT = $order['details']['BT']; $usrST = isset($order['details']['ST']) ? $order['details']['ST'] : ''; $session = JFactory::getSession(); $return_context = $session->getId(); $payment_currency_id = shopFunctions::getCurrencyIDByName(self::AUTHORIZE_DEFAULT_PAYMENT_CURRENCY); $totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total, $payment_currency_id); $cd = CurrencyDisplay::getInstance($cart->pricesCurrency); // Set up data $formdata = array(); $formdata = array_merge($this->_setHeader(), $formdata); $formdata = array_merge($this->_setResponseConfiguration(), $formdata); $formdata = array_merge($this->_setBillingInformation($usrBT), $formdata); if (!empty($usrST)) { $formdata = array_merge($this->_setShippingInformation($usrST), $formdata); } $formdata = array_merge($this->_setTransactionData($order['details']['BT'], $totalInPaymentCurrency['value']), $formdata); $formdata = array_merge($this->_setMerchantData(), $formdata); // prepare the array to post $poststring = ''; foreach ($formdata as $key => $val) { $poststring .= urlencode($key) . "=" . urlencode($val) . "&"; } $poststring = rtrim($poststring, "& "); // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id; $dbValues['payment_method_id'] = $order['details']['BT']->virtuemart_paymentmethod_id; $dbValues['return_context'] = $return_context; $dbValues['payment_name'] = parent::renderPluginName($this->_currentMethod); $dbValues['cost_per_transaction'] = $this->_currentMethod->cost_per_transaction; $dbValues['cost_percent_total'] = $this->_currentMethod->cost_percent_total; $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; $dbValues['payment_currency'] = $payment_currency_id; $this->debugLog("before store", "plgVmConfirmedOrder", 'debug'); $this->storePSPluginInternalData($dbValues); // send a request $response = $this->_sendRequest($poststring); $this->debugLog($response, "plgVmConfirmedOrder", 'debug'); $authnet_values = array(); // to check the values??? // evaluate the response $html = $this->_handleResponse($response, $authnet_values, $order, $dbValues['payment_name']); if ($this->error) { $new_status = $this->_currentMethod->payment_declined_status; $this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html); return; // will not process the order } else { if ($this->approved) { $this->_clearAuthorizeNetSession(); $new_status = $this->_currentMethod->payment_approved_status; } else { if ($this->declined) { vRequest::setVar('html', $html); $new_status = $this->_currentMethod->payment_declined_status; $this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html); return; } else { if ($this->held) { $this->_clearAuthorizeNetSession(); $new_status = $this->_currentMethod->payment_held_status; } } } } $modelOrder = VmModel::getModel('orders'); $order['order_status'] = $new_status; $order['customer_notified'] = 1; $order['comments'] = ''; $modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE); //We delete the old stuff $cart->emptyCart(); vRequest::setVar('html', $html); }
/** * Reimplementation of vmPaymentPlugin::plgVmOnConfirmedOrder() * * @link http://nabvelocity.com/ * Credit Cards Test Numbers * Visa Test Account 4007000000027 * Amex Test Account 370000000000002 * Master Card Test Account 6011000000000012 * Discover Test Account 5424000000000015 * @author Velocity Team */ function plgVmConfirmedOrder(VirtueMartCart $cart, $order) { if (!($this->_currentMethod = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return FALSE; } $this->setInConfirmOrder($cart); $usrBT = $order['details']['BT']; $usrST = isset($order['details']['ST']) ? $order['details']['ST'] : ''; $session = JFactory::getSession(); $return_context = $session->getId(); $payment_currency_id = shopFunctions::getCurrencyIDByName(self::VELOCITY_DEFAULT_PAYMENT_CURRENCY); $totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total, $payment_currency_id); $cd = CurrencyDisplay::getInstance($cart->pricesCurrency); if (!class_exists('ShopFunctions')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php'; } $statecode = self::get2cStateByID($usrBT->virtuemart_state_id); $countrycode = self::get3cCountryByID($usrBT->virtuemart_country_id) == 'USA' ? self::get3cCountryByID($usrBT->virtuemart_country_id) : 'USA'; $avsData = array('Street' => $usrBT->address_1 . ' ' . $usrBT->address_2, 'City' => $usrBT->city, 'StateProvince' => $statecode, 'PostalCode' => $usrBT->zip, 'Country' => $countrycode); $cardData = array('cardtype' => str_replace(' ', '', $this->_cc_type), 'pan' => $this->_cc_number, 'expire' => sprintf("%02d", $this->_cc_expire_month) . substr($this->_cc_expire_year, -2), 'cvv' => $this->_cc_cvv, 'track1data' => '', 'track2data' => ''); $identitytoken = $this->_vmpCtable->identitytoken; $workflowid = $this->_vmpCtable->workflowid; $applicationprofileid = $this->_vmpCtable->applicationprofileid; $merchantprofileid = $this->_vmpCtable->merchantprofileid; if ($this->_vmpCtable->payment_mode) { $isTestAccount = TRUE; } else { $isTestAccount = FALSE; } include_once 'sdk' . DS . 'configuration.php'; include_once 'sdk' . DS . 'Velocity.php'; // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id; $dbValues['payment_method_id'] = $order['details']['BT']->virtuemart_paymentmethod_id; $dbValues['return_context'] = $return_context; $dbValues['payment_name'] = parent::renderPluginName($this->_currentMethod); $dbValues['cost_per_transaction'] = $this->_currentMethod->cost_per_transaction; $dbValues['cost_percent_total'] = $this->_currentMethod->cost_percent_total; $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; $dbValues['payment_currency'] = $payment_currency_id; $this->debugLog("before store", "plgVmConfirmedOrder", 'debug'); $this->storePSPluginInternalData($dbValues); $errMsg = ''; try { $velocityProcessor = new VelocityProcessor($applicationprofileid, $merchantprofileid, $workflowid, $isTestAccount, $identitytoken); } catch (Exception $e) { $this->error = TRUE; $errMsg .= '<br>' . vmText::_($e->getMessage()); } /* Request for the verify avsdata and card data*/ try { $response = $velocityProcessor->verify(array('amount' => $totalInPaymentCurrency['value'], 'avsdata' => $avsData, 'carddata' => $cardData, 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11')); } catch (Exception $e) { $this->error = TRUE; $errMsg .= '<br>' . vmText::_($e->getMessage()); } if (is_array($response) && isset($response['Status']) && $response['Status'] == 'Successful') { /* Request for the authrizeandcapture transaction */ try { $xml = VelocityXmlCreator::authorizeandcaptureXML(array('amount' => $totalInPaymentCurrency['value'], 'avsdata' => $avsData, 'token' => $response['PaymentAccountDataToken'], 'order_id' => $order['details']['BT']->order_number, 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11')); // got authorizeandcapture xml object. $req = $xml->saveXML(); $obj_req = serialize($req); $cap_response = $velocityProcessor->authorizeAndCapture(array('amount' => $totalInPaymentCurrency['value'], 'avsdata' => $avsData, 'token' => $response['PaymentAccountDataToken'], 'order_id' => $order['details']['BT']->order_number, 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11')); if (is_array($cap_response) && !empty($cap_response) && isset($cap_response['Status']) && $cap_response['Status'] == 'Successful') { /* save the authandcap response into 'virtuemart_payment_plg_velocity' custom table.*/ $response_fields['transaction_id'] = $cap_response['TransactionId']; $response_fields['transaction_status'] = $cap_response['TransactionState']; $response_fields['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id; $response_fields['request_obj'] = $obj_req; $response_fields['response_obj'] = serialize($cap_response); $this->storePSPluginInternalData($response_fields, 'virtuemart_order_id', TRUE); $html = '<table class="adminlist table">' . "\n"; $html .= $this->getHtmlRow('VELOCITY_PAYMENT_NAME', $this->_vmpCtable->payment_name); $html .= $this->getHtmlRow('VELOCITY_ORDER_NUMBER', $order['details']['BT']->order_number); $html .= $this->getHtmlRow('VELOCITY_AMOUNT', $cap_response['Amount']); $html .= $this->getHtmlRow('VMPAYMENT_VELOCITY_APPROVAL_CODE', $cap_response['ApprovalCode']); if ($cap_response['TransactionId']) { $html .= $this->getHtmlRow('VELOCITY_RESPONSE_TRANSACTION_ID', $cap_response['TransactionId']); } $html .= '</table>' . "\n"; $this->debugLog(vmText::_('VMPAYMENT_VELOCITY_ORDER_NUMBER') . " " . $order['details']['BT']->order_number . ' payment approved', '_handleResponse', 'debug'); $comment = 'ApprovalCode: ' . $cap_response['ApprovalCode'] . '<br>Transaction_Id: ' . $cap_response['TransactionId']; $this->_clearVelocitySession(); $new_status = 'U'; } else { if (is_array($cap_response) && !empty($cap_response)) { $this->error = TRUE; $errMsg .= vmText::_($cap_response['StatusMessage']); } else { if (is_string($cap_response)) { $this->error = TRUE; $errMsg .= '<br>' . vmText::_($cap_response); } else { $this->error = TRUE; $errMsg .= '<br>' . vmText::_('VMPAYMENT_VELOCITY_UNKNOWN_ERROR'); } } } } catch (Exception $e) { $errMsg .= '<br>' . vmText::_($e->getMessage()); } } else { if (is_array($response) && (isset($response['Status']) && $response['Status'] != 'Successful')) { $this->error = TRUE; $errMsg .= '<br>' . vmText::_($response['StatusMessage']); } else { if (is_string($response)) { $this->error = TRUE; $errMsg .= '<br>' . vmText::_($response); } else { $this->error = TRUE; $errMsg .= '<br>' . vmText::_('VMPAYMENT_VELOCITY_UNKNOWN_ERROR'); } } } $this->debugLog($response, "plgVmConfirmedOrder", 'debug'); $modelOrder = VmModel::getModel('orders'); if ($this->error) { $this->debugLog($errMsg, 'getOrderIdByOrderNumber', 'message'); $this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $errMsg); return; } $order['order_status'] = $new_status; $order['customer_notified'] = 1; $order['comments'] = $comment; $modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE); //We delete the old stuff $cart->emptyCart(); vRequest::setVar('html', $html); }
/** * Reimplementation of vmPaymentPlugin::plgVmOnConfirmedOrder() * * @link http://www.authorize.net/support/AIM_guide.pdf * Credit Cards Test Numbers * Visa Test Account 4007000000027 * Amex Test Account 370000000000002 * Master Card Test Account 6011000000000012 * Discover Test Account 5424000000000015 * @author Valerie Isaksen */ function plgVmConfirmedOrder($cart, $order) { if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } $usrBT = $order['details']['BT']; $usrST = isset($order['details']['ST']) ? $order['details']['ST'] : $order['details']['BT']; $session = JFactory::getSession(); $return_context = $session->getId(); $transaction_key = $this->get_passkey(); if ($transaction_key === FALSE) { return FALSE; } // Set up data $formdata = array(); $formdata = array_merge($this->_setHeader(), $formdata); $formdata = array_merge($this->_setResponseConfiguration(), $formdata); $formdata = array_merge($this->_setBillingInformation($usrBT), $formdata); $formdata = array_merge($this->_setShippingInformation($usrST), $formdata); $formdata = array_merge($this->_setTransactionData($order['details']['BT'], $method), $formdata); $formdata = array_merge($this->_setMerchantData($method), $formdata); // prepare the array to post $poststring = ''; foreach ($formdata as $key => $val) { $poststring .= urlencode($key) . "=" . urlencode($val) . "&"; } $poststring = rtrim($poststring, "& "); // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id; $dbValues['payment_method_id'] = $order['details']['BT']->virtuemart_paymentmethod_id; $dbValues['return_context'] = $return_context; $dbValues['payment_name'] = parent::renderPluginName($method); $dbValues['cost_per_transaction'] = $method->cost_per_transaction; $dbValues['cost_percent_total'] = $method->cost_percent_total; $this->storePSPluginInternalData($dbValues); // send a request $response = $this->_sendRequest($this->_getPostUrl($method), $poststring); $this->logInfo($response); $authnet_values = array(); // to check the values??? // evaluate the response $html = $this->_handleResponse($response, $authnet_values, $order, $dbValues['payment_name']); if ($this->error) { $new_status = $method->payment_declined_status; $this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html); return; // will not process the order } else { if ($this->approved) { $this->_clearAuthorizeNetSession(); $new_status = $method->payment_approved_status; } else { if ($this->declined) { JRequest::setVar('html', $html); $new_status = $method->payment_declined_status; $this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html); return; } else { if ($this->held) { $this->_clearAuthorizeNetSession(); $new_status = $method->payment_held_status; } } } } $modelOrder = VmModel::getModel('orders'); $order['order_status'] = $new_status; $order['customer_notified'] = 1; $order['comments'] = ''; $modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE); //We delete the old stuff $cart->emptyCart(); JRequest::setVar('html', $html); }
function plgVmConfirmedOrder(VirtueMartCart $cart, $order) { if (!($this->_currentMethod = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return null; // Another method was selected, do nothing } if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return FALSE; } $session = JFactory::getSession(); $return_context = $session->getId(); // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id; $dbValues['payment_method_id'] = $order['details']['BT']->virtuemart_paymentmethod_id; $dbValues['return_context'] = $return_context; $dbValues['payment_name'] = parent::renderPluginName($this->_currentMethod); $dbValues['cost_per_transaction'] = $this->_currentMethod->cost_per_transaction; $dbValues['cost_percent_total'] = $this->_currentMethod->cost_percent_total; $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; $dbValues['payment_currency'] = $payment_currency_id; $this->debugLog("before store", "plgVmConfirmedOrder", 'debug'); if ($this->_currentMethod->sandbox) { Everypay\Everypay::$isTest = true; } Everypay\Everypay::setApiKey($this->getSecretKey()); $token = $this->getToken(); $response = Everypay\Payment::create(array('token' => $token, 'description' => 'Order #' . $order['details']['BT']->order_number)); if (isset($response->error)) { $new_status = $this->_currentMethod->payment_declined_status; $this->_handlePaymentCancel($order['details']['BT']->virtuemart_order_id, $html); return; // will not process the order } $dbValues['everypay_response_token'] = $response->token; $dbValues['everypay_response_description'] = $response->description; $dbValues['everypay_response_status'] = $response->status; $dbValues['everypay_response_last_four'] = $response->last_four; $dbValues['everypay_response_holder_name'] = $response->holder_name; $dbValues['payment_order_total'] = number_format($response->amount / 100, 2); $this->storePSPluginInternalData($dbValues); $cart->emptyCart(); $session = JFactory::getSession(); $session->clear('everypay_token', 'vm'); }