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 Billing Agreement method
 29:  *
 30:  * @author Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Paypal_Model_Method_Agreement extends Mage_Sales_Model_Payment_Method_Billing_AgreementAbstract
 33:     implements Mage_Payment_Model_Billing_Agreement_MethodInterface
 34: {
 35:     /**
 36:      * Method code
 37:      *
 38:      * @var string
 39:      */
 40:     protected $_code = Mage_Paypal_Model_Config::METHOD_BILLING_AGREEMENT;
 41: 
 42:     /**
 43:      * Method instance settings
 44:      *
 45:      */
 46:     protected $_canAuthorize            = true;
 47:     protected $_canCapture              = true;
 48:     protected $_canCapturePartial       = true;
 49:     protected $_canRefund               = true;
 50:     protected $_canRefundInvoicePartial = true;
 51:     protected $_canVoid                 = true;
 52:     protected $_canUseCheckout          = false;
 53:     protected $_canUseInternal          = false;
 54:     protected $_canFetchTransactionInfo = true;
 55:     protected $_canReviewPayment        = true;
 56: 
 57:     /**
 58:      * Website Payments Pro instance
 59:      *
 60:      * @var Mage_Paypal_Model_Pro
 61:      */
 62:     protected $_pro = null;
 63: 
 64:     /**
 65:      * Initialize Mage_Paypal_Model_Pro model
 66:      *
 67:      * @param array $params
 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('paypal/pro');
 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:      * Init billing agreement
 98:      *
 99:      * @param Mage_Payment_Model_Billing_AgreementAbstract $agreement
100:      * @return Mage_Paypal_Model_Method_Agreement
101:      */
102:     public function initBillingAgreementToken(Mage_Payment_Model_Billing_AgreementAbstract $agreement)
103:     {
104:         $api = $this->_pro->getApi()
105:             ->setReturnUrl($agreement->getReturnUrl())
106:             ->setCancelUrl($agreement->getCancelUrl())
107:             ->setBillingType($this->_pro->getApi()->getBillingAgreementType());
108: 
109:         $api->callSetCustomerBillingAgreement();
110:         $agreement->setRedirectUrl(
111:             $this->_pro->getConfig()->getStartBillingAgreementUrl($api->getToken())
112:         );
113:         return $this;
114:     }
115: 
116:     /**
117:      * Retrieve billing agreement customer details by token
118:      *
119:      * @param Mage_Payment_Model_Billing_AgreementAbstract $agreement
120:      * @return array
121:      */
122:     public function getBillingAgreementTokenInfo(Mage_Payment_Model_Billing_AgreementAbstract $agreement)
123:     {
124:         $api = $this->_pro->getApi()
125:             ->setToken($agreement->getToken());
126:         $api->callGetBillingAgreementCustomerDetails();
127:         $responseData = array(
128:             'token'         => $api->getData('token'),
129:             'email'         => $api->getData('email'),
130:             'payer_id'      => $api->getData('payer_id'),
131:             'payer_status'  => $api->getData('payer_status')
132:         );
133:         $agreement->addData($responseData);
134:         return $responseData;
135:     }
136: 
137:     /**
138:      * Create billing agreement by token specified in request
139:      *
140:      * @param Mage_Payment_Model_Billing_AgreementAbstract $agreement
141:      * @return Mage_Paypal_Model_Method_Agreement
142:      */
143:     public function placeBillingAgreement(Mage_Payment_Model_Billing_AgreementAbstract $agreement)
144:     {
145:         $api = $this->_pro->getApi()
146:             ->setToken($agreement->getToken());
147:         $api->callCreateBillingAgreement();
148:         $agreement->setBillingAgreementId($api->getData('billing_agreement_id'));
149:         return $this;
150:     }
151: 
152:     /**
153:      * Update billing agreement status
154:      *
155:      * @param Mage_Payment_Model_Billing_AgreementAbstract $agreement
156:      * @return Mage_Paypal_Model_Method_Agreement
157:      */
158:     public function updateBillingAgreementStatus(Mage_Payment_Model_Billing_AgreementAbstract $agreement)
159:     {
160:         $targetStatus = $agreement->getStatus();
161:         $api = $this->_pro->getApi()
162:             ->setReferenceId($agreement->getReferenceId())
163:             ->setBillingAgreementStatus($targetStatus);
164:         try {
165:             $api->callUpdateBillingAgreement();
166:         } catch (Mage_Core_Exception $e) {
167:             // when BA was already canceled, just pretend that the operation succeeded
168:             if (!(Mage_Sales_Model_Billing_Agreement::STATUS_CANCELED == $targetStatus
169:                 && $api->getIsBillingAgreementAlreadyCancelled())) {
170:                 throw $e;
171:             }
172:         }
173:         return $this;
174:     }
175: 
176:     /**
177:      * Authorize payment
178:      *
179:      * @param Varien_Object $payment
180:      * @param float $amount
181:      * @return Mage_Paypal_Model_Method_Agreement
182:      */
183:     public function authorize(Varien_Object $payment, $amount)
184:     {
185:         return $this->_placeOrder($payment, $amount);
186:     }
187: 
188:     /**
189:      * Void payment
190:      *
191:      * @param Mage_Sales_Model_Order_Payment $payment
192:      * @return Mage_Paypal_Model_Method_Agreement
193:      */
194:     public function void(Varien_Object $payment)
195:     {
196:         $this->_pro->void($payment);
197:         return $this;
198:     }
199: 
200:     /**
201:      * Capture payment
202:      *
203:      * @param Mage_Sales_Model_Order_Payment $payment
204:      * @param float $amount
205:      * @return Mage_Paypal_Model_Method_Agreement
206:      */
207:     public function capture(Varien_Object $payment, $amount)
208:     {
209:         if (false === $this->_pro->capture($payment, $amount)) {
210:             $this->_placeOrder($payment, $amount);
211:         }
212:         return $this;
213:     }
214: 
215:     /**
216:      * Refund capture
217:      *
218:      * @param Mage_Sales_Model_Order_Payment $payment
219:      * @param float $amount
220:      * @return Mage_Paypal_Model_Method_Agreement
221:      */
222:     public function refund(Varien_Object $payment, $amount)
223:     {
224:         $this->_pro->refund($payment, $amount);
225:         return $this;
226:     }
227: 
228:     /**
229:      * Cancel payment
230:      *
231:      * @param Mage_Sales_Model_Order_Payment $payment
232:      * @return Mage_Paypal_Model_Method_Agreement
233:      */
234:     public function cancel(Varien_Object $payment)
235:     {
236:         $this->_pro->cancel($payment);
237:         return $this;
238:     }
239: 
240:     /**
241:      * Whether payment can be reviewed
242:      *
243:      * @param Mage_Sales_Model_Order_Payment $payment
244:      * @return bool
245:      */
246:     public function canReviewPayment(Mage_Payment_Model_Info $payment)
247:     {
248:         return parent::canReviewPayment($payment) && $this->_pro->canReviewPayment($payment);
249:     }
250: 
251:     /**
252:      * Attempt to accept a pending payment
253:      *
254:      * @param Mage_Sales_Model_Order_Payment $payment
255:      * @return bool
256:      */
257:     public function acceptPayment(Mage_Payment_Model_Info $payment)
258:     {
259:         parent::acceptPayment($payment);
260:         return $this->_pro->reviewPayment($payment, Mage_Paypal_Model_Pro::PAYMENT_REVIEW_ACCEPT);
261:     }
262: 
263:     /**
264:      * Attempt to deny a pending payment
265:      *
266:      * @param Mage_Sales_Model_Order_Payment $payment
267:      * @return bool
268:      */
269:     public function denyPayment(Mage_Payment_Model_Info $payment)
270:     {
271:         parent::denyPayment($payment);
272:         return $this->_pro->reviewPayment($payment, Mage_Paypal_Model_Pro::PAYMENT_REVIEW_DENY);
273:     }
274: 
275:     /**
276:      * Fetch transaction details info
277:      *
278:      * @param Mage_Payment_Model_Info $payment
279:      * @param string $transactionId
280:      * @return array
281:      */
282:     public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
283:     {
284:         return $this->_pro->fetchTransactionInfo($payment, $transactionId);
285:     }
286: 
287:     /**
288:      * Place an order with authorization or capture action
289:      *
290:      * @param Mage_Sales_Model_Order_Payment $payment
291:      * @param float $amount
292:      * @return Mage_Paypal_Model_Method_Agreement
293:      */
294:     protected function _placeOrder(Mage_Sales_Model_Order_Payment $payment, $amount)
295:     {
296:         $order = $payment->getOrder();
297:         $billingAgreement = Mage::getModel('sales/billing_agreement')->load(
298:             $payment->getAdditionalInformation(
299:                 Mage_Sales_Model_Payment_Method_Billing_AgreementAbstract::TRANSPORT_BILLING_AGREEMENT_ID
300:             )
301:         );
302: 
303:         $api = $this->_pro->getApi()
304:             ->setReferenceId($billingAgreement->getReferenceId())
305:             ->setPaymentAction($this->_pro->getConfig()->paymentAction)
306:             ->setAmount($amount)
307:             ->setNotifyUrl(Mage::getUrl('paypal/ipn/'))
308:             ->setPaypalCart(Mage::getModel('paypal/cart', array($order)))
309:             ->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled)
310:             ->setInvNum($order->getIncrementId())
311:         ;
312: 
313:         // call api and import transaction and other payment information
314:         $api->callDoReferenceTransaction();
315:         $this->_pro->importPaymentInfo($api, $payment);
316:         $api->callGetTransactionDetails();
317:         $this->_pro->importPaymentInfo($api, $payment);
318: 
319:         $payment->setTransactionId($api->getTransactionId())
320:             ->setIsTransactionClosed(0);
321: 
322:         if ($api->getBillingAgreementId()) {
323:             $order->addRelatedObject($billingAgreement);
324:             $billingAgreement->setIsObjectChanged(true);
325:             $billingAgreement->addOrderRelation($order);
326:         }
327: 
328:         return $this;
329:     }
330: 
331: 
332:     protected function _isAvailable($quote)
333:     {
334:         return $this->_pro->getConfig()->isMethodAvailable($this->_code);
335:     }
336: 
337:     /**
338:      * Payment action getter compatible with payment model
339:      *
340:      * @see Mage_Sales_Model_Payment::place()
341:      * @return string
342:      */
343:     public function getConfigPaymentAction()
344:     {
345:         return $this->_pro->getConfig()->getPaymentAction();
346:     }
347: 
348: }
349: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0