Mage_Sales_Model_Order_Payment Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Payment:

Mage_Payment_Model_Info Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 setOrder (Mage_Sales_Model_Order $order)
 getOrder ()
 canCapture ()
 canRefund ()
 canRefundPartialPerInvoice ()
 canCapturePartial ()
 place ()
 capture ($invoice)
 pay ($invoice)
 cancelInvoice ($invoice)
 canVoid (Varien_Object $document)
 void (Varien_Object $document)
 refund ($creditmemo)
 cancelCreditmemo ($creditmemo)
 cancel ()

Protected Member Functions

 _construct ()
 _invoice ()

Protected Attributes

 $_order


Detailed Description

Order payment information

Definition at line 30 of file Payment.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resource model

Reimplemented from Varien_Object.

Definition at line 42 of file Payment.php.

00043     {
00044         $this->_init('sales/order_payment');
00045     }

_invoice (  )  [protected]

Create new invoice with maximum qty for invoice for each item register this invoice and capture

Returns:
Mage_Sales_Model_Order_Invoice

Definition at line 259 of file Payment.php.

00260     {
00261         $invoice = $this->getOrder()->prepareInvoice();
00262 
00263         $invoice->register();
00264         if ($this->getMethodInstance()->canCapture()) {
00265             $invoice->capture();
00266         }
00267 
00268         $this->getOrder()->addRelatedObject($invoice);
00269         return $invoice;
00270     }

canCapture (  ) 

Check order payment capture action availability

Returns:
unknown

Todo:
checking amounts

Definition at line 74 of file Payment.php.

00075     {
00076         /**
00077          * @todo checking amounts
00078          */
00079         return $this->getMethodInstance()->canCapture();
00080     }

canCapturePartial (  ) 

Definition at line 92 of file Payment.php.

00093     {
00094         return $this->getMethodInstance()->canCapturePartial();
00095     }

cancel (  ) 

Definition at line 331 of file Payment.php.

00332     {
00333         $this->getMethodInstance()
00334             ->setStore($this->getOrder()->getStoreId())
00335             ->cancel($this);
00336 
00337         Mage::dispatchEvent('sales_order_payment_cancel', array('payment' => $this));
00338 
00339         return $this;
00340     }

cancelCreditmemo ( creditmemo  ) 

Definition at line 318 of file Payment.php.

00319     {
00320         $this->setAmountRefunded($this->getAmountRefunded()-$creditmemo->getGrandTotal());
00321         $this->setBaseAmountRefunded($this->getBaseAmountRefunded()-$creditmemo->getBaseGrandTotal());
00322 
00323         $this->setShippingRefunded($this->getShippingRefunded()-$creditmemo->getShippingAmount());
00324         $this->setBaseShippingRefunded($this->getBaseShippingRefunded()-$creditmemo->getBaseShippingAmount());
00325 
00326         Mage::dispatchEvent('sales_order_payment_cancel_creditmemo', array('payment' => $this, 'creditmemo' => $creditmemo));
00327 
00328         return $this;
00329     }

cancelInvoice ( invoice  ) 

Cancel invoice

Parameters:
unknown_type $invoice
Returns:
unknown

Definition at line 240 of file Payment.php.

00241     {
00242         $this->setAmountPaid($this->getAmountPaid()-$invoice->getGrandTotal());
00243         $this->setBaseAmountPaid($this->getBaseAmountPaid()-$invoice->getBaseGrandTotal());
00244 
00245         $this->setShippingCaptured($this->getShippingCaptured()-$invoice->getShippingAmount());
00246         $this->setBaseShippingCaptured($this->getBaseShippingCaptured()-$invoice->getBaseShippingAmount());
00247 
00248         Mage::dispatchEvent('sales_order_payment_cancel_invoice', array('payment' => $this, 'invoice' => $invoice));
00249 
00250         return $this;
00251     }

canRefund (  ) 

Definition at line 82 of file Payment.php.

00083     {
00084         return $this->getMethodInstance()->canRefund();
00085     }

canRefundPartialPerInvoice (  ) 

Definition at line 87 of file Payment.php.

