Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega do Projeto #5

Open
wants to merge 76 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
6ed54ba
feat: :hammer: Create dockerfile
wellingtonalencar Aug 31, 2021
c1bab43
feat: :hammer: Create docker-compose.yml
wellingtonalencar Aug 31, 2021
26fc550
feat: :hammer: Create makefile
wellingtonalencar Aug 31, 2021
7ae1b54
feat: :hammer: crate config xdebug
wellingtonalencar Aug 31, 2021
3b0ffda
docs: :memo: Add coverage to make test
wellingtonalencar Aug 31, 2021
51c719f
feat: :hammer: add secrets token acesss GPG
wellingtonalencar Aug 31, 2021
8f23bcc
feat: :zap: add secrets to ignore
wellingtonalencar Aug 31, 2021
4b70731
feat: :hammer: Add Template PR
wellingtonalencar Sep 1, 2021
cc9a364
Merge pull request #1 from wellalencarweb/feature/github-template
wellalencarweb Sep 1, 2021
842cb9d
Merge branch 'main' into feature/docker
wellingtonalencar Sep 1, 2021
a73aec8
Merge pull request #2 from wellalencarweb/feature/docker
wellalencarweb Sep 1, 2021
c8c7895
ci: :recycle: Test git hub actions
wellingtonalencar Sep 1, 2021
d014ed1
ci: :recycle: Test git hub actions
wellingtonalencar Sep 1, 2021
f91d5c1
test
wellingtonalencar Sep 1, 2021
01152b8
ci: change min-covered infection temporary
wellingtonalencar Sep 1, 2021
974dcc1
refactor: :arrow_up: add branch develop to github action
wellingtonalencar Sep 1, 2021
1b197f7
Merge pull request #3 from wellalencarweb/develop
wellalencarweb Sep 1, 2021
0bd14a2
feat: :hammer: Create Interface and Clients Checkers
wellingtonalencar Sep 1, 2021
8981cea
feat: :hammer: Create Factory to Checkers
wellingtonalencar Sep 1, 2021
5634cc7
feat: :hammer: Create a Fraud Checker Integration
wellingtonalencar Sep 1, 2021
f9282e7
feat: :hammer: Implement FrauCheckerFactory
wellingtonalencar Sep 1, 2021
2f2ae89
refactor: :recycle: Refator to pass test
wellingtonalencar Sep 1, 2021
d725e35
test: :zap: Create test to FraudChecker
wellingtonalencar Sep 1, 2021
4369e4c
refactor: :recycle: Change name file test
wellingtonalencar Sep 1, 2021
3bc4485
refactor: :recycle: remove file
wellingtonalencar Sep 1, 2021
aca7c72
docs: :zap: create commmand to infection
wellingtonalencar Sep 1, 2021
aaaab99
feat: :zap: Implement SOLID: ISP The Interface Segregation Principle
wellingtonalencar Sep 2, 2021
1d6ab73
refactor: :recycle: Refactor after use SOLID: ISP The Interface Segre…
wellingtonalencar Sep 2, 2021
ea7a5a1
refactor: :recycle: Refactor after use SOLID: ISP The Interface Segre…
wellingtonalencar Sep 2, 2021
7796ae8
refactor: :recycle: Adaptater to Interface Segregations
wellingtonalencar Sep 2, 2021
12be1fb
feat: :zap: Implament Logic Order Clients; ConnecT Simulate; Next Cli…
wellingtonalencar Sep 2, 2021
54f5904
test: :white_check_mark: Adapter testes
wellingtonalencar Sep 2, 2021
4cb7035
refactor: :recycle: Removed use
wellingtonalencar Sep 2, 2021
73d224a
refactor: :recycle: Refactor Desing
wellingtonalencar Sep 2, 2021
ee6a31a
refactor: :recycle: Add message to Clients FraudCheckers
wellingtonalencar Sep 2, 2021
13595f2
refactor: :recycle: Implements Messages to Clients FraudCheckers
wellingtonalencar Sep 3, 2021
4c3a9bd
test: :white_check_mark: Create dataproviders to FRauderCheckersSuccess
wellingtonalencar Sep 3, 2021
3bac6db
style: :zap: PSR
wellingtonalencar Sep 3, 2021
fee1d7f
docs: :page_facing_up: Generate Coverage Command
wellingtonalencar Sep 3, 2021
1c6734e
test: :white_check_mark: Tests to FraudCheckers
wellingtonalencar Sep 3, 2021
d4025eb
test: :recycle: Refactor tests
wellingtonalencar Sep 3, 2021
b9bfc5c
style: :hammer: Change folder Client to Contracs
wellingtonalencar Sep 3, 2021
1bf9ed7
feat: :zap: Create Settings Class to Transactions
wellingtonalencar Sep 3, 2021
778fe84
feat: :zap: Create new method transactionTaxValues to Calculate Tax
wellingtonalencar Sep 3, 2021
8bc50b5
feat: :zap: Create a new method checkProcess; initial fix the errors
wellingtonalencar Sep 3, 2021
8d72025
refactor: change to public
wellingtonalencar Sep 3, 2021
6859fd9
fix: :bug: Rename File
wellingtonalencar Sep 3, 2021
1dd34f9
feat: :zap: Create trait to Email
wellingtonalencar Sep 4, 2021
6b30f12
feat: :zap: Apply use Trait Email
wellingtonalencar Sep 4, 2021
3510caf
feat: :zap: Initial solution to method create
wellingtonalencar Sep 4, 2021
3db62a5
feat: :zap: Create Getters and Setters to Notification
wellingtonalencar Sep 4, 2021
84274aa
feat: :zap: Create index to test
wellingtonalencar Sep 4, 2021
16bc59a
feat: :zap: Change name
wellingtonalencar Sep 4, 2021
b4c4bd5
feat: :zap: Implement dispatcherNotify
wellingtonalencar Sep 4, 2021
8ee27bc
feat: :zap: Create Class DispatcherNotification
wellingtonalencar Sep 4, 2021
3259894
feat: :zap: Create Generate Notifications
wellingtonalencar Sep 4, 2021
11ef2cc
feat: :zap: Create DispatcherNotification
wellingtonalencar Sep 4, 2021
d498ab5
feat: :zap: Increment more class to index
wellingtonalencar Sep 4, 2021
725cf88
feat: :zap: Create procedural execution
wellingtonalencar Sep 4, 2021
11459d9
feat: :zap: Implement new Class
wellingtonalencar Sep 4, 2021
9d97eae
refactor: :recycle: refactor index
wellingtonalencar Sep 4, 2021
5dd2149
feat: :zap: Create Notifier Client
wellingtonalencar Sep 4, 2021
6c9bffd
feat: :zap: Create Tax manager Client
wellingtonalencar Sep 4, 2021
bec4214
docs: :memo: remove folder and namespaces
wellingtonalencar Sep 4, 2021
72f1d8b
feat: :zap: Create a Executor for tests aplication
wellingtonalencar Sep 4, 2021
85313fb
feat: :zap: Remove bloc try/catch
wellingtonalencar Sep 4, 2021
64c0dfd
refactor: :zap: Remove display erros
wellingtonalencar Sep 4, 2021
49b904a
refactor: :zap: Refactor validations
wellingtonalencar Sep 4, 2021
4c00ccd
refactor: :recycle: Add try catch
wellingtonalencar Sep 4, 2021
13d242b
test: :white_check_mark: fixes and implements new tests
wellingtonalencar Sep 4, 2021
9b2908f
feat: :zap: Implement teste and new methods
wellingtonalencar Sep 4, 2021
b3e6c29
tests: coverage
wellingtonalencar Sep 4, 2021
a698409
tests: coverage
wellingtonalencar Sep 4, 2021
3639efa
docs: :memo: Create README
wellingtonalencar Sep 4, 2021
b40322d
Merge pull request #4 from wellalencarweb/develop
wellalencarweb Sep 4, 2021
184b681
test: git
wellalencarweb Jan 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Porque?


