/** * @author EB * @param Installation $installation * @return \App\Basket\Template */ public static function fetchDefaultTemplateForInstallation(Installation $installation) { try { return $installation->templates()->firstOrFail(); } catch (ModelNotFoundException $e) { return Template::first(); } }
/** * 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 WN * @param string $installation * @return Installation */ protected function fetchInstallationByExternalId($installation) { $inst = Installation::where('ext_id', $installation)->get(); if (count($inst) == 1) { return $inst[0]; } throw new ModelNotFoundException('Installation ' . $installation . ' not found.'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $installations = Installation::where('active', true); if ($this->auth->user() && $this->auth->user()->merchant_id) { view()->share('available_installations', $installations->where('merchant_id', $this->auth->user()->merchant_id)->get()); } else { view()->share('available_installations', $installations->get()); } return $next($request); }
/** * @author SL * @param Request $request * @param $installation * @param $product * @return array|\Illuminate\Http\Response */ public function getCreditInformationForProduct(Request $request, $installation, $product) { try { if (!$request->has('deposit', 'order_amount')) { throw new Exception('Input field "deposit" and "order_amount" are both required.'); } $inst = Installation::findOrFail(['ext_id' => $installation])->first(); return $this->productGateway->getCreditInfo($inst->ext_id, $product, $inst->merchant->token, ['deposit_amount' => $request->input('deposit'), 'order_amount' => $request->input('order_amount')]); } catch (\Exception $e) { return $this->apiResponseFromException($e); } }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('installations', function (Blueprint $table) { $table->integer('validity')->default(2592000)->change(); }); $installations = \App\Basket\Installation::all(); /** @var \App\Basket\Installation $installation */ foreach ($installations as $installation) { if ($installation->validity < 86400) { $installation->validity = 86400; $installation->save(); } } }
/** * Run the migrations. * * @return void */ public function up() { $installations = \App\Basket\Installation::all(); /** @var \App\Basket\Installation $installation */ foreach ($installations as $installation) { $bitwise = \PayBreak\Foundation\Properties\Bitwise::make($installation->finance_offers); if ($bitwise->contains(\App\Basket\Installation::LINK) || $bitwise->contains(\App\Basket\Installation::EMAIL)) { $bitwise->remove(\App\Basket\Installation::LINK); $bitwise->remove(\App\Basket\Installation::EMAIL); $total = $bitwise->get() + (\App\Basket\Installation::LINK + \App\Basket\Installation::EMAIL); $installation->finance_offers = $total; $installation->save(); } } }
/** * @param InstallationEntity[] $externalInstallations * @param Collection $localInstallations * @param int $merchantId * @return Installation[] */ private function synchroniseNewInstallations(array $externalInstallations, Collection $localInstallations, $merchantId) { $rtn = []; foreach ($externalInstallations as $installation) { if ($this->isNewInstallation($installation->getId(), $localInstallations)) { $newInstallation = new Installation(); $newInstallation->name = $installation->getName(); $newInstallation->merchant_id = $merchantId; $newInstallation->active = false; $newInstallation->linked = false; $newInstallation->ext_id = $installation->getId(); $newInstallation->save(); try { $this->synchroniseInstallation($newInstallation->id); } catch (\Exception $e) { // Empty } $rtn[] = 'New installation ' . $installation->getName() . ' has been added.'; } } return $rtn; }
/** * Run the migrations. * * @return void */ public function up() { \Illuminate\Database\Eloquent\Model::unguard(); $template = new \App\Basket\Template(); $template->html = '<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link href=\'https://fonts.googleapis.com/css?family=Ubuntu\' rel=\'stylesheet\' type=\'text/css\'> <style> * { font-family: Helvetica, Arial; } .top-space { margin-top: 30px; } .top-break { border-top: 10px solid #29abe2; } .display-right { float: right; } .wrapper { margin: auto 50px; } .introduction-text { font-size: 16px; } .retailer-logo { max-height: 100px; max-width: 350px; } .size { float: left; } .size-4 { width: 33%; } .size-8 { width: 67%; } .text-right { text-align: right; padding-right: 20px; } /* Bootstrap Button */ .apply-btn { display: inline-block; padding: 6px 12px; margin-bottom: 0; font-size: 14px; font-weight: 400; line-height: 1.42857143; text-align: center; white-space: nowrap; vertical-align: middle; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-image: none; border-radius: 4px; color: #fff; background-color: #5cb85c; width: 100%; text-shadow: 0 -1px 0 rgba(0,0,0,.2); -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075); box-shadow: inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075); background-image: -webkit-linear-gradient(top,#5cb85c 0,#419641 100%); background-image: -o-linear-gradient(top,#5cb85c 0,#419641 100%); background-image: -webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#419641)); background-image: linear-gradient(to bottom,#5cb85c 0,#419641 100%); background-repeat: repeat-x; border-color: #3e8f3e; } .apply-btn:hover { cursor: hand; } .pad-left { padding-left: 20px; } </style> </head> <header> <div class="top-space"></div> <div class="container"> <table> <tr> <td class="size-4 pad-left"><img src="https://checkout-test.paybreak.com/assets/logo-mobile-no-with.png"></td> <td class="size-8"><img src="{{$installation_logo}}" class="display-right retailer-logo"></td> </tr> </table> </div> </header> <body class="container"> <hr class="top-break"> <div class="row"> <div class="wrapper"> <table> <thead> <tr> <td colspan="2" class="introduction-text"> Dear {{$customer_title}} {{$customer_last_name}}, <br/> You are receiving this email in result to an enquiry you made with <strong>{{$installation_name}}</strong>. </td> </tr> </thead> </table> <br/> <table class="size size-4"> <tbody> <tr><td colspan="2"><h3>How it works</h3></td></tr> <tr> <td> <p>If everything looks OK and you wish to apply for finance, click the button below and your browser will open the finance application form</p> <p>Complete the form - it will only take a few minutes</p> <p>You sign the credit agreement online, so there are no paper forms and nothing to post</p> <p>A decision will be made based on the criteria entered</p> </td> </tr> </tbody> </table> <table class="size size-8"> <tbody> <tr><td colspan="2"><h3>Your Finance Offer</h3></td></tr> <tr> <td class="size-4 text-right">Product:</td> <td class="size-8"><strong>{{$order_description}}</strong></td> </tr> <tr> <td class="size-4 text-right">Monthly Payment:</td> <td class="size-8">{{\'£\' . number_format($payment_regular/100,2)}} for {{$payments}} months</td> </tr> <tr> <td class="size-4 text-right">Finance Details:</td> <td class="size-8">{{$order_description}}</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">Purchase Price: {{\'£\' . number_format($order_amount/100,2)}}</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">Deposit: {{\'£\' . number_format($deposit_amount/100,2)}}</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">Loan Amount: {{\'£\' . number_format($loan_amount/100,2)}}</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">{{$payments}} Monthly payments of: {{\'£\' . number_format($payment_regular/100,2)}}</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">Total Amount Repayable: {{\'£\' . number_format($total_repayment/100,2)}}</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">Rate of Interest (fixed): {{number_format($offered_rate, 2)}}%</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">{{number_format($apr, 2)}}% APR Representative</td> </tr> <tr> <td class="size-4 text-right"></td> <td class="size-8">Total Charge for Credit: {{\'£\' . number_format($loan_cost/100,2)}}</td> </tr> </tbody> </table> </div> </div> <div class="row"> <div class="wrapper"> <div class="size-4"> <a href="{{$apply_url}}"><button class="apply-btn">Apply Now</button></a> </div> <div class="col col-sm-12 col-xs-12"> {!! html_entity_decode($template_footer) !!} </div> </div> </div> <hr class="top-break"> </body> </html>'; $template->merchant_id = null; $template->save(); $installations = \App\Basket\Installation::all(); /** @var \App\Basket\Installation $installation */ foreach ($installations as $installation) { $installation->templates()->attach($template); } }
/** * @author WN * @param string $template * @param integer $id * @return \Illuminate\View\View */ private function renderForm($template, $id = null) { return view('locations.' . $template, ['location' => $id !== null ? $this->fetchLocationById($id) : null, 'installations' => $this->limitToActive($this->limitToMerchant(Installation::query()))->get()->pluck('name', 'id')->toArray()]); }
/** * @author EB */ public function testGetDisclosureAsHtml() { $installation = Installation::query()->find(1); $installation->update(['disclosure' => '## Test Two']); $disclosure = Installation::findOrFail(1)->getDisclosureAsHtml(); $this->assertEquals('<h2>Test Two</h2>', $disclosure); }
/** * @author EB, SL * * @param int $id * @return GroupEntity * @throws RedirectException */ private function fetchProducts($id) { try { $installation = Installation::findOrFail($id); return $this->productGateway->getProductGroupsWithProducts($installation->ext_id, $installation->merchant->token); } catch (\Exception $e) { if ($e->getMessage() !== 'Products are empty') { throw $this->redirectWithException(URL::previous(), $e->getMessage(), $e); } return GroupEntity::make([]); } }
/** * @author WN * @param Builder $query */ protected function limitToInstallationOnMerchant(Builder $query) { if (\Auth::user()->merchant_id) { $query->whereIn('installation_id', Installation::where('merchant_id', \Auth::user()->merchant_id)->get()->pluck('id')->all()); } }
public function pendingCancellations($installationId) { $installation = Installation::query()->findOrFail($installationId); $pendingCancellations = Application::query()->where('installation_id', '=', $installationId)->where('ext_current_status', '=', 'pending_cancellation')->get(); return View('applications.pending-cancellation', ['applications' => $pendingCancellations, 'installation' => $installation]); }