Пример #1
0
 /**
  * @author EB
  */
 public function testCreateHasRequired()
 {
     $this->call('GET', 'users/create');
     $this->assertResponseOk();
     $this->assertViewHas('user', null);
     $merchants = \App\Basket\Merchant::query()->get()->pluck('name', 'id')->toArray();
     $this->assertViewHas('merchants', $merchants);
 }
Пример #2
0
 /**
  * @author WN
  * @param string $view
  * @param int|null $userId
  * @param array $additionalProperties
  * @return \Illuminate\View\View
  */
 private function renderFormPage($view, $userId = null, array $additionalProperties = [])
 {
     $user = $userId !== null ? $this->fetchUserById($userId) : null;
     $merchants = Merchant::query();
     $this->limitToMerchant($merchants, 'id');
     return view($view, array_merge(['user' => $user, 'merchants' => $merchants->get()->pluck('name', 'id')->toArray()], $additionalProperties));
 }
Пример #3
0
 /**
  * Checks for token duplication in the database,returns true if there is no duplication detected.
  *
  * @author EA
  * @param $token
  * @param $merchantName
  * @return bool
  * @throws RedirectException
  */
 public function validateMerchantToken($token, $merchantName)
 {
     $duplicatedTokens = Merchant::all()->where('token', $token);
     if (!$duplicatedTokens->isEmpty()) {
         $this->logError('Cannot create merchant[' . $merchantName . '] merchant:Merchant token already exist in database');
         throw RedirectException::make('/merchants')->setError('Invalid merchant token ');
     }
     return true;
 }
Пример #4
0
 /**
  * Returns all locations from a merchant. If merchant for the user is null (SU), redirects with error
  *
  * @author EA, EB
  * @param User $user
  * @return Collection
  * @throws RedirectException
  */
 protected function fetchMerchantLocationsFromUser(User $user)
 {
     if ($user->merchant_id == null) {
         throw RedirectException::make('/users')->setError('Super Users do not belong to a Merchant, cannot fetch Locations');
     }
     try {
         return $this->fetchMerchantLocations(Merchant::findOrFail($user->merchant_id));
     } catch (ModelNotFoundException $e) {
         throw RedirectException::make('users/' . $user->id)->setError($e->getMessage());
     }
 }
 /**
  * @author EB
  */
 public function testActivateChainsLocation()
 {
     $installation = Installation::query()->find(1);
     $merchant = \App\Basket\Merchant::findOrFail(1)->activate();
     foreach ($installation->locations() as $l1) {
         $l1->active = 0;
     }
     $installation->activate();
     foreach ($installation->locations() as $l2) {
         $this->assertEquals(1, $l2->active);
         $this->assertNotEquals(0, $l2->active);
     }
 }
Пример #6
0
 /**
  * Settlement Report
  *
  * @author MS, EA
  * @param int $merchant
  * @param int $id
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\View\View
  * @throws RedirectException
  */
 public function settlementReport($merchant, $id, Request $request)
 {
     try {
         $aggregateSettlementReport = $this->settlementGateway->getSingleAggregateSettlementReport($this->fetchMerchantById($merchant)->token, $id);
     } catch (\Exception $e) {
         throw $this->redirectWithException('/', 'Failed fetching settlements', $e);
     }
     $settlementDate = $request->get('date');
     return View('settlements.settlement_report', ['settlement_date' => $settlementDate, 'settlement_amount' => $request->get('amount', ''), 'settlement_provider' => $request->get('provider', ''), 'aggregate_settlement_report' => $aggregateSettlementReport, 'aggregate_settlement_total' => array_sum(array_column($aggregateSettlementReport, 'settlement_amount')), 'merchant' => Merchant::where('id', '=', $merchant)->first(), 'export_api_filename' => 'settlement-raw-' . $id . '-' . date_format(DateTime::createFromFormat('Y-m-d', $settlementDate), 'Ymd'), 'export_view_filename' => 'settlement-report-' . $id . '-' . date_format(DateTime::createFromFormat('Y-m-d', $settlementDate), 'Ymd')]);
 }
Пример #7
0
 /**
  * @author EB
  * @param int $id
  * @param string $name
  * @param string $token
  * @return Merchant
  */
 public function createMerchant($id, $name, $token)
 {
     $merchant = new Merchant();
     $merchant->create(['id' => $id, 'name' => $name, 'token' => $token, 'created_at' => time(), 'updated_at' => time()]);
     return $merchant;
 }
Пример #8
0
 /**
  * @author EB
  */
 public function testDeactivateChainsInstallation()
 {
     $merchant = \App\Basket\Merchant::query()->find(1);
     foreach ($merchant->installations() as $i1) {
         $i1->active = 1;
     }
     $merchant->deactivate();
     foreach ($merchant->installations() as $i2) {
         $this->assertEquals(1, $i2->active);
         $this->assertNotEquals(0, $i2->active);
     }
 }