/** * Set up the paypal helper. */ public function _construct() { parent::_construct(); $app = Mage::app(); $locale = $app->getLocale(); $this->_coreHelper = $this->helper('core'); $this->_paymentHelper = Mage::helper('payment'); $this->_helper = Mage::helper('ebayenterprise_paypal'); $this->_config = $this->_helper->getConfigModel(); $this->_localeCode = $locale->getLocaleCode(); $url = $this->_config->shortcutExpressCheckoutButton ?: self::DEFAULT_IMAGE_URL; $this->_payPalImageUrl = str_replace(array('{locale_code}'), array($this->_localeCode), $url); $this->_htmlId = $this->_coreHelper->uniqHash(self::HTML_ID_PREFIX); }
/** * build out an ILineItem payload and add it to the ILineItemIterable. * * @param Mage_Sales_Model_Quote_Item_Abstract * @param ILineItemIterable * @param string * @return self */ public function createLineItem(Mage_Sales_Model_Quote_Item_Abstract $item, ILineItemIterable $lineItems, $currencyCode) { $lineItem = $lineItems->getEmptyLineItem(); $lineItem->setName($this->helper->__($item->getProduct()->getName()))->setSequenceNumber($item->getId())->setQuantity($item->getTotalQty())->setCurrencyCode($currencyCode); if ($this->canIncludeAmounts($item)) { $lineItem->setUnitAmount($item->getPrice()); } $lineItems->offsetSet($lineItem, null); }
/** * Place the order and recurring payment profiles when customer returned from paypal * Until this moment all quote data must be valid * * @param string $token * @param string $shippingMethodCode */ public function place($token, $shippingMethodCode = null) { $this->updateShippingMethod($shippingMethodCode); $isNewCustomer = $this->_prepareQuote(); $this->_ignoreAddressValidation(); $this->_quote->collectTotals(); $this->_getApi(); $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID); $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId); $doAuthorizationReply = $this->_api->doAuthorization($this->_quote); $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply)); $service = Mage::getModel('sales/service_quote', $this->_quote); try { $service->submitAll(); // Any exceptions thrown from submitAll indicate an order that failed // to be created. In any such cases, the payment auth needs to be voided. } catch (Exception $e) { $this->_api->doVoidQuote($this->_quote); // Throw an exception for the controller to handle. Needs to indicate // the failure to complete the PayPal payment as the PayPal process // needs to be restarted once the auth was performed. throw Mage::exception('EbayEnterprise_PayPal', $this->_helper->__(EbayEnterprise_Paypal_Model_Express_Api::EBAYENTERPRISE_PAYPAL_API_FAILED)); } $this->_quote->save(); if ($isNewCustomer) { try { $this->_involveNewCustomer(); } catch (Exception $e) { $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e)); } } $order = $service->getOrder(); if (!$order) { return; } switch ($order->getState()) { // Even after placement, paypal can disallow authorize/capture case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT: break; // regular placement, when everything is ok // regular placement, when everything is ok case Mage_Sales_Model_Order::STATE_PROCESSING: case Mage_Sales_Model_Order::STATE_COMPLETE: case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW: $order->sendNewOrderEmail(); break; } $this->_order = $order; Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote)); }
/** * Process an item or, if the item has children that are calculated, * the item's children. Processing an item consists of building an ILineItem * payload to be added to the ILineItemIterable. The total for each line is * recursively summed and returned. * * @param Mage_Sales_Model_Quote_Item_Abstract * @param ILineItemIterable * @param string * @return self */ protected function processItem(Mage_Sales_Model_Quote_Item_Abstract $item, ILineItemIterable $lineItems, $currencyCode) { // handle the possibility of getting a Mage_Sales_Model_Quote_Address_Item $item = $item->getQuoteItem() ?: $item; if ($item->getHasChildren() && $item->isChildrenCalculated()) { foreach ($item->getChildren() as $child) { $this->processItem($child, $lineItems, $currencyCode); } } else { $lineItem = $lineItems->getEmptyLineItem(); $lineItem->setName($this->helper->__($item->getProduct()->getName()))->setSequenceNumber($item->getId())->setQuantity($item->getQty())->setUnitAmount($item->getPrice())->setCurrencyCode($currencyCode); $lineItems->offsetSet($lineItem, null); } return $this; }
/** * Reserve order ID for specified quote and start checkout on PayPal * * @param string * @param string * @param bool|null $button specifies if we came from Checkout Stream or from Product/Cart directly * @return mixed */ public function start($returnUrl, $cancelUrl, $button = null) { $this->_quote->collectTotals(); if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) { Mage::throwException($this->_helper->__(self::EBAYENTERPRISE_PAYPAL_ZERO_CHECKOUT_NOT_SUPPORTED)); } $this->_quote->reserveOrderId()->save(); $this->_getApi(); $setExpressCheckoutReply = $this->_api->setExpressCheckout($returnUrl, $cancelUrl, $this->_quote); if ($button) { // mark the payment to indicate express checkout was initiated from // outside the normal checkout flow // (e.g. clicked paypal checkout button from product page) $setExpressCheckoutReply[self::PAYMENT_INFO_BUTTON] = 1; } $this->_quote->getPayment()->importData($setExpressCheckoutReply); $this->_quote->getPayment()->save(); return $setExpressCheckoutReply; }
/** * Search for proper checkout token in request or session or (un)set specified one * * @param string $setToken * * @return EbayEnterprise_PayPal_CheckoutController |string */ protected function _initToken($setToken = null) { if (null !== $setToken) { if (false === $setToken) { // security measure for avoid unsetting token twice if (!$this->_getSession()->getExpressCheckoutToken()) { Mage::throwException($this->_helper->__('PayPal Express Checkout Token does not exist.')); } $this->_getSession()->unsExpressCheckoutToken(); } else { $this->_getSession()->setExpressCheckoutToken($setToken); } return $this; } if ($setToken = $this->getRequest()->getParam('token')) { if ($setToken !== $this->_getSession()->getExpressCheckoutToken()) { Mage::throwException($this->_helper->__('Wrong PayPal Express Checkout Token specified.')); } } else { $setToken = $this->_getSession()->getExpressCheckoutToken(); } return $setToken; }
/** * get the translated alt text for the image * * @return string */ public function getPaymentMarkAltText() { return $this->helper->__(self::ALT_TEXT_MESSAGE); }
public function getAcceptanceMarkMessage() { $this->_helper->__('Acceptance Mark'); }