예제 #1
0
파일: test.py 프로젝트: wowkin2/sdk-python
class TestLiqPaySimple(unittest.TestCase):
    def setUp(self):
        self.liqpay = LiqPay('', '')
        self.maxDiff = None

    def test_api(self):
        self.assertTrue(
            self.liqpay.api("payment/status", {"payment_id": "3940"}))

    def test_gen_form(self):
        expected_form_out = (
            u'<form method="post" action="https://www.liqpay.com/api/3/checkout/" accept-charset="utf-8">\n'
            u'\t<input type="hidden" name="data" value="eyJwdWJsaWNfa2V5IjogIiIsICJkZXNjcmlwdGlvbiI6ICJcdTA0NDJcdTA0MzVcdTA0NDFcdTA0NDIiLCAibGFuZ3VhZ2UiOiAicnUiLCAic2FuZGJveCI6IDAsICJjdXJyZW5jeSI6ICJVQUgiLCAiYW1vdW50IjogIjM5NDAiLCAidGVzdCI6ICJjY2NjIn0="/>\n'
            u'\t<input type="hidden" name="signature" value="Zdm/xbS30v9ZTNXrLXeW9QFVxHQ="/>\n'
            u'    <input type="image" src="//static.liqpay.com/buttons/p1ru.radius.png" name="btn_text" />\n'
            u'</form>')
        # test unicode issue with ru symbols
        params = {
            "amount": "3940",
            "currency": "UAH",
            "description": "тест",
            "test": "cccc"
        }
        self.assertEqual(self.liqpay.cnb_form(params), expected_form_out)

        # ru symbols in unicode
        params.update(description=u'тест')
        self.assertEqual(self.liqpay.cnb_form(params), expected_form_out)

        # test gen_form without required param
        del params['amount']
        self.assertRaises(ParamValidationError, self.liqpay.cnb_form, params)
예제 #2
0
파일: test.py 프로젝트: rrader/sdk-python
class TestLiqPaySimple(unittest.TestCase):

    def setUp(self):
        self.liqpay = LiqPay('', '')
        self.maxDiff = None

    def test_api(self):
        self.assertTrue(self.liqpay.api("payment/status", {"payment_id": "3940"}))

    def test_gen_form(self):
        expected_form_out = (
            u'<form method="post" action="https://www.liqpay.com/api/3/checkout/" accept-charset="utf-8">\n'
            u'\t<input type="hidden" name="data" value="eyJwdWJsaWNfa2V5IjogIiIsICJkZXNjcmlwdGlvbiI6ICJcdTA0NDJcdTA0MzVcdTA0NDFcdTA0NDIiLCAibGFuZ3VhZ2UiOiAicnUiLCAic2FuZGJveCI6IDAsICJjdXJyZW5jeSI6ICJVQUgiLCAiYW1vdW50IjogIjM5NDAiLCAidGVzdCI6ICJjY2NjIn0="/>\n'
            u'\t<input type="hidden" name="signature" value="Zdm/xbS30v9ZTNXrLXeW9QFVxHQ="/>\n'
            u'    <input type="image" src="//static.liqpay.com/buttons/p1ru.radius.png" name="btn_text" />\n'
            u'</form>'
        )
        # test unicode issue with ru symbols
        params = dict(
            amount="3940",
            currency="UAH",
            description="тест",
            test="cccc"
        )
        self.assertEqual(self.liqpay.cnb_form(params), expected_form_out)

        # ru symbols in unicode
        params.update(description=u'тест')
        self.assertEqual(self.liqpay.cnb_form(params), expected_form_out)

        # test gen_form without required param
        del params['amount']
        self.assertRaises(ParamValidationError, self.liqpay.cnb_form, params)
예제 #3
0
def PayLoadView(request, picture_id, org_id):
    try:
        picture = Picture.objects.get(pk=picture_id)
        #p_author = User.objects.get(username=request.user.username)
        organization = Organization.objects.get(pk=org_id)
        
        lang = "ru"
        if translation.get_language() == "en":
            lang = "en"

        if request.user.is_authenticated():
            user = User.objects.get(username=request.user.username)
            user_id = user.email
        else:
            user_id = get_client_ip(request)
        order = Download.create(0, picture, organization, user_id, "web-liqpay")
        order.save()

        liqpay = LiqPay(settings.LIQPAY_PUBLIC, settings.LIQPAY_PRIVAT)
        html_f = liqpay.cnb_form({
            "version" : "3",
            "amount" : "1",
            "currency" : "USD",
            "description" : "Donate for "+organization.name,
            "order_id" : order.id,
            "result_url" : "http://pics.ato.care/care/donload/"+picture_id+"/"+org_id+"/"+str(order.id),
            "language" : lang,
            #"sandbox": 1,
        })

        return HttpResponse(simplejson.dumps({'success': "true", 'message': "", 'form':html_f}), content_type="application/json")
    except Exception, e:
        return HttpResponse(simplejson.dumps({'success': "false", 'message': "Wrong request..."}), content_type="application/json")
예제 #4
0
def get_payment(order_id):
    ukraine = timezone(timedelta(hours=2))
    data = CafeOrder.find_one({"order_id": str(order_id)})
    if data is None:
        return "Замовлення не знайдено"

    data_to_send = {
        "version":
        3,
        "public_key":
        UNIT_PUB_KEY,
        "action":
        "pay",
        "amount":
        str(data.price),
        "currency":
        "UAH",
        "description":
        "{order_id} від {datetime} За замовлення в UNIT.cafe".format(
            order_id=order_id,
            datetime=datetime.now(
                tz=ukraine).strftime("%Y-%m-%dT%H:%M:%S.%f")),
        "server_url":
        "https://unit.cafe/index.php?route=extension/payment/liqpay/callback",
        "result_url":
        "https://www.facebook.com/FriendlyFoodBot/",
        "order_id":
        order_id
    }

    liqpay = LiqPay(UNIT_PUB_KEY, UNIT_PRIV_KEY)
    try:
        html = liqpay.cnb_form(data_to_send)
    except:
        return "Замовлення не знайдено"
    return html