-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmercadoPago.py
59 lines (44 loc) · 1.7 KB
/
mercadoPago.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
import requests
#Global Variables
PK='' # Set your public_key here!
AT='' # Set your Access_Token here!
headers = {"Content-Type": "application/json"}
def tokenize(user):
global PK,AT,headers
body= {
"card_number": user['card_number'],
"expiration_month":user['expiration_month'],
"expiration_year": user['expiration_year'],
"cardholder": {
"name": user['first_name'] + ' ' + user['last_name'],
"identification": user['identification']
}
}
result = requests.post('https://api.mercadopago.com/v1/card_tokens?public_key='+ PK, headers=headers, data= json.dumps(body))
return str(result.json()['id'])
def create_customer (user):
global PK,AT,headers
body={
"email":user['email'],
"first_name":user['first_name'],
"last_name":user['last_name'],
"identification":user['identification'],
"metadata": user['metadata']
}
result = requests.post('https://api.mercadopago.com/v1/customers?access_token='+AT,headers=headers, data= json.dumps(body))
return (result.json()['id'])
def save_card(customer_id, token):
global PK,AT,headers
body={
"token":token
}
result = requests.post('https://api.mercadopago.com/v1/customers/'+str(customer_id)+'/cards?access_token='+AT,headers=headers, data= json.dumps(body))
return (result.json()['id'])
def set_default_card(customer_id,card_id):
global PK,AT,headers
body={
"default_card":card_id
}
result = requests.post('https://api.mercadopago.com/v1/customers/'+str(customer_id)+'?access_token='+AT,headers=headers, data= json.dumps(body))
return (result.status_code)