Skip to content
Snippets Groups Projects
Commit 6d6097c1 authored by Brody Wilton's avatar Brody Wilton
Browse files

fix issues caused by me being a fuckhead when merging

parent 66379c64
Branches
No related tags found
No related merge requests found
......@@ -27,8 +27,6 @@ def create_payment(request):
"redirect_urls": {
"return_url": request.build_absolute_uri(reverse('execute_payment')),
"cancel_url": request.build_absolute_uri(reverse('payment_cancelled')),
"return_url": request.build_absolute_uri(reverse('execute_payment')),
"cancel_url": request.build_absolute_uri(reverse('payment_cancelled')),
},
"transactions" : [{
"item_list" : {
......@@ -48,7 +46,6 @@ def create_payment(request):
}]
})
<<<<<<< HEAD
# Successfully communicated with API
if payment.create():
print("Payment created successfully!")
......@@ -101,65 +98,7 @@ def execute_payment(request):
#TODO: Change this to a more appropriate error message
print("exiting at the end of execute_payment()")
return redirect('handler404')
def payment_cancelled(request):
return render(request, 'payment_cancelled.html')
def payment_success(request):
return render(request,'payment_success.html')
=======
if payment.create():
print("Payment created successfully!")
# get url for payment approval
for link in payment.links:
if link.rel == "approval_url":
# turn link into text
approval_url = str(link.href)
# send on merry way
return redirect(approval_url)
else:
print(payment.error)
# Execute a successful payment
def execute_payment(request):
# Get payment id and payer id
payment_id = request.GET.get('paymentId')
payer_id = request.GET.get('PayerID')
#If neither ID, error, restart
if not payment_id or not payer_id:
print("no payment")
#TODO: Change this to a more appropriate path, maybe a generic error page that takes a string:Error to display in a template
return redirect('handler404')
# configure API
paypalrestsdk.configure({
"mode": settings.PAYPAL_MODE,
"client_id": settings.PAYPAL_CLIENT_ID,
"client_secret": settings.PAYPAL_CLIENT_SECRET
})
# Check we've got a successful payment
payment = paypalrestsdk.Payment.find(payment_id)
# If it we do an the payer IDs match
if payment.execute({"payer_id": payer_id}):
print("Payment executed successfully!")
# Allocate some tokens
user = request.user
tokens_purchased = 1
# increment user_tokens
# commit changes
return redirect('success')
else:
#TODO: Change this to a more appropriate error message
print("exiting at the end of execute_payment()")
return redirect('handler404')
def payment_cancelled(request):
return render(request, 'payment_cancelled.html')
......
from django.urls import path
<<<<<<< HEAD
from .views import InstrumentDetectionView, index, users, maintenance, handler404, handler500, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table
=======
from .views import InstrumentDetectionView, index, users, maintenance, handler404, handler500, register, user_login, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table
from .payments import create_payment, execute_payment, payment_cancelled, payment_success
from django.contrib.auth import views as auth_views
......@@ -34,7 +30,7 @@ urlpatterns = [
path('payment/create/', create_payment, name='create_payment'),
path('payment/execute/', execute_payment, name='execute_payment'),
path('payment/cancel/', payment_cancelled, name='payment_cancelled'),
path('payment_success/', payment_success, name='success')
path('payment_success/', payment_success, name='success'),
# Authentication
path('login/', CustomLoginView.as_view(), name='login'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment