public function refundTransaction($transaction_id, $amount)
 {
     $transaction = Braintree_Transaction::refund($transaction_id, $amount);
     if ($transaction) {
         return $transaction;
     } else {
         return false;
     }
 }
 /**
  * Refund transaction
  *
  * @param $transaction_id
  * @param null $amount
  * @param bool $void
  * @return object
  */
 public function refund($transaction_id, $amount = NULL, $void = TRUE)
 {
     //try void
     if ($void == TRUE) {
         $result = Braintree_Transaction::void($transaction_id);
         if ($result->success == TRUE) {
             return $result;
         }
     }
     //if already settled, do refund
     $result = Braintree_Transaction::refund($transaction_id, $amount);
     return $result;
 }
Exemplo n.º 3
0
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>

<div class="list-group">
Exemplo n.º 4
0
 public function refund($transaction_id, $amount = null)
 {
     return Braintree_Transaction::refund($transaction_id, $amount);
 }
 function testRefund_multiplePartialWithPayPal()
 {
     $nonce = Braintree_Test_Nonces::$paypalOneTimePayment;
     $transactionResult = Braintree_Transaction::sale(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce, 'options' => array('submitForSettlement' => true)));
     $this->assertTrue($transactionResult->success);
     $originalTransaction = $transactionResult->transaction;
     Braintree_TestHelper::settle($originalTransaction->id);
     $firstRefund = Braintree_Transaction::refund($transactionResult->transaction->id, $transactionResult->transaction->amount / 2);
     $this->assertTrue($firstRefund->success);
     $firstRefundTransaction = $firstRefund->transaction;
     $secondRefund = Braintree_Transaction::refund($transactionResult->transaction->id, $transactionResult->transaction->amount / 2);
     $this->assertTrue($secondRefund->success);
     $secondRefundTransaction = $secondRefund->transaction;
     $updatedOriginalTransaction = Braintree_Transaction::find($originalTransaction->id);
     $expectedRefundIds = array($secondRefundTransaction->id, $firstRefundTransaction->id);
     $updatedRefundIds = $updatedOriginalTransaction->refundIds;
     $this->assertTrue(in_array($expectedRefundIds[0], $updatedRefundIds));
     $this->assertTrue(in_array($expectedRefundIds[1], $updatedRefundIds));
 }
