91 lines
2.8 KiB
Python
91 lines
2.8 KiB
Python
import requests
|
|
from django.conf import settings
|
|
|
|
class PNAClient:
|
|
normal_sale_request_url = 'https://pna.shaparak.ir/mhipg/api/Payment/NormalSale'
|
|
normal_sale_confirm_url = 'https://pna.shaparak.ir/mhipg/api/Payment/confirm'
|
|
normal_sale_reverse_url = 'https://pna.shaparak.ir/mhipg/api/Payment/Reverse'
|
|
|
|
pg_base_url = 'https://pna.shaparak.ir/mhui/home/index/{token}'
|
|
|
|
corporation_pin = settings.PNA_CORPORATION_PIN
|
|
|
|
def request_normal_sale(self, amount, description, callback_url, order_id: int, phone_number=None):
|
|
data = {
|
|
"CorporationPin": self.corporation_pin,
|
|
"Amount": amount,
|
|
"OrderId": order_id,
|
|
"CallBackUrl": callback_url,
|
|
"AdditionalData": description, # optional
|
|
# "Originator": phone_number, # optional
|
|
}
|
|
|
|
print(data)
|
|
|
|
response = requests.post(self.normal_sale_request_url, json=data)
|
|
print(response.json())
|
|
|
|
tmp = {}
|
|
for key, value in response.json().items():
|
|
tmp[key.lower()] = value
|
|
|
|
response_json_sample = {
|
|
"Token": "MTIzNDU2Nzg5MTA=",
|
|
"Message": "عملیات موفق",
|
|
"Status": "0"
|
|
}
|
|
|
|
response_json_sample_error = {
|
|
'errors': {
|
|
'OrderId': [
|
|
'Error converting value "5c0980a4-ff91-4afb-9f1e-85b15af6fee5" to type \'System.Int64\'. Path \'OrderId\', line 1, position 123.'
|
|
],
|
|
'requestData': ['The requestData field is required.']
|
|
},
|
|
'type': 'https://tools.ietf.org/html/rfc7231#section-6.5.1',
|
|
'title': 'One or more validation errors occurred.',
|
|
'status': 400,
|
|
'traceId': '00-2e5835d18d02352de88318defe53ebc7-bf6082b6fb9f964c-00'
|
|
}
|
|
|
|
return tmp
|
|
|
|
def request_normal_sale_confirm(self, token):
|
|
data = {
|
|
"CorporationPin": self.corporation_pin,
|
|
"Token": token
|
|
}
|
|
|
|
print(data)
|
|
|
|
response_json_sample = {
|
|
"Status": "0",
|
|
"CardNumberMasked ": "627412******2424",
|
|
"RRN": "800473354463",
|
|
"Token": " MTIzNDU2Nzg5MTA="
|
|
}
|
|
|
|
response = requests.post(self.normal_sale_confirm_url, json=data)
|
|
print(response.json())
|
|
|
|
tmp = {}
|
|
for key, value in response.json().items():
|
|
tmp[key.lower()] = value
|
|
|
|
return tmp
|
|
|
|
def request_normal_sale_reverse(self, token):
|
|
data = {
|
|
"CorporationPin": self.corporation_pin,
|
|
"Token": token
|
|
}
|
|
|
|
response_json_sample = {
|
|
"Token": " MTIzNDU2Nzg5MTA=",
|
|
"Message": "عملیات موفق",
|
|
"Status": "0"
|
|
}
|
|
response = requests.post(self.normal_sale_confirm_url, json=data)
|
|
|
|
return response.json()
|
|
|