diff --git a/myproject/myapp/payments.py b/myproject/myapp/payments.py index b103fa59dfa3c8b737d37a947fe3ea9fa958463d..db835be0adf89b58a6c2639da01a74b488e4477f 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,7 @@ def create_payment(request): }] }) -<<<<<<< HEAD + # Successfully communicated with API if payment.create(): print("Payment created successfully!") @@ -107,61 +105,3 @@ def payment_cancelled(request): 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') - -def payment_success(request): - return render(request,'payment_success.html') \ No newline at end of file diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py index 9e02e7020377f1738a53840a86e3b00692240a26..a53b69c7201bf7f2b8c4eb008a1616865c7da36b 100644 --- a/myproject/myapp/urls.py +++ b/myproject/myapp/urls.py @@ -1,9 +1,7 @@ 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 @@ -31,16 +29,13 @@ urlpatterns = [ path('password_change/', auth_views.PasswordChangeView.as_view(template_name='password_change_form.html'), name='password_change'), path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html'), name='password_change_done'), # path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout'), - 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') - + # Authentication path('login/', CustomLoginView.as_view(), name='login'), path('logout/', LogoutView.as_view(), name='logout'), path('register/', RegisterView.as_view(), name='register'), path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout'), + # Payment path('payment/create/', create_payment, name='create_payment'), path('payment/execute/', execute_payment, name='execute_payment'), path('payment/cancel/', payment_cancelled, name='payment_cancelled'),