def __init__(self, affiliation_id, api_key, total, card_type, installments, order_id, card_number, cvc2, exp_month, exp_year, card_holders_name, transaction=CASH, sandbox=False): assert isinstance(total, Decimal), u'total must be an instance of Decimal' assert installments in range(1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and transaction == self.CASH) \ or installments > 1 and transaction != self.CASH, \ u'if installments = 1 then transaction must be None or "cash"' if len(str(exp_year)) == 2: exp_year = '20%s' % exp_year # FIXME: bug do milênio em 2100 self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.card_type = card_type self.affiliation_id = affiliation_id self.api_key = api_key self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order_id self.card_number = card_number self.cvc2 = cvc2 self.exp_month = exp_month self.exp_year = exp_year self.expiration = '%s%s' % (exp_year, exp_month) self.card_holders_name = card_holders_name self._authorized = False self.sandbox = sandbox
def parse_checks_paid(self, line_no, field): self[field] = Transactions() check_pat = re.compile("^(\d+) *(\^?) *(.*?) *(\d\d/\d\d) *(\$?) *([-,.\d]+)") date_amount_pat = re.compile("(\d\d/\d\d) *(\$?) *([-,.\d]+)$") for line in self.text[line_no+1:]: if line in '\x0c\n': break m = check_pat.match(line) if m: parts = m.groups() n = date_amount_pat.search(line) if n: da_parts = n.groups() amt = Decimal(da_parts[2].replace(",","")) tx = Transaction(**{ 'code':parts[0], 'payee':"Check for $%s" % u.moneyfmt(amt), 'note':parts[2].strip(), 'date':self.complete_date(da_parts[0]), }) tx['postings']=[Posting(**{'commodity':da_parts[1] if da_parts[1] else "$", 'account_name':'Income:'+field, 'amount':amt, 'tx':tx, }), Posting(**{'commodity':da_parts[1] if da_parts[1] else "$", 'account_name':self.ledger_account + ':' +field, 'amount':amt * -1, 'tx':tx, }), ] self[field].append(tx)
def __init__( self, affiliation_id, api_key, transaction_id, amount_to_cancel=None, sandbox=False, use_ssl=None, ): super(CancelTransaction, self).__init__(sandbox=sandbox, use_ssl=use_ssl) self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.affiliation_id = affiliation_id self.api_key = api_key self.transaction_id = transaction_id self.sandbox = sandbox self.xml_transaction_id = self.get_xml_transaction_id() self.template = 'templates/cancel.xml' if amount_to_cancel: assert isinstance( amount_to_cancel, Decimal), u'amount must be an instance of Decimal' self.amount_to_cancel = moneyfmt(amount_to_cancel, sep='', dp='') self.template = 'templates/cancel_with_amount.xml'
def __init__( self, affiliation_id, token, api_key, total, card_type, order_id, url_redirect, installments=1, transaction=CASH, sandbox=False, use_ssl=None, ): super(TokenPaymentAttempt, self).__init__(sandbox=sandbox, use_ssl=use_ssl) assert isinstance(total, Decimal), u'total must be an instance of Decimal' assert installments in range(1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and transaction == CASH) \ or installments > 1 and transaction != CASH, \ u'if installments = 1 then transaction must be None or "cash"' self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.card_type = card_type self.token = token self.affiliation_id = affiliation_id self.api_key = api_key self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order_id self._authorized = False self.sandbox = sandbox self.url_redirect = url_redirect
def __init__(self, affiliation_id, total, installments, order_id, card_number, cvc2, exp_month, exp_year, card_holders_name, transaction=None): assert installments in range(1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and (transaction == 'cash' or transaction is None)) \ or installments > 1 and transaction != 'cash', \ u'if installments = 1 then transaction must be None or "cash"' if installments == 1: transaction = 'cash' installments = '00' else: installments = str(installments).zfill(2) if not transaction: transaction = TRANSACTION_TYPE[DEFAULT_TRANSACTION_TYPE] else: transaction = TRANSACTION_TYPE[transaction] self.affiliation_id = affiliation_id self.transaction = transaction self.total = moneyfmt(total) self.installments = installments self.order_id = order_id self.card_number = card_number self.cvc2 = cvc2 self.exp_month = exp_month self.exp_year = exp_year self.card_holders_name = card_holders_name self.client = self._get_connection() self._authorized = False
def transaction(self, total, card_type, installments, order, url_retorno, transaction=CASH): self.card_type = card_type self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order.numero self.url_retorno = url_retorno self.date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') payload = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'authorize.xml'), 'r').read() % self.__dict__ response = requests.post(self.url, data={ 'mensagem': payload, }) dom = xml.dom.minidom.parseString(response.content) if dom.getElementsByTagName('erro'): error_id = dom.getElementsByTagName('erro')[0].getElementsByTagName('codigo')[0].childNodes[0].data error_message = dom.getElementsByTagName('erro')[0].getElementsByTagName('mensagem')[0].childNodes[0].data raise GetAuthorizedException(error_id, error_message) else: redirect_url = dom.getElementsByTagName('url-autenticacao')[0].childNodes[0].data status = int(dom.getElementsByTagName('status')[0].childNodes[0].data) tid = dom.getElementsByTagName('tid')[0].childNodes[0].data valor = dom.getElementsByTagName('dados-pedido')[0].getElementsByTagName('valor')[0].childNodes[0].data moeda = dom.getElementsByTagName('dados-pedido')[0].getElementsByTagName('moeda')[0].childNodes[0].data data = datetime.strptime(dom.getElementsByTagName('dados-pedido')[0].getElementsByTagName('data-hora')[0].childNodes[0].data.split(".")[0],'%Y-%m-%dT%H:%M:%S') bandeira = dom.getElementsByTagName('forma-pagamento')[0].getElementsByTagName('bandeira')[0].childNodes[0].data produto = dom.getElementsByTagName('forma-pagamento')[0].getElementsByTagName('produto')[0].childNodes[0].data parcelas = dom.getElementsByTagName('forma-pagamento')[0].getElementsByTagName('parcelas')[0].childNodes[0].data transaction = Transaction(tid=tid,pedido=order,valor=valor,moeda=moeda,data_criacao=data,bandeira=bandeira,produto=produto,parcelas=parcelas) transaction.save() return redirect_url
def cancel(self, **kwargs): if not hasattr(self, 'transaction_id'): self.transaction_id = kwargs['transaction_id'] self.amount_to_cancel = moneyfmt(kwargs.get('amount'), sep='', dp='') response_dict = self.make_request(self.url, self.cancelation_template) self.handle_response(response_dict) return True
def assert_transaction_value(self, value): self.consult() try: transaction_value = self.dom.getElementsByTagName( 'valor')[0].childNodes[0].data return int(transaction_value) >= int(moneyfmt( value, sep='', dp='')) except Exception: return False
def assert_transaction_value(self, value): self.consult() try: transaction_value = self.dom.getElementsByTagName( 'valor')[0].childNodes[0].data return int(transaction_value) >= int(moneyfmt(value, sep='', dp='')) except Exception: return False
def upgrade01(filename="history", section='DEFAULT'): with open(os.path.join(config.evalpath(config[section]['path']), filename), 'r') as f: with open( os.path.join(config.evalpath(config[section]['path']), filename + ".new"), "w") as wf: writer = csv.writer(wf, delimiter="|") for row in csv.reader(f, delimiter="|"): if len(row) < 9 or row[0].startswith("#"): writer.writerow(row) continue row = map(lambda a: a.strip(), row) rtime = strptime(row[0].split(",")[1].strip(), "%d %b %Y %H:%M:%S") if row[2] == "conv": newrow = [ strftime("%Y-%m-%d %H:%M", rtime), centerify(row[1], 9), centerify(row[2], 8), prependn( moneyfmt(Decimal(row[5]), 8 if row[4].lower() == "btc" else 2), 12), prependn( moneyfmt(Decimal(row[8]), 8 if row[7].lower() == "btc" else 2), 12), centerify(row[3], 9), centerify(row[6], 9), " " + row[9] ] else: newrow = [ strftime("%Y-%m-%d %H:%M", rtime), centerify(row[1], 9), centerify(row[2], 8), prependn( moneyfmt(Decimal(row[8]), 8 if row[7].lower() == "btc" else 2), 12), prependn("", 12), centerify(row[6], 9), centerify("", 9), " " + (row[3] + " " + row[9]).strip() ] newrow = map(lambda a: a, newrow) writer.writerow(newrow)
def __init__(self, affiliation_id, api_key, total, card_type, installments, order_id, card_number, cvc2, exp_month, exp_year, card_holders_name, transaction=CASH, sandbox=False, use_ssl=None, url_redirect='null'): super(PaymentAttempt, self).__init__(sandbox=sandbox, use_ssl=use_ssl) assert isinstance(total, Decimal), u'total must be an instance of Decimal' assert installments in range( 1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and transaction == CASH) \ or installments > 1 and transaction != CASH, \ u'if installments = 1 then transaction must be None or "cash"' if len(str(exp_year)) == 2: exp_year = '20%s' % exp_year # FIXME: bug do milênio em 2100 if len(str(exp_month)) == 1: exp_month = '0%s' % exp_month self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.card_type = card_type self.affiliation_id = affiliation_id self.api_key = api_key self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order_id self.card_number = card_number self.cvc2 = cvc2 self.exp_month = exp_month self.exp_year = exp_year self.expiration = '%s%s' % (exp_year, exp_month) self.card_holders_name = card_holders_name self._authorized = False self.sandbox = sandbox self.url_redirect = url_redirect
def __init__(self, affiliation_id, total, installments, order_id, card_number, cvc2, exp_month, exp_year, card_holders_name, transaction=None, debug=False): assert installments in range( 1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and (transaction == 'cash' or transaction is None)) \ or installments > 1 and transaction != 'cash', \ u'if installments = 1 then transaction must be None or "cash"' if installments == 1: transaction = 'cash' installments = '00' else: installments = str(installments).zfill(2) if not transaction: transaction = TRANSACTION_TYPE[DEFAULT_TRANSACTION_TYPE] else: transaction = TRANSACTION_TYPE[transaction] self.affiliation_id = affiliation_id self.transaction = transaction self.total = moneyfmt(total) self.installments = installments self.order_id = order_id self.card_number = card_number self.cvc2 = cvc2 self.exp_month = exp_month self.exp_year = exp_year self.card_holders_name = card_holders_name self.client = self._get_connection(debug) self._authorized = False self.debug = debug
def __init__( self, affiliation_id, api_key, total, card_type, installments, order_id, card_number, cvc2, exp_month, exp_year, card_holders_name, transaction=CASH, sandbox=False, use_ssl=None, gerar_token=False, version='1.2.1', ): super(UpdatePaymentAttempt, self).__init__(sandbox=sandbox, use_ssl=use_ssl) assert isinstance(total, Decimal), u'total must be an instance of Decimal' assert installments in range(1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and transaction == CASH) or installments > 1 and transaction != CASH, u'if installments = 1 then transaction must be None or "cash"' if len(str(exp_year)) == 2: exp_year = '20%s' % exp_year # FIXME: bug do milênio em 2100 self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.card_type = card_type self.affiliation_id = affiliation_id self.api_key = api_key self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order_id self.card_number = card_number self.cvc2 = cvc2 self.exp_month = exp_month self.exp_year = exp_year self.expiration = '%s%s' % (exp_year, exp_month) self.card_holders_name = card_holders_name self._authorized = False self.sandbox = sandbox self.gerar_token = 'true' if gerar_token else 'false' self.xml_transaction_id = self.get_xml_transaction_id() self.version = version
def __init__( self, affiliation_id, api_key, total, card_type, order_id, card_number, cvc2, exp_month, exp_year, card_holders_name, url_redirect="null", sandbox=False, use_ssl=None, ): super(DebtAttempt, self).__init__(sandbox=sandbox, use_ssl=use_ssl) assert isinstance(total, Decimal), u'total must be an instance of Decimal' if len(str(exp_year)) == 2: exp_year = '20%s' % exp_year if len(str(exp_month)) == 1: exp_month = '0%s' % exp_month self.url_redirect = url_redirect self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.card_type = card_type self.affiliation_id = affiliation_id self.api_key = api_key self.total = moneyfmt(total, sep='', dp='') self.order_id = order_id self.card_number = card_number self.cvc2 = cvc2 self.exp_month = exp_month self.exp_year = exp_year self.expiration = '%s%s' % (exp_year, exp_month) self.card_holders_name = card_holders_name self._authorized = False self.sandbox = sandbox
def __init__( self, affiliation_id, api_key, transaction_id, amount_to_cancel=None, sandbox=False, use_ssl=None, ): super(CancelTransaction, self).__init__(sandbox=sandbox, use_ssl=use_ssl) self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.affiliation_id = affiliation_id self.api_key = api_key self.transaction_id = transaction_id self.sandbox = sandbox self.template = 'templates/cancel.xml' if amount_to_cancel: assert isinstance(amount_to_cancel, Decimal), u'amount must be an instance of Decimal' self.amount_to_cancel = moneyfmt(amount_to_cancel, sep='', dp='') self.template = 'templates/cancel_with_amount.xml'
def __init__( self, affiliation_id, token, api_key, total, card_type, order_id, url_redirect, installments=1, transaction=CASH, sandbox=False, use_ssl=None, authorize=3, ): super(TokenPaymentAttempt, self).__init__(sandbox=sandbox, use_ssl=use_ssl) assert isinstance(total, Decimal), u'total must be an instance of Decimal' assert installments in range( 1, 13), u'installments must be a integer between 1 and 12' assert (installments == 1 and transaction == CASH) \ or installments > 1 and transaction != CASH, \ u'if installments = 1 then transaction must be None or "cash"' self.url = SANDBOX_URL if sandbox else PRODUCTION_URL self.card_type = card_type self.token = token self.affiliation_id = affiliation_id self.api_key = api_key self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order_id self._authorized = False self.sandbox = sandbox self.url_redirect = url_redirect self.authorize = authorize
def amtstr(self): return (" " if self['amount'] >= 0 else "") + u.moneyfmt(self['amount'])
def print_var(name, value): is_btc = name.lower().endswith('btc') print("%s = %s" % (name, moneyfmt(value, 8 if is_btc else 2)))
def transaction(self, total, card_type, installments, order, url_retorno, transaction=CASH): self.card_type = card_type self.transaction = transaction self.transaction_type = transaction # para manter assinatura do pyrcws self.total = moneyfmt(total, sep='', dp='') self.installments = installments self.order_id = order.numero self.url_retorno = url_retorno self.date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') payload = open( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'authorize.xml'), 'r').read() % self.__dict__ response = requests.post(self.url, data={ 'mensagem': payload, }) dom = xml.dom.minidom.parseString(response.content) if dom.getElementsByTagName('erro'): error_id = dom.getElementsByTagName( 'erro')[0].getElementsByTagName('codigo')[0].childNodes[0].data error_message = dom.getElementsByTagName('erro')[ 0].getElementsByTagName('mensagem')[0].childNodes[0].data raise GetAuthorizedException(error_id, error_message) else: redirect_url = dom.getElementsByTagName( 'url-autenticacao')[0].childNodes[0].data status = int( dom.getElementsByTagName('status')[0].childNodes[0].data) tid = dom.getElementsByTagName('tid')[0].childNodes[0].data valor = dom.getElementsByTagName('dados-pedido')[ 0].getElementsByTagName('valor')[0].childNodes[0].data moeda = dom.getElementsByTagName('dados-pedido')[ 0].getElementsByTagName('moeda')[0].childNodes[0].data data = datetime.strptime( dom.getElementsByTagName('dados-pedido')[0].getElementsByTagName( 'data-hora')[0].childNodes[0].data.split(".")[0], '%Y-%m-%dT%H:%M:%S') bandeira = dom.getElementsByTagName('forma-pagamento')[ 0].getElementsByTagName('bandeira')[0].childNodes[0].data produto = dom.getElementsByTagName('forma-pagamento')[ 0].getElementsByTagName('produto')[0].childNodes[0].data parcelas = dom.getElementsByTagName('forma-pagamento')[ 0].getElementsByTagName('parcelas')[0].childNodes[0].data transaction = Transaction(tid=tid, pedido=order, valor=valor, moeda=moeda, data_criacao=data, bandeira=bandeira, produto=produto, parcelas=parcelas) transaction.save() return redirect_url
def _conv_val(amount, name): if name == "IRR": return moneyfmt(money_as_dec(amount) / 10, 0) return amount
def fetch_required_arguments(self, **kwargs): super(Attempt, self).fetch_required_arguments(**kwargs) self.order_id = kwargs['order_id'] self.total = moneyfmt(kwargs['total'], sep='', dp='')