Last active
December 3, 2020 02:26
-
-
Save nishantji/646e8495809a7bdbd22cb7727d888e01 to your computer and use it in GitHub Desktop.
Adding Manual Subscriptions for Business SKU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import requests | |
import csv | |
register_endpoint = 'https://api3.fox.com/v2.0/register' | |
login_endpoint = 'https://api3.fox.com/v2.0/login' | |
post_payacc_endpoint = 'https://api3.fox.com/v2.0/paymentaccount/' | |
ev_endpoint = 'https://rest-prod-fox.evergent.com/foxusa/addSubscriptions' | |
# CSV File needs to have 4 fields - [Email, Password, FirstName, LastName, userType[New or Existing]] | |
csvfile = '/Users/nishant.jinsiwale/Desktop/ppv6.csv' | |
subsPackage = "PPB0192L" | |
def main(): | |
addSubslist = readCSV(csvfile) | |
for item in addSubslist: | |
print "We are in here: ", item | |
if item['userType'] == 'Existing' : | |
loginAccount = loginFoxAccount(item['Email'], item["Password"]) | |
registerEvergentAccount(loginAccount['profileId'],loginAccount['accessToken']) | |
addSubscriptionCall(loginAccount['accessToken'], subsPackage) | |
elif item['userType'] == 'New' : | |
print "Fox Profile Register -----------" | |
registeredAccount = registerFoxAccount(item['Email'], item["Password"]) | |
print "Evergent Register ------------" | |
registerEvergentAccount(registeredAccount['profileId'],registeredAccount['accessToken']) | |
print "Evergent AddSubs -------------" | |
addSubscriptionCall(registeredAccount['accessToken'], subsPackage) | |
def readCSV(csvfile): | |
with open(csvfile, mode='r') as f: | |
reader = csv.reader(f, skipinitialspace=True) | |
header = next(reader) | |
list = [dict(zip(header, map(str, row))) for row in reader] | |
return list | |
def registerFoxAccount(email, password): | |
request_headers = {'x-api-gateway-proof': 'iamproofthatinsecureobjectswillalwaysexistbecausesecurityistoofuckinghard', | |
'x-api-key': '11NNxmnTwya3ssk9PgwR61D231txrSMR'} | |
register_json = { | |
"email": email, | |
"password": password, | |
"deviceId": "A57EA09D-994E-4EBA-985D-DB182FA0EF07", | |
"migrateData": "true", | |
"icloud_id": "_e02d9a9b9547ec571e407629b407503a", | |
"newsLetter": True, | |
} | |
register_resp = requests.post(register_endpoint, json=register_json, headers=request_headers) | |
return {'profileId': register_resp.json()['profileId'], 'accessToken':register_resp.json()['accessToken'] } | |
def loginFoxAccount(email, password): | |
request_headers = {'x-api-gateway-proof': 'iamproofthatinsecureobjectswillalwaysexistbecausesecurityistoofuckinghard', | |
'x-api-key': '11NNxmnTwya3ssk9PgwR61D231txrSMR'} | |
r_login = requests.post(login_endpoint, json={"email": email, | |
"password": password}, headers= request_headers) | |
return {'profileId': r_login.json()['profileId'], 'accessToken':r_login.json()['accessToken'] } | |
def registerEvergentAccount(profileID, accessToken): | |
payacc_endpoint = post_payacc_endpoint + profileID | |
payacc_headers = {'Authorization': 'Bearer ' + accessToken, | |
'x-api-key': '11NNxmnTwya3ssk9PgwR61D231txrSMR'} | |
payaccount_json = { | |
"UpdateProfileRequestMessage": { | |
"dateOfBirth": None, | |
"gender": "Unspecified", | |
"emailNotificationFlag": True | |
} | |
} | |
r_payacc = requests.put(payacc_endpoint, json=payaccount_json, headers=payacc_headers) | |
print r_payacc.json() | |
def addSubscriptionCall(accessToken, subsPackage): | |
ev_headers = {'Authorization': 'Bearer ' + accessToken, | |
'x-api-key': '11NNxmnTwya3ssk9PgwR61D231txrSMR'} | |
ev_json = { | |
"AddSubscriptionRequestMessage": { | |
"channelPartnerID": "FOXUSA", | |
"apiKey": "ZF23%ZNLgz4g#EDFN6jbjhug8a6qhKjW", | |
"paymentmethodInfo": { | |
"label": "wallet", | |
"transactionReferenceMsg": { | |
"amount": "0.00", | |
"txMsg": "Success" | |
} | |
}, | |
"services": { | |
"service": [ | |
{ | |
"serviceType": "PACKAGE", | |
"serviceId": subsPackage, | |
"quantity": "1" | |
} | |
] | |
} | |
} | |
} | |
ev_r = requests.post(ev_endpoint, json=ev_json, headers=ev_headers) | |
print ev_r.json()['addSubscriptionsResponseMessage']['message'] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment