Skip to content
Open
99 changes: 99 additions & 0 deletions mercadopago/resources/address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
Address resource for MercadoPago SDK.

This module contains the Address model with properties for representing
physical addresses.
"""

from mercadopago.resources.base import ResourceBase


class Address(ResourceBase):
"""
Address resource model.

Represents a physical address with properties for city, country, state,
street name, street number, and zip code.
"""

_schema = {
"city": str,
"country": str,
"state": str,
"street_name": str,
"street_number": str,
"zip_code": str,
}

def __init__(self, data=None):
"""
Initialize an Address instance.

Args:
data (dict, optional): Dictionary containing address data.
"""
super(Address, self).__init__(data)

self.city = None
self.country = None
self.state = None
self.street_name = None
self.street_number = None
self.zip_code = None

if data:
self._load_from_dict(data)

def _load_from_dict(self, data):
"""
Load address properties from a dictionary.

Args:
data (dict): Dictionary containing address data.
"""
if not isinstance(data, dict):
return

self.city = data.get("city")
self.country = data.get("country")
self.state = data.get("state")
self.street_name = data.get("street_name")
self.street_number = data.get("street_number")
self.zip_code = data.get("zip_code")

def to_dict(self):
"""
Convert the Address instance to a dictionary.

Returns:
dict: Dictionary representation of the address.
"""
result = {}

if self.city is not None:
result["city"] = self.city
if self.country is not None:
result["country"] = self.country
if self.state is not None:
result["state"] = self.state
if self.street_name is not None:
result["street_name"] = self.street_name
if self.street_number is not None:
result["street_number"] = self.street_number
if self.zip_code is not None:
result["zip_code"] = self.zip_code

return result

def __repr__(self):
"""
Return a string representation of the Address instance.

Returns:
str: String representation of the address.
"""
return (
f"Address(city={self.city!r}, country={self.country!r}, "
f"state={self.state!r}, street_name={self.street_name!r}, "
f"street_number={self.street_number!r}, zip_code={self.zip_code!r})"
)
52 changes: 52 additions & 0 deletions mercadopago/resources/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Pagination resource for MercadoPago SDK."""


class Pagination:
"""Represents pagination information for list responses."""

def __init__(self, total: int = 0, limit: int = 0, offset: int = 0):
"""
Initialize Pagination.

Args:
total: Total number of items available
limit: Maximum number of items per page
offset: Number of items to skip
"""
self.total = total
self.limit = limit
self.offset = offset

def to_dict(self):
"""
Convert pagination to dictionary.

Returns:
dict: Dictionary representation of pagination
"""
return {
"total": self.total,
"limit": self.limit,
"offset": self.offset,
}

@classmethod
def from_dict(cls, data: dict):
"""
Create Pagination instance from dictionary.

Args:
data: Dictionary containing pagination data

Returns:
Pagination: New Pagination instance
"""
return cls(
total=data.get("total", 0),
limit=data.get("limit", 0),
offset=data.get("offset", 0),
)

def __repr__(self):
"""String representation of Pagination."""
return f"Pagination(total={self.total}, limit={self.limit}, offset={self.offset})"
22 changes: 19 additions & 3 deletions mercadopago/resources/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,24 @@ def create(self, payment_object, request_options=None):
"""Creates a new payment.

Args:
payment_object: Dict describing the payment (amount, payer,
payment_method_id, token, etc.).
payment_object: Dict describing the payment with the following fields:
- transaction_amount (float, required): Payment amount.
- payer (dict, required): Payer information (PaymentPayer).
- token (string, optional): Card token for card payments.
- payment_method_id (string, optional): Payment method identifier.
- installments (integer, optional): Number of installments.
- issuer_id (string, optional): Card issuer identifier.
- capture (boolean, optional): Whether to capture immediately (default: true).
- binary_mode (boolean, optional): Binary payment mode (default: false).
- external_reference (string, optional): External reference ID.
- statement_descriptor (string, optional): Statement descriptor (max 22 chars).
- date_of_expiration (datetime, optional): Payment expiration date.
- additional_info (dict, optional): Additional payment information (PaymentAdditionalInfo).
- application_fee (float, optional): Application fee amount.
- notification_url (uri, optional, deprecated): IPN notification URL.
- callback_url (uri, optional): Callback URL.
- coupon_code (string, optional): Coupon code.
- coupon_amount (float, optional): Coupon discount amount.
request_options: Per-call configuration overrides.

Raises:
Expand Down Expand Up @@ -92,4 +108,4 @@ def update(self, payment_id, payment_object, request_options=None):
raise ValueError("Param payment_object must be a Dictionary")

return self._put(uri="/v1/payments/" + str(payment_id), data=payment_object,
request_options=request_options)
request_options=request_options)
Loading
Loading