fake gateway
This commit is contained in:
parent
ecda2cf8f3
commit
78033f38c2
1 changed files with 19 additions and 5 deletions
|
|
@ -156,6 +156,7 @@ class PNA(BasePGModel):
|
||||||
client = PNAClient()
|
client = PNAClient()
|
||||||
|
|
||||||
def make_request(self):
|
def make_request(self):
|
||||||
|
self.payment_request.change_state(StateChoices.CREATED, StateChoices.IPG_PENDING, 'can not change state')
|
||||||
amount = self.payment_request.amount
|
amount = self.payment_request.amount
|
||||||
description = 'from addwin ipg'
|
description = 'from addwin ipg'
|
||||||
callback_url = urllib.parse.urljoin(
|
callback_url = urllib.parse.urljoin(
|
||||||
|
|
@ -164,6 +165,7 @@ class PNA(BasePGModel):
|
||||||
order_id = self.id
|
order_id = self.id
|
||||||
phone_number = self.payment_request.phone_number
|
phone_number = self.payment_request.phone_number
|
||||||
|
|
||||||
|
try:
|
||||||
response = self.client.request_normal_sale(amount, description, callback_url, order_id, phone_number)
|
response = self.client.request_normal_sale(amount, description, callback_url, order_id, phone_number)
|
||||||
self.pna_status_code = response['status']
|
self.pna_status_code = response['status']
|
||||||
self.pna_status_message = response.get('title')
|
self.pna_status_message = response.get('title')
|
||||||
|
|
@ -171,6 +173,12 @@ class PNA(BasePGModel):
|
||||||
if response['status'] == 0:
|
if response['status'] == 0:
|
||||||
self.pna_token = response['token']
|
self.pna_token = response['token']
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.payment_request.change_state(self.payment_request.state, StateChoices.FAILED,
|
||||||
|
'error in pardakht novin gateway')
|
||||||
|
except Exception as e:
|
||||||
|
self.payment_request.change_state(self.payment_request.state, StateChoices.FAILED, 'error in pardakht novin gateway')
|
||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def get_pg_page_url(self):
|
def get_pg_page_url(self):
|
||||||
|
|
@ -178,6 +186,10 @@ class PNA(BasePGModel):
|
||||||
return self.client.pg_base_url.format(token=self.pna_token)
|
return self.client.pg_base_url.format(token=self.pna_token)
|
||||||
|
|
||||||
def confirm_request(self, request=None):
|
def confirm_request(self, request=None):
|
||||||
|
if self.payment_request.state not in [StateChoices.IPG_PENDING]:
|
||||||
|
messages.error(request, "وضعیت تراکنش در حالت مناسبی نیست.")
|
||||||
|
return
|
||||||
|
|
||||||
print(dict(request.POST))
|
print(dict(request.POST))
|
||||||
post_dict = dict(request.POST)
|
post_dict = dict(request.POST)
|
||||||
if post_dict.get('status') in [0, '0', [0], ['0']]:
|
if post_dict.get('status') in [0, '0', [0], ['0']]:
|
||||||
|
|
@ -193,6 +205,8 @@ class PNA(BasePGModel):
|
||||||
self.details = response
|
self.details = response
|
||||||
if response['status'] == 0:
|
if response['status'] == 0:
|
||||||
self.pna_status = StateChoices.SUCCESS.value
|
self.pna_status = StateChoices.SUCCESS.value
|
||||||
|
self.payment_request.change_state(StateChoices.IPG_PENDING, StateChoices.IPG_SUCCESS,
|
||||||
|
'error in change state')
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
self.payment_request.charge_wallet_balance()
|
self.payment_request.charge_wallet_balance()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue