Пример #1
0
    def test_functions(self):

        # Test verify_session
        verified = verify_session(self.good_sessid)
        self.assertEqual(verified, True)

        verified = verify_session(self.junk_sessid)
        self.assertEqual(verified, False)

        # Test save_session
        save_session(self.junk_sessid)
        try:
            sess = IpaymuSessionID.objects.get(sessid=self.junk_sessid)
        except IpaymuSessionID.DoesNotExist:
            raise
        else:
            self.assertEqual(sess.sessid, self.junk_sessid)
Пример #2
0
    def test_functions(self):

        # Test verify_session
        verified = verify_session(self.good_sessid)
        self.assertEqual(verified, True)

        verified = verify_session(self.junk_sessid)
        self.assertEqual(verified, False)

        # Test save_session
        save_session(self.junk_sessid)
        try:
            sess = IpaymuSessionID.objects.get(sessid=self.junk_sessid)
        except IpaymuSessionID.DoesNotExist:
            raise
        else:
            self.assertEqual(sess.sessid, self.junk_sessid)
Пример #3
0
def process(request):
    """
    Process transaction request.
    """

    if request.method == 'POST':
        params = IpaymuParamsBuilder(request)

        if params.is_valid():

            # In case of connection/request error
            try:
                req = requests.post(settings.IPAYMU_REQUEST_URL,
                                    data=params.cleaned_params)
            except Timeout:
                return HttpResponse('Request timeout!.')
            except ConnectionError:
                return HttpResponse('Connection Error!.')

            # In case of empty response/Json Encode error
            try:
                resp_json = req.json()
            except:
                return HttpResponse('Empty response received!.')

            payment_url = resp_json.get('url')
            if payment_url:
                # Save session ID
                save_session(resp_json.get('sessionID'))
                # Execute callback when sessionID received.
                execute_callback('session_received', request,
                                 resp_json.get('sessionID'))
                return HttpResponseRedirect(payment_url)

            return HttpResponse(req.text)

        return HttpResponse(json.dumps(params.errors))

    return HttpResponse('Invalid request.')
Пример #4
0
def process(request):
    """
    Process transaction request.
    """

    if request.method == 'POST':
        params = IpaymuParamsBuilder(request)

        if params.is_valid():

            # In case of connection/request error
            try:
                req = requests.post(settings.IPAYMU_REQUEST_URL, data=params.cleaned_params)
            except Timeout:
                return HttpResponse('Request timeout!.')
            except ConnectionError:
                return HttpResponse('Connection Error!.')

            # In case of empty response/Json Encode error
            try:
                resp_json = req.json()
            except:
                return HttpResponse('Empty response received!.')

            payment_url = resp_json.get('url')
            if payment_url:
                # Save session ID
                save_session(resp_json.get('sessionID'))
                # Execute callback when sessionID received.
                execute_callback('session_received', request, resp_json.get('sessionID'))
                return HttpResponseRedirect(payment_url)

            return HttpResponse(req.text)

        return HttpResponse(json.dumps(params.errors))
        
    return HttpResponse('Invalid request.')