Exemplo n.º 1
0
 def import_billing_history(self, user_id):
     c = self.mconn.cursor()
     c.execute('''
         select p.date, p.amount, p.included_tax_amount, p.comment, p1.amount refund, p1.date refund_date, p1.comment refund_comment, h.cc_num, p.id
         from payments p 
             left outer join payments p1 on (p1.ref_transaction_id = p.transaction_id and p1.trxtype = 'C')
             left outer join billing_history_records h on (h.trans_id = p.transaction_id)
         where p.trxtype in ('D', 'S') and p.ref_user = %s
         group by p.id
     ''', [user_id])
     for date, amount, tax, comment, refund, refund_date, refund_comment, cc_num, _id in c.fetchall():
         cc_num = 'XXXX-XXXX-XXXX-' + cc_num[-4:] if cc_num else ''
         o = BillingHistory(
             user_id = user_id,
             timestamp = date,
             payment_method = cc_num,
             description = comment,
             debit = decimal.Decimal('%.02f' % amount),
             tax = decimal.Decimal('%.02f' % tax) if tax else decimal.Decimal('0.0'),
             status = TransactionStatus.Passed, 
             type = TransactionType.RentPayment,
         )
         o.save()
         if refund:
             r = Refund(
                 payment = o,
                 amount = decimal.Decimal('%.02f' % refund),
                 comment = refund_comment,
                 timestamp = refund_date,
             )
             r.save()
Exemplo n.º 2
0
    def take_penalty_payment(self):
        if self.penalty_payment != None:
            return True, None
        
        aim = create_aim()
        profile = self.user.get_profile()
        card = profile.get_billing_card_data()
        data = {
            'amount': decimal.Decimal('50.0'),
            'number': card['number'], 
            'exp': '/'.join(('%s' % card['exp_month'], ('%s' % card['exp_year'])[-2:])),
            'code': card['code'],
            'billing': profile.get_billing_data(), 
            'shipping': profile.get_shipping_data(), 
            'invoice_num': 'RENT_CLAIM_%s_%s' % (self.user.id, self.id), 
            'description': '%s - Unreturned Game Fees' % self.get_title(),
            'x_email': self.user.email,
            'x_cust_id': self.user.id,
        }
        res = aim.capture(**data)

        billing_history = BillingHistory(user=self.user, 
                                         payment_method=profile.get_payment_card().display_number, 
                                         description=data['description'], 
                                         debit=data['amount'], 
                                         reason='rent', 
                                         type=TransactionType.RentPayment,
                                         status=TransactionStatus.Passed,
                                         card_data=card,
                                         aim_transaction_id=res.transaction_id,
                                         aim_response=res._as_dict,
                                         message=res.response_reason_text)

        if res.response_code != 1:
            self.penalty_payment_tries += 1
            self.next_penalty_payment_date = datetime.now() + timedelta(2)
            self.save()
            billing_history.status = TransactionStatus.Declined
            billing_history.save()
            return False, res
        billing_history.save()
        self.next_penalty_payment_date = None
        self.penalty_payment = billing_history
        self.save()
        return True, res