This repository has been archived by the owner on May 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spoofer.py
191 lines (152 loc) · 5.44 KB
/
spoofer.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import requests
from errorchecker import ErrorChecker, McDonaldsException
from order import Order
from itemfactory import ItemFactory
class Spoofer(object):
BASE = 'https://eu-mcd.eu.cloudhub.io'
ORDER = BASE + '/v3/order/total'
SIGNIN = BASE + '/v3/customer/session/sign-in-and-authenticate'
PAYMENT = BASE + '/v3/order/payment'
PICKUP = BASE + '/v3/order/finalization/pickup'
def __init__(self, api_key:str, *, hashstr:str="McD_API_Spoofer", market_id:str='UK', application:str='MOT', language_name:str='en-GB', platform:str='android', version_id:str='0.0.1.I', nonce:str='happybaby'):
# Auth stuff
self.token = None
self.api_key = api_key
self.nonce = nonce
self.username = None
# Login
self.hash = hashstr
# Used in order
self.platform = platform
self.market_id = market_id
self.application = application
self.language_name = language_name
self.version_id = version_id
# Payment info
self.order_payment_id = None
@property
def headers(self):
'''
Gets the headers for the class
'''
v = {
'marketId': self.market_id,
'mcd_apikey': self.api_key
}
if self.token:
v.update({'Token': self.token})
return v
def _check_signed_in(f):
def wrapper(self, *args, **kwargs):
if not self.username:
raise McDonaldsException('Not signed in.')
return f(self, *args, **kwargs)
return wrapper
def sign_in(self, username:str, password:str):
'''
Signs in and gets the token for you
'''
# Get the url and params
url = self.SIGNIN
json = {
"marketId": self.market_id,
"application": self.application,
"languageName": self.language_name,
"platform": self.platform,
"versionId": self.version_id,
"nonce": self.nonce,
"hash": self.hash,
"userName": username,
"password": password,
"newPassword": None
}
# Send request to McD
site = requests.post(url, json=json, headers=self.headers)
# Make sure there's no status error
ErrorChecker.check(site)
# Store relevant information in class
self.username = username
self.token = site.json()['Data']['AccessData']['Token']
return
@_check_signed_in
def new_order(self, store_id:str):
'''
Gets a new order object for you
'''
# Requires you to be signed in
return Order(
store_id=store_id,
market_id=self.market_id,
application=self.application,
language_name=self.language_name,
platform=self.platform,
username=self.username
)
@_check_signed_in
def get_total(self, order:Order):
'''
Gets you the total for an order
'''
# Generate params
json = order.output()
# Send request
site = requests.post(self.ORDER, json=order.output(), headers=self.headers)
# Make sure it's valid
if not site.status_code == 200:
return site
# Return the relevant info
json = site.json()
try:
return json['Data']['OrderView']['TotalValue']
except KeyError:
raise McDonaldsException('Login timed out.')
@_check_signed_in
def payment(self, order:Order, customer_payment_method_id:int, *, price_type:int=2, payment_data_id:int=-1, payment_method_id:int=5, pod:int=0):
'''
Sends a payment to the store location
'''
# Generate params
json = order.output()
json['orderView']['Payment'] = {
"POD": pod,
"CustomerPaymentMethodId": customer_payment_method_id,
"PaymentDataId": payment_data_id,
"PaymentMethodId": payment_method_id
}
json['orderView']['PriceType'] = price_type
url = self.PAYMENT
# Send request
site = requests.post(url, json=json, headers=self.headers)
# Check it's valid
ErrorChecker.check(site)
# Store the useful data
data = site.json()
# self.order_payment_id = data['Data']['OrderView']['OrderPaymentId']
self.order_payment_id = -1
@_check_signed_in
def pickup(self, order:Order, customer_payment_method_id:int, *, check_in_data:str='0', price_type:int=2, payment_data_id:int=-1, payment_method_id:int=5, pod:int=0):
'''
Lets you pick up your order - THIS WILL CHARGE YOUR PAYMENT METHOD
'''
# Generate the params
json = order.output()
json['orderView']['Payment'] = {
"POD": pod,
"CustomerPaymentMethodId": customer_payment_method_id,
"PaymentDataId": payment_data_id,
"PaymentMethodId": payment_method_id,
"OrderPaymentId": self.order_payment_id
}
json['orderView']['PriceType'] = price_type
json['checkInData'] = check_in_data
url = self.PICKUP
# Send request
site = requests.post(url, json=json, headers=self.headers)
# Check it's valid
ErrorChecker.check(site)
# Return relevant info
data = site.json()
try:
return data['Data']['OrderNumber']
except:
return data