Created
March 15, 2016 19:15
-
-
Save Verurteilt/78c0ff6ecf7abc1d7ecb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from decimal import Decimal | |
def url_mercadopago_transaction(usuario, matricula, nombre, apellido, email, campus, nivel, programa, monto, moneda, | |
nombre_producto, descripcion, referencia, periodo, telefono_lada, telefono, calle, calle_numero, cp, extra_info=""): | |
try: | |
from Simoba.mercadopago.views.mercadopago import get_preference_url_and_instance | |
from Simoba.mercadopago.models import CuentaMercado, Transaction as TransactionMP | |
mercadopago_cuenta = CuentaMercado.objects.get(id=1) | |
tra = TransactionMP.objects.create( | |
cuenta_mercado=mercadopago_cuenta, | |
usuario=usuario, | |
matricula=matricula, | |
monto_intento_pagar=Decimal(str(monto)), | |
referencia_pago=referencia, | |
campus=campus, | |
nivel=nivel, | |
licenciatura=programa, | |
moneda=moneda, | |
periodo=periodo, | |
extra_info=extra_info | |
) | |
url, preference = get_preference_url_and_instance( | |
mercadopago_cuenta, | |
tra.id, | |
nombre_producto or "Compra actual", | |
descripcion or "Compra actual", | |
float(str(monto)), | |
moneda.divisa, | |
1, | |
matricula, | |
nombre, | |
apellido, | |
email, | |
telefono_lada, | |
telefono, | |
calle, | |
calle_numero, | |
cp | |
) | |
tra.pref_id = preference | |
tra.save() | |
return url | |
except Exception as e: | |
print e | |
try: | |
tra.exception = str(e) | |
tra.save() | |
except: | |
pass | |
raise e | |
def construir_clacon_mercadopago(campus): | |
from Simoba.concentrador.models import InstitucionOrigen | |
from Simoba.bancos.models import ClaconDestino | |
from SistemaV2.institucion.models import Campus | |
institucion = InstitucionOrigen.objects.get(institucion__contains="MERCADO").codigo | |
numero_campus = Campus.objects.get(clave=campus).numero_campus | |
_clacon = ClaconDestino.TDC_INTERNET | |
clacon = ClaconDestino.objects.get(pk=_clacon) | |
return str(numero_campus) + str(institucion) + str(clacon.codigo_banner_id) | |
def registrar_pago_mercadopago_concentrador(transaction_mercadopago): | |
from Simoba.bancos.helpers import obtener_clacon_banco | |
from Simoba.concentrador.helper import insert_movement_concentrador | |
from Simoba.bancos.models import FormaPago, ClaconFormaPago | |
from Simoba.mercadopago.models import Transaction | |
from django.contrib.auth.models import User | |
from datetime import datetime | |
transaccion = transaction_mercadopago | |
cuenta = transaction_mercadopago.cuenta_mercado | |
clacon_mercadopago = construir_clacon_mercadopago(transaccion.campus) | |
cuenta_banco = cuenta.cuenta_banco | |
clacon = obtener_clacon_banco(clacon_mercadopago, paymeru=True) | |
clacon_destino = clacon.clacon_destino | |
forma_pago = clacon.forma_pago | |
fecha_movimiento = transaccion.date_approved | |
folio_movimiento = str(transaccion.id_pago) | |
usuario_conciliador = User.objects.get(username="conciliadorpagosenlinea") | |
alumno = transaccion.usuario | |
periodo = transaccion.periodo | |
if transaccion.extra_info: | |
from Simoba.bancos.models import InformacionSSBRefencia | |
cargos = InformacionSSBRefencia.objects.filter(clave_tran=transaccion.extra_info) | |
cont = 1 | |
if cargos.count() > 0: | |
registro_concentrador = [] | |
for cargo in cargos: | |
_registro_concentrador = insert_movement_concentrador(Transaction, transaccion.pk, cargo.monto, forma_pago, fecha_movimiento, | |
folio_movimiento + "-" + str(cont), usuario_conciliador, datetime.now(), True, cuenta_banco, alumno, "A", clacon_destino, periodo, clacon, iddestino=cargo.tran_num) | |
cont+=1 | |
registro_concentrador.append(_registro_concentrador) | |
else: | |
registro_concentrador = insert_movement_concentrador(Transaction, transaccion.pk, transaccion.transaction_amount, forma_pago, fecha_movimiento, | |
folio_movimiento, usuario_conciliador, datetime.now(), True, cuenta_banco, alumno, "A", clacon_destino, periodo, clacon, iddestino=transaccion.id_pago) | |
registro_concentrador = [registro_concentrador] | |
return registro_concentrador | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment