Skip to content

Commit

Permalink
Merge pull request #2 from romatallinn/v0.0.3
Browse files Browse the repository at this point in the history
v0.0.3
  • Loading branch information
MrLightful authored Jan 29, 2024
2 parents 49aadcc + ed29c0f commit 67eec2c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 14 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.0.3

The release contains multiple critical bug fixes and improvements.

- Bump project development status classifier to 4 - Beta
- Add description to project config
- Add `Address.district`
- Fix base request's response handler
- Fix API endpoints in Payments module
- Fix API formatting of lists in `ObjectJSON`
- Fix typo in `SplitPayment.subordinate_merchant_id`
- Add `SplitMerchant.birthday_date` and `SplitMerchant.business_activity_id` as required for merchants registered by CPF document
- Accept data via kwargs in payment's capture request (e.g., for split payment details)

## 0.0.2

The release mostly meant to improve project & code quality.
Expand Down
1 change: 1 addition & 0 deletions braspag_sdk/apps/payments/data/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def __init__(self):
self.street = None
self.number = None
self.complement = None
self.district = None
self.zip_code = None
self.city = None
self.state = None
Expand Down
2 changes: 1 addition & 1 deletion braspag_sdk/apps/payments/requests/create_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, merchant_credentials: MerchantCredentials, environment: Payme
self.environment = environment

def execute(self, sale):
uri = '%s/sales' % self.environment.api
uri = '%s/v2/sales' % self.environment.api
response = self.send_request("POST", uri, sale)
sale.update_return(response)
return response
2 changes: 1 addition & 1 deletion braspag_sdk/apps/payments/requests/query_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ def __init__(self, merchant_credentials: MerchantCredentials, environment: Payme
self.environment = environment

def execute(self, payment_id):
uri = '%s/sales/%s' % (self.environment.query_api, payment_id)
uri = '%s/v2/sales/%s' % (self.environment.query_api, payment_id)
return self.send_request("GET", uri)
11 changes: 9 additions & 2 deletions braspag_sdk/apps/payments/requests/update_sale.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from braspag_sdk.utils import ApiBase

from braspag_sdk.apps.payments.environment import PaymentsEnvironment
Expand All @@ -14,11 +16,13 @@ def __init__(self, type: str, merchant_credentials: MerchantCredentials, environ
self.type = type
self.service_tax_amount = None
self.amount = None
self.data = None

def execute(self, payment_id):

uri = '%s/sales/%s/%s' % (self.environment.api, payment_id, self.type)
uri = '%s/v2/sales/%s/%s' % (self.environment.api, payment_id, self.type)

data = {}
params = {}

if self.amount:
Expand All @@ -27,4 +31,7 @@ def execute(self, payment_id):
if self.service_tax_amount:
params['serviceTaxAmount'] = self.service_tax_amount

return self.send_request('PUT', uri, params=params)
if self.data:
data = self.data

return self.send_request('PUT', uri, params=params, data=data)
8 changes: 7 additions & 1 deletion braspag_sdk/apps/payments/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ def create_sale(self, sale: Sale):
request = CreateSale(self.merchant_credentials, self._environment)
return request.execute(sale)

def capture_sale(self, payment_id: str, amount=None, service_tax_amount=None):
def capture_sale(self, payment_id: str, amount=None, service_tax_amount=None, **kwargs):
request = UpdateSale('capture', self.merchant_credentials, self._environment)
request.amount = amount
request.service_tax_amount = service_tax_amount

data = None
if kwargs:
data = json.dumps(kwargs)
request.data = data

return request.execute(payment_id)

def cancel_sale(self, payment_id: str, amount=None):
Expand Down
2 changes: 2 additions & 0 deletions braspag_sdk/apps/split/data/split_merchant.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self, *, master_merchant_id):
self.corporate_name = None
self.document_number = None
self.document_type = None
self.birthday_date = None
self.business_activity_id = None
self.address = None
self.bank_account = None
self.agreements = None
4 changes: 2 additions & 2 deletions braspag_sdk/apps/split/data/split_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, mdr=None, fee=None):

class SplitPayment(ObjectJSON):

def __init__(self, subordinadate_merchant_id, amount, mdr=None, fee=None):
self.subordinadate_merchant_id = subordinadate_merchant_id
def __init__(self, subordinate_merchant_id, amount, mdr=None, fee=None):
self.subordinate_merchant_id = subordinate_merchant_id
self.amount = amount
self.fares = SplitPaymentFares(mdr, fee)
4 changes: 2 additions & 2 deletions braspag_sdk/utils/base_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def send_request(self, method, uri, data=None, params=None):

if not body:
headers['Content-Length'] = '0'
elif not isinstance(data, dict):
elif not isinstance(data, str):
body = body.toJSON()

if 'Content-Type' not in headers:
Expand All @@ -39,7 +39,7 @@ def send_request(self, method, uri, data=None, params=None):

response = s.send(prep)

if 'json' in response.headers['Content-Type'].lower():
if 'json' in response.headers.get('Content-Type', '').lower():
answers = response.json()
else:
answers = [{
Expand Down
12 changes: 10 additions & 2 deletions braspag_sdk/utils/object_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ def __getattribute__(self, attribute):


def process_name_key(dictionary):

# If it's a list, process each item.
if isinstance(dictionary, list):
new_list = []
for item in dictionary:
new_list.append(process_name_key(item))
return new_list

# If it's not a dictionary (and not list), just return it as is.
if not isinstance(dictionary, dict):
return dictionary

# If it's a dictionary, process each key/value.
new_dictionary = {}

for key in dictionary:
new_dictionary[capitalize_key(key)] = process_name_key(dictionary[key])

return new_dictionary


Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "braspag-sdk"
version = "0.0.2"
description = ""
version = "0.0.3"
description = "An unofficial Python SDK for Braspag"
authors = [
"Roman Sirokov <[email protected]>",
]
Expand All @@ -11,7 +11,7 @@ readme = "README.md"
keywords = ["braspag", "sdk", "python", "cielo", "api", "ecommerce", "brazil", "payments"]
packages = [{include = "braspag_sdk"}]
classifiers = [
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
Expand Down

0 comments on commit 67eec2c

Please sign in to comment.