Skip to content

Feature: Get boleto info#243

Closed
lucascarrias wants to merge 7 commits into
brazilian-utils:mainfrom
lucascarrias:feature/get-boleto-info
Closed

Feature: Get boleto info#243
lucascarrias wants to merge 7 commits into
brazilian-utils:mainfrom
lucascarrias:feature/get-boleto-info

Conversation

@lucascarrias

Copy link
Copy Markdown
Contributor

References

[Feature request] Get "boleto" information from digitable line #239

Objectives

Create getBoletoInfo function to get data from a valid boleto.

Usage example:

>> getBoletoInfo('23793381286006069409261000063307486470000004200');

>> {
    valueInCents: 4200,
    expirationDate: 2021-06-10T03:00:00.000Z,
    bankCode: '237'
   }

Changes

  • Create getValueInCents function
  • Create getExpirationDate function
  • Create getBankCode function
  • Create Boleto interface
  • Create getInfo function and export it as getBoletoInfo
  • Add getBoletoInfo to docs

Notes

The currency field mentioned at #239 hasn't been added because, most of cases, the brazilian payment method will be charged with BRL values.

@hyanmandian

Copy link
Copy Markdown
Member

Nice job @lucascarrias ! @all-contributors please add @lucascarrias for docs, tests, and code.

@allcontributors

Copy link
Copy Markdown
Contributor

@hyanmandian

I've put up a pull request to add @lucascarrias! 🎉

Comment thread src/utilities/boleto/index.ts Outdated
Comment thread src/utilities/boleto/index.ts Outdated
Comment thread src/utilities/boleto/index.ts Outdated
Comment thread src/utilities/boleto/index.ts Outdated
@lucascarrias

Copy link
Copy Markdown
Contributor Author

@hyanmandian Thanks for the reviews! I'll follow your recommendations.

* Create BANCO_CENTRAL_BASE_DATE constant
* Create variables to helper values
* Replace .substr() by .slice() method
@lucascarrias

Copy link
Copy Markdown
Contributor Author

@hyanmandian I've refactored the code following the changes requests, with some notes:

  • The substr method was replaced by slice as the substr is considered a legacy method (ref)
  • Negatives indexes were used instead of using the someString.length - reverveIndexPosition expression

@hyanmandian

Copy link
Copy Markdown
Member

As soon I have time I will merge and publish your utility.

Thanks for your contribution and welcome aboard!

}

export function getBankCode(digitableLine: string): string {
if (!digitableLine || !isValid(digitableLine)) return '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid case? (return an empty string here)

const daysSinceBaseDayEndIndex = -10;
const daysSinceBaseDay = digitableLine.slice(daysSinceBaseDayStartIndex, daysSinceBaseDayEndIndex);

const oneDayMilliseconds = 24 * 60 * 60 * 1000;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved outside of the function so it can be evaluated on parsing.

@hyanmandian

Copy link
Copy Markdown
Member

Fala @lucascarrias tudo certo? Cara, to fazendo um refactoring ta lib inteira e vou incluir sua alteracao la! #398 @diasbruno pode ficar tranquilo que incluirei sua sugestao de melhoria tb!

Sintam-se a vontade a fazer o review se quiserem!

@hyanmandian hyanmandian mentioned this pull request Jan 26, 2025
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants