def _executeCancel(self, user, code=None): """Called internally. Do the cancellation of a pending payment order and generate the reply.""" debug("Cancellation attempt from %s (%s)" % (user, code)) try: payment = PaymentOrder(user, code=code) except PaymentNotFoundError: raise CommandError, _(TX, 'error_tx_not_found').format(code=code) payment.cancel() debug("Payment %s (BTC %s to %s) was cancelled by %s" % \ (code, payment.amount, payment.recipient, user)) target = self.target if target == payment.target: if 0 == len(payment.comment): reply = _(TX, 'cancel_recap_target').format(amount=payment.amount) else: reply = _(TX, 'cancel_recap_target_comment').format(amount=payment.amount, comment=payment.comment) else: if 0 == len(payment.comment): reply = _(TX, 'cancel_recap_other').format(amount=payment.amount, recipient=payment.recipient) else: reply = _(TX, 'cancel_recap_other_comment').format(amount=payment.amount, recipient=payment.recipient, comment=payment.comment) if target is None: reply += ' ' + _(TX, 'cancel_recap_warning_global') else: reply += ' ' + _(TX, 'cancel_recap_warning_other') return reply
def _executePay(self, sender, amount, target, comment=''): """Called internally. Actually place the payment order in the pending list and generate the reply.""" debug("Pay order (BTC %s to %s from %s, %s)" % (amount, target, sender, comment)) try: amount = int(amount) except ValueError: raise CommandSyntaxError, _(TX, 'error_amount_non_number') if amount <= 0: raise CommandSyntaxError, _(TX, 'error_amount_non_positive') try: order = PaymentOrder(sender, target, amount, comment) except PaymentToSelfError: raise CommandSyntaxError, _(TX, 'error_payment_to_self') order.queue() info("Payment order valid, queued: %s -> %s (BTC %s, %s)" % \ (sender, target, amount, order.code)) if 0 == len(comment): reply = _(TX, 'confirm_recap').format(amount=amount, recipient=order.recipient) else: reply = _(TX, 'confirm_recap_comment').format(amount=amount, recipient=order.recipient, comment=comment) reply += ' ' + _(COMMANDS, 'confirm_prompt').format(code=order.code) if sender.getBalance() - amount < WARNING_LIMIT: reply += ' ' + _(TX, 'warning_low_balance').format(amount=sender.getBalance()) return reply
def _executeConfirm(self, user, code=None): """Called internally. Do the actual confirmation of a given payment order and generate the reply.""" debug("Confirmation attempt from %s (%s)" % (user, code)) try: payment = PaymentOrder(user, code=code) except PaymentNotFoundError: raise CommandError, _(TX, 'error_tx_not_found').format(code=code) try: transactionId = payment.confirm() except NotEnoughBitcoinsError: raise CommandError, _(TX, 'error_insufficient_funds') except PaymentError, message: raise CommandError, _(TX, 'error_payment_impossible').format(reason=message)