Exemplo n.º 6
0
 } 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>";
             echo "--------------------------------------------------------------------------------------------------------------------------";
         } else {
             if ($_REQUEST['_act'] == 'refund_process') {
                 $result = Braintree_Transaction::refund((string) $_POST['id'], (string) $_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>";
                 exit;
             } else {
                 if ($_POST['_act'] == 'find') {
                     $result = Braintree_Transaction::find($_POST['id']);
                     print_r($result);
                 } else {
                     if ($_POST['_act'] == 'clone') {
                         $result = Braintree_Transaction::cloneTransaction($_POST['id'], array('amount' => '10.00', 'options' => array('submitForSettlement' => true)));
                         print_r($result);
                     } else {
                         if ($_POST['_act'] == 'createCustomer') {
                             if (isset($_POST['data'])) {
Exemplo n.º 7
0
 /**
  * Refund specified amount for payment
  *
  * @param \Varien_Object $payment
  * @param float          $amount
  *
  * @return $this
  * @throws \Mage_Core_Exception
  */
 public function refund(Varien_Object $payment, $amount)
 {
     try {
         // Attempt to load the invoice
         /* @var $invoice Mage_Sales_Model_Order_Invoice */
         $invoice = $payment->getCreditmemo()->getInvoice();
         if (!$invoice) {
             Mage::throwException('Unable to load invoice from credit memo.');
         }
         // Init the environment
         $this->_getWrapper()->init($payment->getOrder()->getStoreId());
         // Convert the refund amount
         $refundAmount = $this->_getWrapper()->getCaptureAmount($payment->getOrder(), $amount);
         // Retrieve the transaction ID
         $transactionId = $this->_getWrapper()->getCleanTransactionId($invoice->getTransactionId());
         // Load the transaction from Braintree
         $transaction = Braintree_Transaction::find($transactionId);
         // If the transaction hasn't yet settled we can't do partial refunds
         if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             // If we're doing a partial refund and it's not settled it's a no go
             if ($transaction->amount != $refundAmount) {
                 Mage::throwException($this->_getHelper()->__('This transaction has not yet settled, please wait until the transaction has settled to process a partial refund.'));
             }
         }
         // Swap between refund and void
         $result = $transaction->status === Braintree_Transaction::SETTLED || $transaction->status == Braintree_Transaction::SETTLING || isset($transaction->paypal) && isset($transaction->paypal['paymentId']) && !empty($transaction->paypal['paymentId']) ? Braintree_Transaction::refund($transactionId, $refundAmount) : Braintree_Transaction::void($transactionId);
         // If it's a success close the transaction
         if ($result->success) {
             // Pass over the transaction ID
             $payment->getCreditmemo()->setRefundTransactionId($result->transaction->id);
             // Only close the transaction once the
             if ($transaction->amount == $refundAmount) {
                 $payment->setIsTransactionClosed(1);
                 // Mark the invoice as canceled if the invoice was completely refunded
                 $invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_CANCELED);
             }
         } else {
             if ($result->errors->deepSize() > 0) {
                 Mage::throwException($this->_getWrapper()->parseErrors($result->errors->deepAll()));
             } else {
                 Mage::throwException('An unknown error has occurred whilst trying to process the transaction');
             }
         }
     } catch (Exception $e) {
         Mage::throwException($this->_getHelper()->__('An error occurred whilst trying to process the refund: ') . $e->getMessage());
     }
     return $this;
 }
Exemplo n.º 8
0
 function testRefundWithUnsuccessfulPartialAmount()
 {
     $transaction = $this->createTransactionToRefund();
     $result = Braintree_Transaction::refund($transaction->id, '150.00');
     $this->assertFalse($result->success);
     $errors = $result->errors->forKey('transaction')->onAttribute('amount');
     $this->assertEquals(Braintree_Error_Codes::TRANSACTION_REFUND_AMOUNT_IS_TOO_LARGE, $errors[0]->code);
 }
 public function refund(Varien_Object $payment, $amount)
 {
     try {
         $transaction = Braintree_Transaction::find($payment->getCcTransId());
         if ($transaction->amount != $amount && $transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             Mage::throwException('This refund is for a partial amount but the Transaction has not settled.  Please wait 24 hours before trying to issue a partial refund.');
         }
         $result = $transaction->status === Braintree_Transaction::SETTLED ? Braintree_Transaction::refund($payment->getCcTransId(), $amount) : Braintree_Transaction::void($payment->getCcTransId());
         if ($result->success) {
             $payment->setIsTransactionClosed(1);
         } else {
             Mage::throwException($result->message);
         }
     } catch (Exception $e) {
         Mage::throwException(sprintf('There was an error refunding the transaction. (%s)', $e->getMessage()));
     }
     return $this;
 }
 /**
  * Creates a new record via the API
  *
  * @param   object  $model
  * @param   array   $fields
  * @param   array   $values
  * @return  bool
  */
 public function create(Model $model, $fields = null, $values = null)
 {
     $to_save = $this->_createSaveArray($fields, $values);
     if (!empty($model->id) && empty($return[$model->primaryKey])) {
         $to_save = array_merge(array($model->primaryKey => $model->id), $to_save);
     }
     $entity = $this->_getModelEntity($model);
     try {
         switch ($entity) {
             case 'Customer':
                 $result = Braintree_Customer::create($to_save);
                 if (!$result->success) {
                     $this->showError($result->message);
                     return false;
                 }
                 $id = $result->customer->id;
                 break;
             case 'Transaction':
                 unset($to_save['id']);
                 if (!empty($to_save['type']) && $to_save['type'] == 'credit') {
                     if (empty($to_save['braintreeTransactionId'])) {
                         $this->showError(__('A refundable transaction ID must be provided.', true));
                         return false;
                     }
                     $transaction_valid = $this->_checkTransaction($model, $to_save['braintreeTransactionId'], array('type' => 'sale', 'not_found_msg' => __('The transaction attempting to be refunded could not be found.', true), 'type_mismatch_msg' => __('The transaction attempting to be refunded is a credit, not a sale.', true)));
                     if (!$transaction_valid) {
                         return false;
                     }
                     $exploded = explode('|', $to_save['braintreeTransactionId']);
                     $braintree_transaction_id = isset($exploded[1]) ? $exploded[1] : $to_save['braintreeTransactionId'];
                     $result = Braintree_Transaction::refund($braintree_transaction_id, $to_save['amount']);
                 } elseif (!empty($to_save['type']) && $to_save['type'] == 'authorization') {
                     unset($to_save['type'], $to_save['braintreeTransactionId']);
                     $result = Braintree_Transaction::sale(array_merge(array('options' => array('submitForSettlement' => false)), $to_save));
                 } else {
                     // it's a a sale
                     unset($to_save['type'], $to_save['braintreeTransactionId']);
                     $result = Braintree_Transaction::sale(array_merge(array('options' => array('submitForSettlement' => true)), $to_save));
                 }
                 if (!$result->success) {
                     $this->showError($result->message);
                     return false;
                 }
                 $id = $result->transaction->id;
                 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;
     }
     $model->setInsertID($id);
     $model->id = $id;
     return true;
 }
 public function process_refund($order_id, $amount = null, $reason = '')
 {
     $order = new WC_Order($order_id);
     require_once 'includes/Braintree.php';
     Braintree_Configuration::environment($this->environment);
     Braintree_Configuration::merchantId($this->merchant_id);
     Braintree_Configuration::publicKey($this->public_key);
     Braintree_Configuration::privateKey($this->private_key);
     $transation_id = get_post_meta($order_id, 'wc_braintree_gateway_transaction_id', true);
     $result = Braintree_Transaction::refund($transation_id, $amount);
     if ($result->success) {
         $this->add_log(print_r($result, true));
         $max_remaining_refund = wc_format_decimal($order->get_total() - $amount);
         if (!$max_remaining_refund > 0) {
             $order->update_status('refunded');
         }
         if (ob_get_length()) {
             ob_end_clean();
         }
         return true;
     } else {
         $wc_message = apply_filters('wc_braintree_refund_message', $result->message, $result);
         $this->add_log(print_r($result, true));
         return new WP_Error('wc_braintree_gateway_refund-error', $wc_message);
     }
 }
Exemplo n.º 12
0
 /**
  * @param $transactionId
  *
  * @return array
  */
 public function voidTransaction($transactionId)
 {
     try {
         $transaction = \Braintree_Transaction::find($transactionId);
     } catch (\Exception $e) {
         return false;
     }
     if ($transaction) {
         if ($transaction->status == \Braintree_Transaction::AUTHORIZED || $transaction->status == \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             $result = \Braintree_Transaction::void($transactionId);
         } else {
             $result = \Braintree_Transaction::refund($transactionId);
         }
         if ($result->success == true) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 13
0
 function braintree_refund()
 {
     $result = Braintree_Transaction::refund('fbysy6');
     $result->success;
     # true
     print_r($result);
     exit;
     $refund = $result->transaction;
     $refund->type;
     # 'credit'
     $refund->refundedTransactionId;
     # original transaction ID
     Braintree_Transaction::find($transaction->id)->refundId;
     # ID of refund associated to a transaction, if any
     /* $result = Braintree_Customer::create(array(
       'creditCard' => array(
         'number' => '4111111111111111'
       )
     ));
     foreach($result->errors->deepAll() AS $error) {
       print_r($error->code . ": " . $error->message . "\n");
     } */
 }
Exemplo n.º 14
0
 function submitTransaction($request)
 {
     return Braintree_Transaction::refund($request);
 }
 /**
  * Refunds specified amount
  * 
  * @param Varien_Object $payment
  * @param decimal $amount
  * @return Braintree_Payments_Model_Paymentmethod
  */
 public function refund(Varien_Object $payment, $amount)
 {
     $transactionId = Mage::helper('braintree_payments')->clearTransactionId($payment->getRefundTransactionId());
     try {
         $transaction = Braintree_Transaction::find($transactionId);
         $this->_debug($payment->getCcTransId());
         $this->_debug($transaction);
         if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             if ($transaction->amount != $amount) {
                 Mage::throwException(Mage::helper('braintree_payments')->__('This refund is for a partial amount but the Transaction has not settled. ' . 'Please wait 24 hours before trying to issue a partial refund.'));
             } else {
                 Mage::throwException(Mage::helper('braintree_payments')->__('The Transaction has not settled. ' . 'Please wait 24 hours before trying to issue a refund or use Void option.'));
             }
         }
         if ($transaction->status === Braintree_Transaction::SETTLED || $transaction->status === Braintree_Transaction::SETTLING) {
             $result = Braintree_Transaction::refund($transactionId, $amount);
         } else {
             $result = Braintree_Transaction::void($transactionId);
         }
         $this->_debug($result);
         if ($result->success) {
             $payment->setIsTransactionClosed(1);
         } else {
             Mage::throwException(Mage::helper('braintree_payments/error')->parseBraintreeError($result));
         }
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('braintree_payments')->__('There was an error refunding the transaction.') . ' ' . $e->getMessage());
     }
     return $this;
 }
 function test_multipleValueNode_type_withRefund()
 {
     $customer = Braintree_Customer::createNoValidate();
     $creditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Joe Everyman' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard;
     $sale = Braintree_Transaction::saleNoValidate(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodToken' => $creditCard->token, 'options' => array('submitForSettlement' => true)));
     Braintree_Http::put('/transactions/' . $sale->id . '/settle');
     $refund = Braintree_Transaction::refund($sale->id)->transaction;
     $credit = Braintree_Transaction::creditNoValidate(array('amount' => '100.00', 'paymentMethodToken' => $creditCard->token));
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::type()->is($credit->type), Braintree_TransactionSearch::refund()->is(True)));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($refund->id, $collection->firstItem()->id);
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::type()->is($credit->type), Braintree_TransactionSearch::refund()->is(False)));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($credit->id, $collection->firstItem()->id);
 }
Exemplo n.º 17
0
 public function refundReward($id)
 {
     /*if (!$this->request->is('post')) {
           throw new NotFoundException(__d('billing', 'Incorrect request type'));
       }*/
     $this->loadModel('InvestSponsor');
     $this->InvestSponsor->Behaviors->load('Containable');
     $sponsor = $this->InvestSponsor->find('first', array('fields' => array('InvestSponsor.*', 'InvestReward.*', 'InvestProject.user_id'), 'contain' => array('InvestReward', 'InvestProject'), 'conditions' => array('InvestSponsor.id' => $id)));
     if (!empty($sponsor)) {
         throw new NotFoundException('Could not find funds transfer');
     }
     if (!in_array($this->currUserID, array($sponsor['InvestSponsor']['user_id'], $sponsor['InvestProject']['user_id']))) {
         throw new NotFoundException('Could not find funds transfer');
     }
     if (!empty($sponsor['InvestSponsor']['remote_transaction_id'])) {
         $transaction = Braintree_Transaction::find($sponsor['InvestSponsor']['remote_transaction_id']);
         if (!$transaction) {
             throw new NotFoundException('Could not find your funds transfer');
         }
         if ($transaction->status == Braintree_Transaction::SETTLED || $transaction->status == Braintree_Transaction::SETTLING) {
             $result = Braintree_Transaction::refund($transaction->id);
         } else {
             $result = Braintree_Transaction::void($transaction->id);
         }
         //TODO: little buggy cancelation
         if ($result->success || $transaction->status) {
             $this->InvestSponsor->id = $id;
             $this->InvestSponsor->saveField('canceled', 1);
         }
     }
     $this->redirect(array('action' => 'view', $sponsor['InvestReward']['project_id']));
 }