00088     {
00089         return $this->getMethodInstance()->canRefundPartialPerInvoice();
00090     }

canVoid ( Varien_Object document  ) 

Check order payment void availability

Returns:
bool

Definition at line 277 of file Payment.php.

00278     {
00279         return $this->getMethodInstance()->canVoid($document);
00280     }

capture ( invoice  ) 

Capture payment

Returns:
Mage_Sales_Model_Order_Payment

Definition at line 199 of file Payment.php.

00200     {
00201         if (is_null($invoice)) {
00202             $invoice = $this->_invoice();
00203         }
00204 
00205         Mage::dispatchEvent('sales_order_payment_capture', array('payment' => $this, 'invoice' => $invoice));
00206 
00207         $this->getMethodInstance()
00208             ->setStore($this->getOrder()->getStoreId())
00209             ->capture($this, sprintf('%.2f', $invoice->getBaseGrandTotal()));
00210         $this->getMethodInstance()->processInvoice($invoice, $this);
00211         return $this;
00212     }

getOrder (  ) 

Retrieve order model object

Returns:
Mage_Sales_Model_Order

Definition at line 64 of file Payment.php.

00065     {
00066         return $this->_order;
00067     }

pay ( invoice  ) 

Register payment fact

Parameters:
unknown_type $invoice
Returns:
unknown

Definition at line 221 of file Payment.php.

00222     {
00223         $this->setAmountPaid($this->getAmountPaid()+$invoice->getGrandTotal());
00224         $this->setBaseAmountPaid($this->getBaseAmountPaid()+$invoice->getBaseGrandTotal());
00225 
00226         $this->setShippingCaptured($this->getShippingCaptured()+$invoice->getShippingAmount());
00227         $this->setBaseShippingCaptured($this->getBaseShippingCaptured()+$invoice->getBaseShippingAmount());
00228 
00229         Mage::dispatchEvent('sales_order_payment_pay', array('payment' => $this, 'invoice' => $invoice));
00230 
00231         return $this;
00232     }

place (  ) 

Place payment information

This method is called when order will be placed

Returns:
Mage_Sales_Model_Order_Payment

validating payment method again

Run action declared for payment method in configuration

Change order status if it specified

Definition at line 104 of file Payment.php.

00105     {
00106         Mage::dispatchEvent('sales_order_payment_place_start', array('payment' => $this));
00107 
00108         $this->setAmountOrdered($this->getOrder()->getTotalDue());
00109         $this->setBaseAmountOrdered($this->getOrder()->getBaseTotalDue());
00110 
00111         $this->setShippingAmount($this->getOrder()->getShippingAmount());
00112         $this->setBaseShippingAmount($this->getOrder()->getBaseShippingAmount());
00113 
00114         $methodInstance = $this->getMethodInstance()->setStore($this->getOrder()->getStoreId());
00115 
00116         $orderState = Mage_Sales_Model_Order::STATE_NEW;
00117         $orderStatus= false;
00118 
00119         $stateObject = new Varien_Object();
00120 
00121         /**
00122          * validating payment method again
00123          */
00124         $methodInstance->validate();
00125         if ($action = $methodInstance->getConfigData('payment_action')) {
00126             /**
00127              * Run action declared for payment method in configuration
00128              */
00129 
00130             if ($methodInstance->isInitializeNeeded()) {
00131                 $methodInstance->initialize($action, $stateObject);
00132             } else {
00133                 switch ($action) {
00134                     case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
00135                     case Mage_Paypal_Model_Api_Abstract::PAYMENT_TYPE_AUTH:
00136                         $methodInstance->authorize($this, $this->getOrder()->getBaseTotalDue());
00137 
00138                         $this->setAmountAuthorized($this->getOrder()->getTotalDue());
00139                         $this->setBaseAmountAuthorized($this->getOrder()->getBaseTotalDue());
00140 
00141                         $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
00142                         break;
00143                     case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
00144                     case Mage_Paypal_Model_Api_Abstract::PAYMENT_TYPE_SALE:
00145                         $invoice = $this->_invoice();
00146 
00147                         $this->setAmountAuthorized($this->getOrder()->getTotalDue());
00148                         $this->setBaseAmountAuthorized($this->getOrder()->getBaseTotalDue());
00149 
00150                         $orderState = Mage_Sales_Model_Order::STATE_PROCESSING;
00151                         break;
00152                     default:
00153                         break;
00154                 }
00155             }
00156         }
00157 
00158         $orderIsNotified = null;
00159         if ($stateObject->getState() && $stateObject->getStatus()) {
00160             $orderState      = $stateObject->getState();
00161             $orderStatus     = $stateObject->getStatus();
00162             $orderIsNotified = $stateObject->getIsNotified();
00163         } else {
00164             /*
00165              * this flag will set if the order went to as authorization under fraud service for payflowpro
00166              */
00167             if ($this->getFraudFlag()) {
00168                 $orderStatus = $methodInstance->getConfigData('fraud_order_status');
00169                 $orderState = Mage_Sales_Model_Order::STATE_HOLDED;
00170             } else {
00171                 /**
00172                  * Change order status if it specified
00173                  */
00174                 $orderStatus = $methodInstance->getConfigData('order_status');
00175             }
00176 
00177             if (!$orderStatus) {
00178                 $orderStatus = $this->getOrder()->getConfig()->getStateDefaultStatus($orderState);
00179             }
00180         }
00181 
00182         $this->getOrder()->setState($orderState);
00183         $this->getOrder()->addStatusToHistory(
00184             $orderStatus,
00185             $this->getOrder()->getCustomerNote(),
00186             (null !== $orderIsNotified ? $orderIsNotified : $this->getOrder()->getCustomerNoteNotify())
00187         );
00188 
00189         Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
00190 
00191         return $this;
00192     }

