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:  * PayPal Website Payments Pro implementation for payment method instaces
 29:  * This model was created because right now PayPal Direct and PayPal Express payment methods cannot have same abstract
 30:  */
 31: class Mage_Paypal_Model_Pro
 32: {
 33:     /**
 34:      * Possible payment review actions (for FMF only)
 35:      *
 36:      * @var string
 37:      */
 38:     const PAYMENT_REVIEW_ACCEPT = 'accept';
 39:     const PAYMENT_REVIEW_DENY = 'deny';
 40: 
 41:     /**
 42:      * Config instance
 43:      *
 44:      * @var Mage_Paypal_Model_Config
 45:      */
 46:     protected $_config = null;
 47: 
 48:     /**
 49:      * API instance
 50:      *
 51:      * @var Mage_Paypal_Model_Api_Nvp
 52:      */
 53:     protected $_api = null;
 54: 
 55:     /**
 56:      * PayPal info object
 57:      *
 58:      * @var Mage_Paypal_Model_Info
 59:      */
 60:     protected $_infoInstance = null;
 61: 
 62:     /**
 63:      * API model type
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_apiType = 'paypal/api_nvp';
 68: 
 69:     /**
 70:      * Config model type
 71:      *
 72:      * @var string
 73:      */
 74:     protected $_configType = 'paypal/config';
 75: 
 76:     /**
 77:      * Payment method code setter. Also instantiates/updates config
 78:      *
 79:      * @param string $code
 80:      * @param int|null $storeId
 81:      */
 82:     public function setMethod($code, $storeId = null)
 83:     {
 84:         if (null === $this->_config) {
 85:             $params = array($code);
 86:             if (null !== $storeId) {
 87:                 $params[] = $storeId;
 88:             }
 89:             $this->_config = Mage::getModel($this->_configType, $params);
 90:         } else {
 91:             $this->_config->setMethod($code);
 92:             if (null !== $storeId) {
 93:                 $this->_config->setStoreId($storeId);
 94:             }
 95:         }
 96:         return $this;
 97:     }
 98: 
 99:     /**
100:      * Config instance setter
101:      *
102:      * @param Mage_Paypal_Model_Config $instace
103:      * @param int $storeId
104:      */
105:     public function setConfig(Mage_Paypal_Model_Config $instace, $storeId = null)
106:     {
107:         $this->_config = $instace;
108:         if (null !== $storeId) {
109:             $this->_config->setStoreId($storeId);
110:         }
111:         return $this;
112:     }
113: 
114:     /**
115:      * Config instance getter
116:      *
117:      * @return Mage_Paypal_Model_Config
118:      */
119:     public function getConfig()
120:     {
121:         return $this->_config;
122:     }
123: 
124:     /**
125:      * API instance getter
126:      * Sets current store id to current config instance and passes it to API
127:      *
128:      * @return Mage_Paypal_Model_Api_Nvp
129:      */
130:     public function getApi()
131:     {
132:         if (null === $this->_api) {
133:             $this->_api = Mage::getModel($this->_apiType);
134:         }
135:         $this->_api->setConfigObject($this->_config);
136:         return $this->_api;
137:     }
138: 
139:     /**
140:      * Destroy existing NVP Api object
141:      *
142:      * @return Mage_Paypal_Model_Pro
143:      */
144:     public function resetApi()
145:     {
146:         $this->_api = null;
147: 
148:         return $this;
149:     }
150: 
151:     /**
152:      * Instantiate and return info model
153:      *
154:      * @return Mage_Paypal_Model_Info
155:      */
156:     public function getInfo()
157:     {
158:         if (null === $this->_infoInstance) {
159:             $this->_infoInstance = Mage::getModel('paypal/info');
160:         }
161:         return $this->_infoInstance;
162:     }
163: 
164:     /**
165:      * Transfer transaction/payment information from API instance to order payment
166:      *
167:      * @param Mage_Paypal_Model_Api_Abstract $from
168:      * @param Mage_Payment_Model_Info $to
169:      * @return Mage_Paypal_Model_Pro
170:      */
171:     public function importPaymentInfo(Varien_Object $from, Mage_Payment_Model_Info $to)
172:     {
173:         // update PayPal-specific payment information in the payment object
174:         $this->getInfo()->importToPayment($from, $to);
175: 
176:         /**
177:          * Detect payment review and/or frauds
178:          * PayPal pro API returns fraud results only in the payment call response
179:          */
180:         if ($from->getDataUsingMethod(Mage_Paypal_Model_Info::IS_FRAUD)) {
181:             $to->setIsTransactionPending(true);
182:             $to->setIsFraudDetected(true);
183:         } elseif ($this->getInfo()->isPaymentReviewRequired($to)) {
184:             $to->setIsTransactionPending(true);
185:         }
186: 
187:         // give generic info about transaction state
188:         if ($this->getInfo()->isPaymentSuccessful($to)) {
189:             $to->setIsTransactionApproved(true);
190:         } elseif ($this->getInfo()->isPaymentFailed($to)) {
191:             $to->setIsTransactionDenied(true);
192:         }
193: 
194:         return $this;
195:     }
196: 
197:     /**
198:      * Void transaction
199:      *
200:      * @param Varien_Object $payment
201:      */
202:     public function void(Varien_Object $payment)
203:     {
204:         if ($authTransactionId = $this->_getParentTransactionId($payment)) {
205:             $api = $this->getApi();
206:             $api->setPayment($payment)->setAuthorizationId($authTransactionId)->callDoVoid();
207:             $this->importPaymentInfo($api, $payment);
208:         } else {
209:             Mage::throwException(Mage::helper('paypal')->__('Authorization transaction is required to void.'));
210:         }
211:     }
212: 
213:     /**
214:      * Attempt to capture payment
215:      * Will return false if the payment is not supposed to be captured
216:      *
217:      * @param Varien_Object $payment
218:      * @param float $amount
219:      * @return false|null
220:      */
221:     public function capture(Varien_Object $payment, $amount)
222:     {
223:         $authTransactionId = $this->_getParentTransactionId($payment);
224:         if (!$authTransactionId) {
225:             return false;
226:         }
227:         $api = $this->getApi()
228:             ->setAuthorizationId($authTransactionId)
229:             ->setIsCaptureComplete($payment->getShouldCloseParentTransaction())
230:             ->setAmount($amount)
231:             ->setCurrencyCode($payment->getOrder()->getBaseCurrencyCode())
232:             ->setInvNum($payment->getOrder()->getIncrementId())
233:             // TODO: pass 'NOTE' to API
234:         ;
235: 
236:         $api->callDoCapture();
237:         $this->_importCaptureResultToPayment($api, $payment);
238:     }
239: 
240:     /**
241:      * Refund a capture transaction
242:      *
243:      * @param Varien_Object $payment
244:      * @param float $amount
245:      */
246:     public function refund(Varien_Object $payment, $amount)
247:     {
248:         $captureTxnId = $this->_getParentTransactionId($payment);
249:         if ($captureTxnId) {
250:             $api = $this->getApi();
251:             $order = $payment->getOrder();
252:             $api->setPayment($payment)
253:                 ->setTransactionId($captureTxnId)
254:                 ->setAmount($amount)
255:                 ->setCurrencyCode($order->getBaseCurrencyCode())
256:             ;
257:             $canRefundMore = $payment->getCreditmemo()->getInvoice()->canRefund();
258:             $isFullRefund = !$canRefundMore
259:                 && (0 == ((float)$order->getBaseTotalOnlineRefunded() + (float)$order->getBaseTotalOfflineRefunded()));
260:             $api->setRefundType($isFullRefund ? Mage_Paypal_Model_Config::REFUND_TYPE_FULL
261:                 : Mage_Paypal_Model_Config::REFUND_TYPE_PARTIAL
262:             );
263:             $api->callRefundTransaction();
264:             $this->_importRefundResultToPayment($api, $payment, $canRefundMore);
265:         } else {
266:             Mage::throwException(Mage::helper('paypal')->__('Impossible to issue a refund transaction because the capture transaction does not exist.'));
267:         }
268:     }
269: 
270:     /**
271:      * Cancel payment
272:      *
273:      * @param Varien_Object $payment
274:      */
275:     public function cancel(Varien_Object $payment)
276:     {
277:         if (!$payment->getOrder()->getInvoiceCollection()->count()) {
278:             $this->void($payment);
279:         }
280:     }
281: 
282:     /**
283:      *
284:      * @param Mage_Sales_Model_Order_Payment $payment
285:      * @return bool
286:      */
287:     public function canReviewPayment(Mage_Payment_Model_Info $payment)
288:     {
289:         return Mage_Paypal_Model_Info::isPaymentReviewRequired($payment);
290:     }
291: 
292:     /**
293:      * Perform the payment review
294:      *
295:      * @param Mage_Payment_Model_Info $payment
296:      * @param string $action
297:      * @return bool
298:      */
299:     public function reviewPayment(Mage_Payment_Model_Info $payment, $action)
300:     {
301:         $api = $this->getApi()->setTransactionId($payment->getLastTransId());
302: 
303:         // check whether the review is still needed
304:         $api->callGetTransactionDetails();
305:         $this->importPaymentInfo($api, $payment);
306:         if (!$this->getInfo()->isPaymentReviewRequired($payment)) {
307:             return false;
308:         }
309: 
310:         // perform the review action
311:         $api->setAction($action)->callManagePendingTransactionStatus();
312:         $api->callGetTransactionDetails();
313:         $this->importPaymentInfo($api, $payment);
314:         return true;
315:     }
316: 
317:     /**
318:      * Fetch transaction details info
319:      *
320:      * @param Mage_Payment_Model_Info $payment
321:      * @param string $transactionId
322:      * @return array
323:      */
324:     public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
325:     {
326:         $api = $this->getApi()
327:             ->setTransactionId($transactionId)
328:             ->setRawResponseNeeded(true);
329:         $api->callGetTransactionDetails();
330:         $this->importPaymentInfo($api, $payment);
331:         $data = $api->getRawSuccessResponseData();
332:         return ($data) ? $data : array();
333:     }
334: 
335:     /**
336:      * Validate RP data
337:      *
338:      * @param Mage_Payment_Model_Recurring_Profile $profile
339:      * @throws Mage_Core_Exception
340:      */
341:     public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
342:     {
343:         $errors = array();
344:         if (strlen($profile->getSubscriberName()) > 32) { // up to 32 single-byte chars
345:             $errors[] = Mage::helper('paypal')->__('Subscriber name is too long.');
346:         }
347:         $refId = $profile->getInternalReferenceId(); // up to 127 single-byte alphanumeric
348:         if (strlen($refId) > 127) { //  || !preg_match('/^[a-z\d\s]+$/i', $refId)
349:             $errors[] = Mage::helper('paypal')->__('Merchant reference ID format is not supported.');
350:         }
351:         $scheduleDescr = $profile->getScheduleDescription(); // up to 127 single-byte alphanumeric
352:         if (strlen($refId) > 127) { //  || !preg_match('/^[a-z\d\s]+$/i', $scheduleDescr)
353:             $errors[] = Mage::helper('paypal')->__('Schedule description is too long.');
354:         }
355:         if ($errors) {
356:             Mage::throwException(implode(' ', $errors));
357:         }
358:     }
359: 
360:     /**
361:      * Submit RP to the gateway
362:      *
363:      * @param Mage_Payment_Model_Recurring_Profile $profile
364:      * @param Mage_Payment_Model_Info $paymentInfo
365:      * @throws Mage_Core_Exception
366:      */
367:     public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
368:         Mage_Payment_Model_Info $paymentInfo
369:     ) {
370:         $api = $this->getApi();
371:         Varien_Object_Mapper::accumulateByMap($profile, $api, array(
372:             'token', // EC fields
373:             // TODO: DP fields
374:             // profile fields
375:             'subscriber_name', 'start_datetime', 'internal_reference_id', 'schedule_description',
376:             'suspension_threshold', 'bill_failed_later', 'period_unit', 'period_frequency', 'period_max_cycles',
377:             'billing_amount' => 'amount', 'trial_period_unit', 'trial_period_frequency', 'trial_period_max_cycles',
378:             'trial_billing_amount', 'currency_code', 'shipping_amount', 'tax_amount', 'init_amount', 'init_may_fail',
379:         ));
380:         $api->callCreateRecurringPaymentsProfile();
381:         $profile->setReferenceId($api->getRecurringProfileId());
382:         if ($api->getIsProfileActive()) {
383:             $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
384:         } elseif ($api->getIsProfilePending()) {
385:             $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_PENDING);
386:         }
387:     }
388: 
389:     /**
390:      * Fetch RP details
391:      *
392:      * @param string $referenceId
393:      * @param Varien_Object $result
394:      */
395:     public function getRecurringProfileDetails($referenceId, Varien_Object $result)
396:     {
397:         $api = $this->getApi();
398:         $api->setRecurringProfileId($referenceId)
399:             ->callGetRecurringPaymentsProfileDetails($result)
400:         ;
401:     }
402: 
403:     /**
404:      * Update RP data
405:      *
406:      * @param Mage_Payment_Model_Recurring_Profile $profile
407:      */
408:     public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
409:     {
410: 
411:     }
412: 
413:     /**
414:      * Manage status
415:      *
416:      * @param Mage_Payment_Model_Recurring_Profile $profile
417:      */
418:     public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
419:     {
420:         $api = $this->getApi();
421:         $action = null;
422:         switch ($profile->getNewState()) {
423:             case Mage_Sales_Model_Recurring_Profile::STATE_CANCELED: $action = 'cancel'; break;
424:             case Mage_Sales_Model_Recurring_Profile::STATE_SUSPENDED: $action = 'suspend'; break;
425:             case Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE: $action = 'activate'; break;
426:         }
427:         $state = $profile->getState();
428:         $api->setRecurringProfileId($profile->getReferenceId())
429:             ->setIsAlreadyCanceled($state == Mage_Sales_Model_Recurring_Profile::STATE_CANCELED)
430:             ->setIsAlreadySuspended($state == Mage_Sales_Model_Recurring_Profile::STATE_SUSPENDED)
431:             ->setIsAlreadyActive($state == Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE)
432:             ->setAction($action)
433:             ->callManageRecurringPaymentsProfileStatus()
434:         ;
435:     }
436: 
437:     /**
438:      * Import capture results to payment
439:      *
440:      * @param Mage_Paypal_Model_Api_Nvp
441:      * @param Mage_Sales_Model_Order_Payment
442:      */
443:     protected function _importCaptureResultToPayment($api, $payment)
444:     {
445:         $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(false);
446:         $this->importPaymentInfo($api, $payment);
447:     }
448: 
449:     /**
450:      * Import refund results to payment
451:      *
452:      * @param Mage_Paypal_Model_Api_Nvp
453:      * @param Mage_Sales_Model_Order_Payment
454:      * @param bool $canRefundMore
455:      */
456:     protected function _importRefundResultToPayment($api, $payment, $canRefundMore)
457:     {
458:         $payment->setTransactionId($api->getRefundTransactionId())
459:                 ->setIsTransactionClosed(1) // refund initiated by merchant
460:                 ->setShouldCloseParentTransaction(!$canRefundMore)
461:             ;
462:         $this->importPaymentInfo($api, $payment);
463:     }
464: 
465:     /**
466:      * Parent transaction id getter
467:      *
468:      * @param Varien_Object $payment
469:      * @return string
470:      */
471:     protected function _getParentTransactionId(Varien_Object $payment)
472:     {
473:         return $payment->getParentTransactionId();
474:     }
475: }
476: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0