/**
  * Capture payment
  *
  * @param Mage_Sales_Model_Order_Payment $payment
  * @param float $amount
  * @return Mage_Paypal_Model_Express
  */
 public function capture(Varien_Object $payment, $amount)
 {
     $authorizationTransaction = $payment->getAuthorizationTransaction();
     $authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period')));
     $maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number')));
     $order = $payment->getOrder();
     $isAuthorizationCreated = false;
     if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
         $voided = false;
         if (!$authorizationTransaction->getIsClosed() && $this->_isTransactionExpired($authorizationTransaction, $authorizationPeriod)) {
             //Save payment state and configure payment object for voiding
             $isCaptureFinal = $payment->getShouldCloseParentTransaction();
             $captureTrxId = $payment->getTransactionId();
             $payment->setShouldCloseParentTransaction(false);
             $payment->setParentTransactionId($authorizationTransaction->getTxnId());
             $payment->unsTransactionId();
             $payment->setVoidOnlyAuthorization(true);
             $payment->void(new Varien_Object());
             //Revert payment state after voiding
             $payment->unsAuthorizationTransaction();
             $payment->unsTransactionId();
             $payment->setShouldCloseParentTransaction($isCaptureFinal);
             $voided = true;
         }
         if ($authorizationTransaction->getIsClosed() || $voided) {
             if ($payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) {
                 Mage::throwException(Mage::helper('paypal')->__('The maximum number of child authorizations is reached.'));
             }
             $api = $this->_callDoAuthorize($amount, $payment, $authorizationTransaction->getParentTxnId());
             //Adding authorization transaction
             $this->_pro->importPaymentInfo($api, $payment);
             $payment->setTransactionId($api->getTransactionId());
             $payment->setParentTransactionId($authorizationTransaction->getParentTxnId());
             $payment->setIsTransactionClosed(false);
             $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
             if ($payment->getIsTransactionPending()) {
                 $message = Mage::helper('paypal')->__('Authorizing amount of %s is pending approval on gateway.', $formatedPrice);
             } else {
                 $message = Mage::helper('paypal')->__('Authorized amount of %s.', $formatedPrice);
             }
             $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, null, true, $message);
             $payment->setParentTransactionId($api->getTransactionId());
             $isAuthorizationCreated = true;
         }
         //close order transaction if needed
         if ($payment->getShouldCloseParentTransaction()) {
             $orderTransaction = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER);
             if ($orderTransaction) {
                 $orderTransaction->setIsClosed(true);
                 $order->addRelatedObject($orderTransaction);
             }
         }
     }
     if (false === $this->_pro->capture($payment, $amount)) {
         $this->_placeOrder($payment, $amount);
     }
     if ($isAuthorizationCreated && isset($transaction)) {
         $transaction->setIsClosed(true);
     }
     return $this;
 }