Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout transparente #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist/**
.pydevproject
.settings
nbproject/
.idea
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Camada de abstração para integração via API com o MoIP em Python.
- Author: Hebert Amaral
- Contributor: Ale Borba
- Contributor: Igor Hercowitz
- Contributor: Victor Hugo

- Version: v0.2
- Version: v0.3

Dependências
------------
Expand Down Expand Up @@ -37,9 +38,9 @@ Uso

Basta importar a classe do MoIP e sair brincando :-)

from moipy import MoIP
from moipy import Moip

moip = MoIP('Razao do Pagamento')
moip = Moip('Razao do Pagamento')

moip.set_credenciais(token='seu_token',key='sua_key')
moip.set_ambiente('sandbox')
Expand All @@ -50,21 +51,36 @@ Basta importar a classe do MoIP e sair brincando :-)

print moip.get_resposta() # {sucesso:'Sucesso','token':'KJHSDASKD392847293AHFJKDSAH'}


Para checkout transparente basta chamar:

self.moip.set_checkout_transparente()

neste caso é obrigatorio passar os dados do pagador:

endereco = dict(Logradouro='Rua xxxxx',Numero='222',Bairro='xxxx',Cidade='xxxx',Estado='xx',CEP='xxxxxx',TelefoneFixo='xxxxxxxxxx')
self.moip.set_pagador(Nome='xxxx',Email='xxxxxx',Apelido='vitalbh',IdPagador='x',EnderecoCobranca=endereco)


ChangeLog
----------

v0.3
- Suporte a checkout transparente
- Adição dos dados do Pagador
- Teste do envio de intrução para checkout transparente

v0.2
- Refatorações de código
- Retirada dos DocTests
v0.2
- Refatorações de código
- Retirada dos DocTests

v0.1
- First version
v0.1
- First version

ToDo
------

- Aplicar testes automatizados usando unittest
- Incluir dados do pagador
- Validar campos


Expand Down
22 changes: 19 additions & 3 deletions moipy/moip.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,31 @@ def set_recebedor(self,login_moip,email,apelido):
self._monta_xml(self.xml_node, unique=True, InstrucaoUnica=dict(Recebedor=dict(LoginMoip=login_moip, Email=email, Apelido=apelido)))

return self


def set_pagador(self, **pagador):

if not 'EnderecoCobranca' in pagador:
return False

if not 'Pais' in pagador['EnderecoCobranca']:
pagador['EnderecoCobranca']['Pais'] = 'BRA'

self._monta_xml(self.xml_node, unique=True, InstrucaoUnica=dict(Pagador=pagador))

return self

def set_checkout_transparente(self):

instrucao = self._monta_xml(self.xml_node, unique=True, InstrucaoUnica=dict())
instrucao.find('InstrucaoUnica').set('TipoValidacao','Transparente')

def envia(self):
resposta = RespostaMoIP()

passwd = self.token + ":" + self.key

passwd64 = base64.b64encode(passwd)

curl = pycurl.Curl()
curl.setopt(pycurl.URL,self.url)
curl.setopt(pycurl.HTTPHEADER,["Authorization: Basic " + passwd64])
Expand All @@ -102,7 +118,7 @@ def envia(self):
curl.setopt(pycurl.WRITEFUNCTION,resposta.callback)
curl.perform()
curl.close()

self.retorno = resposta.conteudo

return self
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
setup(name='Moipy',
version='0.2',
description='Python integration with MoIP payment gateway via API',
author=['Herberth Amaral','Ale Borba'],
author_email=['[email protected]','[email protected]'],
author=['Herberth Amaral','Ale Borba','Victor'],
author_email=['[email protected]','[email protected]','[email protected]'],
url='http://labs.moip.com.br/',
packages=['moipy'],
classifiers=[
Expand Down
Empty file added test/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from moipy.moip import Moip
import random

class MoipTestCase(unittest.TestCase):

def setUp(self):
self.moip = Moip('Razao do Pagamento')
self.moip.set_credenciais(token='seu token',key='sua key')
self.moip.set_ambiente('sandbox')


def test_set_pagador(self):

self.moip.set_checkout_transparente()
self.moip.set_valor('12345')
self.moip.set_data_vencimento('yyyy-mm-dd')
self.moip.set_id_proprio(str(random.randrange(500000)))

endereco = dict(Logradouro='Rua santa ceia',Numero='222',Bairro='Buritis',Cidade='Belo Horizonte',Estado='MG',CEP='30850170',TelefoneFixo='3125124444')

self.moip.set_pagador(Nome='Victor',Email='[email protected]',Apelido='vitalbh',IdPagador='1',EnderecoCobranca=endereco)

self.moip.envia()

resposta = self.moip.get_resposta()

self.assertEqual(resposta['sucesso'],'Sucesso')
self.assertIsInstance(resposta['token'],str)



if __name__ == '__main__':
unittest.main()