Skip to content
Merged
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
11 changes: 7 additions & 4 deletions mercadopago/resources/advanced_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Wraps ``/v1/advanced_payments`` endpoints used in marketplace split-payment
scenarios where funds are distributed among multiple receivers.

`API reference
<https://www.mercadopago.com/developers/en/reference>`_ (advanced_payments section not found in current reference)
`API reference <https://www.mercadopago.com/developers/en/reference>`_
(advanced_payments section not found in current reference)
"""
from datetime import datetime

Expand All @@ -30,8 +30,11 @@ def search(self, filters=None, request_options=None):
Returns:
dict: Paginated list of matching advanced payments.
"""
return self._get(uri="/v1/advanced_payments/search", filters=filters,
request_options=request_options)
return self._get(
uri="/v1/advanced_payments/search",
filters=filters,
request_options=request_options,
)

def get(self, advanced_payment_id, request_options=None):
"""Retrieves an advanced payment by its ID.
Expand Down
19 changes: 15 additions & 4 deletions mercadopago/resources/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def process(self, order_id, request_options=None):
if not isinstance(order_id, str):
raise ValueError("Param order_id must be a string")

return self._post(uri="/v1/orders/" + str(order_id) + "/process", request_options=request_options) # pylint: disable=line-too-long
return self._post(
uri=f"/v1/orders/{order_id}/process",
request_options=request_options,
)

def cancel(self, order_id, request_options=None):
"""Cancels an existing order.
Expand All @@ -117,7 +120,10 @@ def cancel(self, order_id, request_options=None):
if not isinstance(order_id, str):
raise ValueError("Param order_id must be a string")

return self._post(uri="/v1/orders/" + str(order_id) + "/cancel", request_options=request_options) # pylint: disable=line-too-long
return self._post(
uri=f"/v1/orders/{order_id}/cancel",
request_options=request_options,
)

def capture(self, order_id, request_options=None):
"""Captures a previously authorised order.
Expand All @@ -141,7 +147,10 @@ def capture(self, order_id, request_options=None):
if not isinstance(order_id, str):
raise ValueError("Param order_id must be a string")

return self._post(uri="/v1/orders/" + str(order_id) + "/capture", request_options=request_options) # pylint: disable=line-too-long
return self._post(
uri=f"/v1/orders/{order_id}/capture",
request_options=request_options,
)

def create_transaction(self, order_id, transaction_object, request_options=None):
"""Adds a payment transaction to an existing order.
Expand All @@ -165,7 +174,9 @@ def create_transaction(self, order_id, transaction_object, request_options=None)
return self._post(uri=f"/v1/orders/{order_id}/transactions", data=transaction_object,
request_options=request_options)

def update_transaction(self, order_id, transaction_id, transaction_object, request_options=None): # pylint: disable=line-too-long
def update_transaction(
self, order_id, transaction_id, transaction_object, request_options=None
):
"""Updates a transaction within an order.

Args:
Expand Down
16 changes: 9 additions & 7 deletions mercadopago/webhook/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, reason, request_id=None, timestamp=None):
request_id: ``x-request-id`` value associated with the request.
timestamp: ``ts`` extracted from the header, if available.
"""
super().__init__("Invalid webhook signature: {0}".format(reason.value))
super().__init__(f"Invalid webhook signature: {reason.value}")
self.reason = reason
self.request_id = request_id
self.timestamp = timestamp
Expand All @@ -73,7 +73,7 @@ def __init__(self, reason, request_id=None, timestamp=None):
_VERSION_KEY_REGEX = re.compile(r"^v\d+$")


class WebhookSignatureValidator:
class WebhookSignatureValidator: # pylint: disable=too-few-public-methods
"""Stateless utility that validates the signature of a MercadoPago webhook.

On failure :func:`validate` raises :class:`InvalidWebhookSignatureError`;
Expand All @@ -85,11 +85,12 @@ class WebhookSignatureValidator:
"""

@staticmethod
def validate(
def validate( # pylint: disable=too-many-arguments
x_signature,
x_request_id,
data_id,
secret,
*,
tolerance_seconds=None,
supported_versions=None,
now=None,
Expand Down Expand Up @@ -130,7 +131,8 @@ def validate(
data_id = _normalize(data_id)
versions = tuple(supported_versions) if supported_versions else _DEFAULT_SUPPORTED_VERSIONS
if now is None:
now = lambda: int(time.time() * 1000)
def now():
return int(time.time() * 1000)

if x_signature is None:
raise InvalidWebhookSignatureError(
Expand Down Expand Up @@ -214,8 +216,8 @@ def _build_manifest(data_id, request_id, ts):
"""Builds the HMAC manifest, omitting empty pairs per the documented rule."""
parts = []
if data_id:
parts.append("id:{0}".format(data_id.lower()))
parts.append(f"id:{data_id.lower()}")
if request_id:
parts.append("request-id:{0}".format(request_id))
parts.append("ts:{0}".format(ts))
parts.append(f"request-id:{request_id}")
parts.append(f"ts:{ts}")
return ";".join(parts) + ";"
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ py-version = 3.9

[pylint.FORMAT]
max-line-length = 100
ignore-long-lines = ^\s*((`[^`]*`?\s+)?<?https?://\S+>?`?_?|Reference:\s+https?://\S+)(\s+.*)?$

[isort]
# Vertical Hanging Indent
Expand Down
Loading