public function searchTransactions() { $transactions = Braintree_Transaction::search($data); if ($transactions) { return $transactions; } else { return false; } }
/** * Prepare the collection for the report * * @return $this|Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { // Add in a new collection $collection = new Varien_Data_Collection(); // Init the wrapper $wrapper = Mage::getModel('gene_braintree/wrapper_braintree'); // Validate the credentials if ($wrapper->validateCredentials()) { // Grab all transactions $transactions = Braintree_Transaction::search($this->_prepareBraintreeSearchQuery()); // Retrieve the order IDs $orderIds = array(); /* @var $transaction Braintree_Transaction */ foreach ($transactions as $transaction) { $orderIds[] = $transaction->orderId; } // Retrieve all of the orders from a collection $orders = Mage::getResourceModel('sales/order_collection')->addAttributeToFilter('increment_id', array('in' => $orderIds)); /* @var $transaction Braintree_Transaction */ foreach ($transactions as $transaction) { // Create a new varien object $transactionItem = new Varien_Object(); $transactionItem->setData((array) $transaction->_attributes); // Grab the Magento order from the previously built collection /* @var $magentoOrder Mage_Sales_Model_Order */ $magentoOrder = $orders->getItemByColumnValue('increment_id', $transaction->orderId); // Set the Magento Order ID into the collection // Not all transactions maybe coming from Magento if ($magentoOrder && $magentoOrder->getId()) { $transactionItem->setMagentoOrderId($magentoOrder->getId()); $transactionItem->setOrderStatus($magentoOrder->getStatus()); } else { $transactionItem->setOrderStatus('<em>Unknown</em>'); } // Add the item into the collection $collection->addItem($transactionItem); } } else { // If the Braintree details aren't valid take them to the configuration page Mage::getSingleton('adminhtml/session')->addError(Mage::helper('gene_braintree')->__('You must enter valid details into the Braintree v.zero - Configuration payment method before viewing transactions.')); // Send the users on their way Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('/system_config/edit/section/payment') . '#payment_gene_braintree-head'); Mage::app()->getResponse()->sendResponse(); // Stop processing this method return false; } $this->setCollection($collection); parent::_prepareCollection(); return $this; }
public function subscriptions() { /* //test for members operate after subscription change $this->BillingSubscription->Behaviors->load('Billing.Limitable', array( 'remoteModel' => 'GroupLimit', 'remoteField' => 'members_limit', 'scope' => 'owner_id', )); $this->BillingSubscription->membersOperate(71); exit(); */ $this->layout = 'profile_new'; $this->BillingSubscription->recursive = -1; $subscriptions = $this->BillingSubscription->find('all', array('conditions' => array('BillingSubscription.user_id' => $this->currUser['User']['id'], 'BillingSubscription.active' => true))); //maybe buggy foreach ($subscriptions as $key => $subscription) { if (isset($subscription['BraintreeSubscription']->status) && $subscription['BraintreeSubscription']->status == 'Canceled') { unset($subscriptions[$key]); $sameGroupCount = Hash::extract($subscriptions, "{n}.BillingSubscription[group_id=" . $subscription['BillingSubscription']['group_id'] . "]"); if (count($sameGroupCount) > 0) { $this->BillingSubscription->cancel($subscription['BillingSubscription']['id']); } } else { $this->BillingGroup->recursive = -1; $this->BillingGroup->unbindTranslations(); $subscriptions[$key] = Hash::merge($subscriptions[$key], $this->BillingGroup->find('first', array('conditions' => array('BillingGroup.id' => $subscription['BillingSubscription']['group_id']), 'callbacks' => false))); $this->BillingPlan->recursive = -1; $this->BillingPlan->unbindTranslations(); $billingPlans = $this->BillingPlan->find('first', array('conditions' => array('BillingPlan.id' => $subscription['BillingSubscription']['plan_id']))); unset($billingPlans['BraintreePlan']); $subscriptions[$key] = Hash::merge($subscriptions[$key], $billingPlans); } } $this->BillingPlan->recursive = 0; $plans = $this->BillingPlan->find('all'); foreach ($plans as $plan) { $subscribedInGroup = Hash::extract($subscriptions, "{n}.BillingSubscription[group_id=" . $plan['BillingPlan']['group_id'] . "]"); if ($plan['BillingPlan']['free'] == true && empty($subscribedInGroup)) { $subscriptions[] = Hash::merge(array('BillingSubscription' => array('group_id' => $plan['BillingPlan']['group_id'], 'plan_id' => $plan['BillingPlan']['id'], 'user_id' => $this->currUser['User']['id'], 'remote_subscription_id' => null, 'remote_plan_id' => null, 'limit_value' => $plan['BillingPlan']['limit_value'], 'active' => true, 'status' => 'Active', 'expires' => null, 'created' => $this->currUser['User']['created'], 'modified' => $this->currUser['User']['modified'])), $plan); } } $subscriptions = Hash::sort($subscriptions, '{n}.BillingSubscription.group_id', 'asc'); $transactions = Braintree_Transaction::search([Braintree_TransactionSearch::customerId()->is('konstruktor-' . $this->currUser['User']['id'])]); $this->set(compact('subscriptions', 'transactions', 'plans')); }
<?php date_default_timezone_set('America/Chicago'); require_once 'lib/Braintree.php'; Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('5xwqxqd7pkqwxfjs'); Braintree_Configuration::publicKey('8pfkt34wzyvrnnwy'); Braintree_Configuration::privateKey('8b63a0ae59085a11912527848633b848'); $output = fopen('transaction_report.csv', 'w'); fputcsv($output, ['id', 'type', 'amount', 'status', 'created_at', 'service_fee_amount', 'merchant_account_id']); $now = new DateTime(); $yesterday = $now->modify('-365 day'); $transactions = Braintree_Transaction::search([Braintree_TransactionSearch::settledAt()->greaterThanOrEqualTo($yesterday)]); foreach ($transactions as $transaction) { $id = $transaction->id; $type = $transaction->type; $amount = $transaction->amount; $status = $transaction->status; $createdAt = $transaction->createdAt->format('d/m/Y H:i:s'); $serviceFeeAmount = $transaction->serviceFeeAmount; $merchantAccountId = $transaction->merchantAccountId; $csvrow = [$id, $type, $amount, $status, $createdAt, $serviceFeeAmount, $merchantAccountId]; fputcsv($output, $csvrow); } echo "Download the CSV file <a href='transaction_report.csv'>Download</a>";
function test_advancedSearchGivesIterableResult() { $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardNumber()->startsWith("411111"))); $this->assertTrue($collection->maximumCount() > 100); $arr = array(); foreach ($collection as $transaction) { array_push($arr, $transaction->id); } $unique_transaction_ids = array_unique(array_values($arr)); $this->assertEquals($collection->maximumCount(), count($unique_transaction_ids)); }
public function get_transactions() { return Braintree_Transaction::search(array()); }
/** * Provides statistic reports * @param $id - project id */ public function index($id) { $this->loadModel('FinanceAccount'); $this->loadModel('Group'); $this->loadModel('Project'); $accounts = $this->FinanceAccount->search((int) $id); $fromMonth = $this->request->query('fromMonth'); $accountId = $this->request->query('accountId'); $groupProjectId = $this->request->query('groupProjectId'); if ($groupProjectId == 'none') { $groupProjectId = null; } if ($groupProjectId) { $project = $this->Project->findById($this->request->query('groupProjectId')); $accountId = Hash::get($project, 'Project.finance_account_id'); $categoryId = Hash::get($project, 'Project.finance_category_id'); } else { if (!$fromMonth) { $fromMonth = date('Y-m'); } if (!$accountId && !empty($accounts['aFinanceAccount'])) { $currAccount = current($accounts['aFinanceAccount']); $accountId = $currAccount['FinanceAccount']['id']; } $categoryId = null; } $this->loadModel('FinanceProject'); $project = $this->FinanceProject->getProject((int) $id, true); $this->loadModel('FinanceCategory'); $this->loadModel('FinanceBudget'); $budget = $this->FinanceBudget->search((int) $id, $accountId, null, $categoryId); $currency = @$accounts['aFinanceAccount'][$accountId]['FinanceAccount']['currency']; $month1 = date('Y-m', strtotime($fromMonth)); $month2 = date('Y-m', strtotime('+1 month', strtotime($fromMonth))); $month3 = date('Y-m', strtotime('+2 month', strtotime($fromMonth))); $month4 = date('Y-m', strtotime('+3 month', strtotime($fromMonth))); $report = $this->FinanceCategory->getBudget((int) $id, $accountId, $month1, $month2, $month3, $month4, $categoryId); $this->set($budget + $report + $project + $accounts + compact('id', 'accountId', 'groupProjectId', 'currency', 'month1', 'month2', 'month3', 'month4', 'fromMonth')); //для фильтров по проектам $conditions = array('Group.finance_project_id' => $id); $group = $this->Group->find('first', compact('conditions')); $this->set('group', $group); $conditions = array('Project.group_id' => Hash::get($group, 'Group.id'), 'NOT' => array('Project.finance_account_id' => null, 'Project.finance_category_id' => null)); $aProjectOptions = $this->Project->find('all', compact('conditions')); $aProjectOptions = Hash::combine($aProjectOptions, '{n}.Project.id', '{n}.Project.title'); $this->set('aProjectOptions', $aProjectOptions); $conditions = array('Project.group_id' => Hash::get($group, 'Group.id'), 'NOT' => array('Project.finance_category_id' => null)); //TODO ФИнансовый отчет $this->loadModel('Task'); $this->loadModel('Subproject'); $this->loadModel('FinanceOperation'); $this->loadModel('CrmTask'); $this->loadModel('InvestProject'); //$this->loadModel('BillingPlan'); //$this->loadModel('BillingSubscription'); $projectsFull = $this->Project->find('all', compact('conditions')); $projectsFull = Hash::combine($projectsFull, '{n}.Project.id', '{n}'); $conditions = array('Subproject.project_id' => Hash::extract($projectsFull, '{n}.Project.id')); $subprojectsFull = $this->Subproject->find('all', compact('conditions')); $subprojectsFull = Hash::combine($subprojectsFull, '{n}.Subproject.id', '{n}'); $conditions = array('Task.subproject_id' => Hash::extract($subprojectsFull, '{n}.Subproject.id')); $taskFull = $this->Task->find('all', compact('conditions')); $taskFull = Hash::combine($taskFull, '{n}.Task.id', '{n}'); // $conditions = array( // 'FinanceOperation.account_id' => Hash::extract($taskFull, '{n}.Task.id'), // ); // $finOperationFull = $this->FinanceOperation->find('all',compact('conditions')); // $finOperationFull = Hash::combine($finOperationFull, '{n}.FinanceOperation.id', '{n}'); $conditions = array('CrmTask.task_id' => Hash::extract($taskFull, '{n}.Task.id')); $crmTaskFull = $this->CrmTask->find('all', compact('conditions')); $crmTaskFull = Hash::combine($crmTaskFull, '{n}.CrmTask.task_id', '{n}'); // $conditions = array( // 'FinanceAccount.project_id' => $id, // ); //$financeAccountFull = $this->FinanceAccount->find('all',compact('conditions')); //$financeAccountFull = Hash::combine($financeAccountFull, '{n}.FinanceAccount.id', '{n}'); //echo strtotime('+1 month', strtotime($fromMonth)); foreach ($taskFull as $key => $item) { $taskFull[$key]['Task']['fullExpense_m1'] = $this->FinanceAccount->fullExpense($item['CrmTask']['account_id'], strtotime($fromMonth), null, strtotime('+1 month', strtotime($fromMonth))); $taskFull[$key]['Task']['fullIncome_m1'] = $this->FinanceAccount->fullIncome($item['CrmTask']['account_id'], strtotime($fromMonth), null, strtotime('+1 month', strtotime($fromMonth))); $taskFull[$key]['Task']['fullExpense_m2'] = $this->FinanceAccount->fullExpense($item['CrmTask']['account_id'], strtotime('+1 month', strtotime($fromMonth)), null, strtotime('+2 month', strtotime($fromMonth))); $taskFull[$key]['Task']['fullIncome_m2'] = $this->FinanceAccount->fullIncome($item['CrmTask']['account_id'], strtotime('+1 month', strtotime($fromMonth)), null, strtotime('+2 month', strtotime($fromMonth))); } $transactions = Braintree_Transaction::search([Braintree_TransactionSearch::customerId()->is('konstruktor-' . $this->currUser['User']['id'])]); $transact = array(); $transact['month1'] = 0; $transact['month2'] = 0; foreach ($transactions as $transaction) { $trans_stamp = $transaction->updatedAt->getTimestamp(); if ($trans_stamp >= strtotime($fromMonth) && $trans_stamp < strtotime('+1 month', strtotime($fromMonth))) { $transact['month1'] += $transaction->amount; } if ($trans_stamp >= strtotime('+1 month', strtotime($fromMonth)) && $trans_stamp < strtotime('+2 month', strtotime($fromMonth))) { $transact['month2'] += $transaction->amount; } //echo $transaction->amount.' '.$transaction->currencyIsoCode." - ".$transaction->updatedAt->format('Y-m-d H:i:s'); } $investProject = $this->InvestProject->findByGroupId($group['Group']['id']); $this->set(compact('investProject', 'transact', 'projectsFull', 'subprojectsFull', 'taskFull', 'crmTaskFull')); }
function testHandlesPayPalAccounts() { $http = new Braintree_HttpClientApi(Braintree_Configuration::$global); $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('access_token' => 'PAYPAL_ACCESS_TOKEN'))); $result = Braintree_Transaction::sale(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce)); $this->assertTrue($result->success); $paypalDetails = $result->transaction->paypalDetails; $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::paypalPaymentId()->is($paypalDetails->paymentId), Braintree_TransactionSearch::paypalAuthorizationId()->is($paypalDetails->authorizationId), Braintree_TransactionSearch::paypalPayerEmail()->is($paypalDetails->payerEmail))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($result->transaction->id, $collection->firstItem()->id); }
public function transactions() { $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::ids()->in($this->transactionIds))); return $collection; }
function test_handles_search_timeout() { $this->setExpectedException('Braintree_Exception_DownForMaintenance'); $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::amount()->is('-5'))); }