createsVoucherEntityMapping = $createsVoucherEntityMapping; $this->createsVoucherifyCustomer = $createsVoucherifyCustomer; } /** * @param int $companyId * @param User $user * @param bool $isNew * @return void * @throws \App\Classes\Exceptions\MalformedRequestException */ public function execute(int $companyId, User $user, bool $isNew) { try { $createVoucherifyCustomerObject = new CreateVoucherifyCustomerObject($companyId, $user, $isNew); $result = $this->createsVoucherifyCustomer->execute($createVoucherifyCustomerObject); $voucherify_entity = $user->voucherifyEntities()->get(); if($result && isset($result->id) && count($voucherify_entity) === 0){ $voucherEntityObject = new VoucherEntityObject($result->id, VoucherifyEntityType::CUSTOMER); $this->createsVoucherEntityMapping->execute($createVoucherifyCustomerObject->getUser(), $voucherEntityObject); } } catch (\Exception $e) { Log::error($e); } } }