Skip to content

Instantly share code, notes, and snippets.

@plinionaves
Created February 19, 2025 17:23
Show Gist options
  • Save plinionaves/4980400c7f0f3442c3a8835ef3758b7e to your computer and use it in GitHub Desktop.
Save plinionaves/4980400c7f0f3442c3a8835ef3758b7e to your computer and use it in GitHub Desktop.
Stark Infra Credit Note Test
import starkinfra
######################
###### CCB DATA ######
######################
INTEREST_RATE_MULTIPLIER = 100
borrower_tax_id = "239.413.720-76"
borrower_name = "Plinio Naves"
disbursement_date = "2025-02-19"
net_amount = 10
first_installment_date = "2025-03-21"
installments = 12
interest_rate = 0.11
######################
#### SIMULATION ######
######################
monthly_interest = interest_rate
annual_interest = (1 + monthly_interest) ** 12 - 1
previews = starkinfra.creditpreview.create(
previews=[
starkinfra.CreditPreview(
type="credit-note",
credit=starkinfra.creditpreview.CreditNotePreview(
amount=int(net_amount * 100),
nominal_amount=None,
initial_due=first_installment_date,
count=installments,
nominal_interest=float(annual_interest * INTEREST_RATE_MULTIPLIER), # 3.5% -> 3.5
rebate_amount=0,
scheduled=disbursement_date,
tax_id=borrower_tax_id,
interval="month",
type="price"
)
)
]
)
credit_preview = previews[0]
######################
#### CREDIT NOTE #####
######################
notes = starkinfra.creditnote.create([
starkinfra.CreditNote(
template_id="5706627130851328",
name=borrower_name,
tax_id=borrower_tax_id,
amount=credit_preview.credit.amount,
nominal_amount=credit_preview.credit.nominal_amount,
scheduled=disbursement_date,
invoices=credit_preview.credit.invoices,
tags=["test"],
payment=starkinfra.creditnote.Transfer(
bank_code="00000000",
branch_code="001",
account_number="123456-0",
name=borrower_name,
tax_id=borrower_tax_id,
),
signers=[
starkinfra.CreditSigner(
name="Plinio Naves",
contact="[email protected]",
method="link"
)
],
external_id=str(uuid.uuid4()),
street_line_1="Rua ABC",
street_line_2="",
district="Jardim Paulista",
city="São Paulo",
state_code="SP",
zip_code="01234-567",
)
])
for note in notes:
print(note)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment