undefined undefined undefined

Liqpay Payment system.

Open in new window

Liqpay

pip install git+https://github.com/liqpay/sdk-python#egg=liqpay

NOT this for Python 3 !!!

pip install liqpay-python

Doc

https://www.liqpay.ua/documentation/api/aquiring/checkout/doc

LIQPAY_PUBLIC_KEY   = '***'
LIQPAY_PRIVATE_KEY  = '***'

URL

path('pay_order/<int:order_id>', pay_order, name="pay_order"),

Link

<td><a href="{% url 'pay_order' order_id=o.id %}">Pay</a></td>

View

from liqpay.liqpay3 import LiqPay
from django.conf import settings
...

def pay_order(request,order_id):

    liqpay = LiqPay(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY)
    form_html = liqpay.cnb_form({
        'action': 'pay',
        'amount': '10',
        'currency': 'UAH',
        'description': 'pizza description',
        'order_id': 'order_id',
        'version': '3'
    })
    return render(request,'shop/pay_order.html',{'form_html': form_html})

|## Callback process

@method_decorator(csrf_exempt, name='dispatch')    
class ProcessPayment(View):    
    def post(self, request, *args, **kwargs):
        liqpay = LiqPay(LIQPAY_PUBLIC_KEY,LIQPAY_PRIVATE_KEY)
        data = request.POST.get('data')
        signature = request.POST.get('signature')
        sign = liqpay.str_to_sign(LIQPAY_PRIVATE_KEY + data + LIQPAY_PRIVATE_KEY)
        response = liqpay.decode_data_from_str(data)
        if sign == signature:
            try:
                o = LessonPayments.objects.get(pk=int(response['order_id']))
                o.is_paid = True
                o.save()
            except Exception, e:
                print(str(e))

        print('callback data', response)
        return HttpResponse()

Other topics