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

Feature: Get boleto info #243

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lucascarrias
Copy link
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
Member

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

@allcontributors
Copy link
Contributor

@hyanmandian

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

src/utilities/boleto/index.ts Outdated Show resolved Hide resolved
src/utilities/boleto/index.ts Outdated Show resolved Hide resolved
src/utilities/boleto/index.ts Outdated Show resolved Hide resolved
src/utilities/boleto/index.ts Outdated Show resolved Hide resolved
@lucascarrias
Copy link
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
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
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 '';

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;

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.

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