diff --git a/myproject/myapp/payments.py b/myproject/myapp/payments.py index b103fa59dfa3c8b737d37a947fe3ea9fa958463d..be44f082d93723baa85659d5b491dcc098ff7316 100644 --- a/myproject/myapp/payments.py +++ b/myproject/myapp/payments.py @@ -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') diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py index 9e02e7020377f1738a53840a86e3b00692240a26..c34f38a253dccf80cf7b267441d107efbdb5c395 100644 --- a/myproject/myapp/urls.py +++ b/myproject/myapp/urls.py @@ -1,9 +1,5 @@ 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'),