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:  * Abstract class for Paypal API wrappers
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: abstract class Mage_Paypal_Model_Api_Abstract extends Varien_Object
 33: {
 34:     /**
 35:      * Config instance
 36:      * @var Mage_Paypal_Model_Config
 37:      */
 38:     protected $_config = null;
 39: 
 40:     /**
 41:      * Global private to public interface map
 42:      * @var array
 43:      */
 44:     protected $_globalMap = array();
 45: 
 46:     /**
 47:      * Filter callbacks for exporting $this data to API call
 48:      *
 49:      * @var array
 50:      */
 51:     protected $_exportToRequestFilters = array();
 52: 
 53:     /**
 54:      * Filter callbacks for importing API result to $this data
 55:      *
 56:      * @var array
 57:      */
 58:     protected $_importFromRequestFilters = array();
 59: 
 60:     /**
 61:      * Line items export to request mapping settings
 62:      * @var array
 63:      */
 64:     protected $_lineItemExportItemsFormat = array();
 65:     protected $_lineItemExportItemsFilters = array();
 66:     protected $_lineItemTotalExportMap = array();
 67: 
 68:     /**
 69:      * PayPal shopping cart instance
 70:      *
 71:      * @var Mage_Paypal_Model_Cart
 72:      */
 73:     protected $_cart = null;
 74: 
 75:     /**
 76:      * Shipping options export to request mapping settings
 77:      * @var array
 78:      */
 79:     protected $_shippingOptionsExportItemsFormat = array();
 80: 
 81:     /**
 82:      * Imported recurring profiles array
 83:      *
 84:      * @var array
 85:      */
 86:     protected $_recurringPaymentProfiles = array();
 87: 
 88:    /**
 89:      * Fields that should be replaced in debug with '***'
 90:      *
 91:      * @var array
 92:      */
 93:     protected $_debugReplacePrivateDataKeys = array();
 94: 
 95:     /**
 96:      * Return Paypal Api user name based on config data
 97:      *
 98:      * @return string
 99:      */
100:     public function getApiUsername()
101:     {
102:         return $this->_config->apiUsername;
103:     }
104: 
105:     /**
106:      * Return Paypal Api password based on config data
107:      *
108:      * @return string
109:      */
110:     public function getApiPassword()
111:     {
112:         return $this->_config->apiPassword;
113:     }
114: 
115:     /**
116:      * Return Paypal Api signature based on config data
117:      *
118:      * @return string
119:      */
120:     public function getApiSignature()
121:     {
122:         return $this->_config->apiSignature;
123:     }
124: 
125:     /**
126:      * Return Paypal Api certificate based on config data
127:      *
128:      * @return string
129:      */
130:     public function getApiCertificate()
131:     {
132:         return $this->_config->getApiCertificate();
133:     }
134: 
135:     /**
136:      * BN code getter
137:      *
138:      * @return string
139:      */
140:     public function getBuildNotationCode()
141:     {
142:         return $this->_config->getBuildNotationCode();
143:     }
144: 
145:     /**
146:      * Return Paypal Api proxy status based on config data
147:      *
148:      * @return bool
149:      */
150:     public function getUseProxy()
151:     {
152:         return $this->_getDataOrConfig('use_proxy', false);
153:     }
154: 
155:     /**
156:      * Return Paypal Api proxy host based on config data
157:      *
158:      * @return string
159:      */
160:     public function getProxyHost()
161:     {
162:         return $this->_getDataOrConfig('proxy_host', '127.0.0.1');
163:     }
164: 
165:     /**
166:      * Return Paypal Api proxy port based on config data
167:      *
168:      * @return string
169:      */
170:     public function getProxyPort()
171:     {
172:         return $this->_getDataOrConfig('proxy_port', '808');
173:     }
174: 
175:     /**
176:      * @deprecated after 1.4.1.0
177:      *
178:      * @return bool
179:      */
180:     public function getDebug()
181:     {
182:         return $this->getDebugFlag();
183:     }
184: 
185:     /**
186:      * PayPal page CSS getter
187:      *
188:      * @return string
189:      */
190:     public function getPageStyle()
191:     {
192:         return $this->_getDataOrConfig('page_style');
193:     }
194: 
195:     /**
196:      * PayPal page header image URL getter
197:      *
198:      * @return string
199:      */
200:     public function getHdrimg()
201:     {
202:         return $this->_getDataOrConfig('paypal_hdrimg');
203:     }
204: 
205:     /**
206:      * PayPal page header border color getter
207:      *
208:      * @return string
209:      */
210:     public function getHdrbordercolor()
211:     {
212:         return $this->_getDataOrConfig('paypal_hdrbordercolor');
213:     }
214: 
215:     /**
216:      * PayPal page header background color getter
217:      *
218:      * @return string
219:      */
220:     public function getHdrbackcolor()
221:     {
222:         return $this->_getDataOrConfig('paypal_hdrbackcolor');
223:     }
224: 
225:     /**
226:      * PayPal page "payflow color" (?) getter
227:      *
228:      * @return string
229:      */
230:     public function getPayflowcolor()
231:     {
232:         return $this->_getDataOrConfig('paypal_payflowcolor');
233:     }
234: 
235:     /**
236:      * Payment action getter
237:      *
238:      * @return string
239:      */
240:     public function getPaymentAction()
241:     {
242:         return $this->_getDataOrConfig('payment_action');
243:     }
244: 
245:     /**
246:      * PayPal merchant email getter
247:      */
248:     public function getBusinessAccount()
249:     {
250:         return $this->_getDataOrConfig('business_account');
251:     }
252: 
253:     /**
254:      * Import $this public data to specified object or array
255:      *
256:      * @param array|Varien_Object $to
257:      * @param array $publicMap
258:      * @return array|Varien_Object
259:      */
260:     public function &import($to, array $publicMap = array())
261:     {
262:         return Varien_Object_Mapper::accumulateByMap(array($this, 'getDataUsingMethod'), $to, $publicMap);
263:     }
264: 
265:     /**
266:      * Export $this public data from specified object or array
267:      *
268:      * @param array|Varien_Object $from
269:      * @param array $publicMap
270:      * @return Mage_Paypal_Model_Api_Abstract
271:      */
272:     public function export($from, array $publicMap = array())
273:     {
274:         Varien_Object_Mapper::accumulateByMap($from, array($this, 'setDataUsingMethod'), $publicMap);
275:         return $this;
276:     }
277: 
278:     /**
279:      * Set PayPal cart instance
280:      *
281:      * @param Mage_Paypal_Model_Cart $cart
282:      * @return Mage_Paypal_Model_Api_Abstract
283:      */
284:     public function setPaypalCart(Mage_Paypal_Model_Cart $cart)
285:     {
286:         $this->_cart = $cart;
287:         return $this;
288:     }
289: 
290:     /**
291:      * Config instance setter
292:      * @param Mage_Paypal_Model_Config $config
293:      * @return Mage_Paypal_Model_Api_Abstract
294:      */
295:     public function setConfigObject(Mage_Paypal_Model_Config $config)
296:     {
297:         $this->_config = $config;
298:         return $this;
299:     }
300: 
301:     /**
302:      * Current locale code getter
303:      *
304:      * @return string
305:      */
306:     public function getLocaleCode()
307:     {
308:         return Mage::app()->getLocale()->getLocaleCode();
309:     }
310: 
311:     /**
312:      * Always take into accoun
313:      */
314:     public function getFraudManagementFiltersEnabled()
315:     {
316:         return 1;
317:     }
318: 
319:     /**
320:      * Set recurring profiles
321:      *
322:      * @param array $items
323:      * @return Mage_Paypal_Model_Api_Abstract
324:      */
325:     public function addRecurringPaymentProfiles(array $items)
326:     {
327:         if ($items) {
328:             $this->_recurringPaymentProfiles = $items;
329:         }
330:         return $this;
331:     }
332: 
333:     /**
334:      * Export $this public data to private request array
335:      *
336:      * @param array $internalRequestMap
337:      * @param array $request
338:      * @return array
339:      */
340:     protected function &_exportToRequest(array $privateRequestMap, array $request = array())
341:     {
342:         $map = array();
343:         foreach ($privateRequestMap as $key) {
344:             if (isset($this->_globalMap[$key])) {
345:                 $map[$this->_globalMap[$key]] = $key;
346:             }
347:         }
348:         $result = Varien_Object_Mapper::accumulateByMap(array($this, 'getDataUsingMethod'), $request, $map);
349:         foreach ($privateRequestMap as $key) {
350:             if (isset($this->_exportToRequestFilters[$key]) && isset($result[$key])) {
351:                 $callback   = $this->_exportToRequestFilters[$key];
352:                 $privateKey = $result[$key];
353:                 $publicKey  = $map[$this->_globalMap[$key]];
354:                 $result[$key] = call_user_func(array($this, $callback), $privateKey, $publicKey);
355:             }
356:         }
357:         return $result;
358:     }
359: 
360:     /**
361:      * Import $this public data from a private response array
362:      *
363:      * @param array $privateResponseMap
364:      * @param array $response
365:      */
366:     protected function _importFromResponse(array $privateResponseMap, array $response)
367:     {
368:         $map = array();
369:         foreach ($privateResponseMap as $key) {
370:             if (isset($this->_globalMap[$key])) {
371:                 $map[$key] = $this->_globalMap[$key];
372:             }
373:             if (isset($response[$key]) && isset($this->_importFromRequestFilters[$key])) {
374:                 $callback = $this->_importFromRequestFilters[$key];
375:                 $response[$key] = call_user_func(array($this, $callback), $response[$key], $key, $map[$key]);
376:             }
377:         }
378:         Varien_Object_Mapper::accumulateByMap($response, array($this, 'setDataUsingMethod'), $map);
379:     }
380: 
381:     /**
382:      * Prepare line items request
383:      *
384:      * Returns true if there were line items added
385:      *
386:      * @param array &$request
387:      * @param int $i
388:      * @return true|bool
389:      */
390:     protected function _exportLineItems(array &$request, $i = 0)
391:     {
392:         if (!$this->_cart) {
393:             return;
394:         }
395: 
396:         // always add cart totals, even if line items are not requested
397:         if ($this->_lineItemTotalExportMap) {
398:             foreach ($this->_cart->getTotals() as $key => $total) {
399:                 if (isset($this->_lineItemTotalExportMap[$key])) { // !empty($total)
400:                     $privateKey = $this->_lineItemTotalExportMap[$key];
401:                     $request[$privateKey] = $this->_filterAmount($total);
402:                 }
403:             }
404:         }
405: 
406:         // add cart line items
407:         $items = $this->_cart->getItems();
408:         if (empty($items) || !$this->getIsLineItemsEnabled()) {
409:             return;
410:         }
411:         $result = null;
412:         foreach ($items as $item) {
413:             foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
414:                 $result = true;
415:                 $value = $item->getDataUsingMethod($publicKey);
416:                 if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
417:                     $callback   = $this->_lineItemExportItemsFilters[$publicKey];
418:                     $value = call_user_func(array($this, $callback), $value);
419:                 }
420:                 if (is_float($value)) {
421:                     $value = $this->_filterAmount($value);
422:                 }
423:                 $request[sprintf($privateFormat, $i)] = $value;
424:             }
425:             $i++;
426:         }
427:         return $result;
428:     }
429: 
430:     /**
431:      * Prepare shipping options request
432:      * Returns false if there are no shipping options
433:      *
434:      * @param array &$request
435:      * @param int $i
436:      * @return bool
437:      */
438:     protected function _exportShippingOptions(array &$request, $i = 0)
439:     {
440:         $options = $this->getShippingOptions();
441:         if (empty($options)) {
442:             return false;
443:         }
444:         foreach ($options as $option) {
445:             foreach ($this->_shippingOptionsExportItemsFormat as $publicKey => $privateFormat) {
446:                 $value = $option->getDataUsingMethod($publicKey);
447:                 if (is_float($value)) {
448:                     $value = $this->_filterAmount($value);
449:                 }
450:                 if (is_bool($value)) {
451:                     $value = $this->_filterBool($value);
452:                 }
453:                 $request[sprintf($privateFormat, $i)] = $value;
454:             }
455:             $i++;
456:         }
457:         return true;
458:     }
459: 
460:     /**
461:      * Filter amounts in API calls
462:      * @param float|string $value
463:      * @return string
464:      */
465:     protected function _filterAmount($value)
466:     {
467:         return sprintf('%.2F', $value);
468:     }
469: 
470:     /**
471:      * Filter boolean values in API calls
472:      *
473:      * @param mixed $value
474:      * @return string
475:      */
476:     protected function _filterBool($value)
477:     {
478:         return ($value) ? 'true' : 'false';
479:     }
480: 
481:     /**
482:      * Filter int values in API calls
483:      *
484:      * @param mixed $value
485:      * @return int
486:      */
487:     protected function _filterInt($value)
488:     {
489:         return (int)$value;
490:     }
491: 
492:     /**
493:      * Unified getter that looks in data or falls back to config
494:      *
495:      * @param string $key
496:      * @param mixed $default
497:      * @return mixed
498:      */
499:     protected function _getDataOrConfig($key, $default = null)
500:     {
501:         if ($this->hasData($key)) {
502:             return $this->getData($key);
503:         }
504:         return $this->_config->$key ? $this->_config->$key : $default;
505:     }
506: 
507: 
508:     /**
509:      * region_id workaround: PayPal requires state code, try to find one in the address
510:      *
511:      * @param Varien_Object $address
512:      * @return string
513:      */
514:     protected function _lookupRegionCodeFromAddress(Varien_Object $address)
515:     {
516:         if ($regionId = $address->getData('region_id')) {
517:             $region = Mage::getModel('directory/region')->load($regionId);
518:             if ($region->getId()) {
519:                 return $region->getCode();
520:             }
521:         }
522:         return '';
523:     }
524: 
525:     /**
526:      * Street address workaround: divides address lines into parts by specified keys
527:      * (keys should go as 3rd, 4th[...] parameters)
528:      *
529:      * @param Varien_Object $address
530:      * @param array $request
531:      */
532:     protected function _importStreetFromAddress(Varien_Object $address, array &$to)
533:     {
534:         $keys = func_get_args(); array_shift($keys); array_shift($keys);
535:         $street = $address->getStreet();
536:         if (!$keys || !$street || !is_array($street)) {
537:             return;
538:         }
539: 
540:         $street = Mage::helper('customer/address')
541:             ->convertStreetLines($address->getStreet(), count($keys));
542: 
543:         $i = 0;
544:         foreach ($keys as $key) {
545:             $to[$key] = isset($street[$i]) ? $street[$i]: '';
546:             $i++;
547:         }
548:     }
549: 
550:     /**
551:      * Build query string from request
552:      *
553:      * @param array $request
554:      * @return string
555:      */
556:     protected function _buildQuery($request)
557:     {
558:         return http_build_query($request);
559:     }
560: 
561:     /**
562:      * Filter qty in API calls
563:      * Paypal note: The value for quantity must be a positive integer. Null, zero, or negative numbers are not allowed.
564:      *
565:      * @param float|string|int $value
566:      * @return string
567:      */
568:     protected function _filterQty($value)
569:     {
570:         return intval($value);
571:     }
572: 
573:     /**
574:      * Log debug data to file
575:      *
576:      * @param mixed $debugData
577:      */
578:     protected function _debug($debugData)
579:     {
580:         if ($this->getDebugFlag()) {
581:             Mage::getModel('core/log_adapter', 'payment_' . $this->_config->getMethodCode() . '.log')
582:                ->setFilterDataKeys($this->_debugReplacePrivateDataKeys)
583:                ->log($debugData);
584:         }
585:     }
586: 
587:     /**
588:      * Define if debugging is enabled
589:      *
590:      * @return bool
591:      */
592:     public function getDebugFlag()
593:     {
594:         return $this->_config->debug;
595:     }
596: 
597:     /**
598:      * Check whether API certificate authentication should be used
599:      *
600:      * @return bool
601:      */
602:     public function getUseCertAuthentication()
603:     {
604:         return (bool)$this->_config->apiAuthentication;
605:     }
606: }
607: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0