/**
  * Handle any risk decision returned from Braintree
  *
  * @param                $result
  * @param \Varien_Object $payment
  *
  * @return $this
  */
 protected function handleFraud($result, Varien_Object $payment)
 {
     // Verify we have risk data
     if (isset($result->transaction) && isset($result->transaction->riskData) && isset($result->transaction->riskData->decision)) {
         // If the decision is to review the payment mark the payment as such
         if ($result->transaction->riskData->decision == self::ADVANCED_FRAUD_REVIEW || $result->transaction->riskData->decision == self::ADVANCED_FRAUD_DECLINE) {
             // Mark the payment as pending
             $payment->setIsTransactionPending(true);
             // If the payment got marked as fraud/decline, we mark it as fraud
             if ($result->transaction->riskData->decision == self::ADVANCED_FRAUD_DECLINE) {
                 $payment->setIsFraudDetected(true);
             }
         }
     }
     return $this;
 }
 /**
  * Makes method specific manipulations after authorize/clone transaction success
  * 
  * @param Varien_Object $payment $payment
  * @param array $result
  */
 protected function _processMethodSpecificTransactionSuccess($payment, $result)
 {
     // Saving token if applicable, additional manipulations for multishipping
     if (isset($result->transaction->creditCard['token']) && $result->transaction->creditCard['token']) {
         $token = $result->transaction->creditCard['token'];
         $payment->setTransactionAdditionalInfo('token', $token);
         if ($payment->getIsMultishipping()) {
             if (!Mage::registry(self::REGISTER_NAME)) {
                 Mage::register(self::REGISTER_NAME, $token);
             }
             if (Mage::getSingleton('checkout/session')->getBraintreeDeleteCard() === true) {
                 Mage::getSingleton('checkout/session')->setBraintreeDeleteCard($token);
             }
         }
     }
     // Advanced fraud protection data
     if (isset($result->transaction->riskData) && $this->getConfigData('fraudprotection')) {
         $decision = $result->transaction->riskData->decision;
         $helper = Mage::helper('braintree_payments');
         if ($decision == self::RISK_DATA_NOT_EVALUATED || $decision == self::RISK_DATA_REVIEW) {
             $payment->setIsTransactionPending(true);
             $payment->setIsFraudDetected(true);
         } else {
             if ($decision == self::RISK_DATA_DECLINE) {
                 Braintree_Transaction::void($result->transaction->id);
                 throw new Mage_Payment_Model_Info_Exception($helper->__('Try another card'));
             }
         }
         $system = $this->getConfigData('kount_id') ? 'Kount' : $helper->__('Braintree Advanced Fraud Protection Tool');
         $id = '';
         if ($result->transaction->riskData->id) {
             $id = $helper->__(', ID is "%s"', $result->transaction->riskData->id);
         }
         $comment = $helper->__('Transaction was evaluated with %s: decision is "%s"', $system, $decision) . $id;
         $payment->getOrder()->addStatusHistoryComment($comment);
     }
 }
 /**
  * Authorize payment
  *
  * @param Mage_Sales_Model_Order_Payment | Mage_Sales_Model_Quote_Payment $payment
  * @param mixed $amount
  * @return Mage_Paypal_Model_Payflowlink
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     $txnId = $payment->getAdditionalInformation('authorization_id');
     /** @var $transaction Mage_Paypal_Model_Payment_Transaction */
     $transaction = Mage::getModel('paypal/payment_transaction');
     $transaction->loadByTxnId($txnId);
     $payment->setTransactionId($txnId)->setIsTransactionClosed(0);
     if ($payment->getAdditionalInformation('paypal_fraud_filters') !== null) {
         $payment->setIsTransactionPending(true);
         $payment->setIsFraudDetected(true);
     }
     if ($transaction->getId() && $payment->getAdditionalInformation('authorization_amount') != Mage_Paypal_Model_Config::AUTHORIZATION_AMOUNT_FULL) {
         $this->_addTransaction($payment, $txnId);
     }
     $this->_authorize($payment, $amount, $transaction, $txnId);
     if ($payment->getAdditionalInformation('authorization_amount') != Mage_Paypal_Model_Config::AUTHORIZATION_AMOUNT_FULL) {
         $payment->setParentTransactionId($txnId);
         parent::authorize($payment, $amount);
         if ($payment->getTransactionId()) {
             $payment->setAdditionalInformation('authorization_id', $payment->getTransactionId());
         }
     }
     $transaction->delete();
     return $this;
 }