Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Paypal_Adminhtml_Paypal_ReportsController
  • Mage_Paypal_Block_Adminhtml_Settlement_Details
  • Mage_Paypal_Block_Adminhtml_Settlement_Details_Form
  • Mage_Paypal_Block_Adminhtml_Settlement_Report
  • Mage_Paypal_Block_Adminhtml_Settlement_Report_Grid
  • Mage_Paypal_Block_Adminhtml_System_Config_ApiWizard
  • Mage_Paypal_Block_Adminhtml_System_Config_Field_Country
  • Mage_Paypal_Block_Adminhtml_System_Config_Field_Hidden
  • Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Expanded
  • Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Group
  • Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Hint
  • Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Location
  • Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Payment
  • Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Store
  • Mage_Paypal_Block_Adminhtml_System_Config_Payflowlink_Advanced
  • Mage_Paypal_Block_Adminhtml_System_Config_Payflowlink_Info
  • Mage_Paypal_Block_Express_Form
  • Mage_Paypal_Block_Express_Review
  • Mage_Paypal_Block_Express_Review_Billing
  • Mage_Paypal_Block_Express_Review_Details
  • Mage_Paypal_Block_Express_Review_Shipping
  • Mage_Paypal_Block_Express_Shortcut
  • Mage_Paypal_Block_Hosted_Pro_Form
  • Mage_Paypal_Block_Hosted_Pro_Iframe
  • Mage_Paypal_Block_Hosted_Pro_Info
  • Mage_Paypal_Block_Iframe
  • Mage_Paypal_Block_Logo
  • Mage_Paypal_Block_Payflow_Advanced_Form
  • Mage_Paypal_Block_Payflow_Advanced_Iframe
  • Mage_Paypal_Block_Payflow_Advanced_Info
  • Mage_Paypal_Block_Payflow_Link_Form
  • Mage_Paypal_Block_Payflow_Link_Iframe
  • Mage_Paypal_Block_Payflow_Link_Info
  • Mage_Paypal_Block_Payment_Info
  • Mage_Paypal_Block_Standard_Form
  • Mage_Paypal_Block_Standard_Redirect
  • Mage_Paypal_Controller_Express_Abstract
  • Mage_Paypal_ExpressController
  • Mage_Paypal_Helper_Data
  • Mage_Paypal_Helper_Hss
  • Mage_Paypal_HostedproController
  • Mage_Paypal_IpnController
  • Mage_Paypal_Model_Api_Abstract
  • Mage_Paypal_Model_Api_Nvp
  • Mage_Paypal_Model_Api_Standard
  • Mage_Paypal_Model_Cart
  • Mage_Paypal_Model_Cert
  • Mage_Paypal_Model_Config
  • Mage_Paypal_Model_Direct
  • Mage_Paypal_Model_Express
  • Mage_Paypal_Model_Express_Checkout
  • Mage_Paypal_Model_Hostedpro
  • Mage_Paypal_Model_Hostedpro_Request
  • Mage_Paypal_Model_Info
  • Mage_Paypal_Model_Ipn
  • Mage_Paypal_Model_Method_Agreement
  • Mage_Paypal_Model_Mysql4_Cert
  • Mage_Paypal_Model_Mysql4_Report_Settlement
  • Mage_Paypal_Model_Mysql4_Report_Settlement_Row
  • Mage_Paypal_Model_Mysql4_Report_Settlement_Row_Collection
  • Mage_Paypal_Model_Mysql4_Setup
  • Mage_Paypal_Model_Observer
  • Mage_Paypal_Model_Payflow_Request
  • Mage_Paypal_Model_Payflowadvanced
  • Mage_Paypal_Model_Payflowlink
  • Mage_Paypal_Model_Payflowpro
  • Mage_Paypal_Model_Payment_Transaction
  • Mage_Paypal_Model_Pro
  • Mage_Paypal_Model_Report_Settlement
  • Mage_Paypal_Model_Report_Settlement_Row
  • Mage_Paypal_Model_Resource_Cert
  • Mage_Paypal_Model_Resource_Report_Settlement
  • Mage_Paypal_Model_Resource_Report_Settlement_Row
  • Mage_Paypal_Model_Resource_Report_Settlement_Row_Collection
  • Mage_Paypal_Model_Resource_Setup
  • Mage_Paypal_Model_Session
  • Mage_Paypal_Model_Standard
  • Mage_Paypal_Model_System_Config_Backend_Cert
  • Mage_Paypal_Model_System_Config_Backend_Cron
  • Mage_Paypal_Model_System_Config_Backend_MerchantCountry
  • Mage_Paypal_Model_System_Config_Source_BuyerCountry
  • Mage_Paypal_Model_System_Config_Source_FetchingSchedule
  • Mage_Paypal_Model_System_Config_Source_Logo
  • Mage_Paypal_Model_System_Config_Source_MerchantCountry
  • Mage_Paypal_Model_System_Config_Source_PaymentActions
  • Mage_Paypal_Model_System_Config_Source_PaymentActions_Express
  • Mage_Paypal_Model_System_Config_Source_RequireBillingAddress
  • Mage_Paypal_Model_System_Config_Source_UrlMethod
  • Mage_Paypal_PayflowadvancedController
  • Mage_Paypal_PayflowController
  • Mage_Paypal_StandardController

Exceptions

  • Mage_Paypal_Exception
  • Overview
  • Package
  • Class
  • Tree
  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_Paypal
 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:  *
 29:  * PayPal Direct Module
 30:  *
 31:  * @author      Magento Core Team <core@magentocommerce.com>
 32:  */
 33: class Mage_Paypal_Model_Direct extends Mage_Payment_Model_Method_Cc
 34: {
 35:     protected $_code  = Mage_Paypal_Model_Config::METHOD_WPP_DIRECT;
 36:     protected $_infoBlockType = 'paypal/payment_info';
 37: 
 38:     /**
 39:      * Availability options
 40:      */
 41:     protected $_isGateway               = true;
 42:     protected $_canAuthorize            = true;
 43:     protected $_canCapture              = true;
 44:     protected $_canCapturePartial       = true;
 45:     protected $_canRefund               = true;
 46:     protected $_canRefundInvoicePartial = true;
 47:     protected $_canVoid                 = true;
 48:     protected $_canUseInternal          = true;
 49:     protected $_canUseCheckout          = true;
 50:     protected $_canUseForMultishipping  = true;
 51:     protected $_canSaveCc = false;
 52:     protected $_canFetchTransactionInfo = true;
 53:     protected $_canReviewPayment        = true;
 54: 
 55:     /**
 56:      * Website Payments Pro instance
 57:      *
 58:      * @var Mage_Paypal_Model_Pro
 59:      */
 60:     protected $_pro = null;
 61: 
 62:     /**
 63:      * Website Payments Pro instance type
 64:      *
 65:      * @var $_proType string
 66:      */
 67:     protected $_proType = 'paypal/pro';
 68: 
 69:     public function __construct($params = array())
 70:     {
 71:         $proInstance = array_shift($params);
 72:         if ($proInstance && ($proInstance instanceof Mage_Paypal_Model_Pro)) {
 73:             $this->_pro = $proInstance;
 74:         } else {
 75:             $this->_pro = Mage::getModel($this->_proType);
 76:         }
 77:         $this->_pro->setMethod($this->_code);
 78:     }
 79: 
 80:     /**
 81:      * Store setter
 82:      * Also updates store ID in config object
 83:      *
 84:      * @param Mage_Core_Model_Store|int $store
 85:      */
 86:     public function setStore($store)
 87:     {
 88:         $this->setData('store', $store);
 89:         if (null === $store) {
 90:             $store = Mage::app()->getStore()->getId();
 91:         }
 92:         $this->_pro->getConfig()->setStoreId(is_object($store) ? $store->getId() : $store);
 93:         return $this;
 94:     }
 95: 
 96:     /**
 97:      * Whether method is available for specified currency
 98:      *
 99:      * @param string $currencyCode
100:      * @return bool
101:      */
102:     public function canUseForCurrency($currencyCode)
103:     {
104:         return $this->_pro->getConfig()->isCurrencyCodeSupported($currencyCode);
105:     }
106: 
107:     /**
108:      * Payment action getter compatible with payment model
109:      *
110:      * @see Mage_Sales_Model_Payment::place()
111:      * @return string
112:      */
113:     public function getConfigPaymentAction()
114:     {
115:         return $this->_pro->getConfig()->getPaymentAction();
116:     }
117: 
118:     /**
119:      * Return available CC types for gateway based on merchant country
120:      *
121:      * @return string
122:      */
123:     public function getAllowedCcTypes()
124:     {
125:         $ccTypes = explode(',', $this->_pro->getConfig()->cctypes);
126:         $country = $this->_pro->getConfig()->getMerchantCountry();
127: 
128:         if ($country == 'GB') {
129:             $ccTypes = array_intersect(array('SM', 'SO', 'MC', 'DI', 'VI'), $ccTypes);
130:         } elseif ($country == 'CA') {
131:             $ccTypes = array_intersect(array('MC', 'VI'), $ccTypes);
132:         }
133:         return implode(',', $ccTypes);
134:     }
135: 
136:     /**
137:      * Check whether payment method can be used
138:      * @param Mage_Sales_Model_Quote
139:      * @return bool
140:      */
141:     public function isAvailable($quote = null)
142:     {
143:         if (parent::isAvailable($quote) && $this->_pro->getConfig()->isMethodAvailable()) {
144:             return true;
145:         }
146:         return false;
147:     }
148: 
149:     /**
150:      * Custom getter for payment configuration
151:      *
152:      * @param string $field
153:      * @param int $storeId
154:      * @return mixed
155:      */
156:     public function getConfigData($field, $storeId = null)
157:     {
158:         $value = null;
159:         switch ($field)
160:         {
161:             case 'cctypes':
162:                 $value = $this->getAllowedCcTypes();
163:                 break;
164:             default:
165:                 $value = $this->_pro->getConfig()->$field;
166:         }
167:         return $value;
168:     }
169: 
170:     /**
171:      * Authorize payment
172:      *
173:      * @param Mage_Sales_Model_Order_Payment $payment
174:      * @return Mage_Paypal_Model_Direct
175:      */
176:     public function authorize(Varien_Object $payment, $amount)
177:     {
178:         return $this->_placeOrder($payment, $amount);
179:     }
180: 
181:     /**
182:      * Void payment
183:      *
184:      * @param Mage_Sales_Model_Order_Payment $payment
185:      * @return Mage_Paypal_Model_Direct
186:      */
187:     public function void(Varien_Object $payment)
188:     {
189:         $this->_pro->void($payment);
190:         return $this;
191:     }
192: 
193:     /**
194:      * Capture payment
195:      *
196:      * @param Mage_Sales_Model_Order_Payment $payment
197:      * @return Mage_Paypal_Model_Direct
198:      */
199:     public function capture(Varien_Object $payment, $amount)
200:     {
201:         if (false === $this->_pro->capture($payment, $amount)) {
202:             $this->_placeOrder($payment, $amount);
203:         }
204:         return $this;
205:     }
206: 
207:     /**
208:      * Refund capture
209:      *
210:      * @param Mage_Sales_Model_Order_Payment $payment
211:      * @return Mage_Paypal_Model_Direct
212:      */
213:     public function refund(Varien_Object $payment, $amount)
214:     {
215:         $this->_pro->refund($payment, $amount);
216:         return $this;
217:     }
218: 
219:     /**
220:      * Cancel payment
221:      *
222:      * @param Mage_Sales_Model_Order_Payment $payment
223:      * @return Mage_Paypal_Model_Direct
224:      */
225:     public function cancel(Varien_Object $payment)
226:     {
227:         $this->void($payment);
228: 
229:         return $this;
230:     }
231: 
232:     /**
233:      * Whether payment can be reviewed
234:      *
235:      * @param Mage_Sales_Model_Order_Payment $payment
236:      * @return bool
237:      */
238:     public function canReviewPayment(Mage_Payment_Model_Info $payment)
239:     {
240:         return parent::canReviewPayment($payment) && $this->_pro->canReviewPayment($payment);
241:     }
242: 
243:     /**
244:      * Attempt to accept a pending payment
245:      *
246:      * @param Mage_Sales_Model_Order_Payment $payment
247:      * @return bool
248:      */
249:     public function acceptPayment(Mage_Payment_Model_Info $payment)
250:     {
251:         parent::acceptPayment($payment);
252:         return $this->_pro->reviewPayment($payment, Mage_Paypal_Model_Pro::PAYMENT_REVIEW_ACCEPT);
253:     }
254: 
255:     /**
256:      * Attempt to deny a pending payment
257:      *
258:      * @param Mage_Sales_Model_Order_Payment $payment
259:      * @return bool
260:      */
261:     public function denyPayment(Mage_Payment_Model_Info $payment)
262:     {
263:         parent::denyPayment($payment);
264:         return $this->_pro->reviewPayment($payment, Mage_Paypal_Model_Pro::PAYMENT_REVIEW_DENY);
265:     }
266: 
267:     /**
268:      * Set fallback API URL if not defined in configuration
269:      *
270:      * @return Mage_Centinel_Model_Service
271:      */
272:     public function getCentinelValidator()
273:     {
274:         $validator = parent::getCentinelValidator();
275:         if (!$validator->getCustomApiEndpointUrl()) {
276:             $validator->setCustomApiEndpointUrl($this->_pro->getConfig()->centinelDefaultApiUrl);
277:         }
278:         return $validator;
279:     }
280: 
281:     /**
282:      * Fetch transaction details info
283:      *
284:      * @param Mage_Payment_Model_Info $payment
285:      * @param string $transactionId
286:      * @return array
287:      */
288:     public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
289:     {
290:         return $this->_pro->fetchTransactionInfo($payment, $transactionId);
291:     }
292: 
293:     /**
294:      * Place an order with authorization or capture action
295:      *
296:      * @param Mage_Sales_Model_Order_Payment $payment
297:      * @param float $amount
298:      * @return Mage_Paypal_Model_Direct
299:      */
300:     protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
301:     {
302:         $order = $payment->getOrder();
303:         $api = $this->_pro->getApi()
304:             ->setPaymentAction($this->_pro->getConfig()->paymentAction)
305:             ->setIpAddress(Mage::app()->getRequest()->getClientIp(false))
306:             ->setAmount($amount)
307:             ->setCurrencyCode($order->getBaseCurrencyCode())
308:             ->setInvNum($order->getIncrementId())
309:             ->setEmail($order->getCustomerEmail())
310:             ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
311:             ->setCreditCardType($payment->getCcType())
312:             ->setCreditCardNumber($payment->getCcNumber())
313:             ->setCreditCardExpirationDate(
314:                 $this->_getFormattedCcExpirationDate($payment->getCcExpMonth(), $payment->getCcExpYear())
315:             )
316:             ->setCreditCardCvv2($payment->getCcCid())
317:             ->setMaestroSoloIssueNumber($payment->getCcSsIssue())
318:         ;
319:         if ($payment->getCcSsStartMonth() && $payment->getCcSsStartYear()) {
320:             $year = sprintf('%02d', substr($payment->getCcSsStartYear(), -2, 2));
321:             $api->setMaestroSoloIssueDate(
322:                 $this->_getFormattedCcExpirationDate($payment->getCcSsStartMonth(), $year)
323:             );
324:         }
325:         if ($this->getIsCentinelValidationEnabled()) {
326:             $this->getCentinelValidator()->exportCmpiData($api);
327:         }
328: 
329:         // add shipping and billing addresses
330:         if ($order->getIsVirtual()) {
331:             $api->setAddress($order->getBillingAddress())->setSuppressShipping(true);
332:         } else {
333:             $api->setAddress($order->getShippingAddress());
334:             $api->setBillingAddress($order->getBillingAddress());
335:         }
336: 
337:         // add line items
338:         $api->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
339:             ->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled)
340:         ;
341: 
342:         // call api and import transaction and other payment information
343:         $api->callDoDirectPayment();
344:         $this->_importResultToPayment($api, $payment);
345: 
346:         try {
347:             $api->callGetTransactionDetails();
348:         } catch (Mage_Core_Exception $e) {
349:             // if we recieve errors, but DoDirectPayment response is Success, then set Pending status for transaction
350:             $payment->setIsTransactionPending(true);
351:         }
352:         $this->_importResultToPayment($api, $payment);
353:         return $this;
354:     }
355: 
356:     /**
357:      * Format credit card expiration date based on month and year values
358:      * Format: mmyyyy
359:      *
360:      * @param string|int $month
361:      * @param string|int $year
362:      * @return string
363:      */
364:     protected function _getFormattedCcExpirationDate($month, $year)
365:     {
366:         return sprintf('%02d%02d', $month, $year);
367:     }
368: 
369:     /**
370:      * Import direct payment results to payment
371:      *
372:      * @param Mage_Paypal_Model_Api_Nvp
373:      * @param Mage_Sales_Model_Order_Payment
374:      */
375:     protected function _importResultToPayment($api, $payment)
376:     {
377:         $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(0);
378:         $this->_pro->importPaymentInfo($api, $payment);
379:     }
380: 
381:     /**
382:      * Check void availability
383:      *
384:      * @param   Varien_Object $payment
385:      * @return  bool
386:      */
387:     public function canVoid(Varien_Object $payment)
388:     {
389:         if ($payment instanceof Mage_Sales_Model_Order_Invoice
390:             || $payment instanceof Mage_Sales_Model_Order_Creditmemo
391:         ) {
392:             return false;
393:         }
394: 
395:         return $this->_canVoid;
396:     }
397: }
398: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0