Django-pay pal IPN ответ не получен
Я пытаюсь интегрировать платежный шлюз для моего проекта, но у меня проблемы с пониманием того, как работать с частью IPN listener, я действительно запутался, нужно ли создавать новое представление для него, или где должна находиться форма, а также как реализовать сигналы, которые он посылает, я потратил часы на поиск ответа, но безрезультатно! Спасибо заранее
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 != "receiver_email@example.com":
# 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)