Created
March 15, 2016 19:14
-
-
Save Verurteilt/ca042d47fd335ed81dcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -*- | |
import json | |
import mercadopago as mep | |
import logging | |
from General.utils.color import Color | |
from General.utils import environment_produccion | |
logger = logging.getLogger('mercadopago') | |
MSG_INFO = Color.colorear('%s.', color=Color.OKBLUE) | |
MSG_ERROR = Color.colorear('%s', color=Color.FAIL) | |
class MercadoPago(object): | |
def __init__(self,cuentamercado): | |
self.cuentamercado = cuentamercado | |
#self.mp = mep.MP("1096924737978613", "df0yCw9cU3S40EyMNXp2esEDcd7vKzPr") | |
self.mp = mep.MP(self.cuentamercado.client_id, self.cuentamercado.client_secret) | |
self.mp.sandbox_mode(not(environment_produccion())) | |
def create_url_payment(self, | |
title, | |
external_reference, | |
currency_key, | |
unit_price, | |
quantity, | |
name, | |
surname, | |
email, | |
area_code, | |
number, | |
street_name, | |
street_number, | |
zip_code, | |
category_id = "others"): | |
preference = { | |
"items": [ | |
{ | |
"title": title, | |
"quantity": quantity, | |
"currency_id": currency_key, | |
"unit_price": unit_price, | |
"category_id": category_id | |
} | |
], | |
"back_urls": { | |
"success": self.cuentamercado.success_url, | |
"pending": self.cuentamercado.pending_url, | |
"failure": self.cuentamercado.failure_url | |
}, | |
"payer": { | |
"name": name, | |
"surname": surname, | |
"email": email, | |
"phone":{ | |
"area_code": area_code, | |
"number": number | |
}, | |
"address": { | |
"street_name": street_name, | |
"street_number": street_number, | |
"zip_code": zip_code | |
} | |
}, | |
"auto_return": "approved", | |
"external_reference": external_reference, | |
"additional_info": external_reference, | |
"payment_methods": { | |
"excluded_payment_methods": [ | |
{ | |
"id": "bancomer" | |
}, | |
{ | |
"id": "banamex" | |
}, | |
{ | |
"id": "serfin" | |
}, | |
{ | |
"id": "oxxo" | |
} | |
], | |
"installments": 1 | |
} | |
} | |
try: | |
preferenceResult = self.mp.create_preference(preference) | |
except Exception as e: | |
logger.error(MSG_ERROR % "ERROR CREANDO URL WHAT??? %s" % str(e)) | |
return {} | |
else: | |
logger.error(MSG_INFO % "Al parecer todo bien" ) | |
return preferenceResult |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment