<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def dispatch(self,request,*args,**kwargs):
        '''
        Check that a valid Invoice ID has been passed in session data,
        and that said invoice is marked as paid.
        '''
        paymentSession = request.session.get(INVOICE_VALIDATION_STR, {})
        self.invoiceID = paymentSession.get('invoiceID')
        self.amount = paymentSession.get('amount',0)
        self.success_url = paymentSession.get('success_url',reverse('registration'))

        # Check that Invoice matching passed ID exists
        try:
            i = Invoice.objects.get(id=self.invoiceID)
        except ObjectDoesNotExist:
            return HttpResponseBadRequest(_('Invalid invoice information passed.'))

        if i.unpaid or i.amountPaid != self.amount:
            return HttpResponseBadRequest(_('Passed invoice is not paid.'))

        return super(GiftCertificateCustomizeView,self).dispatch(request,*args,**kwargs)