Search code examples
pythondjangopaypalpayment

Getting the information after finishing payment with PayPal using Django


I'm using django-paypal for managing payments on my website and it works well with the money transfer part but I can't get the user information to input into my database. I looked at some stuff online and what people do is just getting the requset.POST and request.GET data and the information is there but somehow it's not working for me. Here is my view:

def index(request):
paypal_dict = {
    "business": "testmail@gmail.com",
    "amount": "10.00",
    "currency_code": "USD",
    "item_name": "Donation",
    "invoice": randomString(20),
    "notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
    "return": request.build_absolute_uri(reverse('pay_app:completed')),
    "cancel_return": request.build_absolute_uri(reverse('pay_app:canceled')),
    "custom": "premium_plan",  # Custom command to correlate to some function later (optional)
}

form = PayPalPaymentsForm(initial=paypal_dict)

return render(request, "pay_app/donation.html", context={'form': form})


@csrf_exempt
def paypal_return(request):
    context = {'post': request.POST, 'get': request.GET}
    return render(request, 'pay_app/complete-pp.html', context=context)

It's probably something simple but I just can't figure it out.


Solution

  • I didn't figure out the solution for getting the data with request.POST or request.GET but I did manage to use the information from the PayPalIpn table in the database so that is good enough in my situation but if somebody in the meantime figures it out feel free to answer.