refund ( creditmemo  ) 

Definition at line 295 of file Payment.php.

00296     {
00297         if ($this->getMethodInstance()->canRefund() && $creditmemo->getDoTransaction()) {
00298             $this->setCreditmemo($creditmemo);
00299             if ($creditmemo->getInvoice()) {
00300                 $this->getMethodInstance()->setStore($this->getOrder()->getStoreId());
00301                 $this->getMethodInstance()->processBeforeRefund($creditmemo->getInvoice(), $this);
00302                 $this->getMethodInstance()->refund($this, $creditmemo->getBaseGrandTotal());
00303                 $this->getMethodInstance()->processCreditmemo($creditmemo, $this);
00304             }
00305         }
00306 
00307         $this->setAmountRefunded($this->getAmountRefunded()+$creditmemo->getGrandTotal());
00308         $this->setBaseAmountRefunded($this->getBaseAmountRefunded()+$creditmemo->getBaseGrandTotal());
00309 
00310         $this->setShippingRefunded($this->getShippingRefunded()+$creditmemo->getShippingAmount());
00311         $this->setBaseShippingRefunded($this->getBaseShippingRefunded()+$creditmemo->getBaseShippingAmount());
00312 
00313         Mage::dispatchEvent('sales_order_payment_refund', array('payment' => $this, 'creditmemo' => $creditmemo));
00314 
00315         return $this;
00316     }

setOrder ( Mage_Sales_Model_Order order  ) 

Declare order model object

Parameters:
Mage_Sales_Model_Order $order
Returns:
Mage_Sales_Model_Order_Payment

Definition at line 53 of file Payment.php.

00054     {
00055         $this->_order = $order;
00056         return $this;
00057     }

void ( Varien_Object document  ) 

Definition at line 282 of file Payment.php.

00283     {
00284         $this->getMethodInstance()
00285             ->setStore($this->getOrder()->getStoreId())
00286             ->processBeforeVoid($document, $this);
00287         //$this->getMethodInstance()->void($document);
00288         $this->getMethodInstance()->void($this);
00289 
00290         Mage::dispatchEvent('sales_order_payment_void', array('payment' => $this, 'invoice' => $document));
00291 
00292         return $this;
00293     }


Member Data Documentation

$_order [protected]

Definition at line 37 of file Payment.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:47 2009 for Magento by  doxygen 1.5.8