Skip to content

Instantly share code, notes, and snippets.

@thiagomarini
Last active December 20, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomarini/cd4d49aa3931a7c78b7bb5e108eb43b9 to your computer and use it in GitHub Desktop.
Save thiagomarini/cd4d49aa3931a7c78b7bb5e108eb43b9 to your computer and use it in GitHub Desktop.
Weengs Service Example
<?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