Skip to content

Commit

Permalink
Override __str__ and bump version 0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Nov 29, 2020
1 parent b95d289 commit 9e2eda0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
pix.set_merchant_name('Daniel Yohan')
pix.set_merchant_city('MACEIO')
pix.set_txid('Aquele Lanche')
print(pix.get_payload())
print(pix)
30 changes: 15 additions & 15 deletions pypix/pix.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ def __init__(self):
self.txid = None
self.amount = None

def __str__(self):
payload = "{}{}{}{}{}{}{}{}{}".format(
self.get_value(self._ID_PAYLOAD_FORMAT_INDICATOR, "01"),
self.get_merchant_account_information(),
self.get_value(self._ID_MERCHANT_CATEGORY_CODE, "0000"),
self.get_value(self._ID_TRANSACTION_CURRENCY, "986"),
self.get_value(self._ID_TRANSACTION_AMOUNT, self.amount),
self.get_value(self._ID_COUNTRY_CODE, self.country_code),
self.get_value(self._ID_MERCHANT_NAME, self.merchant_name),
self.get_value(self._ID_MERCHANT_CITY, self.merchant_city),
self.get_additional_data_field_template(),
)

return "{}{}".format(payload, self.get_crc16(payload))

def set_pixkey(self, pixkey: str):
self.pixkey = pixkey

Expand Down Expand Up @@ -95,18 +110,3 @@ def get_crc16(self, payload: str):
else:
crc = crc << 1
return "{}{}{}".format(self._ID_CRC16, "04", self.toHex(crc & 0xFFFF).upper())

def get_payload(self):
payload = "{}{}{}{}{}{}{}{}{}".format(
self.get_value(self._ID_PAYLOAD_FORMAT_INDICATOR, "01"),
self.get_merchant_account_information(),
self.get_value(self._ID_MERCHANT_CATEGORY_CODE, "0000"),
self.get_value(self._ID_TRANSACTION_CURRENCY, "986"),
self.get_value(self._ID_TRANSACTION_AMOUNT, self.amount),
self.get_value(self._ID_COUNTRY_CODE, self.country_code),
self.get_value(self._ID_MERCHANT_NAME, self.merchant_name),
self.get_value(self._ID_MERCHANT_CITY, self.merchant_city),
self.get_additional_data_field_template(),
)

return "{}{}".format(payload, self.get_crc16(payload))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pypix"
version = "0.1.3"
version = "0.1.4"
description = "Python library for generating pix codes with CRC16 validation"
authors = ["Daniel Yohan <dyohan9@gmail.com>"]
readme = "README.md"
Expand Down

0 comments on commit 9e2eda0

Please sign in to comment.