Django-pay pal IPN response not receiving

72 Views Asked by At

I am trying to integrate a payment gateway for my Project , but I am having trouble understanding how to handle the IPN listener part of it, I am really confused about whether to create a new view for it , or where should form reside and also how to implement the signals which it sends , I have spent hours looking for an answer but no avail ! thanks in advance

class PaymentProcess(View):
    def get(self,request):
        host = request.get_host()
        payment = PaymentRecords.objects.get(
            order_id = request.session['order_id']
        )
        print(payment.total_amount)
        print(host)
        paypal_dict = {
            'business': settings.PAYPAL_RECEIVER_EMAIL,
            'amount': payment.total_amount,
            'item_name': 'Item_Name_xyz',
            'invoice': 'Test Payment Invoice'+'INV12323244'+str(randint(10,5000)),
            'currency_code': 'USD',
            # 'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')), <---  how to deal with this one 
            # 'return_url': 'http://{}{}'.format(host, reverse('payment_done')),
            # 'cancel_return': 'http://{}{}'.format(host, reverse('payment_canceled')),
        }
        form = PayPalPaymentsForm(initial=paypal_dict)
        return render(request , 'restprac/index.html',{'form':form})

signals.py

def show_me_the_money(sender, **kwargs):
    ipn_obj = sender
    print(sender)
    if ipn_obj.payment_status == ST_PP_COMPLETED:
        # WARNING !
        # Check that the receiver email is the same we previously
        # set on the `business` field. (The user could tamper with
        # that fields on the payment form before it goes to PayPal)
        if ipn_obj.receiver_email != "[email protected]":
        # Not a valid payment
            return

        # ALSO: for the same reason, you need to check the amount
        # received, `custom` etc. are all what you expect or what
        # is allowed.

        # Undertake some action depending upon `ipn_obj`.
        if ipn_obj.custom == "premium_plan":
            price = ...
        else:
            price = ...

        if ipn_obj.mc_gross == price and ipn_obj.mc_currency == 'USD':
            ...
        else:
            pass
            #...
            



valid_ipn_received.connect(show_me_the_money)
0

There are 0 best solutions below