Skip to content

Instantly share code, notes, and snippets.

@meadsteve
Created Feb 6, 2020
Embed
What would you like to do?
with and without DI
def complete_purchase(request, user_db: UserDb, payment_service: Payments, basket: BasketApi):
some_validation(request)
customer = user_db.get_customer(request.user.id)
customer.check_credit_history()
try:
payment = payment_service.complete_payment(request.payment_token)
customer.add_to_payment_history(payment)
basket.close_basket(request.basket_id)
return Response({"okey": "dokey"})
except:
return Response({"fail": "bad"})
add_to_app_route(POST, "/purchase/", bind_dependencies_somehow(complete_purchase))
def complete_purchase(request):
some_validation(request)
customer = user_db.get_customer(request.user.id)
customer.check_credit_history()
try:
payment = payment_service.complete_payment(request.payment_token)
customer.add_to_payment_history(payment)
basket.close_basket(request.basket_id)
return Response({"okey": "dokey"})
except:
return Response({"fail": "bad"})
add_to_app_route(POST, "/purchase/", complete_purchase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment