Ejemplo n.º 1
0
 /**
  * Appends Sweet Tooth information 
  * @note: As of Sweet Tooth 1.5.0.3, this rewrite has been replaced with the TBT_Rewards_Model_Paypal_Observer observer for 
  *        all versions of Magento greater than or equal to 1.4.1.  Previous versions do not dispatch the paypal_prepare_line_items 
  *        event
  * @deprecated for Magento 1.4.1+ as of  Sweet Tooth 1.5.0.3
  *
  * @return array paypal checkout fields
  */
 public function getStandardCheckoutFormFields()
 {
     $scf = parent::getStandardCheckoutFormFields();
     // Only run for Magento 1.4.0.x and lower; newer versions use thew paypal_prepare_line_items event obsrever in the TBT_Rewards_Model_Paypal_Observer class
     if (Mage::helper('rewards/version')->isBaseMageVersionAtLeast('1.4.1')) {
         return $scf;
     }
     $items = $this->_getQuote()->getAllItems();
     //@nelkaake -a 16/11/10: There are two major things we need to do here:
     // 1. If the balance is 0, make sure there is at least 1 penny in the subtotal so PayPal lets us checkout.
     // 2. Gather all of our catalog points redemption discounts and add them to the final cart discount total.
     Mage::getSingleton('rewards/redeem')->refactorRedemptions($items);
     $disc_attr = 'discount_amount';
     if (isset($scf[$disc_attr])) {
         $discountAmount = (double) $scf[$disc_attr];
         if ($discountAmount >= $this->_getQuote()->getSubtotal()) {
             //@nelkaake Sunday April 25, 2010 : We're discounting the whole amount, so we need to add a premium in order for PayPal to see the output.
             $scf[$disc_attr] = (double) $scf[$disc_attr] - $this->getPaypalZeroCheckoutFee();
             $scf[$disc_attr] = (string) $scf[$disc_attr];
         }
     } else {
         $scf[$disc_attr] = 0;
     }
     $scf[$disc_attr] = (double) $scf[$disc_attr];
     //@nelkaake -a 16/11/10: Figure out the accumulated difference in price so we can add to the discount amount
     //TODO @nelkaake: Can we calculate the discount amount another way, perhaps using the new getCatalogDiscount method in the Redeem singleton?
     $acc_diff = $this->getDiscountDisplacement();
     $scf[$disc_attr] += $acc_diff;
     //@nelkaake Added on Monday October 4, 2010: Uncomment this if you want to see what's being sent to PayPal standard checkout
     //Mage::helper('rewards/debug')->dd(array($scf, Mage::helper('rewards/debug')->getSimpleBacktrace() ));
     return $scf;
 }
Ejemplo n.º 2
0
 /**
  * Appends Sweet Tooth information 
  * @note: As of Sweet Tooth 1.5.0.3, this rewrite has been replaced with the TBT_Rewards_Model_Paypal_Observer observer for 
  * all versions of Magento greater than or equal to 1.4.2.  Previous versions do not dispatch the paypal_prepare_line_items 
  * event
  * There are two major things we need to do here: 
  * 1. If the balance is 0, make sure there is at least 1 penny in the subtotal so PayPal lets us checkout.  
  * 2. Gather all of our catalog points redemption discounts and add them to the final cart discount total.
  * @deprecated for Magento 1.4.2+ as of  Sweet Tooth 1.5.0.3
  *
  * @return array paypal checkout fields
  */
 public function getStandardCheckoutFormFields()
 {
     $scf = parent::getStandardCheckoutFormFields();
     // Only run for Magento 1.4.0.x and lower; newer versions use thew paypal_prepare_line_items event obsrever in the TBT_Rewards_Model_Paypal_Observer class
     if (Mage::helper('rewards/version')->isBaseMageVersionAtLeast('1.4.2')) {
         return $scf;
     }
     $items = $this->_getQuote()->getAllItems();
     //@nelkaake -a 16/11/10:
     Mage::getSingleton('rewards/redeem')->refactorRedemptions($items);
     // In Magento 1.4.1 - 1.4.1.1 for some reason discount_amount_cart is used instead of discount_amount
     if (Mage::helper('rewards/version')->isBaseMageVersionAtLeast('1.4.1')) {
         $disc_attr = 'discount_amount_cart';
     } else {
         $disc_attr = 'discount_amount';
     }
     // Init discount amount field
     if (!isset($scf[$disc_attr])) {
         $scf[$disc_attr] = 0;
     }
     $scf[$disc_attr] = (double) $scf[$disc_attr];
     //@nelkaake -a 16/11/10: Figure out the accumulated difference in price so we can add to the discount amount
     $acc_diff = $this->getDiscountDisplacement();
     $scf[$disc_attr] += $acc_diff;
     //@nelkaake Added on Monday October 4, 2010: Uncomment this if you want to see what's being sent to PayPal standard checkout
     //Mage::helper('rewards/debug')->dd(array($scf, Mage::helper('rewards/debug')->getSimpleBacktrace() ));
     return $scf;
 }
