Git Product home page Git Product logo

liqpay-sdk-python3's Introduction

Python 3.6+

SDK-Python3

What python version is supported?

  • Python 3.4, 3.5, 3.6

Get Started

  1. Sign up in https://www.liqpay.ua/en/authorization.
  2. Create a company.
  3. In company settings, on API tab, get Public key and Private key.
  4. Done.

Installation

From pip pip install liqpay-sdk-python3

Working with LiqPay Callback locally

If you need debugging API Callback on local environment use https://localtunnel.github.io/www/

How it use?

Example 1: Basic

Backend Get payment button (html response)

liqpay = LiqPay(public_key, private_key)
html = liqpay.cnb_form({
    'action': 'pay',
    'amount': '1',
    'currency': 'USD',
    'description': 'description text',
    'order_id': 'order_id_1',
    'version': '3',
    'language': 'ru|uk|en'
})

Get plain checkout url:

liqpay = LiqPay(public_key, private_key)
html = liqpay.checkout_url({
    'action': 'auth',
    'amount': '1',
    'currency': 'USD',
    'description': 'description text',
    'order_id': 'order_id_1',
    'version': '3',
    'language': 'ru|uk|en',
    'recurringbytoken': '1'
})
# Response:

str: https://www.liqpay.ua/api/3/checkout/?data=<decoded data>&signature=<decoded signature>

Frontend

Variable html will contain next html form

    <form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
        <input type="hidden" name="data" value="eyAidmVyc2lvbiIgOiAzLCAicHVibGljX2tleSIgOiAieW91cl9wdWJsaWNfa2V5IiwgImFjdGlv
        biIgOiAicGF5IiwgImFtb3VudCIgOiAxLCAiY3VycmVuY3kiIDogIlVTRCIsICJkZXNjcmlwdGlv
        biIgOiAiZGVzY3JpcHRpb24gdGV4dCIsICJvcmRlcl9pZCIgOiAib3JkZXJfaWRfMSIgfQ=="/>
        <input type="hidden" name="signature" value="QvJD5u9Fg55PCx/Hdz6lzWtYwcI="/>
        <input type="image"
        src="//static.liqpay.ua/buttons/p1ru.radius.png"/>
    </form>

Example 2: Integrate Payment widget to Django

Payment widget documentation https://www.liqpay.ua/documentation/en/api/aquiring/widget/

Backend

views.py


    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(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY)
        params = {
            'action': 'pay',
            'amount': '100',
            'currency': 'USD',
            '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(settings.LIQPAY_PUBLIC_KEY, settings.LIQPAY_PRIVATE_KEY)
            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()

urls.py


    from django.conf.urls import url

    from billing.views import PayView, PayCallbackView


    urlpatterns = [
        url(r'^pay/$', PayView.as_view(), name='pay_view'),
        url(r'^pay-callback/$', PayCallbackView.as_view(), name='pay_callback'),
    ]

Frontend


    <div id="liqpay_checkout"></div>
    <script>
        window.LiqPayCheckoutCallback = function() {
            LiqPayCheckout.init({
                data: "{{ data }}",
                signature: "{{ signature }}",
                embedTo: "#liqpay_checkout",
                mode: "embed" // embed || popup,
            }).on("liqpay.callback", function(data){
                console.log(data.status);
                console.log(data);
            }).on("liqpay.ready", function(data){
                // ready
            }).on("liqpay.close", function(data){
                // close
            });
        };
    </script>
    <script src="//static.liqpay.ua/libjs/checkout.js" async></script>

liqpay-sdk-python3's People

Contributors

aorzh avatar viplifes avatar jff-bohdan avatar stormteller avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.