Esempio n. 1
0
    def get_gateway_url(self, request):
        if PaymentProcessor.get_backend_setting('testing', False):
            gateway_url = u"https://desenvolvedor.moip.com.br/sandbox"
        else:
            gateway_url = u"https://www.moip.com.br"

        xml_body = etree.Element("EnviarInstrucao")
        xml_instruction = etree.SubElement(xml_body, "InstrucaoUnica")

        etree.SubElement(xml_instruction, "Razao").text = self.get_order_description(self.payment, self.payment.order)

        xml_values = etree.SubElement(xml_instruction, "Valores")
        etree.SubElement(xml_values, "Valor", moeda=self.payment.currency).text = str(self.payment.amount)

        etree.SubElement(xml_instruction, "IdProprio").text = "%s-%s" % (str(self.payment.id), str(time.time()))
        etree.SubElement(xml_instruction, "URLRetorno").text = PaymentProcessor._get_view_full_url(
            request, 'getpaid:moip:success', args=(self.payment.id,)
        )
        etree.SubElement(xml_instruction, "URLNotificacao").text = PaymentProcessor._get_view_full_url(
            request, 'getpaid:moip:notifications'
        )

        # collect customer data
        customer_info = {}
        user_data_query.send(sender=None, order=self.payment.order, user_data=customer_info)

        if customer_info:
            xml_buyer = etree.SubElement(xml_instruction, "Pagador")

            for field in ('name', 'email'):
                if field in customer_info and field in ('name', 'email'):
                    etree.SubElement(xml_buyer, self._USER_DATA_TO_MOIP[field]).text = customer_info[field]

            xml_buyer_address = etree.SubElement(xml_buyer, "EnderecoCobranca")
            for field in self._USER_DATA_TO_MOIP:
                if field in customer_info and field not in ('name', 'email'):
                    etree.SubElement(xml_buyer_address, self._USER_DATA_TO_MOIP[field]).text = customer_info[field]

        payment_full_url = "%s%s" % (gateway_url, self._SEND_INSTRUCTION_PAGE)
        user = PaymentProcessor.get_backend_setting('token')
        pwd = PaymentProcessor.get_backend_setting('key')
        contents = etree.tostring(xml_body, encoding='utf-8')

        response = requests.post(payment_full_url, auth=(user, pwd), data=contents).text
        moip_payment_token = etree.XML(response)[0][2].text

        return u"%s/%s%s " % (gateway_url, self._RUN_INSTRUCTION_PAGE, moip_payment_token), 'GET', {}
Esempio n. 2
0
    def get_gateway_url(self, request):
        if PaymentProcessor.get_backend_setting('testing', False):
            gateway_url = u"https://desenvolvedor.moip.com.br/sandbox"
        else:
            gateway_url = u"https://www.moip.com.br"

        xml_body = etree.Element("EnviarInstrucao")
        xml_instruction = etree.SubElement(xml_body, "InstrucaoUnica")

        etree.SubElement(xml_instruction, "Razao").text = self.get_order_description(self.payment, self.payment.order)

        xml_values = etree.SubElement(xml_instruction, "Valores")
        etree.SubElement(xml_values, "Valor", moeda=self.payment.currency).text = str(self.payment.amount)

        etree.SubElement(xml_instruction, "IdProprio").text = "%s-%s" % (str(self.payment.id), str(time.time()))
        etree.SubElement(xml_instruction, "URLRetorno").text = PaymentProcessor._get_view_full_url(request, 'getpaid-moip-success', args=(self.payment.id,))
        etree.SubElement(xml_instruction, "URLNotificacao").text = PaymentProcessor._get_view_full_url(request, 'getpaid-moip-notifications')

        # collect customer data
        customer_info = {}
        user_data_query.send(sender=None, order=self.payment.order, user_data=customer_info)

        if customer_info:
            xml_buyer = etree.SubElement(xml_instruction, "Pagador")

            for field in ('name', 'email'):
                if field in customer_info and field in ('name', 'email'):
                    etree.SubElement(xml_buyer, self._USER_DATA_TO_MOIP[field]).text = customer_info[field]

            xml_buyer_address = etree.SubElement(xml_buyer, "EnderecoCobranca")
            for field in self._USER_DATA_TO_MOIP:
                if field in customer_info and field not in ('name', 'email'):
                    etree.SubElement(xml_buyer_address, self._USER_DATA_TO_MOIP[field]).text = customer_info[field]

        payment_full_url = "%s%s" % (gateway_url, self._SEND_INSTRUCTION_PAGE)
        user = PaymentProcessor.get_backend_setting('token')
        pwd = PaymentProcessor.get_backend_setting('key')
        contents = etree.tostring(xml_body, encoding='utf-8')

        response = requests.post(payment_full_url, auth=(user, pwd), data=contents).text
        moip_payment_token = etree.XML(response)[0][2].text

        return u"%s/%s%s " % (gateway_url, self._RUN_INSTRUCTION_PAGE, moip_payment_token), 'GET', {}