Ejemplo n.º 3
0
 public function getStandardCheckoutFormFields()
 {
     if (!Mage::helper('imagecc')->isActive()) {
         return parent::getStandardCheckoutFormFields();
     }
     $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
     $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
     $api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig());
     $api->setOrderId($orderIncrementId)->setCurrencyCode($order->getOrderCurrencyCode())->setOrder($order)->setNotifyUrl(Mage::getUrl('paypal/ipn/'))->setReturnUrl(Mage::getUrl('paypal/standard/success'))->setCancelUrl(Mage::getUrl('paypal/standard/cancel'));
     // export address
     $isOrderVirtual = $order->getIsVirtual();
     $address = $isOrderVirtual ? $order->getBillingAddress() : $order->getShippingAddress();
     if ($isOrderVirtual) {
         $api->setNoShipping(true);
     } elseif ($address->validate()) {
         $api->setAddress($address);
     }
     // add cart totals and line items
     $api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))->setIsLineItemsEnabled($this->_config->lineItemsEnabled);
     $api->setCartSummary($this->_getAggregatedCartSummary());
     $result = $api->getStandardCheckoutRequest();
     //echo "<pre>"; print_r($result); exit;
     return $result;
 }
Ejemplo n.º 4
0
 public function getStandardCheckoutFormFields()
 {
     if (Mage::helper('sarp')->extensionEnabled('AW_Points') && Mage::helper('points')->magentoLess14()) {
         if ($this->getQuote()->getIsVirtual()) {
             $a = $this->getQuote()->getBillingAddress();
             $b = $this->getQuote()->getShippingAddress();
         } else {
             $a = $this->getQuote()->getShippingAddress();
             $b = $this->getQuote()->getBillingAddress();
         }
         //getQuoteCurrencyCode
         $currency_code = $this->getQuote()->getBaseCurrencyCode();
         /*
         //we validate currency before sending paypal so following code is obsolete
         
         if (!in_array($currency_code,$this->_allowCurrencyCode)) {
             //if currency code is not allowed currency code, use USD as default
             $storeCurrency = Mage::getSingleton('directory/currency')
                 ->load($this->getQuote()->getStoreCurrencyCode());
             $amount = $storeCurrency->convert($amount, 'USD');
             $currency_code='USD';
         }
         */
         $sArr = array('charset' => self::DATA_CHARSET, 'business' => Mage::getStoreConfig('paypal/wps/business_account'), 'return' => Mage::getUrl('paypal/standard/success', array('_secure' => true)), 'cancel_return' => Mage::getUrl('paypal/standard/cancel', array('_secure' => false)), 'notify_url' => Mage::getUrl('paypal/standard/ipn'), 'invoice' => $this->getCheckout()->getLastRealOrderId(), 'currency_code' => $currency_code, 'address_override' => 1, 'first_name' => $a->getFirstname(), 'last_name' => $a->getLastname(), 'address1' => $a->getStreet(1), 'address2' => $a->getStreet(2), 'city' => $a->getCity(), 'state' => $a->getRegionCode(), 'country' => $a->getCountry(), 'zip' => $a->getPostcode(), 'bn' => 'Varien_Cart_WPS_US');
         $logoUrl = Mage::getStoreConfig('paypal/wps/logo_url');
         if ($logoUrl) {
             $sArr = array_merge($sArr, array('cpp_header_image' => $logoUrl));
         }
         if ($this->getConfigData('payment_action') == self::PAYMENT_TYPE_AUTH) {
             $sArr = array_merge($sArr, array('paymentaction' => 'authorization'));
         }
         $transaciton_type = $this->getConfigData('transaction_type');
         /*
         O=aggregate cart amount to paypal
         I=individual items to paypal
         */
         if ($transaciton_type == 'O') {
             $businessName = Mage::getStoreConfig('paypal/wps/business_name');
             $storeName = Mage::getStoreConfig('store/system/name');
             $amount = $a->getBaseSubtotal() + $b->getBaseSubtotal() - ($a->getBaseDiscountAmount() + $b->getBaseDiscountAmount());
             $session = Mage::getSingleton('checkout/session');
             if ($session->getData('use_points')) {
                 if ($a->getBaseGrandTotal() || $b->getBaseGrandTotal()) {
                     $pointsAmountUsed = $session->getData('points_amount');
                     $rate = Mage::getModel('points/rate')->loadByDirection(AW_Points_Model_Rate::POINTS_TO_CURRENCY);
                     $moneyBaseCurrencyForPoints = $rate->exchange($pointsAmountUsed);
                     $amount -= $moneyBaseCurrencyForPoints;
                     if ($amount <= 0) {
                         $amount = 0;
                     }
                 }
             }
             $sArr = array_merge($sArr, array('cmd' => '_ext-enter', 'redirect_cmd' => '_xclick', 'item_name' => $businessName ? $businessName : $storeName, 'amount' => sprintf('%.2f', $amount)));
             $_shippingTax = $this->getQuote()->getShippingAddress()->getBaseTaxAmount();
             $_billingTax = $this->getQuote()->getBillingAddress()->getBaseTaxAmount();
             $tax = sprintf('%.2f', $_shippingTax + $_billingTax);
             if ($tax > 0) {
                 $sArr = array_merge($sArr, array('tax' => $tax));
             }
         } else {
             $sArr = array_merge($sArr, array('cmd' => '_cart', 'upload' => '1'));
             //TODO: Individual items discount
             $session = Mage::getSingleton('checkout/session');
             if ($session->getData('use_points')) {
                 if ($a->getBaseGrandTotal() || $b->getBaseGrandTotal()) {
                     $pointsAmountUsed = $session->getData('points_amount');
                     $rate = Mage::getModel('points/rate')->loadByDirection(AW_Points_Model_Rate::POINTS_TO_CURRENCY);
                     $moneyBaseCurrencyForPoints = $rate->exchange($pointsAmountUsed);
                     $sArr = array_merge($sArr, array('discount_amount_cart' => sprintf('%.2f', $moneyBaseCurrencyForPoints)));
                 }
             }
             $items = $this->getQuote()->getAllItems();
             if ($items) {
                 $i = 1;
                 $summaryTax = 0;
                 foreach ($items as $item) {
                     if ($item->getParentItem()) {
                         continue;
                     }
                     //echo "<pre>"; print_r($item->getData()); echo"</pre>";
                     $sArr = array_merge($sArr, array('item_name_' . $i => $item->getName(), 'item_number_' . $i => $item->getSku(), 'quantity_' . $i => $item->getQty(), 'amount_' . $i => sprintf('%.2f', $item->getBaseCalculationPrice() - $item->getBaseDiscountAmount())));
                     if ($item->getBaseTaxAmount() > 0) {
                         $summaryTax += $item->getBaseTaxAmount() / $item->getQty();
                     }
                     $i++;
                 }
             }
         }
         $totalArr = $a->getTotals();
         $shipping = sprintf('%.2f', $this->getQuote()->getShippingAddress()->getBaseShippingAmount());
         if ($shipping > 0 && !$this->getQuote()->getIsVirtual()) {
             if ($transaciton_type == 'O') {
                 $sArr = array_merge($sArr, array('shipping' => $shipping));
             } else {
                 $shippingTax = $this->getQuote()->getShippingAddress()->getBaseShippingTaxAmount();
                 $sArr = array_merge($sArr, array('item_name_' . $i => $totalArr['shipping']->getTitle(), 'quantity_' . $i => 1, 'amount_' . $i => sprintf('%.2f', $shipping)));
                 $summaryTax += $shippingTax;
                 $i++;
             }
         }
         if ($transaciton_type != 'O') {
             $sArr = array_merge($sArr, array('tax_cart' => sprintf('%.2f', $summaryTax)));
         }
         $sReq = '';
         $sReqDebug = '';
         $rArr = array();
         foreach ($sArr as $k => $v) {
             /*
             replacing & char with and. otherwise it will break the post
             */
             $value = str_replace("&", "and", $v);
             $rArr[$k] = $value;
             $sReq .= '&' . $k . '=' . $value;
             $sReqDebug .= '&' . $k . '=';
             if (in_array($k, $this->_debugReplacePrivateDataKeys)) {
                 $sReqDebug .= '***';
             } else {
                 $sReqDebug .= $value;
             }
         }
         if ($this->getDebug() && $sReq) {
             $sReq = substr($sReq, 1);
             $debug = Mage::getModel('paypal/api_debug')->setApiEndpoint($this->getPaypalUrl())->setRequestBody($sReq)->save();
         }
         return $rArr;
     }
     return parent::getStandardCheckoutFormFields();
 }