wip iugu
This commit is contained in:
@@ -1,19 +1,42 @@
|
||||
import json
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
import requests
|
||||
from layercake.extra_types import CreditCard
|
||||
|
||||
from iugu import Credentials, Iugu, Order, Status, Token
|
||||
from iugu import Credentials, Iugu, Order
|
||||
|
||||
iugu = Iugu(
|
||||
Credentials(
|
||||
'AF01CF1B3451459F92666F10589278EE',
|
||||
os.getenv('IUGU_API_TOKEN'),
|
||||
os.getenv('IUGU_API_TOKEN'), # type: ignore
|
||||
test_mode=True,
|
||||
),
|
||||
)
|
||||
|
||||
event = {
|
||||
'name': 'Sérgio Siqueira',
|
||||
'email': 'sergio@somosbeta.com.br',
|
||||
'due_date': '2026-11-12',
|
||||
'cpf': '07879819908',
|
||||
'address': {
|
||||
'postcode': '82100410',
|
||||
'address1': 'Rua Manoel José Pereira',
|
||||
'address2': '202',
|
||||
'neighborhood': 'Pilarzinho',
|
||||
'city': 'Curitiba',
|
||||
'state': 'PR',
|
||||
},
|
||||
'items': [
|
||||
{
|
||||
'id': '1',
|
||||
'name': 'Pen',
|
||||
'unit_price': 100,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class MockResponse:
|
||||
def __init__(self, jsonfile: str | None = None) -> None:
|
||||
@@ -31,22 +54,24 @@ class MockResponse:
|
||||
|
||||
|
||||
def test_create_invoice_pix(monkeypatch):
|
||||
# monkeypatch.setattr(
|
||||
# requests,
|
||||
# 'post',
|
||||
# lambda *args, **kwargs: MockResponse('tests/samples/iugu_invoice_pix.json'),
|
||||
# )
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse('tests/samples/iugu_invoice_pix.json'),
|
||||
)
|
||||
|
||||
order = Order(**event)
|
||||
order = Order(
|
||||
id=str(uuid4()),
|
||||
payment_method='PIX', # type: ignore
|
||||
**event,
|
||||
)
|
||||
invoice = iugu.create_invoice(order, postback_url='http://localhost')
|
||||
|
||||
print(invoice)
|
||||
|
||||
# assert invoice.id == '970cb579-c396-4e59-a323-ce61ae04f7bc-196c'
|
||||
# assert (
|
||||
# invoice.pix.qrcode_text
|
||||
# == 'http://faturas.iugu.com/iugu_pix/970cb579-c396-4e59-a323-ce61ae04f7bc-196c/test/pay'
|
||||
# )
|
||||
assert invoice['id'] == '970CB579C3964E59A323CE61AE04F7BC'
|
||||
assert (
|
||||
invoice['pix']['qrcode_text']
|
||||
== 'http://faturas.iugu.com/iugu_pix/970cb579-c396-4e59-a323-ce61ae04f7bc-196c/test/pay'
|
||||
)
|
||||
|
||||
|
||||
def test_create_invoice_bank_slip(monkeypatch):
|
||||
@@ -58,11 +83,16 @@ def test_create_invoice_bank_slip(monkeypatch):
|
||||
),
|
||||
)
|
||||
|
||||
order = Order(**event | {'payment_method': 'BANK_SLIP'})
|
||||
order = Order(
|
||||
id=str(uuid4()),
|
||||
payment_method='BANK_SLIP', # type: ignore
|
||||
**event,
|
||||
)
|
||||
invoice = iugu.create_invoice(order, postback_url='http://localhost')
|
||||
|
||||
assert invoice['id'] == '16F7AA3D2E0B41E9987B1DC95B957456'
|
||||
assert (
|
||||
invoice.pdf
|
||||
invoice['bank_slip']['bank_slip_url']
|
||||
== 'https://boletos.iugu.com/v1/public/invoice/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2/bank_slip'
|
||||
)
|
||||
|
||||
@@ -71,7 +101,7 @@ def test_payment_token(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse(),
|
||||
lambda *args, **kwargs: MockResponse('tests/samples/iugu_payment_token.json'),
|
||||
)
|
||||
|
||||
credit_card = CreditCard(
|
||||
@@ -82,7 +112,7 @@ def test_payment_token(monkeypatch):
|
||||
exp_year='2029',
|
||||
)
|
||||
token = iugu.payment_token(credit_card)
|
||||
assert isinstance(token, Token)
|
||||
assert token['id'] == 'ae5204f4-663b-451f-ad65-7c512badb84e'
|
||||
|
||||
|
||||
def test_charge_paid(monkeypatch):
|
||||
@@ -93,10 +123,10 @@ def test_charge_paid(monkeypatch):
|
||||
)
|
||||
|
||||
charge = iugu.charge(
|
||||
invoice_id='970cb579-c396-4e59-a323-ce61ae04f7bc-196c',
|
||||
token=Token('testing'),
|
||||
invoice_id='f92efd60-e6a9-45cf-bd8e-6b15a3d5c3ab-173c',
|
||||
token='testing',
|
||||
)
|
||||
assert charge.status == Status.PAID
|
||||
assert charge['success'] is True
|
||||
|
||||
|
||||
def test_charge_declined(monkeypatch):
|
||||
@@ -108,10 +138,10 @@ def test_charge_declined(monkeypatch):
|
||||
|
||||
charge = iugu.charge(
|
||||
invoice_id='970cb579-c396-4e59-a323-ce61ae04f7bc-196c',
|
||||
token=Token('testing'),
|
||||
token='testing',
|
||||
)
|
||||
assert charge.status == Status.DECLINED
|
||||
assert charge.response['status'] == 'unauthorized'
|
||||
|
||||
assert charge['success'] is False
|
||||
|
||||
|
||||
def test_get_invoice(monkeypatch):
|
||||
@@ -123,28 +153,3 @@ def test_get_invoice(monkeypatch):
|
||||
|
||||
invoice = iugu.get_invoice('970cb579-c396-4e59-a323-ce61ae04f7bc-196c')
|
||||
assert isinstance(invoice, dict)
|
||||
|
||||
|
||||
event = {
|
||||
'id': 'testing',
|
||||
'name': 'Sérgio Siqueira',
|
||||
'email': 'sergio@somosbeta.com.br',
|
||||
'due_date': '2026-11-12',
|
||||
'cpf': '07879819908',
|
||||
'payment_method': 'PIX',
|
||||
'address': {
|
||||
'postcode': '82100410',
|
||||
'address1': 'Rua Manoel José Pereira',
|
||||
'address2': '202',
|
||||
'neighborhood': 'Pilarzinho',
|
||||
'city': 'Curitiba',
|
||||
'state': 'PR',
|
||||
},
|
||||
'items': [
|
||||
{
|
||||
'id': '1',
|
||||
'name': 'Pen',
|
||||
'unit_price': 100,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user