46. Payment preference and user charge
import mercadopago
public_key = "APP_USR-8e9c2811-1d99-4346-b8a0-9118201f7216"
access_token = "APP_USR-1378561128003766-083016-a08284dad9da4451cc196354af9f6722-1968090813"
#configure your credentials
sdk = mercadopago.SDK(access_token) #? validating access token
# Create items in the preference. preference = personalized charge for clients
preference_data = {
"items": [
{
"title": "Mi producto",
"quantity": 1,
"unit_price": 75.56
},
{
"title": "Mi producto2",
"quantity": 2,
"unit_price": 96.56
}
], #? links that will be loaded
"back_urls": {
"success": "http://localhost:8000/mercadopago/success/",
"failure": "http://localhost:8000/mercadopago/failure/",
"pending": "http://localhost:8000/mercadopago/pending/"
},
}
# Create a preference
preference_response = sdk.preference().create(preference_data) #? creating request with various informations about the payment
link = preference_response["response"]["init_point"]
payment_id = preference_response["response"]["id"] #? obtaining the payment id to treat it
Last updated