function testOneResultForTextFieldSearch()
 {
     $firstName = 'Tim' . rand();
     $token = 'creditcard' . rand();
     $customerId = 'customer' . rand();
     $transaction = Braintree_Transaction::saleNoValidate(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'creditCard' => array('number' => Braintree_Test_CreditCardNumbers::$visa, 'expirationDate' => '05/2012', 'cardholderName' => 'Tom Smith', 'token' => $token), 'billing' => array('company' => 'Braintree', 'countryName' => 'United States of America', 'extendedAddress' => 'Suite 123', 'firstName' => $firstName, 'lastName' => 'Smith', 'locality' => 'Chicago', 'postalCode' => '12345', 'region' => 'IL', 'streetAddress' => '123 Main St'), 'customer' => array('company' => 'Braintree', 'email' => '*****@*****.**', 'fax' => '5551231234', 'firstName' => 'Tom', 'id' => $customerId, 'lastName' => 'Smith', 'phone' => '5551231234', 'website' => 'http://example.com'), 'options' => array('storeInVault' => true, 'submitForSettlement' => true), 'orderId' => 'myorder', 'shipping' => array('company' => 'Braintree P.S.', 'countryName' => 'Mexico', 'extendedAddress' => 'Apt 456', 'firstName' => 'Thomas', 'lastName' => 'Smithy', 'locality' => 'Braintree', 'postalCode' => '54321', 'region' => 'MA', 'streetAddress' => '456 Road')));
     Braintree_Http::put('/transactions/' . $transaction->id . '/settle');
     $transaction = Braintree_Transaction::find($transaction->id);
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::billingCompany()->is("Braintree"), Braintree_TransactionSearch::billingCountryName()->is("United States of America"), Braintree_TransactionSearch::billingExtendedAddress()->is("Suite 123"), Braintree_TransactionSearch::billingFirstName()->is($firstName), Braintree_TransactionSearch::billingLastName()->is("Smith"), Braintree_TransactionSearch::billingLocality()->is("Chicago"), Braintree_TransactionSearch::billingPostalCode()->is("12345"), Braintree_TransactionSearch::billingRegion()->is("IL"), Braintree_TransactionSearch::billingStreetAddress()->is("123 Main St"), Braintree_TransactionSearch::creditCardCardholderName()->is("Tom Smith"), Braintree_TransactionSearch::creditCardExpirationDate()->is("05/2012"), Braintree_TransactionSearch::creditCardNumber()->is(Braintree_Test_CreditCardNumbers::$visa), Braintree_TransactionSearch::customerCompany()->is("Braintree"), Braintree_TransactionSearch::customerEmail()->is("*****@*****.**"), Braintree_TransactionSearch::customerFax()->is("5551231234"), Braintree_TransactionSearch::customerFirstName()->is("Tom"), Braintree_TransactionSearch::customerId()->is($customerId), Braintree_TransactionSearch::customerLastName()->is("Smith"), Braintree_TransactionSearch::customerPhone()->is("5551231234"), Braintree_TransactionSearch::customerWebsite()->is("http://example.com"), Braintree_TransactionSearch::orderId()->is("myorder"), Braintree_TransactionSearch::paymentMethodToken()->is($token), Braintree_TransactionSearch::processorAuthorizationCode()->is($transaction->processorAuthorizationCode), Braintree_TransactionSearch::settlementBatchId()->is($transaction->settlementBatchId), Braintree_TransactionSearch::shippingCompany()->is("Braintree P.S."), Braintree_TransactionSearch::shippingCountryName()->is("Mexico"), Braintree_TransactionSearch::shippingExtendedAddress()->is("Apt 456"), Braintree_TransactionSearch::shippingFirstName()->is("Thomas"), Braintree_TransactionSearch::shippingLastName()->is("Smithy"), Braintree_TransactionSearch::shippingLocality()->is("Braintree"), Braintree_TransactionSearch::shippingPostalCode()->is("54321"), Braintree_TransactionSearch::shippingRegion()->is("MA"), Braintree_TransactionSearch::shippingStreetAddress()->is("456 Road"), Braintree_TransactionSearch::id()->is($transaction->id)));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($transaction->id, $collection->firstItem()->id);
 }
예제 #2
0
 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'));
 }
 /**
  * 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 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);
 }