## Como?


## Checklist
- [] Escopo do PR é isolado
- [] PR tem no máximo 10 arquivos | 300 linhas
- [] PR foi marcado com label correspondente

[Tarefa no Quadro](https://trello.com/b/ZkolCsrm/slytherin-pay)
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PHP Composer

on:
push:
branches: [ main ]
branches: [ main , develop]
pull_request:
branches: [ main ]

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
vendor/
.phpunit*
.idea*
./tests/reports/*
tests/reports/*
coverage*
secrets-token-access-git
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM webdevops/php-nginx:7.4

ENV WEB_DOCUMENT_ROOT /app/public
ENV WEB_DOCUMENT_INDEX index.php
ENV COMPOSER_VERSION 2
ENV PHP_DATE_TIMEZONE America/Sao_Paulo

RUN pecl install -f xdebug-2.9.8 && \
docker-php-ext-enable xdebug

COPY ./xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

WORKDIR /app
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
setup:
@docker-compose up -d --build
@docker-compose exec -T app composer install -n

bash:
@docker-compose exec app bash

test:
@docker-compose exec -T app php ./vendor/bin/phpunit --coverage-text

test-coverage:
@docker-compose exec -T app php ./vendor/bin/phpunit --coverage-html coverage

infection:
@docker-compose exec -T app composer run-script infection

63 changes: 14 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
# Desafio Consertando o SonserinaPay
_________
## Apresentações
Olá, meu nome é Malfoy, Draco Malfoy, como todo bom desenvolvedor também sou um bruxo.
# slytherin-pay
Projeto SLYTHERIN-PAY: Validador de Transações

Crabbe, Goyle e eu estavamos cansados da burocracia de pagamentos dos duendes e resolvemos criar nosso proprio app
de pagamentos, o Sonserina Pay. Agora estamos expandindo nossas operações para o mundo dos trouxas, vamos concorrer
com um tal de PicPay (eles estão lascados). Para garantir que nosso sistema funcione corretamente e não só por mágica,
contratamos uma consultora externa de qualidade (Hermione Granger, aquela sabe tudo, trouxa de sangu* ***m).
### Instalação

Durante os testes dela ela levantou alguns problemas no nosso software e você deverá corrigi-los, afinal de contas eu
sou um genio da programação das trevas muito importante pra isso, mas os créditos se ficar bom serão meus ok?
1. Clonar o Projeto
1. Esse projeto possui Makefile, para subir o container basta executar `make setup`
1. Existe um arquivo `index.php` na pasta `public`, nele é possível simular a aplicação
1. Para velo rodando localmente, basta acessar o endereço [localhost](http://localhost:8089/), rodando na porta `:8089`

Tarefas:
### Acessar o Container

1 - Você deverá implementar uma classe para checagem anti fraude (App\Domain\Services\FraudChecker), eu já comecei a
criar a classe, mas fiquei com preguiça.
1. Executar o comando `make bash` para testes de Unidade

A Granger pediu para fazer o código de uma maneira que mais regras podem ser implementadas nesse fluxo.
### Testes

As regras dessa classe são:
- Essa classe deve ser chamado toda vez que uma transação for criada
- A classe vai consultar 2 serviços diferentes de checagem, esses serviços são de terceiros e por isso só vamos nos
preocupar em se comunicar com eles através de seus clients (SDK ou API)
- Nossa classe de checagem de deverá chamar o primeiro cliente e caso ele diga que está "Autorizado" nós processaremos a
transação sem consultar o segundo
- Caso o primeiro cliente retorne que "Não está autorizado" ou falhe, iremos chamar o segundo cliente.
- Se o segundo cliente retornar que está "Autorizado" nós processaremos a transação.
- Se o segundo cliente retorne que "Não está autorizado" ou falhe. Iremos retornar uma excessão e não salvaremos a
transação
- Se possível ordem de execução dos clientes devem ser alteradas sem necessáriamente alterar a classe

2 - A classe principal do nosso serviço é o TransactionHandler (App\Domain\Services\TransactionHandler) e segundo a Granger,
nosso código não tá bom e apresenta muito erros. Precisamos que você melhore o código para nós.

Problemas que reportados:

- Tem usuários conseguindo sacar dinheiro dos lojistas
- Não estamos salvando corretamente os valores. Parece que não estão salvando a taxa do SonserinaPay, o valor total das
taxas e o valor total correto das transações
- Notificações não estão funcionando
- Quando as notificações estavam enviando as vezes enviava mesmo quando uma transação falhava na hora de salvar.
- Precisamos colocar essa aplicação em um container (Docker) para que ela não dependa de um ambiente local
- Ela também falou que não estamos cobrindo bem a nossa aplicação com testes, eu até comecei a fazer alguns testes,
mas achei facil demais, se você quiser pode usar ele como exemplo. Ela disse que o ideal é cobrirmos 100% dos testes.
Para executar os testes é só rodar `./vendor/bin/phpunit --coverage-text`.
- A Granger falou que nosso código não tá bom! Quem é essa sang#& ru$% pra falar do meu código. Disse para aplicarmos
melhor SOLID, Object Calisthenics e conceitos do livro Clean Code (Código Limpo) do Uncle Bob. Acredito que não tem
como melhorar esse código afinal de contas, fui eu quem fiz. Mas tenta ai só pra que eu tenha certeza que sou perfeito.
- A Granger criou uma tal de pipeline com o Github Actions, ela pediu para tentar fazer ela passar sem nenhum erro.

Observação:

_Não precisa se preocupar com fazer um endpoint ou cli para a execução do seu código ou com a implementação real das
chamadas para os clientes, ou persistencia em banco de dados. Faremos isso com mágica._
1. Executar o comando `make test` para testes de Unidade
1. Executar o comando `make test-coverage` para testes de Unidade com geração de HTML coma cobertura dos testes [`slytherin-pay/coverage/index.html`]
1. Executar o comando `make infection` para testes de Mutação via infection
1. Executar testes dentro do container `./vendor/bin/phpunit --coverage-html coverage`
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"scripts": {
"test": "vendor/bin/phpunit --coverage-text",
"infection": "vendor/bin/infection --min-msi=100 --min-covered-msi=100"
"infection": "vendor/bin/infection --min-msi=69.53 --min-covered-msi=69.53"
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"
services:
app:
build:
context: ./
container_name: slytherin-pay
ports:
- 8089:80
restart: always
volumes:
- ./:/app
21 changes: 21 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require __DIR__.'/../vendor/autoload.php';

use \App\Domain\Services\Transactions\TransactionExecutator;

$simulateAuthorized = [
0 => ['connect' => true, 'authorized' => true],
1 => ['connect' => true, 'authorized' => true],
3 => ['connect' => true, 'authorized' => true],
];
$orderReverse = true;

$executator = new TransactionExecutator();
$executator->setEmailBuyer('[email protected]');
$executator->setEmailSeller('[email protected]');
$executator->setTransaction(2, 20);

$executator->instantiatesClasses();

$executator->transactionHandlerExecute($orderReverse, $simulateAuthorized);
Binary file added secrets-token-access-git.gpg
Binary file not shown.
16 changes: 16 additions & 0 deletions src/App/Domain/Client/NotifierClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Domain\Client;

use App\Domain\Contracts\NotifierClientInterface;
use App\Domain\Entities\Notification;

class NotifierClient implements NotifierClientInterface
{
public function notify(Notification $notifier): void
{
echo nl2br("email= ".$notifier->getEmail()." message= ".$notifier->getMessage().PHP_EOL);
}
}
21 changes: 21 additions & 0 deletions src/App/Domain/Client/TaxManagerClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Domain\Client;

use App\Domain\Contracts\TaxManagerClientInterface;

class TaxManagerClient implements TaxManagerClientInterface
{
private const DEFAULT_INCREMENT_VALUE = 3.14;

/**
* @param float $tax
* @return float
*/
public function getIncrementValue(float $tax): float
{
return self::DEFAULT_INCREMENT_VALUE;
}
}
13 changes: 13 additions & 0 deletions src/App/Domain/Contracts/FraudCheckerClientAuthorizedInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Domain\Contracts;

