diff --git a/CHANGELOG.md b/CHANGELOG.md index 743e1d66..fcd83b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- rule parameter on DynamicBrcode resource +- display_description parameter on DynamicBrcode resource + ### Added - MerchantSession and MerchantSessionPurchase resources diff --git a/starkbank/dynamicbrcode/__dynamicbrcode.py b/starkbank/dynamicbrcode/__dynamicbrcode.py index a0a7c376..26acd53a 100644 --- a/starkbank/dynamicbrcode/__dynamicbrcode.py +++ b/starkbank/dynamicbrcode/__dynamicbrcode.py @@ -1,46 +1,45 @@ # coding: utf-8 - -from ..utils import rest from starkcore.utils.resource import Resource +from starkcore.utils.api import from_api_json from starkcore.utils.checks import check_datetime, check_date, check_timedelta +from ..utils import rest +from .rule.__rule import _sub_resource as _rule_resource, Rule class DynamicBrcode(Resource): """# DynamicBrcode object - When you initialize a DynamicBrcode, the entity will not be automatically - sent to the Stark Bank API. The 'create' function sends the objects - to the Stark Bank API and returns the list of created objects. - DynamicBrcodes are conciliated BR Codes that can be used to receive Pix transactions in a convenient way. - When a DynamicBrcode is paid, a Deposit is created with the tags parameter containing the character “dynamic-brcode/” followed by the DynamicBrcode’s uuid "dynamic-brcode/{uuid}" for conciliation. - Additionally, all tags passed on the DynamicBrcode will be transferred to the respective Deposit resource. - ## Parameters (required): - - amount [integer]: DynamicBrcode value in cents. Minimum = 0 (any value will be accepted). ex: 1234 (= R$ 12.34) - ## Parameters (optional): - - expiration [integer or datetime.timedelta, default 3600 (1 hour)]: time interval in seconds between due date and expiration date. ex 123456789 - - tags [list of strings, default []]: list of strings for tagging, these will be passed to the respective Deposit resource when paid - ## Attributes (return-only): - - id [string]: id returned on creation, this is the BR code. ex: "00020126360014br.gov.bcb.pix0114+552840092118152040000530398654040.095802BR5915Jamie Lannister6009Sao Paulo620705038566304FC6C" - - uuid [string]: unique uuid returned when the DynamicBrcode is created. ex: "4e2eab725ddd495f9c98ffd97440702d" - - picture_url [string]: public QR Code (png image) URL. ex: "https://sandbox.api.starkbank.com/v2/dynamic-brcode/d3ebb1bd92024df1ab6e5a353ee799a4.png" - - updated [datetime.datetime]: latest update datetime for the DynamicBrcode. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0) - - created [datetime.datetime]: creation datetime for the DynamicBrcode. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0) + Check out our API Documentation at https://starkbank.com/docs/api#dynamic-brcode """ - def __init__(self, amount, expiration=None, tags=None, id=None, uuid=None, picture_url=None, updated=None, created=None): + def __init__(self, amount, expiration=None, tags=None, display_description=None, rules=None, id=None, uuid=None, + picture_url=None, updated=None, created=None): Resource.__init__(self, id=id) self.amount = amount self.expiration = check_timedelta(expiration) + self.display_description = display_description + self.rules = _parse_rules(rules) self.tags = tags self.uuid = uuid self.picture_url = picture_url self.updated = check_datetime(updated) self.created = check_datetime(created) - _resource = {"class": DynamicBrcode, "name": "DynamicBrcode"} +def _parse_rules(rules): + if rules is None: + return None + parsed_rules = [] + for rule in rules: + if isinstance(rule, Rule): + parsed_rules.append(rule) + continue + parsed_rules.append(from_api_json(_rule_resource, rule)) + return parsed_rules + + def create(brcodes, user=None): """# Create DynamicBrcodes Send a list of DynamicBrcode objects for creation in the Stark Bank API diff --git a/starkbank/dynamicbrcode/__init__.py b/starkbank/dynamicbrcode/__init__.py index e8da2a34..8644de14 100644 --- a/starkbank/dynamicbrcode/__init__.py +++ b/starkbank/dynamicbrcode/__init__.py @@ -1 +1,2 @@ +from .rule.__rule import Rule from .__dynamicbrcode import create, get, query, page diff --git a/starkbank/dynamicbrcode/rule/__init__.py b/starkbank/dynamicbrcode/rule/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/starkbank/dynamicbrcode/rule/__rule.py b/starkbank/dynamicbrcode/rule/__rule.py new file mode 100644 index 00000000..89e3e361 --- /dev/null +++ b/starkbank/dynamicbrcode/rule/__rule.py @@ -0,0 +1,11 @@ +from starkcore.utils.subresource import SubResource + + +class Rule(SubResource): + + def __init__(self, key, value): + self.key = key + self.value = value + + +_sub_resource = {"class": Rule, "name": "Rule"} diff --git a/tests/utils/dynamicBrcode.py b/tests/utils/dynamicBrcode.py index 83073f57..79098416 100644 --- a/tests/utils/dynamicBrcode.py +++ b/tests/utils/dynamicBrcode.py @@ -2,13 +2,20 @@ from copy import deepcopy from random import randint from starkbank import DynamicBrcode - +from starkbank.dynamicbrcode import Rule example_brcode = DynamicBrcode( amount=400000, expiration=3600, tags=[ "python-SDK/test" + ], + display_description="Payment for service #1234", + rules=[ + Rule( + key="allowedTaxIds", + value=["012.345.678-90"] + ) ] )