Last active
December 20, 2018 12:22
-
-
Save thiagomarini/cd4d49aa3931a7c78b7bb5e108eb43b9 to your computer and use it in GitHub Desktop.
Weengs Service Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Weengs\Services\Merchant\Onboarding\RequestPhoneCall; | |
use Weengs\Exceptions\BusinessException; | |
use Weengs\Models\User\Onboarding; | |
use Weengs\Models\User\User; | |
use Weengs\Services\Common\BaseService; | |
use Weengs\Services\Common\RequestInterface; | |
use Weengs\Services\Common\ResponseInterface; | |
class Service extends BaseService | |
{ | |
/** | |
* @param RequestInterface $request | |
* @return ResponseInterface | |
*/ | |
public function execute(RequestInterface $request): ResponseInterface | |
{ | |
$params = $request->getParams(); | |
$data = $request->getData(); | |
$user = User::findOrFail($params['user_id']); | |
if ($user->status != User::STATUS_ONBOARDING) { | |
throw new BusinessException('Only onboarding customers can request calls'); | |
} | |
$user->phone = $data['phone']; | |
$user->update(); | |
$user->onboarding->status = Onboarding::STATUS_REQUESTED_CALL; | |
$user->onboarding->save(); | |
return new Response($user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment