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 Express Module
 30:  */
 31: class Mage_Paypal_Model_Express extends Mage_Payment_Model_Method_Abstract
 32:     implements Mage_Payment_Model_Recurring_Profile_MethodInterface
 33: {
 34:     protected $_code  = Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS;
 35:     protected $_formBlockType = 'paypal/express_form';
 36:     protected $_infoBlockType = 'paypal/payment_info';
 37: 
 38:     /**
 39:      * Website Payments Pro instance type
 40:      *
 41:      * @var $_proType string
 42:      */
 43:     protected $_proType = 'paypal/pro';
 44: 
 45:     /**
 46:      * Availability options
 47:      */
 48:     protected $_isGateway                   = false;
 49:     protected $_canOrder                    = true;
 50:     protected $_canAuthorize                = true;
 51:     protected $_canCapture                  = true;
 52:     protected $_canCapturePartial           = true;
 53:     protected $_canRefund                   = true;
 54:     protected $_canRefundInvoicePartial     = true;
 55:     protected $_canVoid                     = true;
 56:     protected $_canUseInternal              = false;
 57:     protected $_canUseCheckout              = true;
 58:     protected $_canUseForMultishipping      = false;
 59:     protected $_canFetchTransactionInfo     = true;
 60:     protected $_canCreateBillingAgreement   = true;
 61:     protected $_canReviewPayment            = true;
 62: 
 63:     /**
 64:      * Website Payments Pro instance
 65:      *
 66:      * @var Mage_Paypal_Model_Pro
 67:      */
 68:     protected $_pro = null;
 69: 
 70:     /**
 71:      * Payment additional information key for payment action
 72:      * @var string
 73:      */
 74:     protected $_isOrderPaymentActionKey = 'is_order_action';
 75: 
 76:     /**
 77:      * Payment additional information key for number of used authorizations
 78:      * @var string
 79:      */
 80:     protected $_authorizationCountKey = 'authorization_count';
 81: 
 82:     public function __construct($params = array())
 83:     {
 84:         $proInstance = array_shift($params);
 85:         if ($proInstance && ($proInstance instanceof Mage_Paypal_Model_Pro)) {
 86:             $this->_pro = $proInstance;
 87:         } else {
 88:             $this->_pro = Mage::getModel($this->_proType);
 89:         }
 90:         $this->_pro->setMethod($this->_code);
 91:     }
 92: 
 93:     /**
 94:      * Store setter
 95:      * Also updates store ID in config object
 96:      *
 97:      * @param Mage_Core_Model_Store|int $store
 98:      */
 99:     public function setStore($store)
100:     {
101:         $this->setData('store', $store);
102:         if (null === $store) {
103:             $store = Mage::app()->getStore()->getId();
104:         }
105:         $this->_pro->getConfig()->setStoreId(is_object($store) ? $store->getId() : $store);
106:         return $this;
107:     }
108: 
109:    /**
110:     * Can be used in regular checkout
111:     *
112:     * @return bool
113:     */
114:    public function canUseCheckout()
115:    {
116:        if (Mage::getStoreConfigFlag('payment/hosted_pro/active')
117:            && !Mage::getStoreConfigFlag('payment/hosted_pro/display_ec')
118:        ) {
119:            return false;
120:        }
121:        return parent::canUseCheckout();
122:    }
123: 
124:     /**
125:      * Whether method is available for specified currency
126:      *
127:      * @param string $currencyCode
128:      * @return bool
129:      */
130:     public function canUseForCurrency($currencyCode)
131:     {
132:         return $this->_pro->getConfig()->isCurrencyCodeSupported($currencyCode);
133:     }
134: 
135:     /**
136:      * Payment action getter compatible with payment model
137:      *
138:      * @see Mage_Sales_Model_Payment::place()
139:      * @return string
140:      */
141:     public function getConfigPaymentAction()
142:     {
143:         return $this->_pro->getConfig()->getPaymentAction();
144:     }
145: 
146:     /**
147:      * Check whether payment method can be used
148:      * @param Mage_Sales_Model_Quote
149:      * @return bool
150:      */
151:     public function isAvailable($quote = null)
152:     {
153:         if (parent::isAvailable($quote) && $this->_pro->getConfig()->isMethodAvailable()) {
154:             return true;
155:         }
156:         return false;
157:     }
158: 
159:     /**
160:      * Custom getter for payment configuration
161:      *
162:      * @param string $field
163:      * @param int $storeId
164:      * @return mixed
165:      */
166:     public function getConfigData($field, $storeId = null)
167:     {
168:         return $this->_pro->getConfig()->$field;
169:     }
170: 
171:     /**
172:      * Order payment
173:      *
174:      * @param Mage_Sales_Model_Order_Payment $payment
175:      * @param float $amount
176:      * @return Mage_Paypal_Model_Express
177:      */
178:     public function order(Varien_Object $payment, $amount)
179:     {
180:         $this->_placeOrder($payment, $amount);
181: 
182:         $payment->setAdditionalInformation($this->_isOrderPaymentActionKey, true);
183: 
184:         if ($payment->getIsFraudDetected()) {
185:             return $this;
186:         }
187: 
188:         $order = $payment->getOrder();
189:         $orderTransactionId = $payment->getTransactionId();
190: 
191:         $api = $this->_callDoAuthorize($amount, $payment, $payment->getTransactionId());
192: 
193:         $state  = Mage_Sales_Model_Order::STATE_PROCESSING;
194:         $status = true;
195: 
196:         $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
197:         if ($payment->getIsTransactionPending()) {
198:             $message = Mage::helper('paypal')->__('Ordering amount of %s is pending approval on gateway.', $formatedPrice);
199:             $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
200:         } else {
201:             $message = Mage::helper('paypal')->__('Ordered amount of %s.', $formatedPrice);
202:         }
203: 
204:         $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER, null, false, $message);
205: 
206:         $this->_pro->importPaymentInfo($api, $payment);
207: 
208:         if ($payment->getIsTransactionPending()) {
209:             $message = Mage::helper('paypal')->__('Authorizing amount of %s is pending approval on gateway.', $formatedPrice);
210:             $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
211:             if ($payment->getIsFraudDetected()) {
212:                 $status = Mage_Sales_Model_Order::STATUS_FRAUD;
213:             }
214:         } else {
215:             $message = Mage::helper('paypal')->__('Authorized amount of %s.', $formatedPrice);
216:         }
217: 
218:         $payment->resetTransactionAdditionalInfo();
219: 
220:         $payment->setTransactionId($api->getTransactionId());
221:         $payment->setParentTransactionId($orderTransactionId);
222: 
223:         $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, null, false,
224:             $message
225:         );
226: 
227:         $order->setState($state, $status);
228: 
229:         $payment->setSkipOrderProcessing(true);
230:         return $this;
231:     }
232: 
233:     /**
234:      * Authorize payment
235:      *
236:      * @param Mage_Sales_Model_Order_Payment $payment
237:      * @param float $amount
238:      * @return Mage_Paypal_Model_Express
239:      */
240:     public function authorize(Varien_Object $payment, $amount)
241:     {
242:         return $this->_placeOrder($payment, $amount);
243:     }
244: 
245:     /**
246:      * Void payment
247:      *
248:      * @param Mage_Sales_Model_Order_Payment $payment
249:      * @return Mage_Paypal_Model_Express
250:      */
251:     public function void(Varien_Object $payment)
252:     {
253:         //Switching to order transaction if needed
254:         if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)
255:             && !$payment->getVoidOnlyAuthorization()
256:         ) {
257:             $orderTransaction = $payment->lookupTransaction(
258:                 false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
259:             );
260:             if ($orderTransaction) {
261:                 $payment->setParentTransactionId($orderTransaction->getTxnId());
262:                 $payment->setTransactionId($orderTransaction->getTxnId() . '-void');
263:             }
264:         }
265:         $this->_pro->void($payment);
266:         return $this;
267:     }
268: 
269:     /**
270:      * Capture payment
271:      *
272:      * @param Mage_Sales_Model_Order_Payment $payment
273:      * @param float $amount
274:      * @return Mage_Paypal_Model_Express
275:      */
276:     public function capture(Varien_Object $payment, $amount)
277:     {
278:         $authorizationTransaction = $payment->getAuthorizationTransaction();
279:         $authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period')));
280:         $maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number')));
281:         $order = $payment->getOrder();
282:         $isAuthorizationCreated = false;
283: 
284:         if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
285:             $voided = false;
286:             if (!$authorizationTransaction->getIsClosed()
287:                 && $this->_isTransactionExpired($authorizationTransaction, $authorizationPeriod)
288:             ) {
289:                 //Save payment state and configure payment object for voiding
290:                 $isCaptureFinal = $payment->getShouldCloseParentTransaction();
291:                 $captureTrxId = $payment->getTransactionId();
292:                 $payment->setShouldCloseParentTransaction(false);
293:                 $payment->setParentTransactionId($authorizationTransaction->getTxnId());
294:                 $payment->unsTransactionId();
295:                 $payment->setVoidOnlyAuthorization(true);
296:                 $payment->void(new Varien_Object());
297: 
298:                 //Revert payment state after voiding
299:                 $payment->unsAuthorizationTransaction();
300:                 $payment->unsTransactionId();
301:                 $payment->setShouldCloseParentTransaction($isCaptureFinal);
302:                 $voided = true;
303:             }
304: 
305:             if ($authorizationTransaction->getIsClosed() || $voided) {
306:                 if ($payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) {
307:                     Mage::throwException(Mage::helper('paypal')->__('The maximum number of child authorizations is reached.'));
308:                 }
309:                 $api = $this->_callDoAuthorize(
310:                     $amount,
311:                     $payment,
312:                     $authorizationTransaction->getParentTxnId()
313:                 );
314: 
315:                 //Adding authorization transaction
316:                 $this->_pro->importPaymentInfo($api, $payment);
317:                 $payment->setTransactionId($api->getTransactionId());
318:                 $payment->setParentTransactionId($authorizationTransaction->getParentTxnId());
319:                 $payment->setIsTransactionClosed(false);
320: 
321:                 $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
322: 
323:                 if ($payment->getIsTransactionPending()) {
324:                     $message = Mage::helper('paypal')->__('Authorizing amount of %s is pending approval on gateway.', $formatedPrice);
325:                 } else {
326:                     $message = Mage::helper('paypal')->__('Authorized amount of %s.', $formatedPrice);
327:                 }
328: 
329:                 $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, null,
330:                     true, $message
331:                 );
332: 
333:                 $payment->setParentTransactionId($api->getTransactionId());
334:                 $isAuthorizationCreated = true;
335:             }
336:             //close order transaction if needed
337:             if ($payment->getShouldCloseParentTransaction()) {
338:                 $orderTransaction = $payment->lookupTransaction(
339:                     false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
340:                 );
341: 
342:                 if ($orderTransaction) {
343:                     $orderTransaction->setIsClosed(true);
344:                     $order->addRelatedObject($orderTransaction);
345:                 }
346:             }
347:         }
348: 
349:         if (false === $this->_pro->capture($payment, $amount)) {
350:             $this->_placeOrder($payment, $amount);
351:         }
352: 
353:         if ($isAuthorizationCreated && isset($transaction)) {
354:             $transaction->setIsClosed(true);
355:         }
356: 
357:         return $this;
358:     }
359: 
360:     /**
361:      * Refund capture
362:      *
363:      * @param Mage_Sales_Model_Order_Payment $payment
364:      * @param float $amount
365:      * @return Mage_Paypal_Model_Express
366:      */
367:     public function refund(Varien_Object $payment, $amount)
368:     {
369:         $this->_pro->refund($payment, $amount);
370:         return $this;
371:     }
372: 
373:     /**
374:      * Cancel payment
375:      *
376:      * @param Mage_Sales_Model_Order_Payment $payment
377:      * @return Mage_Paypal_Model_Express
378:      */
379:     public function cancel(Varien_Object $payment)
380:     {
381:         $this->void($payment);
382: 
383:         return $this;
384:     }
385: 
386:     /**
387:      * Whether payment can be reviewed
388:      *
389:      * @param Mage_Sales_Model_Order_Payment $payment
390:      * @return bool
391:      */
392:     public function canReviewPayment(Mage_Payment_Model_Info $payment)
393:     {
394:         return parent::canReviewPayment($payment) && $this->_pro->canReviewPayment($payment);
395:     }
396: 
397:     /**
398:      * Attempt to accept a pending payment
399:      *
400:      * @param Mage_Sales_Model_Order_Payment $payment
401:      * @return bool
402:      */
403:     public function acceptPayment(Mage_Payment_Model_Info $payment)
404:     {
405:         parent::acceptPayment($payment);
406:         return $this->_pro->reviewPayment($payment, Mage_Paypal_Model_Pro::PAYMENT_REVIEW_ACCEPT);
407:     }
408: 
409:     /**
410:      * Attempt to deny a pending payment
411:      *
412:      * @param Mage_Sales_Model_Order_Payment $payment
413:      * @return bool
414:      */
415:     public function denyPayment(Mage_Payment_Model_Info $payment)
416:     {
417:         parent::denyPayment($payment);
418:         return $this->_pro->reviewPayment($payment, Mage_Paypal_Model_Pro::PAYMENT_REVIEW_DENY);
419:     }
420: 
421:     /**
422:      * Checkout redirect URL getter for onepage checkout (hardcode)
423:      *
424:      * @see Mage_Checkout_OnepageController::savePaymentAction()
425:      * @see Mage_Sales_Model_Quote_Payment::getCheckoutRedirectUrl()
426:      * @return string
427:      */
428:     public function getCheckoutRedirectUrl()
429:     {
430:         return Mage::getUrl('paypal/express/start');
431:     }
432: 
433:     /**
434:      * Fetch transaction details info
435:      *
436:      * @param Mage_Payment_Model_Info $payment
437:      * @param string $transactionId
438:      * @return array
439:      */
440:     public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
441:     {
442:         return $this->_pro->fetchTransactionInfo($payment, $transactionId);
443:     }
444: 
445:     /**
446:      * Validate RP data
447:      *
448:      * @param Mage_Payment_Model_Recurring_Profile $profile
449:      */
450:     public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
451:     {
452:         return $this->_pro->validateRecurringProfile($profile);
453:     }
454: 
455:     /**
456:      * Submit RP to the gateway
457:      *
458:      * @param Mage_Payment_Model_Recurring_Profile $profile
459:      * @param Mage_Payment_Model_Info $paymentInfo
460:      */
461:     public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
462:         Mage_Payment_Model_Info $paymentInfo
463:     ) {
464:         $token = $paymentInfo->
465:             getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_TOKEN);
466:         $profile->setToken($token);
467:         $this->_pro->submitRecurringProfile($profile, $paymentInfo);
468:     }
469: 
470:     /**
471:      * Fetch RP details
472:      *
473:      * @param string $referenceId
474:      * @param Varien_Object $result
475:      */
476:     public function getRecurringProfileDetails($referenceId, Varien_Object $result)
477:     {
478:         return $this->_pro->getRecurringProfileDetails($referenceId, $result);
479:     }
480: 
481:     /**
482:      * Whether can get recurring profile details
483:      */
484:     public function canGetRecurringProfileDetails()
485:     {
486:         return true;
487:     }
488: 
489:     /**
490:      * Update RP data
491:      *
492:      * @param Mage_Payment_Model_Recurring_Profile $profile
493:      */
494:     public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
495:     {
496:         return $this->_pro->updateRecurringProfile($profile);
497:     }
498: 
499:     /**
500:      * Manage status
501:      *
502:      * @param Mage_Payment_Model_Recurring_Profile $profile
503:      */
504:     public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
505:     {
506:         return $this->_pro->updateRecurringProfileStatus($profile);
507:     }
508: 
509:     /**
510:      * Assign data to info model instance
511:      *
512:      * @param   mixed $data
513:      * @return  Mage_Payment_Model_Info
514:      */
515:     public function assignData($data)
516:     {
517:         $result = parent::assignData($data);
518:         $key = Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT;
519:         if (is_array($data)) {
520:             $this->getInfoInstance()->setAdditionalInformation($key, isset($data[$key]) ? $data[$key] : null);
521:         }
522:         elseif ($data instanceof Varien_Object) {
523:             $this->getInfoInstance()->setAdditionalInformation($key, $data->getData($key));
524:         }
525:         return $result;
526:     }
527: 
528:     /**
529:      * Place an order with authorization or capture action
530:      *
531:      * @param Mage_Sales_Model_Order_Payment $payment
532:      * @param float $amount
533:      * @return Mage_Paypal_Model_Express
534:      */
535:     protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
536:     {
537:         $order = $payment->getOrder();
538: 
539:         // prepare api call
540:         $token = $payment->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_TOKEN);
541:         $api = $this->_pro->getApi()
542:             ->setToken($token)
543:             ->setPayerId($payment->
544:                 getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID))
545:             ->setAmount($amount)
546:             ->setPaymentAction($this->_pro->getConfig()->paymentAction)
547:             ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
548:             ->setInvNum($order->getIncrementId())
549:             ->setCurrencyCode($order->getBaseCurrencyCode())
550:             ->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
551:             ->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled)
552:         ;
553:         if ($order->getIsVirtual()) {
554:             $api->setAddress($order->getBillingAddress())->setSuppressShipping(true);
555:         } else {
556:             $api->setAddress($order->getShippingAddress());
557:             $api->setBillingAddress($order->getBillingAddress());
558:         }
559: 
560:         // call api and get details from it
561:         $api->callDoExpressCheckoutPayment();
562: 
563:         $this->_importToPayment($api, $payment);
564:         return $this;
565:     }
566: 
567:     /**
568:      * Import payment info to payment
569:      *
570:      * @param Mage_Paypal_Model_Api_Nvp
571:      * @param Mage_Sales_Model_Order_Payment
572:      */
573:     protected function _importToPayment($api, $payment)
574:     {
575:         $payment->setTransactionId($api->getTransactionId())->setIsTransactionClosed(0)
576:             ->setAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT,
577:                 $api->getRedirectRequired()
578:             );
579: 
580:         if ($api->getBillingAgreementId()) {
581:             $payment->setBillingAgreementData(array(
582:                 'billing_agreement_id'  => $api->getBillingAgreementId(),
583:                 'method_code'           => Mage_Paypal_Model_Config::METHOD_BILLING_AGREEMENT
584:             ));
585:         }
586: 
587:         $this->_pro->importPaymentInfo($api, $payment);
588:     }
589: 
590:     /**
591:      * Check void availability
592:      *
593:      * @param   Varien_Object $payment
594:      * @return  bool
595:      */
596:     public function canVoid(Varien_Object $payment)
597:     {
598:         if ($payment instanceof Mage_Sales_Model_Order_Invoice
599:             || $payment instanceof Mage_Sales_Model_Order_Creditmemo
600:         ) {
601:             return false;
602:         }
603:         $info = $this->getInfoInstance();
604:         if ($info->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
605:             $orderTransaction = $info->lookupTransaction(
606:                 false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
607:             );
608:             if ($orderTransaction) {
609:                 $info->setParentTransactionId($orderTransaction->getTxnId());
610:             }
611:         }
612: 
613:         return $this->_canVoid;
614:     }
615: 
616:     /**
617:      * Check capture availability
618:      *
619:      * @return bool
620:      */
621:     public function canCapture()
622:     {
623:         $payment = $this->getInfoInstance();
624:         $this->_pro->getConfig()->setStoreId($payment->getOrder()->getStore()->getId());
625: 
626:         if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
627:             $orderTransaction = $payment->lookupTransaction(false,
628:                 Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER
629:             );
630:             if ($orderTransaction->getIsClosed()) {
631:                 return false;
632:             }
633: 
634:             $orderValidPeriod = abs(intval($this->getConfigData('order_valid_period')));
635: 
636:             $dateCompass = new DateTime($orderTransaction->getCreatedAt());
637:             $dateCompass->modify('+' . $orderValidPeriod . ' days');
638:             $currentDate = new DateTime();
639: 
640:             if ($currentDate > $dateCompass || $orderValidPeriod == 0) {
641:                 return false;
642:             }
643:         }
644:         return $this->_canCapture;
645:     }
646: 
647:     /**
648:      * Call DoAuthorize
649:      *
650:      * @param int $amount
651:      * @param Varien_Object $payment
652:      * @param string $parentTransactionId
653:      * @return Mage_Paypal_Model_Api_Abstract
654:      */
655:     protected function _callDoAuthorize($amount, $payment, $parentTransactionId)
656:     {
657:         $api = $this->_pro->resetApi()->getApi()
658:             ->setAmount($amount)
659:             ->setCurrencyCode($payment->getOrder()->getBaseCurrencyCode())
660:             ->setTransactionId($parentTransactionId)
661:             ->callDoAuthorization();
662: 
663:         $payment->setAdditionalInformation($this->_authorizationCountKey,
664:             $payment->getAdditionalInformation($this->_authorizationCountKey) + 1
665:         );
666: 
667:         return $api;
668:     }
669: 
670:     /**
671:      * Check transaction for expiration in PST
672:      *
673:      * @param Mage_Sales_Model_Order_Payment_Transaction $transaction
674:      * @param int $period
675:      * @return boolean
676:      */
677:     protected function _isTransactionExpired(Mage_Sales_Model_Order_Payment_Transaction $transaction, $period)
678:     {
679:         $period = intval($period);
680:         if (0 == $period) {
681:             return true;
682:         }
683: 
684:         $transactionClosingDate = new DateTime($transaction->getCreatedAt(), new DateTimeZone('GMT'));
685:         $transactionClosingDate->setTimezone(new DateTimeZone('US/Pacific'));
686:         /**
687:          * 11:49:00 PayPal transactions closing time
688:          */
689:         $transactionClosingDate->setTime(11, 49, 00);
690:         $transactionClosingDate->modify('+' . $period . ' days');
691: 
692:         $currentTime = new DateTime(null, new DateTimeZone('US/Pacific'));
693: 
694:         if ($currentTime > $transactionClosingDate) {
695:             return true;
696:         }
697: 
698:         return false;
699:     }
700: }
701: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0