· 6 years ago · Apr 04, 2019, 02:38 PM
1import json
2import requests
3import hashlib
4
5AFFILIATE_ID = '5c8386156b9ece2cb404c4b8'
6AFFILIATE_TOKEN = '02be1f00-424d-11e9-a363-9f8718f0f778'
7AFFILIATE_SECRET_KEY = '7354b4c2-37da-4f13-b876-a9a491005dd2'
8
9
10def get_hash(request_data, secret_key):
11 to_be_hash = ''.join(sorted(json.dumps(request_data).replace(" ", ""))) + secret_key
12 calculated_hash = hashlib.sha256(to_be_hash.encode('utf-8')).hexdigest()
13 return str(calculated_hash)
14
15
16order_data = {
17 'delivery_charges': 0,
18 'cod_charges': 0,
19 'cart_value': 4110,
20 'cashback_applied': 0,
21 'coupon_value': 0,
22 'coupon_code': '',
23 'is_cod': False,
24 'cart_items': [
25 {'size': 'OS', 'product_id': '816273'},
26 {'size': 'OS', 'product_id': '816271'},
27 {'size': 'OS', 'product_id': '816236'},
28 {'size': 'OS', 'product_id': '816272'}
29 ],
30 'cart_breakup': {},
31 'shipping_address': {
32 'name': 'Nanhe Kumar',
33 'address': 'Delhi Delhi Delhi',
34 'area': 'Delhi',
35 'phone': '7428232817',
36 'pincode': '110009', 'email': 'nanhe.kumar@gmail.com',
37 'address_type': 'home'
38 },
39 'billing_address': {
40 'name': 'Nanhe Kumar',
41 'address': 'Delhi Delhi Delhi',
42 'area': 'Delhi',
43 'phone': '7428232817',
44 'pincode': '110009',
45 'email':
46 'nanhe.kumar@gmail.com',
47 'address_type': 'home'
48 }
49}
50
51url = "https://api.addsale.com/megatron/affiliate/v2/create/order/"
52order_data['request_hash'] = get_hash(order_data, AFFILIATE_SECRET_KEY)
53
54response = requests.post(url, json=order_data, headers={
55 'Fynd-Affiliate-Id': AFFILIATE_ID,
56 'Fynd-Affiliate-Token': AFFILIATE_TOKEN
57})
58print(response.text)