Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from . import errors
from .abstract_api import (
API,
CreatableAPIResource,
DeletableAPIResource,
ListableAPIResource,
RetrievableAPIResource,
SearchableAPIResource,
UpdatableAPIResource,
)
from .client import BaseClient
from .response import Response
class CardAPI(ListableAPIResource, RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource, DeletableAPIResource):
_base_path = '/v1/customers/{customer_id}/cards'
def __init__(self, client, customer_id):
super().__init__(client, path_args={'customer_id': customer_id})
class CardTokenAPI(API):
_base_path = '/v1/card_tokens'
def create(self, public_key, **data):
return self._client.post('/', params={'public_key': public_key}, json=data)
def get(self, id, public_key):
return self._client.get('/{id}', {'id': id}, params={'public_key': public_key})
def disburses(self, id, **data):
return self._client.post('/{disbursement_id}/disburses', {'disbursement_id': id}, json=data)
class ChargebackAPI(RetrievableAPIResource):
_base_path = '/v1/chargebacks'
class PlanAPI(RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource):
_base_path = '/v1/plans'
class PreferenceAPI(RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource, ListableAPIResource):
_base_path = '/checkout/preferences'
class MoneyRequestAPI(RetrievableAPIResource, CreatableAPIResource):
_base_path = '/money_requests'
class PreapprovalAPI(CreatableAPIResource, UpdatableAPIResource,
SearchableAPIResource):
_base_path = '/preapproval'
def get(self, id):
# NOTE: this is actually performing a search with ID and mangling
# the response data to conform to a single object format.
# There is no method to retrieve a preapproval by ID at the moment.
def me(self):
return self._client.get('/me')
def account_balance(self, user_id=None):
if user_id is None:
user_id = self.me().data['id']
return self._client.get('/{user_id}/mercadopago_account/balance', {
'user_id': user_id
})
def test_user_create(self, site_id):
return self._client.post('/test_user', json={'site_id': site_id})
class BankReportAPI(ListableAPIResource):
_base_path = '/v1/account/bank_report'
def get(self, file_name):
return self._client.get('/{file_name}', {'file_name': file_name})
def create(self, **data):
return self._client.post(json=data)
class SettlementReportAPI(SearchableAPIResource):
_base_path = '/v1/account/settlement_report'
def get(self, file_name):
return self._client.get('/{file_name}', {'file_name': file_name})
def config_new(self, **data):
class IdentificationTypeAPI(ListableAPIResource):
_base_path = '/identification_types'
class InvoiceAPI(RetrievableAPIResource):
_base_path = '/v1/invoices'
class MerchantOrderAPI(RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource):
_base_path = '/merchant_orders'
class PaymentMethodAPI(ListableAPIResource):
_base_path = '/v1/payment_methods'
def card_issuers(self, payment_method_id):
return self._client.get('/card_issuers', params={'payment_method_id': payment_method_id})
def installments(self, **data):
return self._client.get('/installments', params=data)
class PaymentAPI(RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource, SearchableAPIResource):
_base_path = '/v1/payments'
def cancel(self, id):
return self.update(id, status='cancelled')
return self._client.get('/{id}', {'id': id}, params={'public_key': public_key})
def update(self, id, public_key, **data):
return self._client.put('/{id}', {'id': id}, params={'public_key': public_key}, json=data)
class CustomerAPI(RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource, DeletableAPIResource,
SearchableAPIResource):
_base_path = '/v1/customers'
def cards(self, id):
return CardAPI(self._client, id)
class IdentificationTypeAPI(ListableAPIResource):
_base_path = '/identification_types'
class InvoiceAPI(RetrievableAPIResource):
_base_path = '/v1/invoices'
class MerchantOrderAPI(RetrievableAPIResource, CreatableAPIResource,
UpdatableAPIResource):
_base_path = '/merchant_orders'
class PaymentMethodAPI(ListableAPIResource):
_base_path = '/v1/payment_methods'
def card_issuers(self, payment_method_id):
return self._client.delete('/schedule')
class AccountAPI(API):
_base_path = '/v1/account'
@property
def bank_report(self):
return BankReportAPI(self._client)
@property
def settlement_report(self):
return SettlementReportAPI(self._client)
class SiteAPI(ListableAPIResource):
_base_path = '/sites'
class Client(BaseClient):
base_url = 'https://api.mercadopago.com'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
from . import __version__
self._session.headers['User-Agent'] = 'PyMercadoPago/%s' % __version__
def is_authenticated(self):
return bool(self._auth)
def authenticate(self):
data = {