Example #1
0
 public function postProcess(Axis_Sales_Model_Order_Row $order)
 {
     $view = Axis::app()->getBootstrap()->getResource('layout')->getView();
     $delivery = $order->getDelivery();
     $formFields = array('business' => $this->_config->email, 'return' => $view->href('paymentpaypal/standard/success'), 'cancel_return' => $view->href('paymentpaypal/standard/cancel'), 'notify_url' => $view->href('paymentpaypal/standard/ipn'), 'invoice' => $order->id, 'address_override' => 1, 'first_name' => $delivery->getFirstname(), 'last_name' => $delivery->getLastname(), 'address1' => $delivery->getStreetAddress(), 'address2' => $delivery->getSuburb(), 'city' => $delivery->getCity(), 'state' => $delivery->getZone()->getCode(), 'country' => $delivery->getCountry()->getIsoCode2(), 'zip' => $delivery->getPostcode());
     if ($this->_config->logo) {
         $formFields['cpp_header_image'] = $this->_config->logo;
     }
     if ($this->_config->paymentAction) {
         $formFields['paymentaction'] = strtolower($this->_config->paymentAction);
     }
     $transaciton_type = $this->_config->transactionType;
     /*
     O=aggregate cart amount to paypal
     I=individual items to paypal
     */
     if ($transaciton_type == 'Aggregate Cart') {
         $businessName = $this->_config->name;
         $formFields = array_merge($formFields, array('cmd' => '_ext-enter', 'redirect_cmd' => '_xclick', 'item_name' => $businessName ? $businessName : Axis::config()->core->store->name, 'currency_code' => $this->getBaseCurrencyCode(), 'amount' => sprintf('%.2f', $this->getAmountInBaseCurrency($order->getSubTotal(), $order->currency))));
         $tax = $order->getTax();
         $shippingTax = $order->getShippingTax();
         $tax = sprintf('%.2f', $tax + $shippingTax);
         if ($tax > 0) {
             $formFields['tax'] = $tax;
         }
     } else {
         $formFields = array_merge($formFields, array('cmd' => '_cart', 'upload' => '1'));
         $products = $order->getProducts();
         if ($products) {
             $i = 1;
             foreach ($products as $product) {
                 $formFields = array_merge($formFields, array('item_name_' . $i => $product['name'], 'item_number_' . $i => $product['sku'], 'quantity_' . $i => intval($product['quantity']), 'amount_' . $i => sprintf('%.2f', $product['final_price'])));
                 if ($product['tax'] > 0) {
                     $formFields = array_merge($formFields, array('tax_' . $i => sprintf('%.2f', $product['tax'])));
                 }
                 $i++;
             }
         }
     }
     $totals = $order->getTotals();
     $shipping = sprintf('%.2f', $totals['shipping']['value']);
     if ($shipping > 0) {
         if ($transaciton_type == 'Aggregate Cart') {
             $formFields['shipping'] = $shipping;
         } else {
             $shippingTax = $totals['shipping_tax']['value'];
             $formFields = array_merge($formFields, array('item_name_' . $i => $order->shipping_method, 'quantity_' . $i => 1, 'amount_' . $i => $shipping, 'tax_' . $i => sprintf('%.2f', $shippingTax)));
             $i++;
         }
     }
     $sReq = '';
     $rArr = array();
     foreach ($formFields as $k => $v) {
         /*
         replacing & char with and. otherwise it will break the post
         */
         $value = str_replace('&', 'and', $v);
         $rArr[$k] = $value;
         $sReq .= '&' . $k . '=' . $value;
     }
     $this->getStorage()->formFields = $rArr;
     return array('redirect' => $view->href('paymentpaypal/standard/submit'));
 }
