pna client
This commit is contained in:
parent
44426d1a70
commit
3d6f9b6972
3 changed files with 82 additions and 2 deletions
|
|
@ -63,7 +63,8 @@ class ChargeRequestView(UpdateView):
|
||||||
messages.error(self.request, 'خطایی رخ داده است')
|
messages.error(self.request, 'خطایی رخ داده است')
|
||||||
charge_request.change_state(from_state=StateChoices.PENDING.value, to_state=StateChoices.EXPECTED_FAILURE.value)
|
charge_request.change_state(from_state=StateChoices.PENDING.value, to_state=StateChoices.EXPECTED_FAILURE.value)
|
||||||
|
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('pg:charge-request-view', kwargs={'pk': self.object.pk})
|
return self.object.callback_url
|
||||||
|
# return reverse('pg:charge-request-view', kwargs={'pk': self.object.pk})
|
||||||
|
|
|
||||||
|
|
@ -243,3 +243,5 @@ CACHES = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PNA_CORPORATION_PIN = config('PNA_CORPORATION_PIN'),
|
||||||
77
utils/pna.py
Normal file
77
utils/pna.py
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
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, phone_number, discription, callback_url, order_id: int):
|
||||||
|
data = {
|
||||||
|
"CorporationPin": self.corporation_pin,
|
||||||
|
"Amount": amount,
|
||||||
|
"OrderId": order_id,
|
||||||
|
"CallBackUrl": callback_url,
|
||||||
|
"AdditionalData": discription, # optional
|
||||||
|
"Originator": phone_number, # optional
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(self.normal_sale_request_url, json=data)
|
||||||
|
print(response.json())
|
||||||
|
|
||||||
|
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 response.json()
|
||||||
|
|
||||||
|
def request_normal_sale_confirm(self, token):
|
||||||
|
data = {
|
||||||
|
"CorporationPin": self.corporation_pin,
|
||||||
|
"Token": token
|
||||||
|
}
|
||||||
|
|
||||||
|
response_json_sample = {
|
||||||
|
"Status": "0",
|
||||||
|
"CardNumberMasked ": "627412******2424",
|
||||||
|
"RRN": "800473354463",
|
||||||
|
"Token": " MTIzNDU2Nzg5MTA="
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(self.normal_sale_confirm_url, json=data)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue