Skip to content

Commit

Permalink
Merge pull request #158 from jonatasoli/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Jônatas Oliveira authored Nov 26, 2020
2 parents 482837f + b708fe0 commit 3484e5e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
26 changes: 14 additions & 12 deletions app/domains/domain_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create_product(db: Session, product_data: ProductSchema):


def get_showcase(db:Session):
showcases = db.query(Product).all()
showcases = db.query(Product).filter_by(showcase=True).all()
products = []

for showcase in showcases:
Expand All @@ -38,24 +38,26 @@ def get_installments(db: Session, cart):
_product_id = _cart['cart'][0]['product_id']
_product_config = db.query(Product).filter_by(id=int(_product_id)).first()
_total_amount = 0
_total_amount_fee = 0
_installments = []

for item in _cart['cart']:
_total_amount += (item['amount'] * item['qty'])

logger.debug(f"Total da soma {_total_amount}")
for n in range(1,13):
_installment = (_total_amount/n)/100
_installments.append({"name": f"{n} x R${_installment}", "value": f"{n}"})


if n <= 3:
_installment = (_total_amount/n)/100
_installments.append({"name": f"{n} x R${round(_installment, 2)}", "value": f"{n}"})
logger.debug(f"Parcela sem juros {_installment}")
else:
_total_amount_fee = _total_amount * (1+ 0.0199) ** n
_installment = (_total_amount_fee/n)/100
_installments.append({"name": f"{n} x R${round(_installment, 2)}", "value": f"{n}"})
logger.debug(f"Parcela com juros {_installment}")

logger.debug(f"array de parcelas {_installments}")
return _installments
# _config_installments = db.query(CreditCardFeeConfig)\
# .filter_by(id=_product_config.installments_config)\
# .first()
# if _installments > 12:
# raise Exception("O número máximo de parcelas é 12")
# elif _installments >= _config_installments.min_installment_with_fee:
# _total_amount = _total_amount * ((1+_config_installments.fee) ** _installments)


def get_product_by_id(db: Session, id):
Expand Down
16 changes: 14 additions & 2 deletions app/domains/domain_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def slip_payment(db: Session, payment: SlipPayment):
"payment_method": "slip-payment",
"boleto_url": r.get("boleto_url"),
"boleto_barcode": r.get("boleto_barcode"),
"gateway_id": r.get("id"),
"errors": r.get("errors")}
except Exception as e:
raise e
Expand Down Expand Up @@ -130,7 +131,7 @@ def process_checkout(db: Session, checkout_data: CheckoutSchema, affiliate=None,
except Exception as e:
db.rollback()
logger.error(f"----- ERROR PAYMENT {e} ")
raise HTTPException(status_code=206, detail="Erro ao processar o pagamento verifique os dados e tente novamente")
raise HTTPException(status_code=206, detail=f"Erro ao processar o pagamento verifique os dados ou veja o motivo a seguir -> Motivo {e}")


def check_user(db: Session, checkout_data: CheckoutSchema):
Expand Down Expand Up @@ -304,6 +305,15 @@ def process_payment(
db.add(db_transaction)
db.commit()

for item in _items:
_product_decrease = db.query(Product).filter_by(id=item.get("id")).first()
_qty_decrease = int(item.get("quantity"))
_product_decrease.quantity -= _qty_decrease
if _product_decrease.quantity < 0:
raise Exception('Produto esgotado')
else:
db.add(_product_decrease)

if checkout_data.get('payment_method') == "credit-card":
logger.info("------------CREDIT CARD--------------")
_payment = CreditCardPayment(
Expand Down Expand Up @@ -368,6 +378,8 @@ def update_gateway_id(db:Session, payment_data, order):
db_payment = db.query(Payment).filter_by(id=db_transaction.payment_id).first()

db_payment.gateway_id=payment_data.get("gateway_id")
order.payment_id = payment_data.get("gateway_id")
order.order_status =payment_data.get("status")
db.add(db_payment)
db.commit()

Expand All @@ -393,4 +405,4 @@ def update_payment_status(db:Session, payment_data, order):
# send_payment_mail(db=db, user=_user, payment=_payment)

except Exception as e:
raise e
raise e
2 changes: 1 addition & 1 deletion app/endpoints/v1/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def zip_code_adress(shipping_data: Shipping):
def zip_code_shipping(shipping_data: ShippingCalc):
from loguru import logger
logger.debug(shipping_data)
return { "shipping": 1000}
return { "shipping": 2000}
2 changes: 1 addition & 1 deletion app/endpoints/v1/tests/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.endpoints.deps import get_db


from app.schemas.order_schema import ProductSchema, OrderStatusSchema
from app.schemas.order_schema import ProductSchema
from domains.domain_order import create_order

from endpoints.v1.order import status_pending, status_paid, order_status, check_status_pedding
Expand Down

0 comments on commit 3484e5e

Please sign in to comment.