getCheckout()->getLastRealOrderId(); $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); /* @var $api Mage_Paypal_Model_Api_Standard */ $api = Mage::getModel('paypal/api_standard')->setConfigObject($this->getConfig()); $api->setOrderId($orderIncrementId) ->setCurrencyCode($order->getStore()->getCurrentCurrencyCode()) //->setPaymentAction() ->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()); $api->setLocale($api->getLocaleCode()); $result = $api->getStandardCheckoutRequest(); if ($order->getStore()->getBaseCurrencyCode() !== $order->getStore()->getCurrentCurrencyCode()) { $result['amount'] = sprintf('%.2f', $order->getStore()->convertPrice($result['amount'])); $result['tax'] = sprintf('%.2f', $order->getStore()->convertPrice($result['tax'])); $result['tax_cart'] = sprintf('%.2f', $order->getStore()->convertPrice($result['tax_cart'])); $result['shipping'] = sprintf('%.2f', $order->getStore()->convertPrice($result['shipping'])); $result['discount_amount'] = sprintf('%.2f', $order->getStore()->convertPrice($result['discount_amount'])); $result['discount_amount_cart'] = sprintf('%.2f', $order->getStore()->convertPrice($result['discount_amount_cart'])); for ($i = 1; isset($result['item_number_' . $i]); $i++) { $result['amount_' . $i] = sprintf('%.2f', $order->getStore()->convertPrice($result['amount_' . $i])); } } return $result; } public function isApplicableToQuote($quote, $checksBitMask) { if ($checksBitMask & self::CHECK_USE_FOR_COUNTRY) { if (!$this->canUseForCountry($quote->getBillingAddress()->getCountry())) { return false; } } if ($checksBitMask & self::CHECK_USE_FOR_CURRENCY) { if (!$this->canUseForCurrency($quote->getStore()->getCurrentCurrencyCode())) { return false; } } if ($checksBitMask & self::CHECK_USE_CHECKOUT) { if (!$this->canUseCheckout()) { return false; } } if ($checksBitMask & self::CHECK_USE_FOR_MULTISHIPPING) { if (!$this->canUseForMultishipping()) { return false; } } if ($checksBitMask & self::CHECK_USE_INTERNAL) { if (!$this->canUseInternal()) { return false; } } if ($checksBitMask & self::CHECK_ORDER_TOTAL_MIN_MAX) { $total = $quote->getBaseGrandTotal(); $minTotal = $this->getConfigData('min_order_total'); $maxTotal = $this->getConfigData('max_order_total'); if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) { return false; } } if ($checksBitMask & self::CHECK_RECURRING_PROFILES) { if (!$this->canManageRecurringProfiles() && $quote->hasRecurringItems()) { return false; } } if ($checksBitMask & self::CHECK_ZERO_TOTAL) { $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount(); if ($total < 0.0001 && $this->getCode() != 'free' && !($this->canManageRecurringProfiles() && $quote->hasRecurringItems()) ) { return false; } } return true; } private function _getAggregatedCartSummary() { if ($this->_config->lineItemsSummary) { return $this->_config->lineItemsSummary; } return Mage::app()->getStore($this->getStore())->getFrontendName(); } }