feat: processamento de simulação de pagamentos - #1
Open
AxelPCG wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an initial (simulated) checkout processing implementation to the TechShop codebase, including a fake payment API call and a single function that performs cart validation, total calculation, discounting, and payment processing.
Changes:
- Added a
FakeResponse/fake_postpair to simulate a payment API call. - Added
processar_tudo(...)to validate stock, compute totals (freight + discount), and trigger the simulated payment flow.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+5
| # Este arquivo contém código propositalmente ruim para fins educacionais em uma aula de refatoração. | ||
| # MÁS PRÁTICAS APLICADAS: | ||
| # 1. Função única com múltiplas responsabilidades (validação, cálculo, pagamento). | ||
| # 2. Nomes de variáveis ruins e não descritivos (x1, val, p, temp, res). | ||
| # 3. Falta de tipagem de dados (sem type hints). |
Comment on lines
+20
to
+23
| def fake_post(url, json): | ||
| """Simula uma chamada POST para uma API de pagamento.""" | ||
| print(f"--- Simulando POST para API de pagamento: {url} ---") | ||
| if json['valor_total'] > 0 and json['valor_total'] < 9999: |
Comment on lines
+21
to
+25
| """Simula uma chamada POST para uma API de pagamento.""" | ||
| print(f"--- Simulando POST para API de pagamento: {url} ---") | ||
| if json['valor_total'] > 0 and json['valor_total'] < 9999: | ||
| print("--- Pagamento APROVADO (simulado) ---") | ||
| return FakeResponse(200, {"status": "pagamento_aprovado", "transacao_id": "xyz123abc"}) |
Comment on lines
+39
to
+48
| if cart_data and 'items' in cart_data: | ||
| # Validação de estoque e cálculo de valor | ||
| for p in cart_data['items']: | ||
| print(f"Verificando estoque para o produto ID: {p['id']}...") | ||
| # Estoque mockado | ||
| estoque_disponivel = 10 | ||
| if p['qtd'] <= estoque_disponivel: | ||
| print(f"Estoque OK para {p['qtd']} unidades do produto {p['id']}.") | ||
| x1 = p['preco'] * p['qtd'] | ||
| val = val + x1 |
Comment on lines
+62
to
+66
| if val > 200: | ||
| if u_data['vip']: | ||
| print("Aplicando desconto VIP de 15%") | ||
| val = val * 0.85 | ||
| else: |
Comment on lines
+75
to
+76
| "info_cartao": "XXXX-XXXX-XXXX-1234" # Dados sensíveis hardcoded | ||
| } |
Comment on lines
+49
to
+52
| else: | ||
| print(f"ERRO: Estoque insuficiente para o produto {p['id']}.") | ||
| return "Erro de estoque" | ||
|
|
Comment on lines
+79
to
+89
|
|
||
| if res.status_code == 200: | ||
| temp = res.json() | ||
| if temp['status'] == 'pagamento_aprovado': | ||
| print(f"Checkout finalizado com sucesso! ID da transação: {temp['transacao_id']}") | ||
| return {"sucesso": True, "transacao": temp['transacao_id']} | ||
| else: | ||
| print("Ocorreu um problema com o pagamento.") | ||
| return {"sucesso": False, "erro": "problema_na_api_de_pagamento"} | ||
| else: | ||
| print("API de pagamento retornou um erro.") |
Comment on lines
+31
to
+37
| def processar_tudo(cart_data, u_data): | ||
| """ | ||
| Função gigante e mal escrita para processar um checkout completo. | ||
| Recebe dados do carrinho e do usuário em formato de dicionário. | ||
| """ | ||
| print("Iniciando processamento de checkout...") | ||
| val = 0 |
21 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
name: Pull Request
about: Crie um novo Pull Request para o projeto TechShop.
title: '[FEAT/FIX/DOCS]: Breve descrição da alteração'
labels: ''
assignees: ''
Descrição
Por favor, inclua um resumo da alteração e qual problema ela resolve. Liste também qualquer motivação e contexto relevantes.
Tipo de Alteração
Marque com um
xas caixas que se aplicam:Como Isso Foi Testado?
Por favor, descreva os testes que você executou para verificar suas alterações. Forneça instruções para que possamos reproduzir.
Checklist