Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # path("", PayView.as_view(), name='pay_view'),
- # path('pay-callback/', PayCallbackView.as_view(), name='pay_callback'),
- from liqpay import LiqPay
- from django.views.generic import TemplateView
- from django.shortcuts import render
- from django.http import HttpResponse
- class PayView(TemplateView):
- template_name = 'billing/pay.html'
- def get(self, request, *args, **kwargs):
- liqpay = LiqPay("i14834950111", "MOd35a45stEweq6tlDeY83HmPkCGe8nbyCdZ9vEV")
- params = {
- 'action': 'pay',
- 'amount': '1',
- 'currency': 'UAH',
- 'description': 'Payment for clothes',
- 'order_id': 'order_id_1',
- 'version': '3',
- 'sandbox': 0, # sandbox mode, set to 1 to enable it
- 'server_url': 'https://test.com/billing/pay-callback/', # url to callback view
- }
- signature = liqpay.cnb_signature(params)
- data = liqpay.cnb_data(params)
- return render(request, self.template_name, {'signature': signature, 'data': data})
- @method_decorator(csrf_exempt, name='dispatch')
- class PayCallbackView(View):
- def post(self, request, *args, **kwargs):
- liqpay = LiqPay("i14834950111", "MOd35a45stEweq6tlDeY83HmPkCGe8nbyCdZ9vEV")
- data = request.POST.get('data')
- signature = request.POST.get('signature')
- sign = liqpay.str_to_sign(settings.LIQPAY_PRIVATE_KEY + data + settings.LIQPAY_PRIVATE_KEY)
- if sign == signature:
- print('callback is valid')
- response = liqpay.decode_data_from_str(data)
- print('callback data', response)
- return HttpResponse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement