Ejemplo n.º 1
0
def confirm(request):
    # The view for payment confirmation
    page_title = "Confirmation"
    if request.method == 'POST':
        payment_form = PaymentForm(request.POST)
        if payment_form.is_valid():
            params_dict = get_posted_parameters(payment_form)
            signature = sign(params_dict)
            params_dict['signature'] = signature
            confirmation_form = ConfirmationForm(params_dict)
            return render_to_response('confirm.html', {
                'page_title': page_title,
                'confirmation_form': confirmation_form,
                'params_dict': params_dict,
                'signature': signature
            },
                                      context_instance=RequestContext(request))
        else:
            from configuration import *
            page_title = "Payment"
            return render_to_response('pay.html', {
                'page_title': page_title,
                'payment_form': payment_form
            },
                                      context_instance=RequestContext(request))
    else:
        return pay(request)
 def _receive_confirmation(self, request, origin):
     query_dict = dict((key.lower(), value) for key, value in request.GET.iteritems())
     query_dict.update({
         'order': query_dict.get('orderid', 0),
         'origin': origin,
     })
     confirmation = ConfirmationForm(query_dict)
     if confirmation.is_valid():
         confirmation.save()
     else:
         raise ValidationError('Confirmation sent by PSP did not validate: %s' % confirmation.errors)
     shaoutsign = self._get_sha_sign(query_dict, self.SHA_OUT_PARAMETERS,
                     settings.VIVEUM_PAYMENT.get('SHA1_OUT_SIGNATURE'))
     if shaoutsign != confirmation.cleaned_data['shasign']:
         raise SuspiciousOperation('Confirm redirection by PSP has a divergent SHA1 signature')
     self.logger.info('PSP redirected client with status %s for order %s',
         confirmation.cleaned_data['status'], confirmation.cleaned_data['orderid'])
     return confirmation
Ejemplo n.º 3
0
 def payment_was_successful(self, request):
     '''
     This listens to a confirmation sent by one of the IPayment servers.
     Valid payments are commited as confirmed payments into their model.
     The intention of this view is not to display any useful information,
     since the HTTP-client is a server located at IPayment.
     '''
     if request.method != 'POST':
         return HttpResponseBadRequest()
     try:
         if settings.IPAYMENT['checkOriginatingIP']:
             self._check_originating_ipaddr(request)
         post = request.POST.copy()
         if 'trx_amount' in post:
             post['trx_amount'] = (Decimal(post['trx_amount']) / Decimal('100')) \
                                                 .quantize(Decimal('0.00'))
         if 'ret_transdate' and 'ret_transtime' in post:
             post['ret_transdatetime'] = datetime.strptime(
                 post['ret_transdate'] + ' ' + post['ret_transtime'],
                 '%d.%m.%y %H:%M:%S')
         confirmation = ConfirmationForm(post)
         if not confirmation.is_valid():
             raise SuspiciousOperation(
                 'Confirmation by IPayment rejected: '
                 'POST data does not contain all expected fields.')
         if not settings.IPAYMENT['useSessionId']:
             self._check_ret_param_hash(request.POST)
         confirmation.save()
         order = self.shop.get_order_for_id(
             confirmation.cleaned_data['shopper_id'])
         self.logger.info('IPayment for %s confirmed %s', order,
                          confirmation.cleaned_data['ret_status'])
         if confirmation.cleaned_data['ret_status'] == 'SUCCESS':
             self.shop.confirm_payment(
                 order, confirmation.cleaned_data['trx_amount'],
                 confirmation.cleaned_data['ret_trx_number'],
                 self.backend_name)
         return HttpResponse('OK')
     except Exception as exception:
         # since this response is sent to IPayment, catch errors locally
         logging.error('POST data: ' + request.POST.__str__())
         logging.error(exception.__str__())
         traceback.print_exc()
         return HttpResponseServerError('Internal error in ' + __name__)