flask_mercadopago package¶
Submodules¶
flask_mercadopago.core module¶
Flask-Mercadopago
Implementation of Mercadopago OAuth in Flask.
- scripts_with_sri(url: str, sri: str) str [source]¶
Create a <script> element.
- Parameters
url (
str
) – Specifies the URL of an external script file.sri (
str
) – The Subresource Integrity value.
- Returns
script – The string with form to <script> tag is used to embed a client-side script.
- Return type
str
- simple_scripts_js(url: str) str [source]¶
Create a <script> element.
- Parameters
url (
str
) – Specifies the URL of an external script file.- Returns
script – The sctring with form to <script> tag is used to embed a client-side script.
- Return type
str
- class Mercadopago(app=None)[source]¶
Bases:
object
Base extension class for different of Mercadopago versions.
Initilize the extension:
from flask import Flask from flask_mercadopago import Mercadopago app = Flask(__name__) mercadopago = Mercadopago(app)
Or with the application factory:
from flask import Flask from flask_mercadopago import Mercadopago mercadopago = Mercadopago() def create_app(): app = Flask(__name__) mercadopago.init_app(app) return app
- mercadopago_js_version = None¶
- mercadopago_js_integrity = None¶
- cdk_base = 'https://sdk.mercadopago.com'¶
- mercadopago_js_filename = 'v2'¶
- static_folder = 'mercadopago'¶
- get_oidc_query_string(response_type: Optional[str] = None, client_id: Optional[str] = None, state: Optional[str] = None, redirect_uri: Optional[str] = None) str [source]¶
Generate oidc query string resources with given version.
- Parameters
response_type (
str
orNone
(optional)) – The response type. The config keyRESPONSE_TYPE
is"code"
.client_id (
str
orNone
(optional)) – The Unique CLIENT_ID that identifies your application given by Mercadopago.state (
str
orNone
(optional)) – A ramdom ID value.redirect_uri (
str
orNone
(optional)) – The URL reported in the Redirect URL field of your application.
- Returns
query_params_str – The query string.
- Return type
str
Examples
>>> import uuid >>> from flask import Flask >>> from flask_mercadopago import Mercadopago >>> app = Flask("app") >>> mercadopago = Mercadopago(app) >>> # The config keys currently understood by the extension: >>> app.config["CLIENT_ID"] = "1314151617108901" >>> app.config["RESPONSE_TYPE"] = "code" >>> app.config["STATE"] = uuid.uuid1() >>> app.config["CALLBACK_URL"]="http://localhost:5000/callback" >>> with app.app_context(): ... mercadopago.get_oidc_query_string() ... 'response_type=code&client_id=1314151617108901& state=5e092018-0ab8-11ed-8e81-e00af63ae0de &redirect_uri=http://localhost:5000/callback' >>>
- get_payload() dict [source]¶
Generate a basic payload (or data).
- Returns
payload – The payload for the connection.
- Return type
dict
Examples
>>> from flask import Flask >>> from flask_mercadopago import Mercadopago >>> app = Flask("app") >>> mercadopago = Mercadopago(app) >>> # The config keys currently understood by the extension: >>> app.config["CLIENT_ID"] = "1314151617108901" >>> app.config["CLIENT_SECRET"] = "C8HUg6ErZF" >>> app.config["CALLBACK_URL"]="http://localhost:5000/callback" >>> with app.app_context(): ... mercadopago.get_payload() ... {'client_id': '1314151617108901', 'client_secret': 'C8HUg6ErZF', 'redirect_uri': 'http://localhost:5000/callback'} >>>
- process_callback_or_refresh_token(endpoint: str, access_token: str, authorization_code: Optional[str] = None, refresh_token: Optional[str] = None) requests.models.Response [source]¶
Sends a POST request.
- Parameters
access_token (
str
orNone
(optional)) – An access token.authorization_code (
str
orNone
(optional)) – The code provided by the Mercadopago authentication server.endpoint (
str
) – The endopoint for process callback or refresh token.refresh_token (
str
orNone
(optional)) – A value received when the access token is created.
- Returns
res –
Response.Response
object.- Return type
requests.Response
- get_location(endpoint: str) str [source]¶
Generate the authorization or token endpoint resources.
- Parameters
endpoint (
str
) – The query string given by for the authorization or token endpoint.- Returns
location – The location from metadata for the application connection.
- Return type
str
Examples
>>> from flask import Flask >>> from flask_mercadopago import Mercadopago >>> app = Flask("app") >>> mercadopago = Mercadopago(app) >>> # call the method with "authorization_endpoint" value. >>> with app.app_context(): ... mercadopago.get_location("authorization_endpoint") ... 'https://auth.mercadopago.com.ar/authorization' >>> # call the method with "token_endpoint" value. >>> with app.app_context(): ... mercadopago.get_location("token_endpoint") ... 'https://api.mercadopago.com/oauth/token' >>>
- get_authorization_url(endpoint: str, response_type: Optional[str] = None, client_id: Optional[str] = None, state: Optional[str] = None, redirect_uri: Optional[str] = None) str [source]¶
Create the necessary authorization URL to operate your application.
- Parameters
endpoint (
str
) – The query string given by for the authorization endpoint.response_type (
str
orNone
(optional)) – The response type. The config keyRESPONSE_TYPE
is"code"
.client_id (
str
orNone
(optional)) – The Unique CLIENT_ID that identifies your application given by Mercadopago.state (
str
orNone
(optional)) – A ramdom ID value.redirect_uri (
str
orNone
(optional)) – The URL reported in the Redirect URL field of your application.
- Returns
authorization_url – The authorization URL the connection.
- Return type
dict
Examples
>>> import uuid >>> from flask import Flask >>> from flask_mercadopago import Mercadopago >>> app = Flask("app") >>> mercadopago = Mercadopago(app) >>> # The config keys currently understood by the extension: >>> app.config["CLIENT_ID"] = "1314151617108901" >>> app.config["RESPONSE_TYPE"] = "code" >>> app.config["STATE"] = uuid.uuid1() >>> app.config["CALLBACK_URL"] = "http://localhost:5000/callback" >>> # call the method with "authorization_endpoint" value. >>> with app.app_context(): ... mercadopago.get_authorization_url("authorization_endpoint") ... 'https://auth.mercadopago.com.ar/authorization?response_type=code &client_id=1314151617108901&state=5e092018-0ab8-11ed-8e81-e00af63ae0de &redirect_uri=http://localhost:5000/callback'
- load_js(version: Optional[str] = None, mercadopago_sri: Optional[str] = None) markupsafe.Markup [source]¶
Load Mercadopago SDK client side given for this version.
- Parameters
version (
str
orNone
(optional)) – The version of Mercadopago SDK client side.mercadopago_sri (
str
orNone
(optional)) – Subresource integrity for Mercadopago SDK client side.
- Returns
scripts – The <script> tag for JavaScipt Mercadopago SDK in client side file.
- Return type
markupsafe.Markup
- advanced_payment(http_client=None, request_options=None) mercadopago.resources.advanced_payment.AdvancedPayment [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.advanced_payment.AdvancedPayment
object.- Return type
mercadopago.resources.advanced_payment.AdvancedPayment
- card_token(http_client=None, request_options=None) mercadopago.resources.card_token.CardToken [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.card_token.CardToken
object.- Return type
mercadopago.resources.card_token.CardToken
- card(http_client=None, request_options=None) mercadopago.resources.card.Card [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.card.Card
object.- Return type
mercadopago.resources.card.Card
- customer(http_client=None, request_options=None) mercadopago.resources.customer.Customer [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.customer.Customer
object.- Return type
mercadopago.resources.customer.Customer
- disbursement_refund(http_client=None, request_options=None) mercadopago.resources.disbursement_refund.DisbursementRefund [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.disbursement_refund.DisbursementRefund
object.- Return type
mercadopago.resources.disbursement_refund.DisbursementRefund
- identification_type(http_client=None, request_options=None) mercadopago.resources.identification_type.IdentificationType [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.identification_type.IdentificationType
object.- Return type
mercadopago.resources.identification_type.IdentificationType
- merchant_order(http_client=None, request_options=None) mercadopago.resources.merchant_order.MerchantOrder [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.merchant_order.MerchantOrder
object.- Return type
mercadopago.resources.merchant_order.MerchantOrder
- payment(http_client=None, request_options=None) mercadopago.resources.payment.Payment [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.payment.Payment
object.- Return type
mercadopago.resources.payment.Payment
- payment_methods(http_client=None, request_options=None) mercadopago.resources.payment_methods.PaymentMethods [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.payment_methods.PaymentMethods
object.- Return type
mercadopago.resources.payment_methods.PaymentMethods
- preapproval(http_client=None, request_options=None) mercadopago.resources.preapproval.PreApproval [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.preapproval.Preapproval
object.- Return type
mercadopago.resources.preapproval.Preapproval
- preference(http_client=None, request_options=None) mercadopago.resources.preference.Preference [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.preference.Preference
object.- Return type
mercadopago.resources.preference.Preference
- refund(http_client=None, request_options=None) mercadopago.resources.refund.Refund [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.refund.Refund
object.- Return type
mercadopago.resources.refund.Refund
- user(http_client=None, request_options=None) mercadopago.resources.user.User [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.user.User
object.- Return type
mercadopago.resources.user.User
- chargeback(http_client=None, request_options=None) mercadopago.resources.chargeback.Chargeback [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.chargeback.Chargeback
object.- Return type
mercadopago.resources.chargeback.Chargeback
- subscription(http_client=None, request_options=None) mercadopago.resources.subscription.Subscription [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.subscription.Subscription
object.- Return type
mercadopago.resources.subscription.Subscription
- plan(http_client=None, request_options=None) mercadopago.resources.plan.Plan [source]¶
Returns the attribute value of the function.
- Parameters
http_client (
mercadopago.http.http_client
orNone
(optional)) – An implementation ofHttpClient
can be pass to be used to make the REST calls. Defaults to Nonerequest_options (
mercadopago.config.request_options
orNone
(optional)) – An instance ofRequestOptions
can be pass changing or adding custom options to ur REST call. Defaults to None.
- Returns
res –
mercadopago.resources.plan.Plan
object.- Return type
mercadopago.resources.plan.Plan
flask_mercadopago.utils module¶
Flask-Mercadopago
Implementation of Mercadopago OAuth in Flask.
- get_payload(client_id: Optional[str] = None, client_secret: Optional[str] = None, redirect_uri: Optional[str] = None) dict [source]¶
Generate a basic payload (or data).
- Parameters
client_id (str) – The client id for organization access.
client_secret (str) – The client secret for organization access.
redirect_uri (str) – The redirect uri for organization access.
- Returns
payload – The payload for the connection.
- Return type
dict