Advertisement
MarkUa

Untitled

Mar 27th, 2020
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1.  # path("", PayView.as_view(), name='pay_view'),
  2. # path('pay-callback/', PayCallbackView.as_view(), name='pay_callback'),
  3.  
  4. from liqpay import LiqPay
  5.  
  6. from django.views.generic import TemplateView
  7. from django.shortcuts import render
  8. from django.http import HttpResponse
  9.  
  10. class PayView(TemplateView):
  11.     template_name = 'billing/pay.html'
  12.  
  13.     def get(self, request, *args, **kwargs):
  14.         liqpay = LiqPay("i14834950111", "MOd35a45stEweq6tlDeY83HmPkCGe8nbyCdZ9vEV")
  15.         params = {
  16.             'action': 'pay',
  17.             'amount': '1',
  18.             'currency': 'UAH',
  19.             'description': 'Payment for clothes',
  20.             'order_id': 'order_id_1',
  21.             'version': '3',
  22.             'sandbox': 0, # sandbox mode, set to 1 to enable it
  23.             'server_url': 'https://test.com/billing/pay-callback/', # url to callback view
  24.         }
  25.         signature = liqpay.cnb_signature(params)
  26.         data = liqpay.cnb_data(params)
  27.         return render(request, self.template_name, {'signature': signature, 'data': data})
  28.  
  29. @method_decorator(csrf_exempt, name='dispatch')
  30. class PayCallbackView(View):
  31.     def post(self, request, *args, **kwargs):
  32.         liqpay = LiqPay("i14834950111", "MOd35a45stEweq6tlDeY83HmPkCGe8nbyCdZ9vEV")
  33.         data = request.POST.get('data')
  34.         signature = request.POST.get('signature')
  35.         sign = liqpay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data + settings.LIQPAY_PRIVATE_KEY)
  36.         if sign == signature:
  37.             print('callback is valid')
  38.         response = liqpay.decode_data_from_str(data)
  39.         print('callback data', response)
  40.         return HttpResponse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement