コード例 #1
0
ファイル: views.py プロジェクト: agiliq/django-ogone
def order_status_update(request):
    '''
    Updates the order status with ogone data.
    There are two ways of reaching this flow
    
    - payment redirect (user gets redirected through this flow)
    - ogone server side call (in case of problems ogone will post to our server
    with an updated version ofo the payment status)
    
    For testing order flow updates
    http://localhost:8080/order_status_update/?orderID=12&currency=EUR&amount=680.44&PM=CreditCard&ACCEPTANCE=test123&STATUS=5&CARDNO=XXXXXXXXXXXX1111&ED=0114&CN=thierry&TRXDATE=09/21/10&PAYID=8254874&NCERROR=0&BRAND=VISA&IPCTY=NL&CCCTY=US&ECI=12&CVCCheck=NO&AAVCheck=NO&VC=NO&IP=85.145.6.230&SHASIGN=B02C883D4D31D9665305EA05CC81D3DED7726C68F18C870A8C8F3119DC1B460D9103944692B6E44D47EEA402630770A8122F6D1B7028CC5FD58847DC43D7C082
    '''
    params = request.POST or request.GET
    ogone = Ogone(params)
    
    if ogone.is_valid():
        #update the order data, different for each site
        #need the ogone data and custom logic, use signals for this
        ogone_signals.ogone_update_order.send(sender=Ogone, ogone=ogone)
        
        #redirect to the appropriate view
        order_id = ogone.get_order_id()
        url = '%s?transaction_id=%s' % (reverse('checkout'), order_id)
        
        return HttpResponseRedirect(url)
コード例 #2
0
def order_status_update(request):
    '''
    Updates the order status with ogone data.
    There are two ways of reaching this flow

    - payment redirect (user gets redirected through this flow)
    - ogone server side call (in case of problems ogone will post to our server
    with an updated version ofo the payment status)

    For testing order flow updates
    http://localhost:8080/order_status_update/?orderID=12&currency=EUR&amount=680.44&PM=CreditCard&ACCEPTANCE=test123&STATUS=5&CARDNO=XXXXXXXXXXXX1111&ED=0114&CN=thierry&TRXDATE=09/21/10&PAYID=8254874&NCERROR=0&BRAND=VISA&IPCTY=NL&CCCTY=US&ECI=12&CVCCheck=NO&AAVCheck=NO&VC=NO&IP=85.145.6.230&SHASIGN=B02C883D4D31D9665305EA05CC81D3DED7726C68F18C870A8C8F3119DC1B460D9103944692B6E44D47EEA402630770A8122F6D1B7028CC5FD58847DC43D7C082
    Accented characters with sha1
    http://127.0.0.1:8000/order_status_update/?orderID=44&currency=CHF&amount=10&PM=CreditCard&ACCEPTANCE=test123&STATUS=5&CARDNO=XXXXXXXXXXXX1111&ED=0115&CN=S%E9bastien+Fievet&TRXDATE=11%2F02%2F10&PAYID=8580040&NCERROR=0&BRAND=VISA&IPCTY=CH&CCCTY=US&ECI=7&CVCCheck=NO&AAVCheck=NO&VC=NO&IP=188%2E62%2E236%2E12&SHASIGN=861D83EAC408746F5A7CFA3F5BDD3C7C6C145817
    '''
    # Workaround because Ogone deals with latin1 characters and we want
    # our website to use another ``DEFAULT_CHARSET`` (default: utf8).
    from django.http import QueryDict
    params = QueryDict(request.META['QUERY_STRING'], encoding='latin1')
    # --//--
    ogone = Ogone(params)

    if ogone.is_valid():
        #update the order data, different for each site
        #need the ogone data and custom logic, use signals for this
        ogone_signals.ogone_update_order.send(sender=Ogone, ogone=ogone)

        #redirect to the appropriate view
        order_id = ogone.get_order_id()
        url = reverse('tracking', args=[order_id])

        return HttpResponseRedirect(url)
コード例 #3
0
def order_status_update(request, order=None):
    '''
    Updates the order status with ogone data.
    There are two ways of reaching this flow
    
    - payment redirect (user gets redirected through this flow)
    - ogone server side call (in case of problems ogone will post to our server
    with an updated version ofo the payment status)
    '''

    log.debug('Attempting to update status information',
              extra={'request': request})

    params = request.GET or request.POST
    if params.get('orderID', False):
        # Get Ogone settings from Satchmo
        ogone = Ogone(params, settings=get_ogone_settings())
    
        # Make sure we check the data, and raise an exception if its wrong
        ogone.is_valid()

        # Fetch parsed params
        parsed_params = ogone.parse_params()   

        log.debug('We have found a valid status feedback message.',
                  extra={'data':{'parsed_params': parsed_params}})
    
        # Get the order 
        payment_id = ogone.get_order_id()
        
        try:
            ogone_payment = OrderPayment.objects.get(pk=payment_id)
        except OrderPayment.DoesNotExist:
            log.warning('Payment with payment_id=%d not found.', payment_id)
            
            return HttpResponse('')
        
        ogone_order = ogone_payment.order
        
        assert not order or (ogone_order.pk == order.pk), \
            'Ogone\'s order and my order are different objects.'
        
        log.debug('Found order %s for payment %s in processing feedback.',
                  ogone_order, ogone_payment)
        
        # Do order processing and status comparisons here
        processor = get_processor_by_key('PAYMENT_OGONE')    
        
        status_code = parsed_params['STATUS']
        status_num = int(status_code)
        
        assert status_num, 'No status number.'
        
        log.debug('Recording status: %s (%s)',
                  status_codes.STATUS_DESCRIPTIONS[status_num],
                  status_code)
        
        # Prepare parameters for recorder
        params = {'amount': Decimal(parsed_params['AMOUNT']),
                  'order': ogone_order,
                  'transaction_id': parsed_params['PAYID'],
                  'reason_code': status_code }
        
        if status_num in (9, 91):
            # Payment was captured
            try:
                authorization = OrderAuthorization.objects.get(order=ogone_order, \
                                                               transaction_id=parsed_params['PAYID'], \
                                                               complete=False)
                params.update({'authorization': authorization})
            except OrderAuthorization.DoesNotExist:
                pass
            
            processor.record_payment(**params)

            # Only change the status when it was empty or 'New' before.
            def _latest_status(order):
                    try:
                        curr_status = order.orderstatus_set.latest()
                        return curr_status.status
                    except OrderStatus.DoesNotExist:
                        return ''

            if _latest_status(ogone_order) in ('', 'New'):
                ogone_order.add_status(status='Billed', 
                    notes=_("Payment accepted by Ogone."))

            
        elif status_num in (5, 51):
            # Record authorization
            processor.record_authorization(**params)
        
        elif status_num in (4, 41):
            # We're still waiting
            ogone_order.add_status(status='New', 
                notes=_("Payment is being processed by Ogone."))
        
        else:
            # Record failure
            processor.record_failure(**params)
            
            if status_num in (1,):
                # Order cancelled

                ogone_order.add_status(status='Cancelled', 
                    notes=_("Order cancelled through Ogone."))

            elif status_num in (2, 93):
                # Payment declined

                ogone_order.add_status(status='Blocked', 
                    notes=_("Payment declined by Ogone."))
            
            elif status_num in (52, 92):
                log.warning('Payment of order %s (ID: %d) uncertain. Status: %s (%d)',
                    ogone_order, ogone_order.pk, 
                    status_codes.STATUS_DESCRIPTIONS[status_num], status_num)
            
            else:
                log.warning('Uknown status code %d found for order %s.',
                            status_num, 
                            ogone_order,
                            exc_info=sys.exc_info()
                           )
    else:
        log.warning('This response does not look valid, orderID not found.',
                    extra={'request': request})
    
    # Return an empty HttpResponse
    return HttpResponse('')