コード例 #1
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)
コード例 #2
0
def get_ogone_request(payment, settings, language,
                      accepturl='NONE', cancelurl='NONE', homeurl='NONE',
                      catalogurl='NONE', declineurl='NONE', 
                      exceptionurl='NONE'):    
    
    order = payment.order

    init_data = {
        'PSPID': settings.PSPID,
        'orderID': payment.pk,
        'amount': u'%d' % (order.balance*100), 
        'language': language,
        'cn': order.bill_addressee,
        'email': order.contact.email,
        'owneraddress': order.bill_street1,
        'owneraddress2': order.bill_street2,
        'ownerstate': order.bill_state,
        'ownertown': order.bill_city,
        'ownerzip': order.bill_postal_code,
        'ownercty': order.bill_country,
        'com': unicode(order),
        # URLs need an appended slash!
        'accepturl': accepturl,
        'cancelurl': cancelurl,
        'declineurl': declineurl,
        'exceptionurl': exceptionurl,
        'homeurl': homeurl,
        'catalogurl': catalogurl,
    }
        
    return {'action': Ogone.get_action(settings=settings), 
            'form': Ogone.get_form(init_data, settings=settings)}
    
コード例 #3
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)
コード例 #4
0
def checkout(request):
    data = {}
    #transaction data
    data['orderID'] = '1'
    data['amount'] = '500'
    data['currency'] = 'EUR'
    data['language'] = 'en'
    data['SHASign'] = Ogone.sign(data)

    context = {}
    context['form'] = Ogone.get_form(data)
    context['action'] = Ogone.get_action()

    return render_to_response('shop/checkout/form.html', context)
コード例 #5
0
    def ogone_notify_handler(self, request):
        response = Ogone(request=request, settings=self.settings)
        if response.is_valid():
            fpath = request.get_full_path()
            query_string = fpath.split("?", 1)[1]
            transaction_feedback = query_string.split('&')
            result = {}
            for item in transaction_feedback:
                k, v = item.split("=")
                result[k] = v

            # Default transaction feedback parameters
            status = result.get('STATUS', False)
            orderid = result.get('orderID', '')
            payid = result.get('PAYID', '')
            ncerror = result.get('NCERROR', '')

            amount = result.get('amount', '')
            currency = result.get('currency', '')

            if status and get_status_category(int(status)) == SUCCESS_STATUS:
                ogone_payment_accepted.send(sender=self, order_id=orderid, \
                    amount=amount, currency=currency, pay_id=payid, status=status, ncerror=ncerror)
                return self.ogone_success_handler(
                    request,
                    response=result,
                    description=get_status_description(int(status)))

            if status and get_status_category(int(status)) == CANCEL_STATUS:
                ogone_payment_cancelled.send(sender=self, order_id=orderid, \
                    amount=amount, currency=currency, pay_id=payid, status=status, ncerror=ncerror)
                return self.ogone_cancel_handler(
                    request,
                    response=result,
                    description=get_status_description(int(status)))

            if status and get_status_category(
                    int(status)) == DECLINE_STATUS or EXCEPTION_STATUS:
                ogone_payment_failed.send(sender=self, order_id=orderid, \
                    amount=amount, currency=currency, pay_id=payid, status=status, ncerror=ncerror)
                return self.ogone_failure_handler(
                    request,
                    response=result,
                    description=get_status_description(int(status)))
        else:
            return HttpResponse('signature validation failed!')
コード例 #6
0
def get_ogone_form(context):
    data = {}
    #transaction data
    #data['PSPID'] = 'mypspid'
    settings = get_ogone_settings()
    order = context['order']
    data['orderID'] = order.pk
    data['amount'] = ("%.2f" % order.total).replace(".","")
    data['currency'] = settings.CURRENCY
    data['language'] = getattr(context['request'], 'LANGUAGE_CODE', 'en_US')
    s="""
    context['success_url'] = reverse_full_url('OGONE_satchmo_checkout-success')
    context['failure_url'] = reverse_full_url('OGONE_satchmo_checkout-failure')
    context['homeurl'] = reverse_full_url('satchmo_shop_home')
    """
    context['catalogurl'] = reverse_full_url('satchmo_category_index')
    context['form'] = Ogone.get_form(data)
    context['action'] = Ogone.get_action()
コード例 #7
0
ファイル: exceptions.py プロジェクト: vparitskiy/Django-ogone
    def __unicode__(self):
        from django_ogone.ogone import Ogone

        try:
            description = Ogone.get_status_description(self.status)
            return u'Ogone returned unknown status: %s (%d)' % \
                (description, self.status)
        except:
            return u'Ogone returned unknown status: %d' % self.status
コード例 #8
0
    def ogone_notify_handler(self, request):
        response = Ogone(request=request, settings=self.settings)
        if response.is_valid():
            fpath = request.get_full_path()
            query_string = fpath.split("?", 1)[1]
            transaction_feedback = query_string.split('&')
            result = {}
            for item in transaction_feedback:
                k, v = item.split("=")
                result[k] = v

            # Default transaction feedback parameters
            status = result.get('STATUS', False)
            orderid = result.get('orderID', '')
            payid = result.get('PAYID', '')
            ncerror = result.get('NCERROR', '')

            amount = result.get('amount', '')
            currency = result.get('currency', '')

            if status and get_status_category(int(status)) == SUCCESS_STATUS:
                ogone_payment_accepted.send(sender=self, order_id=orderid, \
                    amount=amount, currency=currency, pay_id=payid, status=status, ncerror=ncerror)
                return self.ogone_success_handler(request, response=result, description=get_status_description(int(status)))

            if status and get_status_category(int(status)) == CANCEL_STATUS:
                ogone_payment_cancelled.send(sender=self, order_id=orderid, \
                    amount=amount, currency=currency, pay_id=payid, status=status, ncerror=ncerror)
                return self.ogone_cancel_handler(request, response=result, description=get_status_description(int(status)))

            if status and get_status_category(int(status)) == DECLINE_STATUS or EXCEPTION_STATUS:
                ogone_payment_failed.send(sender=self, order_id=orderid, \
                    amount=amount, currency=currency, pay_id=payid, status=status, ncerror=ncerror)
                return self.ogone_failure_handler(request, response=result, description=get_status_description(int(status)))
        else:
            return HttpResponse('signature validation failed!')
コード例 #9
0
ファイル: views.py プロジェクト: agiliq/django-ogone
def checkout(request):
    data = {}
    #transaction data
    data['orderID'] = '1'
    data['amount'] = '500'
    data['currency'] = 'EUR'
    data['language'] = 'en'
    data['SHASign'] = Ogone.sign(data)
    
    context = {}
    context['form'] = ogone_forms.OgoneForm(data)
    
    if ogone_settings.PRODUCTION:
        request.context['action'] = 'https://secure.ogone.com/ncol/test/orderstandard.asp'
    else:
        request.context['action'] = 'https://secure.ogone.com/ncol/prod/orderstandard.asp'
コード例 #10
0
 def service_url(self):
     return Ogone.get_action(production=self.settings.PRODUCTION)
コード例 #11
0
 def generate_form(self):
     form = Ogone.get_form(self.fields, settings=self.settings)
     return form
コード例 #12
0
 def service_url(self):
     return Ogone.get_action(production=self.settings.PRODUCTION)
コード例 #13
0
 def generate_form(self):
     form = Ogone.get_form(self.fields, settings=self.settings)
     return form
コード例 #14
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('')