/** * Build up a search query based on the users entries * * @return $this */ protected function _prepareBraintreeSearchQuery() { // Has the search query been set already? if ($this->searchQuery) { return $this->searchQuery; } $searchArray = array(); // Init some times $to = new Datetime(); $from = clone $to; $from = $from->modify("-24 hour"); // If a from and to date are set modify things if (Mage::app()->getRequest()->getParam('from_date') && Mage::app()->getRequest()->getParam('to_date')) { $from = new DateTime(Mage::app()->getRequest()->getParam('from_date')); $to = new DateTime(Mage::app()->getRequest()->getParam('to_date')); } // We always want to be filtering by a date to some degree $searchArray[] = Braintree_TransactionSearch::createdAt()->between($from, $to); // Type search if ($type = Mage::app()->getRequest()->getParam('type')) { $searchArray[] = Braintree_TransactionSearch::type()->is($type); } // Allow searching upon the status if ($status = Mage::app()->getRequest()->getParam('status')) { $searchArray[] = Braintree_TransactionSearch::status()->is($status); } // Order ID searching can be helpful if ($orderId = Mage::app()->getRequest()->getParam('order_id')) { $searchArray[] = Braintree_TransactionSearch::orderId()->is($orderId); } // Store the search query within the session Mage::getSingleton('adminhtml/session')->setBraintreeSearchQuery($searchArray); return $searchArray; }
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')); }
public static function fetch($query, $ids) { $criteria = array(); foreach ($query as $term) { $criteria[$term->name] = $term->toparam(); } $criteria["ids"] = Braintree_TransactionSearch::ids()->in($ids)->toparam(); $response = Braintree_Http::post('/transactions/advanced_search', array('search' => $criteria)); return Braintree_Util::extractattributeasarray($response['creditCardTransactions'], 'transaction'); }
<?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 fetch($query, $ids) { $criteria = array(); foreach ($query as $term) { $criteria[$term->name] = $term->toparam(); } $criteria["ids"] = Braintree_TransactionSearch::ids()->in($ids)->toparam(); $path = $this->_config->merchantPath() . '/transactions/advanced_search'; $response = $this->_http->post($path, array('search' => $criteria)); return Braintree_Util::extractattributeasarray($response['creditCardTransactions'], 'transaction'); }
/** * 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'))); }
function testHandlesEuropeBankAccounts() { $gateway = new Braintree_Gateway(array('environment' => 'development', 'merchantId' => 'altpay_merchant', 'publicKey' => 'altpay_merchant_public_key', 'privateKey' => 'altpay_merchant_private_key')); $result = $gateway->customer()->create(); $this->assertTrue($result->success); $customer = $result->customer; $clientApi = new Braintree_HttpClientApi($gateway->config); $nonce = $clientApi->nonceForNewEuropeanBankAccount(array("customerId" => $customer->id, "sepa_mandate" => array("locale" => "de-DE", "bic" => "DEUTDEFF", "iban" => "DE89370400440532013000", "accountHolderName" => "Bob Holder", "billingAddress" => array("streetAddress" => "123 Currywurst Way", "extendedAddress" => "Lager Suite", "firstName" => "Wilhelm", "lastName" => "Dix", "locality" => "Frankfurt", "postalCode" => "60001", "countryCodeAlpha2" => "DE", "region" => "Hesse")))); $transactionResult = $gateway->transaction()->sale(array("customerId" => $customer->id, "paymentMethodNonce" => $nonce, "merchantAccountId" => "fake_sepa_ma", "amount" => 100)); $this->assertTrue($transactionResult->success); $collection = $gateway->transaction()->search(array(Braintree_TransactionSearch::customerId()->is($customer->id), Braintree_TransactionSearch::europeBankAccountIban()->is("DE89370400440532013000"))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($transactionResult->transaction->id, $collection->firstItem()->id); }