/** * @author WN * @param Application $application * @param Location $location * @return bool */ public function convertedNotification(Application $application, Location $location) { foreach ($location->getEmails() as $email) { \Mail::send('emails.locations.converted', ['application' => $application, 'location' => $location], function ($message) use($email, $application) { $message->to($email)->subject('Customer Finance Application ' . $application->ext_id . ' has been Approved'); }); } $this->logInfo('LocationNotificationService: Converted Email sent for Application[' . $application->id . ']'); return true; }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // Apply Parents (LIVE) details first parent::applySeederData(); // SET INSTALLATIONS | merchant_ID | name | bool active | bool linked $installations[] = [1, 'Test Installation', 1, 1, 'TestInstall']; $installations[] = [1, 'Unlinked Installation', 0, 0, '']; // SET LOCATIONS | reference | installation_id | bool active | name | email | address $locations[] = ['HIGHLOC', 1, 1, 'Higher Location', '*****@*****.**', 'Higher Location City']; $this->roles[] = ['Merchant Administrator', 'administrator', 'Merchant Administrator']; $this->roles[] = ['Report Role', 'report', 'run reports']; $this->roles[] = ['Manager Role', 'manager', 'run reports and perform cancellations']; $this->roles[] = ['Sales Role', 'sale', 'access in-store finance page and in-store details']; $this->rolesPermissions[] = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14]; $this->rolesPermissions[] = [7, 9, 14]; $this->rolesPermissions[] = [7, 9, 10, 11, 12, 13]; $this->rolesPermissions[] = [7, 9]; $this->users[] = ['Administrator', '*****@*****.**', 'password', 1, 2]; $this->users[] = ['Dev Reporter', '*****@*****.**', 'password', 1, 3]; $this->users[] = ['Dev Manager', '*****@*****.**', 'password', 1, 3]; $this->users[] = ['Dev Sales', '*****@*****.**', 'password', 1, 4]; DB::insert('INSERT INTO merchants (id, name, token, created_at, updated_at) VALUES (?, ?, ?, ?, ?)', [1, 'Test Merchant', 'mytoken', time(), time()]); // Apply Seed Data to Data Source parent::seedDataSource(); // INSTALLATIONS foreach ($installations as $installation) { $installationObject = new Installation(); $installationObject->merchant_id = $installation[0]; $installationObject->name = $installation[1]; $installationObject->active = $installation[2]; $installationObject->linked = $installation[3]; $installationObject->ext_id = $installation[4]; $installationObject->location_instruction = ''; $installationObject->save(); } // LOCATIONS foreach ($locations as $location) { $locationObject = new Location(); $locationObject->reference = $location[0]; $locationObject->installation_id = $location[1]; $locationObject->active = $location[2]; $locationObject->name = $location[3]; $locationObject->email = $location[4]; $locationObject->address = $location[5]; $locationObject->save(); } Model::reguard(); }
/** * @author EB */ public function testPrepareWithAccessToLocationWithoutValidFinanceOfferRoute() { $user = User::find(1); $user->locations()->sync([1]); $installation = \App\Basket\Location::find(1)->installation; $installation->finance_offers = 0; $installation->save(); $this->visit('/locations/1/applications/make')->see('Cannot make an application for location [1]')->seeStatusCode(200); }
/** * Store a newly created resource in storage. * * @param Request $request * @return \Illuminate\Http\RedirectResponse * @throws RedirectException */ public function store(Request $request) { $this->validate($request, ['reference' => 'required|regex:/^[A-Za-z0-9\\-]+$/', 'installation_id' => 'required', 'name' => 'required', 'email' => 'required|max:255', 'address' => 'required']); try { $this->validateEmailAddressInput($request); $toCreate = $request->all(); $toCreate['active'] = $request->has('active') ? 1 : 0; Location::create($toCreate); } catch (\Exception $e) { $this->logError('Could not successfully create new Location' . $e->getMessage()); throw RedirectException::make('/locations/')->setError($e->getMessage()); } return $this->redirectWithSuccessMessage('locations', 'New location has been successfully created'); }
/** * @author EB */ public function testInitialiseAssistedApplicationForException() { $mockApiClient = $this->getMock('PayBreak\\Sdk\\ApiClient\\ProviderApiClient'); $mockApiClient->expects($this->any())->method('post')->willReturn(['application' => 1234, 'url' => 'go.com']); $mock = $this->getMock('PayBreak\\Sdk\\ApiClient\\ApiClientFactoryInterface'); $mock->expects($this->any())->method('makeApiClient')->willReturn($mockApiClient); $appGateway = $this->getMockBuilder('\\PayBreak\\Sdk\\Gateways\\ApplicationGateway')->setConstructorArgs([$mock])->getMock(); $appGateway->expects($this->any())->method('initialiseAssistedApplication')->willThrowException(new Exception('Fail')); $service = new \App\Basket\Synchronisation\ApplicationSynchronisationService($appGateway); $this->setExpectedException('App\\Exceptions\\Exception', 'Fail'); $service->initialiseAssistedApplication('*****@*****.**', \App\Basket\Location::first(), $this->getOrderEntity(), $this->getProductsEntity(), $this->getApplicantEntity(), User::find(1)); }
/** * @author EB * @param int $location * @param int $application * @return \Illuminate\Http\RedirectResponse * @throws RedirectException */ public function finishApplication($location, $application) { try { /** @var Location $location */ $location = Location::findOrFail($location); $application = $this->fetchApplicationById($application, $location->installation->id); ApplicationEvent\ApplicationEventHelper::addEvent($application, ApplicationEvent::TYPE_RESUME_LINK); } catch (\Exception $e) { throw $this->redirectWithException('installations/' . $location->installation->id . '/applications', 'Unable to complete the application: ' . $e->getMessage(), $e); } return $this->redirectWithSuccessMessage('installations/' . $location->installation->id . '/applications/' . $application->id, 'Successfully created an application'); }
/** * @author EB * @param Request $request * @param $location * @return array|\Illuminate\Http\Response */ public function setProfileFinancial(Request $request, $location) { /** @var Location $location */ $location = Location::findOrFail($location)->first(); try { return $this->profileGateway->setFinancial($request->get('user'), ['monthly_income' => (int) $request->get('monthly_income'), 'monthly_outgoings' => (int) $request->get('monthly_outgoings'), 'bank_sort_code' => (string) $request->get('bank_sort_code'), 'bank_account' => (string) $request->get('bank_account')], $location->installation->merchant->token); } catch (\Exception $e) { $this->logError('Set Profile Financial failed: ' . $e->getMessage(), $request->all()); return $this->apiResponseFromException($e, 422); } }