Closed allielbadry closed 3 years ago
i did everything the book says and when i place order i get authorization error caused by this line client_token = gateway.client_token.generate()
`import braintree from django.shortcuts import render, redirect, get_object_or_404 from django.conf import settings from order.models import Order
gateway = braintree.BraintreeGateway(settings.BRAINTREE_CONF)
def payment_process(request): order_id = request.session.get('order_id') order = get_object_or_404(Order, id=order_id) total_cost = order.get_total_cost()
if request.method == 'POST': # retrieve nonce nonce = request.POST.get('payment_method_nonce', None) # create and submit transaction result = gateway.transaction.sale({ 'amount': f'{total_cost:.2f}', 'payment_method_nonce': nonce, 'options': { 'submit_for_settlement': True } }) if result.is_success: # mark the order as paid order.paid = True # store the unique transaction id order.braintree_id = result.transaction.id order.save() return redirect('payment:done') else: return redirect('payment:canceled') else: # generate token client_token = gateway.client_token.generate() return render(request, 'payment/process.html', {'order': order, 'client_token': client_token})`
Hi @allielbadry ,
can you please show me your settings file? Braintree part.
Thank you I solved it when I correct the braintree settings it was a problem I didn't write my ID correctly
i did everything the book says and when i place order i get authorization error caused by this line client_token = gateway.client_token.generate()
`import braintree from django.shortcuts import render, redirect, get_object_or_404 from django.conf import settings from order.models import Order
gateway = braintree.BraintreeGateway(settings.BRAINTREE_CONF)
def payment_process(request): order_id = request.session.get('order_id') order = get_object_or_404(Order, id=order_id) total_cost = order.get_total_cost()