Reputation: 105
i am trying to integrate django app with paypal payment gateway, but i am not getting my signals fired, as well as i am not able to receive paypal ipn notifications,
class Pr_request(models.Model):
number = models.CharField(max_length=20)
subject = models.TextField(max_length=500)
date_posted = models.DateTimeField(auto_now_add=True)
class Purchase(models.Model):
resourse = models.ForeignKey(Pr_request, related_name='purchase')
purchaser = models.ForeignKey(User)
purchased_at = models.DateTimeField(auto_now_add=True)
def payment_proccess(request, id):
pr = get_object_or_404(Pr_request, id=id)
host = request.get_host()
paypal_dict = {
'business': settings.PAYPAL_RECEIVER_EMAIL,
'amount': '%.2f' % pr.fees.quantize(Decimal('.01')),
'item_name': 'purchase Req {}'.format(pr.number),
'invoice': '2',
'currency_code': 'USD',
'notifiy_url' : 'http://da...879.ngrok.io',#also i tried
localhost
'return_url' : 'http://{}{}'.format(host, reverse('payment:done')),
'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')),
}
form = PayPalPaymentsForm(initial=paypal_dict)
print (" iam pyament process function")
return render(request, 'payment/process.html', {'pr':pr, 'form':form})
def payment_notification(request, sender, **kwargs):
ipn_obj = sender
if ipn_obj.payment_status == ST_PP_COMPLETED:
print ("successful payment was done Lol")
pr = get_object_or_404(Pr_request, id=ipn_obj.invoice)
pur = Purchase.objects.get_or_create(resourse=pr,
purchaser=request.user,
tx='some text')
pur.save()
#mark the pr as paid
else:
print (" not able to pay")
# payment was successful
valid_ipn_received.connect(payment_notification)
print ("signal is fired")
default_app_config = 'payment.apps.PaymentConfig'
note that i am getting my signals fired whenever i reload my local server, so any idea about my mistake,thanks ..
Upvotes: 2
Views: 264
Reputation: 105
finally i found my mistake , and it was just a typo, in my views.py
'notifiy_url' : 'http://{}{}'.format(host, reverse('paypal-ipn')),
# should be changed to
'notify_url' : 'http://{}{}'.format(host, reverse('paypal-ipn')),
# also here i have set the logged in user
'payer': request.user,
Upvotes: 1