1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_PaypalUk
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * PayPalUk Express Module
29: */
30: class Mage_PaypalUk_Model_Express extends Mage_Paypal_Model_Express
31: {
32: protected $_code = Mage_Paypal_Model_Config::METHOD_WPP_PE_EXPRESS;
33: protected $_formBlockType = 'paypaluk/express_form';
34: protected $_canCreateBillingAgreement = false;
35: protected $_canManageRecurringProfiles = false;
36:
37: /**
38: * Website Payments Pro instance type
39: *
40: * @var $_proType string
41: */
42: protected $_proType = 'paypaluk/pro';
43:
44: /**
45: * Express Checkout payment method instance
46: *
47: * @var Mage_Paypal_Model_Express
48: */
49: protected $_ecInstance = null;
50:
51: /**
52: * EC PE won't be available if the EC is available
53: *
54: * @param Mage_Sales_Model_Quote $quote
55: * @return bool
56: */
57: public function isAvailable($quote = null)
58: {
59: if (!parent::isAvailable($quote)) {
60: return false;
61: }
62: if (!$this->_ecInstance) {
63: $this->_ecInstance = Mage::helper('payment')->getMethodInstance(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
64: }
65: if ($quote && $this->_ecInstance) {
66: $this->_ecInstance->setStore($quote->getStoreId());
67: }
68: return $this->_ecInstance ? !$this->_ecInstance->isAvailable() : false;
69: }
70:
71: /**
72: * Import payment info to payment
73: *
74: * @param Mage_Paypal_Model_Api_Nvp
75: * @param Mage_Sales_Model_Order_Payment
76: */
77: protected function _importToPayment($api, $payment)
78: {
79: $payment->setTransactionId($api->getPaypalTransactionId())->setIsTransactionClosed(0)
80: ->setAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT,
81: $api->getRedirectRequired() || $api->getRedirectRequested()
82: )
83: ->setIsTransactionPending($api->getIsPaymentPending())
84: ->setTransactionAdditionalInfo(Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID, $api->getTransactionId())
85: ;
86: $payment->setPreparedMessage(Mage::helper('paypaluk')->__('Payflow PNREF: #%s.', $api->getTransactionId()));
87: Mage::getModel('paypal/info')->importToPayment($api, $payment);
88: }
89:
90: /**
91: * Checkout redirect URL getter for onepage checkout (hardcode)
92: *
93: * @see Mage_Checkout_OnepageController::savePaymentAction()
94: * @see Mage_Sales_Model_Quote_Payment::getCheckoutRedirectUrl()
95: * @return string
96: */
97: public function getCheckoutRedirectUrl()
98: {
99: return Mage::getUrl('paypaluk/express/start');
100: }
101: }
102: