def capture_payment(self, testing=False, order=None, amount=None):
        """Execute the post to Sage Pay VSP DIRECT"""
        if not order:
            order = self.order

        if order.paid_in_full:
            self.log_extra('%s is paid in full, no capture attempted.', order)
            self.record_payment()
            return ProcessorResult(self.key, True, _("No charge needed, paid in full."))

        self.log_extra('Capturing payment for %s', order)

        if amount is None:
            amount = order.balance

        self.prepare_post(order, amount)

        if self.valid:
            if self.settings.SKIP_POST.value:
                self.log.info("TESTING MODE - Skipping post to server.  Would have posted %s?%s", self.url, self.postString)
                payment = self.record_payment(order=order, amount=amount,
                    transaction_id="TESTING", reason_code='0')

                return ProcessorResult(self.key, True, _('TESTING MODE'), payment=payment)

            else:
                self.log_extra("About to post to server: %s?%s", self.url, self.postString)
                conn = urllib2.Request(self.url, data=self.postString)
                try:
                    f = urllib2.urlopen(conn)
                    result = f.read()
                    self.log_extra('Process: url=%s\nPacket=%s\nResult=%s', self.url, self.packet, result)

                except urllib2.URLError, ue:
                    self.log.error("error opening %s\n%s", self.url, ue)
                    return ProcessorResult(self.key, False, 'Could not talk to Sage Pay gateway')

                try:
                    self.response = dict([row.split('=', 1) for row in result.splitlines()])
                    status = self.response['Status']
                    success = (status == 'OK')
                    detail = self.response['StatusDetail']

                except __HOLE__, e:
                    self.log.info('Error submitting payment: %s', e)
                    payment = self.record_failure(order=order, amount=amount,
                        transaction_id="", reason_code="error",
                        details='Invalid response from payment gateway')

                    return ProcessorResult(self.key, False, _('Invalid response from payment gateway'))

                payment = None
                transaction_id = ""
                if success:
                    vpstxid = self.response.get('VPSTxID', '')
                    txauthno = self.response.get('TxAuthNo', '')
                    transaction_id="%s,%s" % (vpstxid, txauthno)
                    self.log.info('Success on order #%i, recording payment', self.order.id)
                    payment = self.record_payment(order=order, amount=amount,
                        transaction_id=transaction_id, reason_code=status)

                else:
                    payment = self.record_failure(order=order, amount=amount,
                        transaction_id=transaction_id, reason_code=status,
                        details=detail)

                return ProcessorResult(self.key, success, detail, payment=payment)
        else:
            return ProcessorResult(self.key, False, _('Error processing payment.'))
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/payment/modules/sagepay/processor.py/PaymentProcessor.capture_payment