├── LICENSE ├── README.md └── idpay.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ... 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # idPay Payment for Python 2 | 3 | You should have a [Payment Token](https://idpay.ir/dashboard/web-services) to use this code . 4 | > Then you should place your **Token** in TOKEN constant ( Line 7 ) 5 | 6 | ## Documentation 7 | [IdPay Payment Documentation](https://idpay.ir/web-service/v1.1/index.html) 8 | -------------------------------------------------------------------------------- /idpay.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | 4 | API_URL = "https://api.idpay.ir/v1.1/" 5 | # You can get your Token from this url => https://idpay.ir/dashboard/web-services 6 | TOKEN = "Your Token Here" 7 | SANDBOX = str(1) # 1 or 0 8 | 9 | header = { 10 | "Content-Type": "application/json", 11 | "X-SANDBOX": SANDBOX, 12 | "X-API-KEY": TOKEN 13 | } 14 | 15 | 16 | def payment(order_id, amount, callback, name="", mail="", phone="", description=""): 17 | posts = { 18 | "order_id": str(order_id), 19 | "amount": int(amount), 20 | "callback": callback, 21 | "name": name, 22 | "mail": mail, 23 | "phone": phone, 24 | "desc": description 25 | } 26 | posts = json.dumps(posts) 27 | try: 28 | response = requests.post(f"{API_URL}payment", data=posts, headers=header).text 29 | response = json.loads(response) 30 | except Exception as e: 31 | return False 32 | return response 33 | 34 | 35 | def verify(id, order_id): 36 | order_id = str(order_id) 37 | id = str(id) 38 | posts = { 39 | "id": id, 40 | "order_id": order_id 41 | } 42 | posts = json.dumps(posts) 43 | try: 44 | response = requests.post(f"{API_URL}payment/verify", data=posts, headers=header).text 45 | response = json.loads(response) 46 | except Exception as e: 47 | return False 48 | return response 49 | 50 | 51 | def inquiry(id, order_id): 52 | posts = { 53 | "id": str(id), 54 | "order_id": str(order_id) 55 | } 56 | posts_json = json.dumps(posts) 57 | try: 58 | response = requests.post(f"{API_URL}payment/inquiry", data=posts_json, headers=header).text 59 | response = json.loads(response) 60 | except Exception as e: 61 | return False 62 | return response 63 | --------------------------------------------------------------------------------