use App\Domain\Contracts\FraudCheckerClientInterface;
use App\Domain\Entities\Transaction;

interface FraudCheckerClientAuthorizedInterface extends FraudCheckerClientInterface
{
public function isAuthorized(Transaction $transaction, array $simulateAuthorized): bool;
}
10 changes: 10 additions & 0 deletions src/App/Domain/Contracts/FraudCheckerClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Domain\Contracts;

interface FraudCheckerClientInterface
{
public function connect(bool $return): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Domain\Clients;
namespace App\Domain\Contracts;

use App\Domain\Entities\Notification;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace App\Domain\Clients;
namespace App\Domain\Contracts;

/**
* Interface TaxManagerClientInterface
* @package App\Domain\Clients
* @package App\Domain\Contracts
*/
interface TaxManagerClientInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Domain\Repositories;
namespace App\Domain\Contracts;

use App\Domain\Entities\Transaction;

Expand Down
4 changes: 4 additions & 0 deletions src/App/Domain/Entities/Buyer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace App\Domain\Entities;

use App\Domain\Traits\EmailTrait;

class Buyer
{
use EmailTrait;

/**
* @var string
*/
Expand Down
32 changes: 32 additions & 0 deletions src/App/Domain/Entities/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,36 @@ class Notification
* @var string
*/
private string $message;

/**
* @param string $email
*/
public function setEmail(string $email): void
{
$this->email = $email;
}

/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}

/**
* @param string $message
*/
public function setMessage(string $message)
{
$this->message = $message;
}

/**
* @return string
*/
public function getMessage()
{
return $this->message;
}
}
4 changes: 4 additions & 0 deletions src/App/Domain/Entities/Seller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace App\Domain\Entities;

use App\Domain\Traits\EmailTrait;

class Seller
{
use EmailTrait;

/**
* @var string
*/
Expand Down
21 changes: 21 additions & 0 deletions src/App/Domain/Entities/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class Transaction
*/
private Buyer $buyer;

/**
* @var bool
*/
private bool $status;

/**
* @return string
*/
Expand Down Expand Up @@ -196,4 +201,20 @@ public function setBuyer(Buyer $buyer): void
{
$this->buyer = $buyer;
}

/**
* @return bool $status
*/
public function getStatus(): bool
{
return $this->status;
}

/**
* @param bool $status
*/
public function setStatus(bool $status): void
{
$this->status = $status;
}
}
Loading