add iugu files
This commit is contained in:
34
orders-events/app/app.py
Normal file
34
orders-events/app/app.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
|
||||
from aws_lambda_powertools import Logger, Tracer
|
||||
from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
APIGatewayHttpResolver,
|
||||
Response,
|
||||
)
|
||||
from aws_lambda_powertools.logging import correlation_paths
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ORDER_TABLE
|
||||
|
||||
logger = Logger(__name__)
|
||||
tracer = Tracer()
|
||||
app = APIGatewayHttpResolver(enable_validation=True)
|
||||
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@app.post('/')
|
||||
@tracer.capture_method
|
||||
def postback():
|
||||
return Response(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
|
||||
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP)
|
||||
@tracer.capture_lambda_handler
|
||||
def lambda_handler(
|
||||
event: dict[str, Any],
|
||||
context: LambdaContext,
|
||||
) -> dict[str, Any]:
|
||||
return app.resolve(event, context)
|
||||
16
orders-events/tests/samples/iugu_charge_declined.json
Normal file
16
orders-events/tests/samples/iugu_charge_declined.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"message": "Transa\u00e7\u00e3o negada",
|
||||
"errors": {},
|
||||
"status": "unauthorized",
|
||||
"info_message": "Transa\u00e7\u00e3o negada",
|
||||
"reversible": null,
|
||||
"token": "000000000000000000000000000000000000003",
|
||||
"brand": null,
|
||||
"bin": null,
|
||||
"success": false,
|
||||
"url": "https://faturas.iugu.com/c899b6da-eef8-4737-b556-47ef094c980e-60ac",
|
||||
"pdf": "https://faturas.iugu.com/c899b6da-eef8-4737-b556-47ef094c980e-60ac.pdf",
|
||||
"identification": null,
|
||||
"invoice_id": "C899B6DAEEF84737B55647EF094C980E",
|
||||
"LR": "05"
|
||||
}
|
||||
16
orders-events/tests/samples/iugu_charge_paid.json
Normal file
16
orders-events/tests/samples/iugu_charge_paid.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"message": "Autorizado",
|
||||
"errors": {},
|
||||
"status": "captured",
|
||||
"info_message": "Transa\u00e7\u00e3o capturada",
|
||||
"reversible": null,
|
||||
"token": "000000000000000000000000000000000000001",
|
||||
"brand": null,
|
||||
"bin": null,
|
||||
"success": true,
|
||||
"url": "https://faturas.iugu.com/7abe1e98-0e7e-4de8-a9f8-c40b689ee05c-5a5d",
|
||||
"pdf": "https://faturas.iugu.com/7abe1e98-0e7e-4de8-a9f8-c40b689ee05c-5a5d.pdf",
|
||||
"identification": null,
|
||||
"invoice_id": "7ABE1E980E7E4DE8A9F8C40B689EE05C",
|
||||
"LR": "00"
|
||||
}
|
||||
160
orders-events/tests/samples/iugu_invoice_bank_slip.json
Normal file
160
orders-events/tests/samples/iugu_invoice_bank_slip.json
Normal file
@@ -0,0 +1,160 @@
|
||||
{
|
||||
"id": "16F7AA3D2E0B41E9987B1DC95B957456",
|
||||
"due_date": "2024-07-16",
|
||||
"currency": "BRL",
|
||||
"discount_cents": null,
|
||||
"email": "email@iugu.com",
|
||||
"items_total_cents": 3000,
|
||||
"notification_url": null,
|
||||
"return_url": null,
|
||||
"status": "pending",
|
||||
"tax_cents": null,
|
||||
"total_cents": 3000,
|
||||
"total_paid_cents": 0,
|
||||
"taxes_paid_cents": null,
|
||||
"paid_at": null,
|
||||
"paid_cents": null,
|
||||
"cc_emails": null,
|
||||
"financial_return_date": null,
|
||||
"payable_with": "all",
|
||||
"overpaid_cents": null,
|
||||
"ignore_due_email": null,
|
||||
"ignore_canceled_email": null,
|
||||
"advance_fee_cents": null,
|
||||
"commission_cents": null,
|
||||
"early_payment_discount": false,
|
||||
"order_id": null,
|
||||
"updated_at": "2024-07-16T16:34:54-03:00",
|
||||
"credit_card_brand": null,
|
||||
"credit_card_bin": null,
|
||||
"credit_card_last_4": null,
|
||||
"credit_card_captured_at": null,
|
||||
"credit_card_tid": null,
|
||||
"external_reference": null,
|
||||
"max_installments_value": null,
|
||||
"payer_name": "Nome",
|
||||
"payer_email": null,
|
||||
"payer_cpf_cnpj": "11343675030",
|
||||
"payer_phone": null,
|
||||
"payer_phone_prefix": null,
|
||||
"payer_address_zip_code": null,
|
||||
"payer_address_street": null,
|
||||
"payer_address_district": null,
|
||||
"payer_address_city": null,
|
||||
"payer_address_state": null,
|
||||
"payer_address_number": null,
|
||||
"payer_address_complement": null,
|
||||
"payer_address_country": null,
|
||||
"late_payment_fine": 1,
|
||||
"late_payment_fine_cents": null,
|
||||
"split_id": null,
|
||||
"external_payment_id": null,
|
||||
"external_payment_description": null,
|
||||
"payment_booklet_id": null,
|
||||
"subscription_id": null,
|
||||
"variables": [],
|
||||
"custom_variables": [],
|
||||
"logs": [
|
||||
{
|
||||
"id": "0C7750D2CFEE44F187910416FE7E1661",
|
||||
"description": "Email de Fatura enviado!",
|
||||
"notes": "Fatura enviada com sucesso para: email@iugu.com",
|
||||
"created_at": "16/07, 16:34"
|
||||
},
|
||||
{
|
||||
"id": "F2A2A91E829245BFA72D1DE6244D2374",
|
||||
"description": "Fatura criada com sucesso!",
|
||||
"notes": "Fatura criada!",
|
||||
"created_at": "16/07, 16:34"
|
||||
}
|
||||
],
|
||||
"credit_card_transaction": null,
|
||||
"account_id": "27016E1AD888499A98994E781B6C3762",
|
||||
"bank_account_branch": "0001",
|
||||
"bank_account_number": "3693443-0",
|
||||
"account_name": "IUGU Teste Produto e Integrações",
|
||||
"secure_id": "16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2",
|
||||
"secure_url": "https://checkout.iugu.com/invoices/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2",
|
||||
"customer_id": null,
|
||||
"customer_ref": null,
|
||||
"customer_name": null,
|
||||
"user_id": null,
|
||||
"total": "R$ 30,00",
|
||||
"taxes_paid": "R$ 0,00",
|
||||
"total_paid": "R$ 0,00",
|
||||
"total_overpaid": "R$ 0,00",
|
||||
"total_refunded": "R$ 0,00",
|
||||
"commission": "R$ 0,00",
|
||||
"fines_on_occurrence_day": "R$ 0,00",
|
||||
"total_on_occurrence_day": "R$ 0,00",
|
||||
"fines_on_occurrence_day_cents": 0,
|
||||
"total_on_occurrence_day_cents": 0,
|
||||
"refunded_cents": 0,
|
||||
"remaining_captured_cents": 0,
|
||||
"advance_fee": null,
|
||||
"estimated_advance_fee": null,
|
||||
"paid": "R$ 0,00",
|
||||
"original_payment_id": null,
|
||||
"double_payment_id": null,
|
||||
"per_day_interest": false,
|
||||
"per_day_interest_value": null,
|
||||
"per_day_interest_cents": 0,
|
||||
"interest": null,
|
||||
"discount": null,
|
||||
"duplicated_invoice_id": null,
|
||||
"bank_slip_extra_due": 2,
|
||||
"created_at": "16/07, 16:34",
|
||||
"created_at_iso": "2024-07-16T16:34:53-03:00",
|
||||
"authorized_at": null,
|
||||
"authorized_at_iso": null,
|
||||
"expired_at": null,
|
||||
"expired_at_iso": null,
|
||||
"refunded_at": null,
|
||||
"refunded_at_iso": null,
|
||||
"canceled_at": null,
|
||||
"canceled_at_iso": null,
|
||||
"protested_at": null,
|
||||
"protested_at_iso": null,
|
||||
"chargeback_at": null,
|
||||
"chargeback_at_iso": null,
|
||||
"occurrence_date": null,
|
||||
"refundable": null,
|
||||
"installments": null,
|
||||
"transaction_number": 375641241984723,
|
||||
"payment_method": null,
|
||||
"financial_return_dates": null,
|
||||
"bank_slip": {
|
||||
"digitable_line": "40192024179800000000400001656495597790000003000",
|
||||
"barcode_data": "40195977900000030002024198000000000000165649",
|
||||
"barcode": "https://api.iugu.com/v1/public/invoice/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2/barcode",
|
||||
"bank_slip_url": "https://boletos.iugu.com/v1/public/invoice/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2/bank_slip",
|
||||
"bank_slip_bank": 401,
|
||||
"bank_slip_status": "pending",
|
||||
"bank_slip_error_code": null,
|
||||
"bank_slip_error_message": null,
|
||||
"recipient_cpf_cnpj": "15111975000164"
|
||||
},
|
||||
"pix": {
|
||||
"qrcode": "https://faturas.iugu.com/qr_code/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2",
|
||||
"qrcode_text": "00020101021226840014br.gov.bcb.pix2562qr.iugu.com/public/payload/v2/16F7AA3D2E0B41E9987B1DC95B957456520400005303986540530.005802BR5925IUGU INSTITUICAO DE PAGAM6009SAO PAULO62070503***630446D8",
|
||||
"status": "qr_code_created",
|
||||
"payer_cpf_cnpj": null,
|
||||
"payer_name": null,
|
||||
"end_to_end_id": null,
|
||||
"end_to_end_refund_id": null,
|
||||
"account_number_last_digits": null
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"id": "0F30A8B1ED244325BBC6C8A1AE34AE18",
|
||||
"description": "Item",
|
||||
"price_cents": 3000,
|
||||
"quantity": 1,
|
||||
"created_at": "2024-07-16T16:34:53-03:00",
|
||||
"updated_at": "2024-07-16T16:34:53-03:00",
|
||||
"price": "R$ 30,00"
|
||||
}
|
||||
],
|
||||
"early_payment_discounts": [],
|
||||
"split_rules": null
|
||||
}
|
||||
170
orders-events/tests/samples/iugu_invoice_credit.json
Normal file
170
orders-events/tests/samples/iugu_invoice_credit.json
Normal file
@@ -0,0 +1,170 @@
|
||||
{
|
||||
"id": "7ABE1E980E7E4DE8A9F8C40B689EE05C",
|
||||
"due_date": "2022-09-24",
|
||||
"currency": "BRL",
|
||||
"discount_cents": null,
|
||||
"email": "sergio@somosbeta.com.br",
|
||||
"items_total_cents": 19000,
|
||||
"notification_url": "http://localhost",
|
||||
"return_url": null,
|
||||
"status": "pending",
|
||||
"tax_cents": null,
|
||||
"total_cents": 19000,
|
||||
"total_paid_cents": 0,
|
||||
"taxes_paid_cents": null,
|
||||
"paid_at": null,
|
||||
"paid_cents": null,
|
||||
"cc_emails": null,
|
||||
"financial_return_date": null,
|
||||
"payable_with": "credit_card",
|
||||
"overpaid_cents": null,
|
||||
"ignore_due_email": null,
|
||||
"ignore_canceled_email": null,
|
||||
"advance_fee_cents": null,
|
||||
"commission_cents": null,
|
||||
"early_payment_discount": false,
|
||||
"order_id": "cwt8SZz5PRVkSUmdva3bsg",
|
||||
"updated_at": "2022-09-24T16:37:19-03:00",
|
||||
"credit_card_brand": null,
|
||||
"credit_card_bin": null,
|
||||
"credit_card_last_4": null,
|
||||
"credit_card_captured_at": null,
|
||||
"credit_card_tid": null,
|
||||
"external_reference": "cwt8SZz5PRVkSUmdva3bsg",
|
||||
"max_installments_value": null,
|
||||
"payer_name": "S\u00e9rgio R Siqueira",
|
||||
"payer_email": "sergio@somosbeta.com.br",
|
||||
"payer_cpf_cnpj": "07879819908",
|
||||
"payer_phone": null,
|
||||
"payer_phone_prefix": null,
|
||||
"payer_address_zip_code": "07879819908",
|
||||
"payer_address_street": "Rua Emanuel Jos\u00e9 Pereira",
|
||||
"payer_address_district": "Pilarzinho",
|
||||
"payer_address_city": "Curitiba",
|
||||
"payer_address_state": "Paran\u00e1",
|
||||
"payer_address_number": "202",
|
||||
"payer_address_complement": "Sob 11",
|
||||
"payer_address_country": "Brasil",
|
||||
"late_payment_fine": 0,
|
||||
"late_payment_fine_cents": null,
|
||||
"split_id": null,
|
||||
"account_id": "AF01CF1B3451459F92666F10589278EE",
|
||||
"account_name": "Beta Educa\u00e7\u00e3o",
|
||||
"secure_id": "7abe1e98-0e7e-4de8-a9f8-c40b689ee05c-5a5d",
|
||||
"secure_url": "https://faturas.iugu.com/7abe1e98-0e7e-4de8-a9f8-c40b689ee05c-5a5d",
|
||||
"customer_id": null,
|
||||
"customer_ref": null,
|
||||
"customer_name": null,
|
||||
"user_id": null,
|
||||
"total": "R$ 190,00",
|
||||
"taxes_paid": "R$ 0,00",
|
||||
"total_paid": "R$ 0,00",
|
||||
"total_overpaid": "R$ 0,00",
|
||||
"total_refunded": "R$ 0,00",
|
||||
"commission": "R$ 0,00",
|
||||
"fines_on_occurrence_day": "R$ 0,00",
|
||||
"total_on_occurrence_day": "R$ 0,00",
|
||||
"fines_on_occurrence_day_cents": 0,
|
||||
"total_on_occurrence_day_cents": 0,
|
||||
"refunded_cents": 0,
|
||||
"remaining_captured_cents": 0,
|
||||
"advance_fee": null,
|
||||
"paid": "R$ 0,00",
|
||||
"original_payment_id": null,
|
||||
"double_payment_id": null,
|
||||
"per_day_interest": false,
|
||||
"per_day_interest_value": null,
|
||||
"interest": null,
|
||||
"discount": null,
|
||||
"duplicated_invoice_id": null,
|
||||
"created_at": "24/09, 16:37",
|
||||
"created_at_iso": "2022-09-24T16:37:19-03:00",
|
||||
"authorized_at": null,
|
||||
"authorized_at_iso": null,
|
||||
"expired_at": null,
|
||||
"expired_at_iso": null,
|
||||
"refunded_at": null,
|
||||
"refunded_at_iso": null,
|
||||
"canceled_at": null,
|
||||
"canceled_at_iso": null,
|
||||
"protested_at": null,
|
||||
"protested_at_iso": null,
|
||||
"chargeback_at": null,
|
||||
"chargeback_at_iso": null,
|
||||
"occurrence_date": null,
|
||||
"refundable": null,
|
||||
"installments": null,
|
||||
"transaction_number": 1111,
|
||||
"payment_method": null,
|
||||
"financial_return_dates": null,
|
||||
"bank_slip": null,
|
||||
"pix": {
|
||||
"qrcode": null,
|
||||
"qrcode_text": null,
|
||||
"status": null,
|
||||
"payer_cpf_cnpj": null,
|
||||
"payer_name": null,
|
||||
"end_to_end_id": null,
|
||||
"end_to_end_refund_id": null
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"id": "2A1F9D83D6464F9E996E243664623F7D",
|
||||
"description": "test",
|
||||
"price_cents": 19000,
|
||||
"quantity": 1,
|
||||
"created_at": "2022-09-24T16:37:19-03:00",
|
||||
"updated_at": "2022-09-24T16:37:19-03:00",
|
||||
"price": "R$ 190,00"
|
||||
}
|
||||
],
|
||||
"early_payment_discounts": [],
|
||||
"split_rules": null,
|
||||
"variables": [
|
||||
{ "variable": "next_dunning_date", "value": "2022-09-24" },
|
||||
{ "variable": "payer.address.city", "value": "Curitiba" },
|
||||
{ "variable": "payer.address.city", "value": "Curitiba" },
|
||||
{ "variable": "payer.address.complement", "value": "Sob 11" },
|
||||
{ "variable": "payer.address.complement", "value": "Sob 11" },
|
||||
{ "variable": "payer.address.country", "value": "Brasil" },
|
||||
{ "variable": "payer.address.country", "value": "Brasil" },
|
||||
{ "variable": "payer.address.district", "value": "Pilarzinho" },
|
||||
{ "variable": "payer.address.district", "value": "Pilarzinho" },
|
||||
{ "variable": "payer.address.number", "value": "202" },
|
||||
{ "variable": "payer.address.number", "value": "202" },
|
||||
{ "variable": "payer.address.state", "value": "Paran\u00e1" },
|
||||
{ "variable": "payer.address.state", "value": "Paran\u00e1" },
|
||||
{
|
||||
"variable": "payer.address.street",
|
||||
"value": "Rua Emanuel Jos\u00e9 Pereira"
|
||||
},
|
||||
{
|
||||
"variable": "payer.address.street",
|
||||
"value": "Rua Emanuel Jos\u00e9 Pereira"
|
||||
},
|
||||
{ "variable": "payer.address.zip_code", "value": "07879819908" },
|
||||
{ "variable": "payer.address.zip_code", "value": "07879819908" },
|
||||
{ "variable": "payer.cpf_cnpj", "value": "07879819908" },
|
||||
{ "variable": "payer.cpf_cnpj", "value": "07879819908" },
|
||||
{ "variable": "payer.email", "value": "sergio@somosbeta.com.br" },
|
||||
{ "variable": "payer.email", "value": "sergio@somosbeta.com.br" },
|
||||
{ "variable": "payer.name", "value": "S\u00e9rgio R Siqueira" },
|
||||
{ "variable": "payer.name", "value": "S\u00e9rgio R Siqueira" }
|
||||
],
|
||||
"custom_variables": [],
|
||||
"logs": [
|
||||
{
|
||||
"id": "7B37B1E6DDAB430AA8A27C00746EA303",
|
||||
"description": "Fatura criada com sucesso!",
|
||||
"notes": "Fatura criada!",
|
||||
"created_at": "24/09, 16:37"
|
||||
},
|
||||
{
|
||||
"id": "8683EE4BC4DD4EBE995430B2961A6735",
|
||||
"description": "Email de Fatura enviado!",
|
||||
"notes": "Fatura enviada com sucesso para: sergio@somosbeta.com.br",
|
||||
"created_at": "24/09, 16:37"
|
||||
}
|
||||
],
|
||||
"credit_card_transaction": null
|
||||
}
|
||||
170
orders-events/tests/samples/iugu_invoice_pix.json
Normal file
170
orders-events/tests/samples/iugu_invoice_pix.json
Normal file
@@ -0,0 +1,170 @@
|
||||
{
|
||||
"id": "970CB579C3964E59A323CE61AE04F7BC",
|
||||
"due_date": "2022-09-24",
|
||||
"currency": "BRL",
|
||||
"discount_cents": null,
|
||||
"email": "sergio@somosbeta.com.br",
|
||||
"items_total_cents": 19000,
|
||||
"notification_url": "http://localhost",
|
||||
"return_url": null,
|
||||
"status": "pending",
|
||||
"tax_cents": null,
|
||||
"total_cents": 19000,
|
||||
"total_paid_cents": 0,
|
||||
"taxes_paid_cents": 687,
|
||||
"paid_at": null,
|
||||
"paid_cents": null,
|
||||
"cc_emails": null,
|
||||
"financial_return_date": null,
|
||||
"payable_with": "pix",
|
||||
"overpaid_cents": null,
|
||||
"ignore_due_email": null,
|
||||
"ignore_canceled_email": null,
|
||||
"advance_fee_cents": null,
|
||||
"commission_cents": null,
|
||||
"early_payment_discount": false,
|
||||
"order_id": "aQJt9cfeaNZgJosrC6t3Cf",
|
||||
"updated_at": "2022-09-24T12:00:40-03:00",
|
||||
"credit_card_brand": null,
|
||||
"credit_card_bin": null,
|
||||
"credit_card_last_4": null,
|
||||
"credit_card_captured_at": null,
|
||||
"credit_card_tid": null,
|
||||
"external_reference": "aQJt9cfeaNZgJosrC6t3Cf",
|
||||
"max_installments_value": null,
|
||||
"payer_name": "S\u00e9rgio R Siqueira",
|
||||
"payer_email": "sergio@somosbeta.com.br",
|
||||
"payer_cpf_cnpj": "07879819908",
|
||||
"payer_phone": null,
|
||||
"payer_phone_prefix": null,
|
||||
"payer_address_zip_code": "07879819908",
|
||||
"payer_address_street": "Rua Emanuel Jos\u00e9 Pereira",
|
||||
"payer_address_district": "Pilarzinho",
|
||||
"payer_address_city": "Curitiba",
|
||||
"payer_address_state": "Paran\u00e1",
|
||||
"payer_address_number": "202",
|
||||
"payer_address_complement": "Sob 11",
|
||||
"payer_address_country": "Brasil",
|
||||
"late_payment_fine": 0,
|
||||
"late_payment_fine_cents": null,
|
||||
"split_id": null,
|
||||
"account_id": "AF01CF1B3451459F92666F10589278EE",
|
||||
"account_name": "Beta Educa\u00e7\u00e3o",
|
||||
"secure_id": "970cb579-c396-4e59-a323-ce61ae04f7bc-196c",
|
||||
"secure_url": "https://faturas.iugu.com/970cb579-c396-4e59-a323-ce61ae04f7bc-196c",
|
||||
"customer_id": null,
|
||||
"customer_ref": null,
|
||||
"customer_name": null,
|
||||
"user_id": null,
|
||||
"total": "R$ 190,00",
|
||||
"taxes_paid": "R$ 0,00",
|
||||
"total_paid": "R$ 0,00",
|
||||
"total_overpaid": "R$ 0,00",
|
||||
"total_refunded": "R$ 0,00",
|
||||
"commission": "R$ 0,00",
|
||||
"fines_on_occurrence_day": "R$ 0,00",
|
||||
"total_on_occurrence_day": "R$ 0,00",
|
||||
"fines_on_occurrence_day_cents": 0,
|
||||
"total_on_occurrence_day_cents": 0,
|
||||
"refunded_cents": 0,
|
||||
"remaining_captured_cents": 0,
|
||||
"advance_fee": null,
|
||||
"paid": "R$ 0,00",
|
||||
"original_payment_id": null,
|
||||
"double_payment_id": null,
|
||||
"per_day_interest": false,
|
||||
"per_day_interest_value": null,
|
||||
"interest": null,
|
||||
"discount": null,
|
||||
"duplicated_invoice_id": null,
|
||||
"created_at": "24/09, 12:00",
|
||||
"created_at_iso": "2022-09-24T12:00:40-03:00",
|
||||
"authorized_at": null,
|
||||
"authorized_at_iso": null,
|
||||
"expired_at": null,
|
||||
"expired_at_iso": null,
|
||||
"refunded_at": null,
|
||||
"refunded_at_iso": null,
|
||||
"canceled_at": null,
|
||||
"canceled_at_iso": null,
|
||||
"protested_at": null,
|
||||
"protested_at_iso": null,
|
||||
"chargeback_at": null,
|
||||
"chargeback_at_iso": null,
|
||||
"occurrence_date": null,
|
||||
"refundable": null,
|
||||
"installments": null,
|
||||
"transaction_number": 1111,
|
||||
"payment_method": null,
|
||||
"financial_return_dates": null,
|
||||
"bank_slip": null,
|
||||
"pix": {
|
||||
"qrcode": "https://faturas.iugu.com/iugu_pix/970cb579-c396-4e59-a323-ce61ae04f7bc-196c/test/qr_code",
|
||||
"qrcode_text": "http://faturas.iugu.com/iugu_pix/970cb579-c396-4e59-a323-ce61ae04f7bc-196c/test/pay",
|
||||
"status": "qr_code_created",
|
||||
"payer_cpf_cnpj": null,
|
||||
"payer_name": null,
|
||||
"end_to_end_id": null,
|
||||
"end_to_end_refund_id": null
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"id": "9F3E50A8183247AAA3C8FB6F2B9FE666",
|
||||
"description": "test",
|
||||
"price_cents": 19000,
|
||||
"quantity": 1,
|
||||
"created_at": "2022-09-24T12:00:40-03:00",
|
||||
"updated_at": "2022-09-24T12:00:40-03:00",
|
||||
"price": "R$ 190,00"
|
||||
}
|
||||
],
|
||||
"early_payment_discounts": [],
|
||||
"split_rules": null,
|
||||
"variables": [
|
||||
{ "variable": "next_dunning_date", "value": "2022-09-24" },
|
||||
{ "variable": "payer.address.city", "value": "Curitiba" },
|
||||
{ "variable": "payer.address.city", "value": "Curitiba" },
|
||||
{ "variable": "payer.address.complement", "value": "Sob 11" },
|
||||
{ "variable": "payer.address.complement", "value": "Sob 11" },
|
||||
{ "variable": "payer.address.country", "value": "Brasil" },
|
||||
{ "variable": "payer.address.country", "value": "Brasil" },
|
||||
{ "variable": "payer.address.district", "value": "Pilarzinho" },
|
||||
{ "variable": "payer.address.district", "value": "Pilarzinho" },
|
||||
{ "variable": "payer.address.number", "value": "202" },
|
||||
{ "variable": "payer.address.number", "value": "202" },
|
||||
{ "variable": "payer.address.state", "value": "Paran\u00e1" },
|
||||
{ "variable": "payer.address.state", "value": "Paran\u00e1" },
|
||||
{
|
||||
"variable": "payer.address.street",
|
||||
"value": "Rua Emanuel Jos\u00e9 Pereira"
|
||||
},
|
||||
{
|
||||
"variable": "payer.address.street",
|
||||
"value": "Rua Emanuel Jos\u00e9 Pereira"
|
||||
},
|
||||
{ "variable": "payer.address.zip_code", "value": "07879819908" },
|
||||
{ "variable": "payer.address.zip_code", "value": "07879819908" },
|
||||
{ "variable": "payer.cpf_cnpj", "value": "07879819908" },
|
||||
{ "variable": "payer.cpf_cnpj", "value": "07879819908" },
|
||||
{ "variable": "payer.email", "value": "sergio@somosbeta.com.br" },
|
||||
{ "variable": "payer.email", "value": "sergio@somosbeta.com.br" },
|
||||
{ "variable": "payer.name", "value": "S\u00e9rgio R Siqueira" },
|
||||
{ "variable": "payer.name", "value": "S\u00e9rgio R Siqueira" }
|
||||
],
|
||||
"custom_variables": [],
|
||||
"logs": [
|
||||
{
|
||||
"id": "5F562043384040DCAB20BBD50975D787",
|
||||
"description": "Email de Fatura enviado!",
|
||||
"notes": "Fatura enviada com sucesso para: sergio@somosbeta.com.br",
|
||||
"created_at": "24/09, 12:00"
|
||||
},
|
||||
{
|
||||
"id": "EF2257B6195E41E396EA634FFAC460B9",
|
||||
"description": "Fatura criada com sucesso!",
|
||||
"notes": "Fatura criada!",
|
||||
"created_at": "24/09, 12:00"
|
||||
}
|
||||
],
|
||||
"credit_card_transaction": null
|
||||
}
|
||||
150
orders-events/tests/test_iugu.py
Normal file
150
orders-events/tests/test_iugu.py
Normal file
@@ -0,0 +1,150 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import requests
|
||||
from layercake.extra_types import CreditCard
|
||||
|
||||
from iugu import Credentials, Iugu, Order, Status, Token
|
||||
|
||||
iugu = Iugu(
|
||||
Credentials(
|
||||
'AF01CF1B3451459F92666F10589278EE',
|
||||
os.getenv('IUGU_API_TOKEN'),
|
||||
test_mode=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class MockResponse:
|
||||
def __init__(self, jsonfile: str | None = None) -> None:
|
||||
self.jsonfile = jsonfile
|
||||
|
||||
def json(self):
|
||||
if not self.jsonfile:
|
||||
return {'id': 'testing'}
|
||||
|
||||
with open(self.jsonfile) as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
@staticmethod
|
||||
def raise_for_status(): ...
|
||||
|
||||
|
||||
def test_create_invoice_pix(monkeypatch):
|
||||
# monkeypatch.setattr(
|
||||
# requests,
|
||||
# 'post',
|
||||
# lambda *args, **kwargs: MockResponse('tests/samples/iugu_invoice_pix.json'),
|
||||
# )
|
||||
|
||||
order = Order(**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'
|
||||
# )
|
||||
|
||||
|
||||
def test_create_invoice_bank_slip(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
'tests/samples/iugu_invoice_bank_slip.json'
|
||||
),
|
||||
)
|
||||
|
||||
order = Order(**event | {'payment_method': 'BANK_SLIP'})
|
||||
invoice = iugu.create_invoice(order, postback_url='http://localhost')
|
||||
|
||||
assert (
|
||||
invoice.pdf
|
||||
== 'https://boletos.iugu.com/v1/public/invoice/16f7aa3d-2e0b-41e9-987b-1dc95b957456-d7a2/bank_slip'
|
||||
)
|
||||
|
||||
|
||||
def test_payment_token(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse(),
|
||||
)
|
||||
|
||||
credit_card = CreditCard(
|
||||
holder_name='Sérgio R Siqueira',
|
||||
number='4111111111111111', # type: ignore
|
||||
cvv='123',
|
||||
exp_month='12',
|
||||
exp_year='2029',
|
||||
)
|
||||
token = iugu.payment_token(credit_card)
|
||||
assert isinstance(token, Token)
|
||||
|
||||
|
||||
def test_charge_paid(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse('tests/samples/iugu_charge_paid.json'),
|
||||
)
|
||||
|
||||
charge = iugu.charge(
|
||||
invoice_id='970cb579-c396-4e59-a323-ce61ae04f7bc-196c',
|
||||
token=Token('testing'),
|
||||
)
|
||||
assert charge.status == Status.PAID
|
||||
|
||||
|
||||
def test_charge_declined(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'post',
|
||||
lambda *args, **kwargs: MockResponse('tests/samples/iugu_charge_declined.json'),
|
||||
)
|
||||
|
||||
charge = iugu.charge(
|
||||
invoice_id='970cb579-c396-4e59-a323-ce61ae04f7bc-196c',
|
||||
token=Token('testing'),
|
||||
)
|
||||
assert charge.status == Status.DECLINED
|
||||
assert charge.response['status'] == 'unauthorized'
|
||||
|
||||
|
||||
def test_get_invoice(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
'get',
|
||||
lambda *args, **kwargs: MockResponse('tests/samples/iugu_invoice_pix.json'),
|
||||
)
|
||||
|
||||
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