/** * Prepares the payment form * and returns HTML Form to be displayed to the user * generally will have a message saying, 'confirm entries, then click complete order' * * Submit button target for onsite payments & return URL for offsite payments should be: * index.php?option=com_tienda&view=checkout&task=confirmPayment&orderpayment_type=xxxxxx * where xxxxxxx = $_element = the plugin's filename * * @param $data array form post data * @return string HTML to display */ function _prePayment($data) { // prepare the payment form $vars = new JObject(); $vars->order_id = $data['order_id']; $vars->orderpayment_id = $data['orderpayment_id']; $vars->orderpayment_amount = $data['orderpayment_amount']; $vars->orderpayment_type = $this->_element; // set payment plugin variables $vars->post_url = $this->_getPostUrl(); // TODO: Currency choice not Accepted Yet, but when it is use Tienda::getInstance()->get('currency'); // TODO: Recalculate to SEK with something like: // $vars->Cost = TiendaCurrency::convert( $data['orderpayment_amount'], Tienda::getInstance()->get('currency'), "SEK" ); $vars->currency_code = "SEK"; // set variables for user info $vars->SellerEmail = $this->_getParam('payson_seller_email'); $vars->BuyerFirstName = $data['orderinfo']->shipping_first_name; $vars->BuyerLastName = $data['orderinfo']->shipping_last_name; $vars->BuyerEmail = $data['orderinfo']->user_email; $vars->Cost = str_replace(".", ",", TiendaHelperBase::number($data['orderpayment_amount'], array('thousands' => '', 'currency_decimal' => ',', 'num_decimals' => 2))); $vars->ExtraCost = '0'; // TODO: Implement later, might be configured from plugin parameters to let the shop owner take an extra cost? $vars->RefNr = $data['orderpayment_id']; $vars->PaymentMethod = $this->_getParam('PaymentMethod'); $vars->OkUrl = JURI::root() . "index.php?option=com_tienda&view=checkout&task=confirmPayment&orderpayment_type=" . $this->_element . "&paction=display_message"; $vars->CancelUrl = JURI::root() . "index.php?option=com_tienda&view=checkout&task=confirmPayment&orderpayment_type=" . $this->_element . "&paction=cancel"; $vars->AgentId = $this->_getParam('payson_agent_id', ''); $vars->GuaranteeOffered = $this->_getParam('payson_guarantee', ''); $vars->payson_image = $this->_getParam('payson_image', ''); // Create the MD5 to validate the request at Payson $Key = $this->_getParam('payson_md5'); $MD5string = $vars->SellerEmail . ":" . $vars->Cost . ":" . $vars->ExtraCost . ":" . $vars->OkUrl . ":" . $vars->GuaranteeOffered . $Key; $vars->MD5 = md5($MD5string); $html = $this->_getLayout('prepayment', $vars); return $html; }
function _process($data) { $post = JRequest::get('post'); $orderpayment_id = @$data['ssl_invoice_number']; $errors = array(); $send_email = false; // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); if (empty($orderpayment_id) || empty($orderpayment->orderpayment_id)) { $errors[] = JText::_('VIRTUALMERCHANT MESSAGE INVALID ORDERPAYMENTID'); return count($errors) ? implode("\n", $errors) : ''; } $orderpayment->transaction_details = $data['ssl_result_message']; $orderpayment->transaction_id = $data['ssl_txn_id']; $orderpayment->transaction_status = $data['ssl_result']; // check the stored amount against the payment amount Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['ssl_amount'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('VIRTUALMERCHANT MESSAGE AMOUNT INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if (count($errors)) { // if an error occurred $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED } else { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : ''; return true; }
/** * * @return HTML */ function _process() { $send_email = false; $data = JRequest::getVar('DATA', '', 'post'); // Invalidate data if it is in the wrong format if (!preg_match(':^[a-zA-Z0-9]+$:', $data)) { $data = ''; } $this->os_info = $this->_getOperatingSystemInfo(); // set sips checkout type // Next line is there to help me to debug // should not be removed //$data = '2020333732603028502c2360532d5328532d2360522d4360502c4360502c3334502c3330512d2324562d5334592c3324512c33242a2c2360532c2360502d2324502c23602a2c2360552c2360502d433c552e3328572c4048512c2334502c23605435444533303048502c2338502c2324542c4360512c2360582c4344502e3334582d233c2a2c3360532c2360502d4324512d3344502c5048512c2330502c2360582c4360512c2360582c43442a2c3360512c2360502c4360505c224324502c4360502c3360512c4340532c233c552e3330535c224324502c2360502c2338502d5334592d232c2a2c2328582c2360502c4639525c224360522e3360502c2329463c4048502c2340502c2360532e333c585c224324502d4360502c233c512c3324512b4360505c224324512d2360502c2338522c2324522c23242a2c2360592c2360502c4639525c224360532c2360502c4321413b26255438364c512c232160383651413d26254b2b4659453d6048502c3338502c23605334552d2c5c224360502d5360502c2328502c4048502c5340502c2360522e33382a2c2330502c2360512d2425353524412f34455d2330352134353529255c224360532e3360502c2324505c224324502e3360502c23292e335048512c3360502c236051334048512c3324502c2360522c23602a2c2328562c2360502d5344572d3344522d53282adc970880f8cf2717'; // // Récupération de la variable cryptée DATA $message = "message=" . $data; $pathfile .= " pathfile=" . $this->_getPathfileFileName($this->params->get('pathfile')); $bin_response = $this->_getBinPath("response"); $parm = $message . " " . $pathfile; $result = exec("{$bin_response} {$parm}"); $sips_response_array = explode("!", $result); list(, $code, $error, $merchant_id, $merchant_country, $amount, $transaction_id, $payment_means, $transmission_date, $payment_time, $payment_date, $response_code, $payment_certificate, $authorisation_id, $currency_code, $card_number, $cvv_flag, $cvv_response_code, $bank_response_code, $complementary_code, $complementary_info, $return_context, $caddie, $receipt_complement, $merchant_language, $language, $customer_id, $orderpayment_id, $customer_email, $customer_ip_address, $capture_day, $capture_mode, $data) = $sips_response_array; if ($code != 0) { $errors[] = JText::_('TIENDA_SIPS_RETURN_CODE_INVALID') . " " . $code; } elseif ($error != 0) { $errors[] = JText::_('TIENDA_SIPS_RETURN_ERROR') . " " . $sips_error; } elseif ($merchant_id != $this->params->get('merchant_id')) { $errors[] = JText::_('TIENDA_SIPS_MERCHANT_ID_RECEIVED_INVALID'); } else { // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_tienda' . DS . 'tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); if (empty($orderpayment_id) || empty($orderpayment->orderpayment_id)) { $errors[] = JText::_('TIENDA_SIPS_INVALID ORDERPAYMENTID'); } } if (count($errors)) { echo $errors; print_r($errors); $this->_sendErrorEmail($errors, $sips_response_array); return false; } // check the stored amount against the payment amount Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($amount, array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('TIENDA_SIPS_AMOUNT_INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if (count($errors) or $response_code != '00') { if ($response_code != '00') { $orderpayment->transaction_details = JText::_('TIENDA_SIPS_RESPONSE_CODE') . $response_code . "\n" . JText::_('TIENDA_SIPS_RESPONSE_CODE_SIPS_ERROR') . constant('TIENDA_SIPS_RESPONSE_' . $response['response_code']) . "\n" . JText::_('TIENDA_SIPS_READ_SIPS_DOCUMENTATION'); } else { $orderpayment->transaction_details = implode(" ", $errors); } $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED // save the order if (!$order->save()) { $errors[] = $order->getError(); } $send_email = false; } else { define($credit_card_type, $payment_means); $credit_card = split('\\.', $card_number); $credit_card_number = $credit_card[0] . ' #### #### ##' . $credit_card[1]; // TO DO: DECODE TIME AND DATE $orderpayment->transaction_details = JText::_('TIENDA_SIPS_TRANSMISSION_DATE') . $transmission_date . "\n" . JText::_('TIENDA_SIPS_RESPONSE_PAYMENT_TIME') . " : " . $payment_time . "\n" . JText::_('TIENDA_SIPS_RESPONSE_PAYMENT_DATE') . " : " . $payment_date . "\n" . JText::_('TIENDA_SIPS_RESPONSE_PAYMENT_CERTIFICATE') . " : " . $payment_certificate . "\n" . JText::_('TIENDA_SIPS_RESPONSE_AUTHORIZATION_ID') . $authorisation_id . "\n" . JText::_('TIENDA_SIPS_RESPONSE_CREDIT_CARD_TYPE') . " : " . constant($credit_card_type) . "\n" . JText::_('TIENDA_SIPS_RESPONSE_CREDIT_CARD_NUMBER') . " : " . $credit_card_number; $orderpayment->transaction_id = $transaction_id; $orderpayment->transaction_status = $response_code; // ??? $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // save the order if (!$order->save()) { $errors[] = $order->getError(); } // PAYMENT RECEIVED $this->setOrderPaymentReceived($orderpayment->order_id); // send email $send_email = true; } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : 'processed'; }
/** * Processing the payment * * @param $data array form post data * @return string HTML to display */ function _process($data) { $errors = array(); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment_id = $data['orderpayment_id']; $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = $data['orderpayment_type']; $orderpayment->transaction_id = $data['orderpayment_id']; $orderpayment->transaction_status = "Payment Incomplete"; // check the stored amount against the payment amount Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['orderpayment_amount'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('TIENDA ALPHAUSERPOINTS PAYMENT MESSAGE AMOUNT INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // check if user has enough points $userpoints = $this->getUserpoints(); if ($data['amount_points'] > $userpoints) { $errors[] = JText::_('TIENDA ALPHAUSERPOINTS PAYMENT MESSAGE NOT ENOUGH POINTS'); } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if (count($errors)) { // if an error occurred $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED $setOrderPaymentReceived = false; $send_email = false; } else { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED $orderpayment->transaction_status = "Payment Received"; //reduce number of alphauserpoints $errors[] = $this->reduceUserpoints($data['amount_points']); // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : ''; }
function _process($data) { $errors = array(); $user = JFactory::getUser(); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment_id = $data['orderpayment_id']; $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = $data['orderpayment_type']; $orderpayment->transaction_id = $data['orderpayment_id']; $orderpayment->transaction_status = "Incomplete"; // check the stored amount against the payment amount thousand Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['orderpayment_amount'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('TIENDA AMBRAPOINTS PAYMENT MESSAGE AMOUNT INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); // check if user has enough points JLoader::import('com_ambra.helpers.user', JPATH_ADMINISTRATOR . '/components'); $current_points = AmbraHelperUser::getPoints($order->user_id); if ($data['amount_points'] > $current_points) { $errors[] = JText::_('TIENDA AMBRAPOINTS PAYMENT MESSAGE NOT ENOUGH POINTS'); } if (count($errors)) { // if an error occurred $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED $send_email = false; } else { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED $orderpayment->transaction_status = "Payment Received"; // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } // substract spent points from user's ambra total points // successful payment // if here, all OK // create a pointhistory table object $pointhistory = JTable::getInstance('PointHistory', 'AmbraTable'); // set properties $pointhistory->user_id = $user->id; $pointhistory->points = "-" . $data['amount_points']; $pointhistory->points_updated = 0; $pointhistory->pointhistory_enabled = 1; $pointhistory->pointhistory_name = JText::_('For making purchase in Tienda'); $pointhistory->pointhistory_description = JText::_('COM_TIENDA_PAYMENT_ID') . ": " . $orderpayment_id . "\n" . JText::_('COM_TIENDA_TRANSACTION_ID') . ": " . $orderpayment->transaction_id; // save it and move on if (!$pointhistory->save()) { $errors[] = $pointhistory->getError(); // if saving the record failed, disable sub? } return count($errors) ? implode("\n", $errors) : ''; }
?> '> <?php $i = 1; foreach ($vars->orderitems as $item) { //TODO /* TiendaHelperBase::number( @$item->orderitem_final_price / @$item->orderitem_quantity, array( 'thousands' =>'', 'decimal'=> '.' ) ); * TiendaHelperBase::number( @$item->orderitem_price + @$item->orderitem_attributes_price, array( 'thousands' =>'', 'decimal'=> '.' ) ); * THis doesn't work because it doesn't take into account pricing discounts from coupons * */ ?> <input type='hidden' name='amount_<?php echo $i; ?> ' value='<?php echo TiendaHelperBase::number(@$item->orderitem_final_price / @$item->orderitem_quantity, array('thousands' => '', 'decimal' => '.')); ?> '> <input type='hidden' name='item_name_<?php echo $i; ?> ' value='<?php echo $item->_description; ?> '> <input type='hidden' name='item_number_<?php echo $i; ?> ' value='<?php echo $item->product_id; ?>
/** * Prepares parameters for the payment processing * * @param object $data Post variables * @return array * @access protected */ function _getProcessVars($data) { $vendor_name = $this->vendor_name; // for now, we impomenet only standard payment method $paymenttype = 'PAYMENT'; // joomla info $user = JFactory::getUser(); $submitted_email = !empty($data['email']) ? $data['email'] : ''; $sagepay_userid = $user->id; $sagepay_useremail = empty($user->id) ? $submitted_email : $user->email; // order info JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($data['order_id']); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($data['orderpayment_id']); $orderinfo = JTable::getInstance('OrderInfo', 'TiendaTable'); $orderinfo->load(array('order_id' => $data['order_id'])); $billingzone = JTable::getInstance('Zones', 'TiendaTable'); $billingzone->load($orderinfo->billing_zone_id); $currency = JTable::getInstance('Currencies', 'TiendaTable'); $currency->load(array('currency_id' => $order->currency_id)); $country = JTable::getInstance('Countries', 'TiendaTable'); $country->load(array('country_id' => $orderinfo->billing_country_id)); Tienda::load('TiendaHelperBase', 'helpers._base'); $sagepay_description = JText::_('COM_TIENDA_ORDER_NUMBER') . ": " . $order->order_id; $sagepay_amount = TiendaHelperBase::number($orderpayment->orderpayment_amount, array('thousands' => '')); $sagepay_invoice_num = $data['orderpayment_id']; // customer information $sagepay_fname = $orderinfo->billing_first_name; $sagepay_lname = $orderinfo->billing_last_name; $sagepay_address1 = substr($orderinfo->billing_address_1, 0, 100); $sagepay_address2 = substr($orderinfo->billing_address_2, 0, 100); $sagepay_city = $orderinfo->billing_city; $sagepay_zip = $orderinfo->billing_postal_code; $sagepay_country = $country->country_isocode_2; if ($sagepay_country == 'US') { $sagepay_state = $billingzone->code; } else { $sagepay_state = ''; } $sagepay_card_num = str_replace(" ", "", str_replace("-", "", $data['cardnum'])); $sagepay_phone = $orderinfo->billing_phone_1; $sagepay_exp_date = $this->_getFormattedCardDate('my', $data['cardexp']); $sagepay_start_date = $this->_getFormattedCardDate('my', $data['cardst']); $vendorTxCode = $data['order_id']; // put all values into an array (does not support Gift Aid Payment) $sagepay_values = array("VPSProtocol" => $this->sagepay_protocol, "TxType" => $paymenttype, "Vendor" => $vendor_name, "VendorTxCode" => $vendorTxCode, "Amount" => $sagepay_amount, "Currency" => $currency->currency_code, "Description" => $sagepay_description, "CardHolder" => $data['cardholder'], "CardNumber" => $sagepay_card_num, "StartDate" => $sagepay_start_date, "ExpiryDate" => $sagepay_exp_date, "IssueNumber" => $data['cardissuenum'], "CV2" => $data['cardcv2'], "CardType" => $data['cardtype'], "BillingSurname" => $sagepay_lname, "BillingFirstnames" => $sagepay_fname, "BillingAddress1" => $sagepay_address1, "BillingAddress2" => $sagepay_address2, "BillingCity" => $sagepay_city, "BillingPostCode" => $sagepay_zip, "BillingCountry" => $sagepay_country, "BillingState" => $sagepay_state, "BillingPhone" => $sagepay_phone, "DeliverySurname" => $sagepay_lname, "DeliveryFirstnames" => $sagepay_fname, "DeliveryAddress1" => $sagepay_address1, "DeliveryAddress2" => $sagepay_address2, "DeliveryCity" => $sagepay_city, "DeliveryPostCode" => $sagepay_zip, "DeliveryCountry" => $sagepay_country, "DeliveryState" => $sagepay_state, "DeliveryPhone" => $sagepay_phone, "CustomerEMail" => $sagepay_useremail, "ClientIPAddress" => $_SERVER['REMOTE_ADDR'], "AccountType" => 'E'); return $sagepay_values; }
?> </td> </tr> <tr> <th><a href="<?php echo $stats->link; ?> "><?php echo JText::_('COM_TIENDA_LIFETIME_SALES'); ?> </a></th> <td style="text-align: right;"><?php echo TiendaHelperBase::number($stats->lifetime->num, $options_int); ?> </td> <td style="text-align: right;"><?php echo TiendaHelperBase::number($stats->lifetime->average_daily, $options_decimal); ?> </td> <td style="text-align: right;"><?php echo TiendaHelperBase::currency($stats->lifetime->average, '', $options_decimal); ?> </td> <td style="text-align: right;"><?php echo TiendaHelperBase::currency($stats->lifetime->amount, '', $options_decimal); ?> </td> </tr> </tbody> </table>
<?php } else { ?> <td style="text-align: center; width: 33%;"><h3><?php echo TiendaSelect::range(@$state->stats_interval, 'stats_interval', $attribs, null, true); ?> </h3></td> <?php } ?> <td style="text-align: center; width: 33%;"><h3><?php echo TiendaHelperBase::currency(@$this->sum); ?> </h3></td> <td style="text-align: center; width: 33%;"><h3><?php echo TiendaHelperBase::number(@$this->total, array('num_decimals' => '0')); ?> </h3></td> </tr> </tbody> </table> <div class="section"> <?php $chart = new HighRoller(); $chart->chart->renderTo = 'chart'; $chart->chart->type = 'mixed'; $chart->plotOptions = new stdClass(); $chart->plotOptions->column = new stdClass(); $chart->plotOptions->column->pointStart = strtotime(@$this->revenue[0][0]) * 1000; $chart->plotOptions->column->pointInterval = @$this->interval->pointinterval;
/** * Processes the form data */ function _processSale($data, $vars) { $errors = array(); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment_id = JRequest::getVar('orderpayment_id'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); $orderpayment->transaction_details = $data['key']; $orderpayment->transaction_id = $data['order_number']; $orderpayment->transaction_status = $data['credit_card_processed']; // check the stored amount against the payment amount Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['total'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('COM_TIENDA_2CO_MESSAGE_AMOUNT_INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); $send_email = false; if (!$vars->approved) { //incorrect hash $order->order_state_id = '14'; // Unspecified Error } else { if (count($errors)) { // if an error occurred $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED } else { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; } } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : ''; }
/** * Prepares parameters for the payment processing * * @param object $data Post variables * @return array * @access protected */ function _getProcessVars($data) { $merchant_id = $this->merchant_id; $merchant_key = $this->merchant_key; // for now, we impomenet only standard payment method $paymenttype = '01'; // joomla info $user = JFactory::getUser(); $sagepayments_userid = $user->id; // order info JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($data['order_id']); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($data['orderpayment_id']); $orderinfo = JTable::getInstance('OrderInfo', 'TiendaTable'); $orderinfo->load(array('order_id' => $data['order_id'])); $billingzone = JTable::getInstance('Zones', 'TiendaTable'); $billingzone->load($orderinfo->billing_zone_id); $currency = JTable::getInstance('Currencies', 'TiendaTable'); $currency->load(array('currency_id' => $order->currency_id)); $country = JTable::getInstance('Countries', 'TiendaTable'); $country->load(array('country_id' => $orderinfo->billing_country_id)); Tienda::load('TiendaHelperBase', 'helpers._base'); $sagepayments_description = JText::_('COM_TIENDA_ORDER_NUMBER') . ": " . $order->order_id; $sagepayments_amount = TiendaHelperBase::number($orderpayment->orderpayment_amount, array('thousands' => '')); $sagepayments_invoice_num = $data['orderpayment_id']; // customer information $sagepayments_fname = $orderinfo->billing_first_name; $sagepayments_lname = $orderinfo->billing_last_name; $sagepayments_address1 = substr($orderinfo->billing_address_1, 0, 100); $sagepayments_address2 = substr($orderinfo->billing_address_2, 0, 100); $sagepayments_address = $sagepayments_address1; if (!empty($sagepayments_address2)) { $sagepayments_address .= $sagepayments_address2; } $sagepayments_city = $orderinfo->billing_city; $sagepayments_zip = $orderinfo->billing_postal_code; $sagepayments_country = $country->country_isocode_2; $sagepayments_state = $billingzone->code; $sagepayments_card_num = str_replace(" ", "", str_replace("-", "", $data['cardnum'])); $sagepayments_phone = $orderinfo->billing_phone_1; $sagepayments_exp_date = $this->_getFormattedCardDate('my', $data['cardexp']); $sagepayments_useremail = empty($orderinfo->user_email) ? $user->email : $orderinfo->user_email; // put all values into an array (does not support Gift Aid Payment) $sagepayments_values = array("T_code" => $paymenttype, "M_id" => $merchant_id, "M_key" => $merchant_key, "T_amt" => $sagepayments_amount, "T_ordernum" => $order->order_id, "C_name" => $data['cardholder'], "C_cardnumber" => $sagepayments_card_num, "C_exp" => $sagepayments_exp_date, "C_cvv" => $data['cardcv2'], "C_address" => $sagepayments_address, "C_city" => $sagepayments_city, "C_state" => $sagepayments_state, "C_zip" => $sagepayments_zip, "C_email" => $sagepayments_useremail); return $sagepayments_values; }
/** * Processes the recurring payment * * @param array $data Payment data * @param object $user * @param string $payment_details Formatted payment details to store * @param array $errors * @return array * @access protected */ function _processSubscription($data, $errors) { $keyarray = $data; $keyarray['status'] = $this->_getMBStatus($data['status']); $payment_details = $this->_getFormattedPaymentDetails($keyarray); // check that payment amount is correct for order_id JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($data['orderpayment_id']); if (empty($orderpayment->order_id)) { $errors[] = JText::_('TIENDA MONEYBOOKERS MESSAGE INVALID ORDER'); $this->_sendErrorEmails($error, 'A18 -' . $data['orderpayment_id']); } $orderpayment->transaction_details = $payment_details; $orderpayment->transaction_id = $data['rec_payment_id']; $orderpayment->transaction_status = $this->_getMBStatus($data['status']); Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['amount'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('TIENDA MONEYBOOKERS MESSAGE PAYMENT AMOUNT INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; $this->_sendErrorEmails($error, 'A19 -' . $stored_amount . " != " . $respond_amount); } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if (count($errors)) { // if an error occurred $order->order_state_id = $this->_getParam('failed_order_state', '10'); // FAILED } else { $order->order_state_id = $this->_getParam('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = false; // make subscription $subscription = true; } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order_email = $model->getItem(); $helper->sendEmailNotices($order_email, 'new_order'); } if ($subscription) { // is the recipient correct? if (empty($data['pay_to_email']) || $data['pay_to_email'] != $this->_getParam('receiver_email')) { $errors[] = JText::_('TIENDA MONEYBOOKERS MESSAGE RECEIVER INVALID'); } // if no subscription exists for this subscr_id, // create new subscription for the user $subscription = JTable::getInstance('Subscriptions', 'TiendaTable'); $subscription->load(array('transaction_id' => $data['rec_payment_id'])); if (empty($subscription->subscription_id)) { $date = JFactory::getDate(); // create new subscription // if recurring trial, set it // for the order's recurring_trial_period_interval // using its recurring_trial_period_unit // otherwise, do the normal recurring_period_interval // and the recurring_period_unit $recurring_period_unit = $order->recurring_period_unit; $recurring_period_interval = $order->recurring_period_interval; if (!empty($order->recurring_trial)) { $recurring_period_unit = $order->recurring_trial_period_unit; $recurring_period_interval = $order->recurring_trial_period_interval; } error_reporting(E_ALL); //$items = $order->getItems(); // $item = $items[0]; $items = $order->getItems(); foreach ($items as $item) { $subscription->product_id = $item->product_id; $subscription->orderitem_id = $item->orderitem_id; } $subscription->user_id = $order->user_id; $subscription->order_id = $order->order_id; $subscription->transaction_id = $data['rec_payment_id']; $subscription->created_datetime = $date->toMySQL(); $subscription->subscription_enabled = '1'; switch ($recurring_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "D": default: $period_unit = "DAY"; break; } $database = JFactory::getDBO(); $query = " SELECT DATE_ADD('{$subscription->created_datetime}', INTERVAL {$recurring_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'TiendaTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'creation'; $subscriptionhistory->created_datetime = $date->toMySQL(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('TIENDA MONEYBOOKERS NEW SUBSCRIPTION CREATED'); $subscriptionhistory->save(); } else { // subscription exists, just update its expiration date // based on normal interval and period switch ($order->recurring_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "D": default: $period_unit = "DAY"; break; } $database = JFactory::getDBO(); $today = $date = JFactory::getDate(); $query = " SELECT DATE_ADD('{$today}', INTERVAL {$order->recurring_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'TiendaTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'payment'; $subscriptionhistory->created_datetime = $date->toMySQL(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION PAYMENT RECEIVED'); $subscriptionhistory->save(); } } // update order status Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; // save the order if (!$order->save()) { $errors[] = $order->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } $error = count($errors) ? implode("\n", $errors) : ''; if (!empty($error)) { $this->setError($error); return false; } return true; }
/** * Proceeds the simple payment * * @param string $resp * @param array $submitted_values * @return object Message object * @access protected */ function _evaluateSimplePaymentResponse($resp, $submitted_values) { $send_email = false; $object = new JObject(); $object->message = ''; $html = ''; $errors = array(); $payment_status = '0'; $order_status = '0'; $auth_x_delim_char = "|"; # not to be changed if (!($user = $this->_getUser($submitted_values))) { $errors[] = JText::_('COM_TIENDA_AUTHORIZEDOTNET_MESSAGE_UNKNOWN_USER'); $user = JFactory::getUser(); $user->set('id', 0); } // Evaluate a typical response from auth.net $exploded = explode($auth_x_delim_char, $resp); for ($i = 0; $i < count($exploded); $i++) { $value = $exploded[$i]; if ($value == "") { $value = "NO VALUE RETURNED"; } $key = $i + 1; switch ($key) { case 1: // Response Code $paymentResponse = $value; switch ($value) { case "1": // Approved $payment_status = '1'; $subs_status = '1'; break; case "2": // Declined $payment_status = '0'; $order_status = '0'; $errors[] = JText::_('COM_TIENDA_CARD_WAS_DECLINED'); break; case "3": default: // Error $payment_status = '0'; $order_status = '0'; $errors[] = JText::_('COM_TIENDA_TIENDA_AUTHORIZEDOTNET_PAYMENT_ERROR_PROCESSING_PAYMENT_MESSAGE') . $exploded[3]; break; } break; case 2: // Response Subcode $subcodeResponse = $value; break; case 3: // Response Reason Code $reasoncodeResponse = $value; break; case 4: // Response Reason Text $reasonResponse = $value; break; case 5: // Approval Code $approvalcodeResponse = $value; break; case 6: // AVS Result Code $avsResponse = $value; break; case 7: // Transaction ID $transactionidResponse = $value; break; case 8: // Invoice Number (x_invoice_num) $invoiceResponse = $value; break; case 9: // Description (x_description) $descriptionResponse = $value; break; case 10: // Amount (x_amount) $amountResponse = $value; break; case 11: // Method (x_method) $methodResponse = $value; break; case 12: // Transaction Type (x_type) $transactiontypeResponse = $value; break; case 13: // Customer ID (x_cust_id) $customeridResponse = $value; break; case 14: // Cardholder First Name (x_first_name) $fnameResponse = $value; break; case 15: // Cardholder Last Name (x_last_name) $lnameResponse = $value; break; case 16: // Company (x_company) $companyResponse = $value; break; case 17: // Billing Address (x_address) $addressResponse = $value; break; case 18: // City (x_city) $cityResponse = $value; break; case 19: // State (x_state) $stateResponse = $value; break; case 20: // ZIP (x_zip) $zipResponse = $value; break; case 21: // Country (x_country) $countryResponse = $value; break; case 22: // Phone (x_phone) $phoneResponse = $value; break; case 23: // Fax (x_fax) $faxResponse = $value; break; case 24: // E-Mail Address (x_email) $emailResponse = $value; break; case 25: // Ship to First Name (x_ship_to_first_name) $shipfnameResponse = $value; break; case 26: // Ship to Last Name (x_ship_to_last_name) $shiplnameResponse = $value; break; case 27: // Ship to Company (x_ship_to_company) $shipcompanyResponse = $value; break; case 28: // Ship to Address (x_ship_to_address) $shipaddressResponse = $value; break; case 29: // Ship to City (x_ship_to_city) $shipcityResponse = $value; break; case 30: // Ship to State (x_ship_to_state) $shipstateResponse = $value; break; case 31: // Ship to ZIP (x_ship_to_zip) $shipzipResponse = $value; break; case 32: // Ship to Country (x_ship_to_country) $shipcountryResponse = $value; break; case 33: // Tax Amount (x_tax) $taxResponse = $value; break; case 34: // Duty Amount (x_duty) $dutyResponse = $value; break; case 35: // Freight Amount (x_freight) $freightResponse = $value; break; case 36: // Tax Exempt Flag (x_tax_exempt) $taxexemptResponse = $value; break; case 37: // PO Number (x_po_num) $ponumResponse = $value; break; case 38: // MD5 Hash $md5hashResponse = $value; break; case 39: // Card Code Response (CVV) $cvvResponse = $value; switch ($value) { case "M": // Match $cvv_status = '1'; break; case "N": // NO Match $cvv_status = '0'; $payment_status = '0'; $order_status = '0'; $errors[] = JText::_('COM_TIENDA_CVV_DID_NOT_MATCH'); break; case "P": // Not Processed $cvv_status = '0'; break; case "S": // Should have been present $cvv_status = '0'; $payment_status = '0'; $order_status = '0'; $errors[] = JText::_('COM_TIENDA_CVV_SHOULD_HAVE_BEEN_PRESENT'); break; case "U": // Issuer unable to process request $cvv_status = '0'; $payment_status = '0'; $order_status = '0'; $errors[] = JText::_('COM_TIENDA_CVV_ISSUER_UNABLE_TO_PROCESS_REQUEST'); break; default: // No Value returned $cvv_status = null; break; } break; case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 55: case 56: case 57: case 58: case 59: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 67: case 68: // Reserved by auth.net break; default: // if here, then $key is not one of the reserved 68 fields // we're now processing custom fields sent through auth.net and back to us // such as itemTypeid, paymentType, and cardtype switch ($key) { case "tienda_orderpayment_id": $orderpayment_id = $value; break; default: // orphan key break; } break; } } // orderpayment_id is always in this part of the response $orderpayment_id = $exploded[69]; // ======================= // verify & create payment // ======================= // check that payment amount is correct for order_id JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($orderpayment_id); if (empty($orderpayment->order_id)) { // TODO fail } $orderpayment->transaction_details = $resp; $orderpayment->transaction_id = $transactionidResponse; $orderpayment->transaction_status = $paymentResponse; Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($amountResponse, array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('COM_TIENDA_TIENDA_AUTHORIZEDOTNET_MESSAGE_PAYMENT_AMOUNT_INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if (count($errors)) { // if an error occurred $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED } else { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } if (empty($errors)) { $return = JText::_('COM_TIENDA_TIENDA_AUTHORIZEDOTNET_MESSAGE_PAYMENT_SUCCESS'); return $return; } if (!empty($errors)) { $string = implode("\n", $errors); $return = "<div class='note_pink'>" . $string . "</div>"; return $return; } // =================== // end custom code // =================== }
/** * Generates the xml for the update request * @param unknown_type $product * @param string $etag - etag of the product */ protected function getUpdateXML($product, $etag) { // perform the insertion Tienda::load('TiendaArrayToXML', 'library.xml'); // Populate the xml request $xml = array(); $xml['app:control']['sc:required_destination']['attributes']['dest'] = 'ProductSearch'; // Title, id and description $xml['title'] = $product->product_name; $xml['content']['attributes']['type'] = 'text/html'; $xml['content'] = $product->product_description; $xml['sc:id'] = $product->product_id; // Link to the product Tienda::load('TiendaHelperRoute', 'helpers.route'); $xml['link']['attributes']['rel'] = 'alternate'; $xml['link']['attributes']['type'] = 'text/html'; $baseurl = str_replace("/administrator/", "/", JURI::base()); $xml['link']['attributes']['href'] = $baseurl . TiendaHelperRoute::product($product->product_id); //$xml['link']['attributes']['href'] = 'http://www.weble.it/products/'.$product->product_id; // Condition $xml['scp:condition'] = 'new'; // Price $currency_id = Tienda::getInstance()->get('default_currencyid', '1'); Tienda::load('TiendaTableCurrencies', 'tables.currencies'); $currency = JTable::getInstance('Currencies', 'TiendaTable'); $currency->load((int) $currency_id); $xml['scp:price']['attributes']['unit'] = trim(strtoupper($currency->currency_code)); $xml['scp:price']['@value'] = TiendaHelperBase::number(TiendaHelperProduct::getPrice($product->product_id)->product_price, array('num_decimals', '0')); // Manufacturer Tienda::load('TiendaTableManufacturers', 'tables.manufacturers'); $manufacturer = JTable::getInstance('Manufacturers', 'TiendaTable'); if ($manufacturer->load($product->manufacturer_id)) { $xml['scp:brand'] = $manufacturer->manufacturer_name; } $xml['entry']['attributes']['gd:etag'] = $etag; // Create the request $null = null; $helper = new TiendaArrayToXML(); $ns = array(array('name' => 'app', 'url' => "http://www.w3.org/2007/app"), array('name' => 'gd', 'url' => "http://schemas.google.com/g/2005"), array('name' => 'sc', 'url' => "http://schemas.google.com/structuredcontent/2009"), array('name' => 'scp', 'url' => "http://schemas.google.com/structuredcontent/2009/products")); $xml = $helper->toXml($xml, 'entry', $null, $ns, "http://www.w3.org/2005/Atom"); return $xml; }
/** * Processes the sale payment * * @param array $data IPN data * @return boolean Did the IPN Validate? * @access protected */ public function _processSale($data) { /* * validate the payment data */ $errors = array(); $payment_id = JFactory::getSession()->get('paypal_pro.orderpayment.id', 0); // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($payment_id); ob_start(); print_r($data); $orderpayment->transaction_details = ob_get_contents(); ob_end_clean(); $orderpayment->transaction_id = $data['PNREF']; $orderpayment->transaction_status = $data['RESPMSG']; // check the stored amount against the payment amount Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['AMT'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('PLG_TIENDA_PAYMENT_PAYPALPRO_MESSAGE_AMOUNT_INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // supported error codes $supported_errors = array(0, 1, 2, 12, 30); // check the payment status if (empty($data['RESULT']) || (int) $data['RESULT'] > 0) { // dad, we've got a problem $data['RESULT'] = (int) $data['RESULT']; if (in_array($data['RESULT'], $supported_errors) === false) { // unknown error => just play innocent and blame it on Paypal :) $errors[] = JText::sprintf('PLG_TIENDA_PAYMENT_PAYPALPRO_MESSAGE_STATUS_INVALID', @$data['RESULT']); } else { // OK, so this is a common error, so display a cool message switch ($data['RESULT']) { case 1: $errors[] = JText::_('PLG_TIENDA_PAYMENT_PAYPALPRO_MESSAGE_USER_AUTH_FAILED'); break; case 2: $errors[] = JText::_('PLG_TIENDA_PAYMENT_PAYPALPRO_MESSAGE_TENDER_INVALID'); break; case 12: $errors[] = JText::_('PLG_TIENDA_PAYMENY_PAYPALPRO_MESSAGE_OPERATION_DECLINED'); break; case 30: $errors[] = JText::_('PLG_TIENDA_PAYMENT_PAYPALPRO_MESSAGE_DUPLICATE_TRANSACTION'); break; } } } // set the order's new status and update quantities if necessary Tienda::load('TiendaHelperOrder', 'helpers.order'); Tienda::load('TiendaHelperCarts', 'helpers.carts'); $tbl_order = JTable::getInstance('Orders', 'TiendaTable'); $tbl_order->load($orderpayment->order_id); if (count($errors)) { // if an error occurred $tbl_order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED } else { // we received the payment $tbl_order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $this->setOrderPaymentReceived($orderpayment->order_id); // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } // save the order if (!$tbl_order->save()) { $errors[] = $tbl_order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } return count($errors) ? implode("\n", $errors) : ''; }
/** * Processes the sale payment * * @param array $data IPN data * @return boolean Did the IPN Validate? * @access protected */ function _processSale($data, $ipnValidationFailed = '') { $send_email = false; /* * validate the payment data */ $errors = array(); if (!empty($ipnValidationFailed)) { $errors[] = $ipnValidationFailed; } // is the recipient correct? if (empty($data['receiver_email']) || $data['receiver_email'] != $this->_getParam('merchant_email')) { $errors[] = JText::_('PAYPAL MESSAGE RECEIVER INVALID'); } // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($data['custom']); $orderpayment->transaction_details = $data['transaction_details']; $orderpayment->transaction_id = $data['txn_id']; $orderpayment->transaction_status = $data['payment_status']; // check the stored amount against the payment amount Tienda::load('TiendaHelperBase', 'helpers._base'); $stored_amount = TiendaHelperBase::number($orderpayment->get('orderpayment_amount'), array('thousands' => '')); $respond_amount = TiendaHelperBase::number($data['mc_gross'], array('thousands' => '')); if ($stored_amount != $respond_amount) { $errors[] = JText::_('PAGSEGURO MESSAGE PAYMENT AMOUNT INVALID'); $errors[] = $stored_amount . " != " . $respond_amount; } // check the payment status if (empty($data['payment_status']) || $data['payment_status'] != 'Completed' && $data['payment_status'] != 'Pending') { $errors[] = JText::sprintf('PAYPAL MESSAGE STATUS INVALID', @$data['payment_status']); } // set the order's new status and update quantities if necessary JLoader::import('com_tienda.helpers.order', JPATH_ADMINISTRATOR . '/components'); JLoader::import('com_tienda.helpers.carts', JPATH_ADMINISTRATOR . '/components'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($orderpayment->order_id); if (count($errors)) { // if an error occurred $order->order_state_id = $this->params->get('failed_order_state', '10'); // FAILED } elseif (@$data['payment_status'] == 'Pending') { // if the transaction has the "pending" status, $order->order_state_id = Tienda::getInstance('pending_order_state', '1'); // PENDING // Update quantities for echeck payments TiendaHelperOrder::updateProductQuantities($orderpayment->order_id, '-'); // remove items from cart TiendaHelperCarts::removeOrderItems($orderpayment->order_id); } else { $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; } // save the order if (!$order->save()) { $errors[] = $order->getError(); } // save the orderpayment if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Tienda::load("TiendaHelperBase", 'helpers._base'); $helper = TiendaHelperBase::getInstance('Email'); $model = Tienda::getClass("TiendaModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } return count($errors) ? implode("\n", $errors) : ''; }
/** * Processes the payment * * This method process only real time (simple and subscription create) payments * The scheduled recurring payments are processed by the corresponding method * * @return string * @access protected */ function _process() { /* * perform initial checks */ if (!JRequest::checkToken()) { return $this->_renderHtml(JText::_('TIENDA LINKPOINT FIRSTDATA MESSAGE INVALID TOKEN')); } //validate plugin parameters have been set if (empty($this->store_number)) { return JText::_('TIENDA LINKPOINT FIRSTDATA MESSAGE MISSING STORE NUMBER'); } if (empty($this->key_file)) { return JText::_('TIENDA LINKPOINT FIRSTDATA MESSAGE MISSING CERTIFICATE FILE'); } //get the information to send to LinkPoint / FirstData $data = JRequest::get('post'); // get order information $order_id = $data['order_id']; $order_payment_id = $data['orderpayment_id']; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($order_id); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'TiendaTable'); $orderpayment->load($order_payment_id); $orderinfo = JTable::getInstance('OrderInfo', 'TiendaTable'); $orderinfo->load(array('order_id' => $order_id)); if (empty($order->order_id) || empty($orderpayment) || empty($orderinfo)) { return JText::_('TIENDA LINKPOINT FIRSTDATA MESSAGE INVALID ORDER'); } //setting up the payment gateway information $host = $this->_getPaymentGatewayHost(); $port = "1129"; //card information $card_num = str_replace(" ", "", str_replace("-", "", $data['cardnum'])); $card_expmonth = $data["cardexpmonth"]; $card_expyear = $data["cardexpyear"]; $cvv = $data['cardcvv']; //set the order total to be charged to the credit card Tienda::load('TiendaHelperBase', 'helpers._base'); $charge_total = TiendaHelperBase::number($orderpayment->orderpayment_amount, array('thousands' => '')); $user_email = $this->_getUserEmail($data); $order_values = array("host" => $host, "port" => $port, "keyfile" => realpath($this->key_file), "configfile" => $this->store_number, "cvmindicator" => "provided", "cardnumber" => $card_num, "cardexpmonth" => $card_expmonth, "cardexpyear" => $card_expyear, "cvmvalue" => $cvv, "name" => $orderinfo->billing_first_name . ' ' . $orderinfo->billing_last_name, "company" => $orderinfo->billing_company, "address1" => $orderinfo->billing_address_1, "address2" => $orderinfo->billing_address_2, "city" => $orderinfo->billing_city, "state" => $orderinfo->billing_zone_name, "country" => $orderinfo->billing_country_name, "phone" => $orderinfo->billing_phone_1, "fax" => $orderinfo->billing_fax, "email" => $user_email, "zip" => $orderinfo->billing_postal_code, "chargetotal" => $charge_total, "oid" => $order->order_id, "ordertype" => "SALE"); //process the payment through the LinkPoint / FirstData payment gateway $result = $this->curl_process($order_values, $this->params->get('sandbox')); # use curl methods return $this->_evaluatePaymentResponse($result, $order_values, $order_payment_id); }