Example #2
0
 /**
  * Prepare request to gateway
  *
  * @link http://www.authorize.net/support/AIM_guide.pdf
  * @param Axis_Sales_Model_Order_Row $order
  * @return Axis_Object
  */
 protected function _buildRequest(Axis_Sales_Model_Order_Row $order)
 {
     $request = $this->getRequest();
     if (!$request->getAnetTransMethod()) {
         $request->setAnetTransMethod('CC');
     }
     $request->setXVersion(3.1)->setXDelimData('True')->setXDelimChar(',')->setXRelayResponse('False');
     // @what is getIncrementId
     if ($order->id) {
         $request->setXInvoiceNum($order->id);
         //use orderId instead invoice number
     }
     $request->setXTestRequest($this->_config->test ? 'TRUE' : 'FALSE');
     $request->setXLogin($this->_config->xLogin)->setXTranKey($this->_config->xTransactionKey)->setXType($request->getAnetTransType())->setXMethod($request->getAnetTransMethod());
     if ($order->getAmount()) {
         $request->setXAmount(Axis::single('locale/currency')->convert($order->getAmount(), $order->currency, Axis::config('locale/main/baseCurrency')));
         $request->setXCurrencyCode(Axis::config('locale/main/baseCurrency'));
     }
     switch ($request->getAnetTransType()) {
         case 'CREDIT':
         case 'VOID':
         case 'PRIOR_AUTH_CAPTURE':
             $request->setXTransId($request->getCcTransId());
             break;
             //            case 'CAPTURE_ONLY':
             //                $request->setXAuthCode($request->getCcAuthCode());
             //                break;
     }
     $billing = $order->getBilling();
     $request->setXFirstname($billing->getFirstname())->setXLastname($billing->getLastname())->setXCompany($billing->getCompany())->setXAddress($billing->getStreetAddress())->setXCity($billing->getCity())->setXState($billing->getZone()->getName())->setXZip($billing->getPostcode())->setXCountry($billing->getCountry()->getName())->setXPhone($billing->getPhone())->setXFax($billing->getFax())->setXCustId($billing->getCustomerId())->setXCustomerIp($order->getIp())->setXCustomerTaxId($billing->getTaxId())->setXEmail($order->getCustomerEmail())->setXEmailCustomer($this->_config->emailCustomer ? 'TRUE' : 'FALSE')->setXMerchantEmail($this->_config->emailMerchant);
     $delivery = $order->getDelivery();
     $request->setXShipToFirstname($delivery->getFirstname())->setXShipToLastname($delivery->getLastname())->setXShipToCompany($delivery->getCompany())->setXShipToAddress($delivery->getStreetAddress())->setXShipToCity($delivery->getCity())->setXShipToState($delivery->getZone()->getName())->setXShipToZip($delivery->getPostcode())->setXShipToCountry($delivery->getCountry()->getName());
     $request->setXPoNum($order->id)->setXTax($order->getTaxAmount())->setXFreight($order->getShipping());
     switch ($request->getAnetTransMethod()) {
         case 'CC':
             $cc = $this->getCreditCard();
             if ($cc->getCcNumber()) {
                 $request->setXCardNum($cc->getCcNumber())->setXExpDate(sprintf('%02d-%02d', $cc->getCcExpiresMonth(), $cc->getCcExpiresYear()))->setXCardCode($cc->getCcCvv());
             }
             break;
             //            case 'ECHECK':
             //                $echeck = $this->getEcheck();
             //                $request->setXBankAbaCode($echeck->getEcheckRoutingNumber())
             //                    ->setXBankName($echeck->getEcheckBankName())
             //                    ->setXBankAcctNum($echeck->getEcheckAccountNumber())
             //                    ->setXBankAcctType($echeck->getEcheckAccountType())
             //                    ->setXBankAcctName($echeck->getEcheckAccountName())
             //                    ->setXEcheckType($echeck->getEcheckType());
             //                break;
     }
     $this->_request = $request;
     return $request;
 }
Example #3
0
 /**
  * Register new customer, fill the customer_id in order
  * and save the customer addresses
  *
  * @param Axis_Sales_Model_Order_Row $order
  * @return void
  */
 public function saveCustomerAfterPlaceOrder(Axis_Sales_Model_Order_Row $order)
 {
     $checkout = Axis::single('checkout/checkout');
     $billing = $checkout->getBilling()->toFlatArray();
     $delivery = $checkout->getDelivery()->toFlatArray();
     $newCustomer = false;
     if (!empty($billing['register']) && !Axis::getCustomerId()) {
         $modelCustomer = Axis::model('account/customer');
         $userData = $billing;
         $userData['site_id'] = Axis::getSiteId();
         $userData['is_active'] = 1;
         unset($userData['id']);
         list($customer, $password) = $modelCustomer->create($userData);
         $customer->setDetails($userData);
         $modelCustomer->login($userData['email'], $password);
         $newCustomer = true;
         $order->customer_id = $customer->id;
         $order->save();
     }
     // save address if needed
     if ($customer = Axis::getCustomer()) {
         if (empty($billing['id'])) {
             $customer->setAddress($billing);
         }
         if (empty($delivery['id']) && empty($billing['use_for_delivery'])) {
             $customer->setAddress($delivery);
         }
     }
     if ($newCustomer) {
         Axis::dispatch('account_customer_register_success', array('customer' => $customer, 'password' => $password));
     }
 }
Example #4
0
 /**
  * "processing" => "ship"
  *
  * @param Axis_Sales_Model_Order_Row $order
  * @return bool
  */
 public function ship(Axis_Sales_Model_Order_Row $order)
 {
     $modelStock = Axis::single('catalog/product_stock');
     $products = $order->getProducts();
     // check the availability of all products
     foreach ($products as $product) {
         if (!$product['backorder']) {
             continue;
         }
         if (!$modelStock->find($product['product_id'])->current()->canShipping($product['quantity'], $product['variation_id'])) {
             Axis::message()->addError(Axis::translate('sales')->__("Product can't be shipped. Name: %s, Sku: %s", $product['name'], $product['sku']));
             return false;
         }
     }
     // update stock data for backordered products
     // normal products update the stock in pending status
     foreach ($products as $product) {
         if (!$product['backorder']) {
             continue;
         }
         $stockRow = $modelStock->find($product['product_id'])->current();
         $quantity = $stockRow->getQuantity($product['variation_id']);
         $stockRow->setQuantity($quantity - $product['quantity'], $product['variation_id']);
     }
     return true;
 }