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
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v7
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v7

# Sets up python
- uses: actions/setup-python@v7
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v7
with:
python-version: 3.12

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v7
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v7
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v7
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pip "setuptools>=83.0.0"
python -m pip install requests

- name: Lint with Pylint
Expand Down
9 changes: 7 additions & 2 deletions mercadopago/resources/advanced_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,10 @@ def update_release_date(self, advanced_payment_id, release_date, request_options
disbursement_object = {
"money_release_date": release_date.strftime("%Y-%m-%d %H:%M:%S.%f")}

return self._post(uri="/v1/advanced_payments/" + self._path_param(advanced_payment_id) + "/disburses",
data=disbursement_object, request_options=request_options)
return self._post(
uri="/v1/advanced_payments/"
+ self._path_param(advanced_payment_id)
+ "/disburses",
data=disbursement_object,
request_options=request_options,
)
9 changes: 7 additions & 2 deletions mercadopago/resources/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,10 @@ def delete(self, customer_id, card_id, request_options=None):

Reference: https://www.mercadopago.com/developers/en/reference/online-payments/checkout-api/cards/delete-card/delete
"""
return self._delete(uri="/v1/customers/" + self._path_param(customer_id)
+ "/cards/" + self._path_param(card_id), request_options=request_options)
return self._delete(
uri="/v1/customers/"
+ self._path_param(customer_id)
+ "/cards/"
+ self._path_param(card_id),
request_options=request_options,
)
5 changes: 4 additions & 1 deletion mercadopago/resources/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def get(self, customer_id, request_options=None):

Reference: https://www.mercadopago.com/developers/en/reference/online-payments/checkout-api/customers/get-customer/get
"""
return self._get(uri="/v1/customers/" + self._path_param(customer_id), request_options=request_options)
return self._get(
uri="/v1/customers/" + self._path_param(customer_id),
request_options=request_options,
)

def create(self, customer_object, request_options=None):
"""Creates a new customer record.
Expand Down
34 changes: 25 additions & 9 deletions mercadopago/resources/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ def get(self, order_id, request_options=None):
if not isinstance(order_id, str):
raise ValueError("Param order_id must be a string")

return self._get(uri="/v1/orders/" + self._path_param(order_id), request_options=request_options)
return self._get(
uri="/v1/orders/" + self._path_param(order_id),
request_options=request_options,
)

def process(self, order_id, request_options=None):
"""Processes (executes payment for) an existing order.
Expand Down Expand Up @@ -225,8 +228,11 @@ def create_transaction(self, order_id, transaction_object, request_options=None)
if not isinstance(transaction_object, dict):
raise ValueError("Param transaction_object must be a Dictionary")

return self._post(uri=f"/v1/orders/{self._path_param(order_id)}/transactions", data=transaction_object,
request_options=request_options)
return self._post(
uri=f"/v1/orders/{self._path_param(order_id)}/transactions",
data=transaction_object,
request_options=request_options,
)

def update_transaction(
self, order_id, transaction_id, transaction_object, request_options=None
Expand All @@ -249,8 +255,12 @@ def update_transaction(
if not isinstance(transaction_object, dict):
raise ValueError("Param transaction_object must be a Dictionary")

return self._put(uri=f"/v1/orders/{self._path_param(order_id)}/transactions/{self._path_param(transaction_id)}",
data=transaction_object, request_options=request_options)
return self._put(
uri=f"/v1/orders/{self._path_param(order_id)}"
f"/transactions/{self._path_param(transaction_id)}",
data=transaction_object,
request_options=request_options,
)

def refund_transaction(self, order_id, transaction_object=None, request_options=None):
"""Refunds an order's transactions.
Expand All @@ -275,8 +285,11 @@ def refund_transaction(self, order_id, transaction_object=None, request_options=
if transaction_object is not None and not isinstance(transaction_object, dict):
raise ValueError("Param transaction_object must be a Dictionary")

return self._post(uri=f"/v1/orders/{self._path_param(order_id)}/refund", data=transaction_object,
request_options=request_options)
return self._post(
uri=f"/v1/orders/{self._path_param(order_id)}/refund",
data=transaction_object,
request_options=request_options,
)

def refund(self, order_id, refund_object=None, request_options=None):
"""Refunds an order.
Expand Down Expand Up @@ -315,5 +328,8 @@ def delete_transaction(self, order_id, transaction_id, request_options=None):
if not isinstance(order_id, str) or not isinstance(transaction_id, str):
raise ValueError("Params order_id and transaction_id must be strings")

return self._delete(uri=f"/v1/orders/{self._path_param(order_id)}/transactions/{self._path_param(transaction_id)}",
request_options=request_options)
return self._delete(
uri=f"/v1/orders/{self._path_param(order_id)}"
f"/transactions/{self._path_param(transaction_id)}",
request_options=request_options,
)
5 changes: 4 additions & 1 deletion mercadopago/resources/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def get(self, payment_id, request_options=None):

Reference: https://www.mercadopago.com/developers/en/reference/online-payments/checkout-api-payments/get-payment/get
"""
return self._get(uri="/v1/payments/" + self._path_param(payment_id), request_options=request_options)
return self._get(
uri="/v1/payments/" + self._path_param(payment_id),
request_options=request_options,
)

def create(self, payment_object, request_options=None):
"""Creates a new payment.
Expand Down
4 changes: 3 additions & 1 deletion mercadopago/resources/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def create(self, device_id, payment_intent_object, request_options=None):
raise ValueError("Param payment_intent_object must be a Dictionary")

return self._post(
uri="/point/integration-api/devices/" + self._path_param(device_id) + "/payment-intents",
uri="/point/integration-api/devices/"
+ self._path_param(device_id)
+ "/payment-intents",
data=payment_intent_object,
request_options=request_options,
)
Expand Down
5 changes: 4 additions & 1 deletion mercadopago/resources/preapproval.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def get(self, preapproval_id, request_options=None):

Reference: https://www.mercadopago.com/developers/en/reference/online-payments/subscriptions/get-preapproval/get
"""
return self._get(uri="/preapproval/" + self._path_param(preapproval_id), request_options=request_options)
return self._get(
uri="/preapproval/" + self._path_param(preapproval_id),
request_options=request_options,
)

def create(self, preapproval_object, request_options=None):
"""Creates a new preapproval (ad-hoc subscription).
Expand Down
7 changes: 5 additions & 2 deletions mercadopago/resources/preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ def update(self, preference_id, preference_object, request_options=None):
if not isinstance(preference_object, dict):
raise ValueError("Param preference_object must be a Dictionary")

return self._put(uri="/checkout/preferences/" + self._path_param(preference_id), data=preference_object,
request_options=request_options)
return self._put(
uri="/checkout/preferences/" + self._path_param(preference_id),
data=preference_object,
request_options=request_options,
)

def create(self, preference_object, request_options=None):
"""Creates a new checkout preference.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools >= 61.0"]
requires = ["setuptools >= 83.0.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
71 changes: 32 additions & 39 deletions tests/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,26 @@ class TestOrder(unittest.TestCase):
"""
sdk = mercadopago.SDK(os.environ['ACCESS_TOKEN'])

def create_master_test_card(self, status="APRO"):
card_token_object = {
"card_number": "5031433215406351",
"security_code": "123",
"expiration_year": "2030",
"expiration_month": "11",
"cardholder": {"name": status}
}
card_token_created = self.sdk.card_token().create(card_token_object)
return card_token_created["response"]["id"]

def create_visa_test_card(self, status="APRO"):
card_token_object = {
"card_number": "4235647728025682",
"card_number": "4074090000000004",
"security_code": "123",
"expiration_year": "2030",
"expiration_month": "11",
"expiration_month": "12",
"cardholder": {"name": status}
}
card_token_created = self.sdk.card_token().create(card_token_object)
return card_token_created["response"]["id"]

def create_master_test_card(self, status="APRO"):
return self.create_visa_test_card(status)

def create_order_canceled_or_captured(self, card_token_id):
random_email_id = random.randint(100000, 999999)
order_object_cc = {
"type": "online",
"processing_mode": "automatic",
"total_amount": "200.00",
"total_amount": "1000.00",
"external_reference": "ext_ref_1234",
"payer": {
"email": f"test_payer_{random_email_id}@testuser.com"
Expand All @@ -53,9 +45,9 @@ def create_order_canceled_or_captured(self, card_token_id):
"transactions": {
"payments": [
{
"amount": "200.00",
"amount": "1000.00",
"payment_method": {
"id": "master",
"id": "visa",
"type": "credit_card",
"token": card_token_id,
"installments": 1
Expand All @@ -74,7 +66,7 @@ def create_order_builder_mode(self):
order_object_cc = {
"type": "online",
"processing_mode": "manual",
"total_amount": "200.00",
"total_amount": "1000.00",
"external_reference": "ext_ref_1234",
"payer": {
"email": f"test_payer_{random_email_id}@testuser.com"
Expand All @@ -90,14 +82,14 @@ def create_order_oneshot_mode_complete(self, card_token_id):
order_mode_oneshot_complete = {
"type": "online",
"processing_mode": "automatic",
"total_amount": "200.00",
"total_amount": "1000.00",
"external_reference": "ext_ref_1234",
"transactions": {
"payments": [
{
"amount": "200.00",
"amount": "1000.00",
"payment_method": {
"id": "master",
"id": "visa",
"type": "credit_card",
"token": card_token_id,
"installments": 1
Expand All @@ -122,14 +114,14 @@ def create_order_builder_mode_complete(self, card_token_id):
order_mode_builder_complete = {
"type": "online",
"processing_mode": "manual",
"total_amount": "200.00",
"total_amount": "1000.00",
"external_reference": "ext_ref_1234",
"transactions": {
"payments": [
{
"amount": "200.00",
"amount": "1000.00",
"payment_method": {
"id": "master",
"id": "visa",
"type": "credit_card",
"token": card_token_id,
"installments": 12
Expand Down Expand Up @@ -157,23 +149,24 @@ def test_create_order_and_get_by_id(self):
random_email_id = random.randint(100000, 999999)
order_object = {
"type": "online",
"processing_mode": "automatic",
"total_amount": "1000.00",
"external_reference": "ext_ref_1234",
"transactions": {
"payments": [
{
"amount": "1000.00",
"payment_method": {
"id": "master",
"type": "credit_card",
"token": card_token_id,
"installments": 12
}
}
]
"payments": [
{
"amount": "1000.00",
"payment_method": {
"id": "visa",
"type": "credit_card",
"token": card_token_id,
"installments": 1
}
}
]
},
"payer": {
"email": f"test_payer_{random_email_id}@testuser.com"
"email": f"test_payer_{random_email_id}@testuser.com"
}
}

Expand All @@ -191,13 +184,13 @@ def test_process_order(self):
"type": "online",
"processing_mode": "manual",
"external_reference": "ext_ref_1234",
"total_amount": "200.00",
"total_amount": "1000.00",
"transactions": {
"payments": [
{
"amount": "200.00",
"amount": "1000.00",
"payment_method": {
"id": "master",
"id": "visa",
"type": "credit_card",
"token": card_token_id,
"installments": 1
Expand Down Expand Up @@ -240,7 +233,7 @@ def test_create_transaction(self):
transaction_object = {
"payments": [
{
"amount": "200.00",
"amount": "1000.00",
"payment_method": {
"id": "master",
"type": "credit_card",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_order_checkout_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_create_checkout_pro_order_live(self):
self.assertEqual(order_created["response"]["type"], "online")
self.assertEqual(order_created["response"]["processing_mode"], "manual")
self.assertIn("id", order_created["response"])
self.assertIn("checkout_url", order_created["response"])
self.assertIn("client_token", order_created["response"])


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_path_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_path_param_escapes_path_traversal(self):

self.assertEqual(
"..%2F..%2Fapplications%2F123",
base._path_param("../../applications/123"),
base._path_param("../../applications/123"), # pylint: disable=protected-access
)


Expand Down
7 changes: 1 addition & 6 deletions tests/test_payment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Module: test_payment
"""
from datetime import datetime
import os
import unittest
import mercadopago
Expand All @@ -20,7 +19,7 @@ def test_create_and_find(self):
card_token_object = {
"card_number": "4074090000000004",
"security_code": "123",
"expiration_year": datetime.now().strftime("%Y"),
"expiration_year": "2030",
"expiration_month": "12",
"cardholder": {
"name": "APRO",
Expand Down Expand Up @@ -75,10 +74,6 @@ def test_create_and_find(self):
"is_prime_user": False,
"is_first_purchase_online": False,
"last_purchase": "2024-01-01T12:01:01.000-03:00",
"identification": {
"type": "CPF",
"number": "19119119100"
},
"phone": {
"area_code": "011",
"number": "987654321"
Expand Down
Loading