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

Add new option parameter rule on DynamicBrcode entity #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 20 additions & 21 deletions starkbank/dynamicbrcode/__dynamicbrcode.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions starkbank/dynamicbrcode/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .rule.__rule import Rule
from .__dynamicbrcode import create, get, query, page
Empty file.
11 changes: 11 additions & 0 deletions starkbank/dynamicbrcode/rule/__rule.py
Original file line number Diff line number Diff line change
@@ -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"}
9 changes: 8 additions & 1 deletion tests/utils/dynamicBrcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
]
)

Expand Down