public function getTransaction($transaction_id)
 {
     $transaction = Braintree_Transaction::submitForSettlement($transaction_id, $amount);
     if ($transaction) {
         return $transaction;
     } else {
         return false;
     }
 }
 public function getTransaction($transaction_id)
 {
     Braintree_Configuration::environment($this->session->userdata('environment'));
     Braintree_Configuration::merchantId($this->session->userdata('merchantId'));
     Braintree_Configuration::publicKey($this->session->userdata('publicKey'));
     Braintree_Configuration::privateKey($this->session->userdata('privateKey'));
     $transaction = Braintree_Transaction::submitForSettlement($transaction_id);
     if ($transaction) {
         return $transaction;
     } else {
         return false;
     }
 }
 function charge(&$order)
 {
     //create a code for the order
     if (empty($order->code)) {
         $order->code = $order->getRandomCode();
     }
     //what amount to charge?
     $amount = $order->InitialPayment;
     //tax
     $order->subtotal = $amount;
     $tax = $order->getTax(true);
     $amount = round((double) $order->subtotal + (double) $tax, 2);
     //create a customer
     $this->getCustomer($order);
     if (empty($this->customer)) {
         //failed to create customer
         return false;
     }
     //charge
     try {
         $response = Braintree_Transaction::sale(array('amount' => $amount, 'customerId' => $this->customer->id));
     } catch (Exception $e) {
         //$order->status = "error";
         $order->errorcode = true;
         $order->error = "Error: " . $e->getMessage();
         $order->shorterror = $order->error;
         return false;
     }
     if ($response->success) {
         //successful charge
         $transaction_id = $response->transaction->id;
         $response = Braintree_Transaction::submitForSettlement($transaction_id);
         if ($response->success) {
             $order->payment_transaction_id = $transaction_id;
             $order->updateStatus("success");
             return true;
         } else {
             $order->errorcode = true;
             $order->error = __("Error during settlement:", "pmpro") . " " . $response->message;
             $order->shorterror = $response->message;
             return false;
         }
     } else {
         //$order->status = "error";
         $order->errorcode = true;
         $order->error = __("Error during charge:", "pmpro") . " " . $response->message;
         $order->shorterror = $response->message;
         return false;
     }
 }
 /**
  * Submit a payment for settlement using the Braintree PHP SDK
  *
  * @param $transactionId
  * @param $amount
  *
  * @return object
  */
 public function submitForSettlement($transactionId, $amount)
 {
     // Attempt to submit for settlement
     $result = Braintree_Transaction::submitForSettlement($transactionId, $amount);
     return $result;
 }
Esempio n. 5
0
<?php

require 'template/header.php';
?>

<?php 
require 'credentials.php';
$id = $_GET['id'];
$method = $_GET['method'];
switch ($method) {
    case 'capture':
        $result = Braintree_Transaction::submitForSettlement($id);
        break;
    case 'void':
        $result = Braintree_Transaction::void($id);
        break;
    case 'refund':
        $result = Braintree_Transaction::refund($id);
        break;
    default:
        die('invalid request');
        break;
}
?>

<div class="page-header">
  <h1><?php 
echo $method . " " . $id;
?>
</h1>
</div>
 /**
  * @param string $transactionId
  * @param null|float $amount
  * @return \Braintree_Result_Successful|\Braintree_Result_Error
  */
 public function submitForSettlement($transactionId, $amount = null)
 {
     return \Braintree_Transaction::submitForSettlement($transactionId, $amount);
 }
 function testSubmitForSettlement_withAmount()
 {
     $transaction = Braintree_Transaction::saleNoValidate(array('amount' => '100.00', 'creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12')));
     $this->assertEquals(Braintree_Transaction::AUTHORIZED, $transaction->status);
     $submitResult = Braintree_Transaction::submitForSettlement($transaction->id, '50.00');
     $this->assertEquals(true, $submitResult->success);
     $this->assertEquals(Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT, $submitResult->transaction->status);
     $this->assertEquals('50.00', $submitResult->transaction->amount);
 }
Esempio n. 8
0
    echo '<input type="hidden" name="_act" value="find" />';
    echo '</br>Transaction ID: <input type="text" name="id" value="' . $result->transaction->_attributes['id'] . '" />';
    echo '</br><input type="submit" name="" value="Proceed to Find ID " />';
    echo "</form>";
    echo "--------------------------------------------------------------------------------------------------------------------------";
    echo "</br></br><form method='POST' action='createTrans.php'><h3>Proceed to clone for " . $result->transaction->_attributes['id'] . "</h3></br>";
    //echo "<a href='?_act=settlement&id=".$result -> transaction -> _attributes['id']."'>Do the settlement</a>";
    echo '<input type="hidden" name="_act" value="clone" />';
    echo '</br>Transaction ID: <input type="text" name="id" value="' . $result->transaction->_attributes['id'] . '" />';
    echo '</br><input type="submit" name="" value="Proceed to clone transaction " />';
    echo "</form>";
    echo "--------------------------------------------------------------------------------------------------------------------------";
    exit;
} else {
    if ($_POST['_act'] == 'settlement') {
        $result = Braintree_Transaction::submitForSettlement($_POST['id'], $_POST['amt']);
        echo "<div style='height:300px; overflow-y:scroll; background-color:#fff;'> <h3>API response</h3>";
        echo json_encode($result, JSON_PRETTY_PRINT);
        echo "</div>";
    } else {
        if ($_POST['_act'] == 'void') {
            $result = Braintree_Transaction::void($_POST['id']);
            print_r($result);
        } else {
            if ($_REQUEST['_act'] == 'refund') {
                echo "</br></br><form method='POST' action=''><h2>Proceed to refund</h2></br>";
                echo '<input type="hidden" name="_act" value="refund_process" />';
                echo '</br>Transaction ID: <input type="text" name="id" value="" />';
                echo '</br>Amount: <input type="text" name="amt" value="" />';
                echo '</br><input type="submit" name="" value="Proceed to Refund " />';
                echo "</form>";
 /**
  * Captures specified amount
  * 
  * @param Varien_Object $payment
  * @param decimal $amount
  * @return Braintree_Payments_Model_Paymentmethod
  */
 public function capture(Varien_Object $payment, $amount)
 {
     try {
         if ($payment->getCcTransId()) {
             $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->addFieldToFilter('payment_id', $payment->getId())->addFieldToFilter('txn_type', Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
             if ($collection->getSize() > 0) {
                 $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->addPaymentIdFilter($payment->getId())->addTxnTypeFilter(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH)->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC)->setOrder('transaction_id', Varien_Data_Collection::SORT_ORDER_DESC)->setPageSize(1)->setCurPage(1);
                 $authTransaction = $collection->getFirstItem();
                 if (!$authTransaction->getId()) {
                     Mage::throwException(Mage::helper('braintree_payments')->__('Please try again later'));
                 }
                 if ($token = $authTransaction->getAdditionalInformation('token')) {
                     //order was placed using saved card or card was saved during checkout token
                     $found = true;
                     try {
                         Braintree_PaymentMethod::find($token);
                     } catch (Exception $e) {
                         $found = false;
                     }
                     if ($found) {
                         $this->_initEnvironment($payment->getOrder()->getStoreId());
                         $this->_authorize($payment, $amount, true, $token);
                     } else {
                         // case if payment token is no more applicable. attempt to clone transaction
                         $result = $this->_cloneTransaction($amount, $authTransaction->getTxnId());
                         if ($result && $result->success) {
                             $payment = $this->_processSuccessResult($payment, $result, $amount);
                         } else {
                             if ($result === false) {
                                 Mage::throwException(Mage::helper('braintree_payments')->__('Please try again later'));
                             } else {
                                 Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result));
                             }
                         }
                     }
                 } else {
                     // order was placed without saved card and card wasn't saved during checkout
                     $result = $this->_cloneTransaction($amount, $authTransaction->getTxnId());
                     if ($result && $result->success) {
                         $payment = $this->_processSuccessResult($payment, $result, $amount);
                     } else {
                         if ($result === false) {
                             Mage::throwException(Mage::helper('braintree_payments')->__('Please try again later'));
                         } else {
                             Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result));
                         }
                     }
                 }
             } else {
                 $result = Braintree_Transaction::submitForSettlement($payment->getCcTransId(), $amount);
                 $this->_debug($payment->getCcTransId() . ' - ' . $amount);
                 $this->_debug($result);
                 if ($result->success) {
                     $payment->setIsTransactionClosed(0)->setAmountPaid($result->transaction->amount)->setShouldCloseParentTransaction(false);
                 } else {
                     Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result));
                 }
             }
         } else {
             $this->_authorize($payment, $amount, true);
         }
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('braintree_payments')->__('There was an error capturing the transaction.') . ' ' . $e->getMessage());
     }
     return $this;
 }
 /**
  * Updates an existing record via the API
  *
  * @param   object  $model
  * @param   array   $fields
  * @param   array   $values
  * @return  bool
  */
 public function update(Model $model, $fields = null, $values = null, $conditions = null)
 {
     $to_save = $this->_createSaveArray($fields, $values);
     if (!empty($to_save['id'])) {
         $model->id = $to_save['id'];
         unset($to_save['id']);
     }
     if (empty($model->id)) {
         false;
     }
     $entity = $this->_getModelEntity($model);
     try {
         switch ($entity) {
             case 'Customer':
                 $result = Braintree_Customer::update($model->id, $to_save);
                 break;
             case 'Transaction':
                 $transaction = $this->read($model, array('conditions' => array($model->alias . '.' . $model->primaryKey => $model->id)));
                 if (empty($transaction)) {
                     return false;
                 }
                 $exploded = explode('|', $model->id);
                 $braintree_transaction_id = isset($exploded[1]) ? $exploded[1] : $model->id;
                 if (!empty($to_save['status']) && $to_save['status'] == 'voided') {
                     if ($transaction[0][$model->alias]['status'] != 'authorized' && $transaction[0][$model->alias]['status'] != 'submitted_for_settlement') {
                         $this->showError(__('A transaction can only be VOIDED when the status is AUTHORIZED or SUBMITTED FOR SETTLEMENT.', true));
                         return false;
                     }
                     $result = Braintree_Transaction::void($braintree_transaction_id);
                     if (!$result->success) {
                         $this->showError($result->message);
                         return false;
                     }
                 } elseif (!empty($to_save['status']) && $to_save['status'] == 'submitted_for_settlement') {
                     if ($transaction[0][$model->alias]['status'] != 'authorized') {
                         $this->showError(__('A transaction can only be SUBMITTED FOR SETTLEMENT when the status is AUTHORIZED.', true));
                         return false;
                     }
                     if (!empty($to_save['amount'])) {
                         $result = Braintree_Transaction::submitForSettlement($braintree_transaction_id, $to_save['amount']);
                     } else {
                         $result = Braintree_Transaction::submitForSettlement($braintree_transaction_id);
                     }
                     if (!$result->success) {
                         $this->showError($result->message);
                         return false;
                     }
                 } else {
                     $this->showError(__('The only update that can be made to a transaction is a VOID.', true));
                     return false;
                 }
                 break;
             case 'CreditCard':
                 return false;
                 break;
             case 'Address':
                 return false;
                 break;
             default:
                 $result = false;
                 break;
         }
     } catch (Exception $e) {
         $this->showError(print_r($e, true));
         return false;
     }
     $success = $result->success;
     if (!$success) {
         return false;
     }
     return $success;
 }
 public function capture(Varien_Object $payment, $amount)
 {
     try {
         if ($payment->getCcTransId()) {
             $result = Braintree_Transaction::submitForSettlement($payment->getCcTransId(), $amount);
             if ($result->success) {
                 $payment->setIsTransactionClosed(0)->setAmountPaid($result->transaction->amount);
             } else {
                 Mage::throwException($result->message);
             }
         } else {
             $this->_authorize($payment, $amount, true);
         }
     } catch (Exception $e) {
         Mage::throwException(sprintf('There was an error capturing the transaction. (%s)', $e->getMessage()));
     }
     return $this;
 }