diff --git a/apps/pg/models.py b/apps/pg/models.py index 792b4ae..4c196b7 100644 --- a/apps/pg/models.py +++ b/apps/pg/models.py @@ -159,14 +159,18 @@ class PaymentRequest(models.Model): logger.error(f"[Deposit Verify] Failed to get response from wallet service | payment_id={self.pk}") raise Exception('Failed to get response from wallet service') - if not verify_response.uuid or verify_response.state != 5: + if not verify_response.uuid: + logger.error(f"[Deposit Verify] Failed to get response uuid from wallet service | payment_id={self.pk}") + raise Exception('Failed to get response uuid from wallet service') + + if verify_response.state != 5: logger.error(f"[Deposit Verify] Wallet verification failed | payment_id={self.pk}, response={verify_response}") - to_pay_failed = PaymentRequest.objects.filter( - pk=self.pk, - state=StateChoices.WALLET_SUBMIT_SUCCESS.value - ).update( - state=StateChoices.FAILED.value, - ) + # to_pay_failed = PaymentRequest.objects.filter( + # pk=self.pk, + # state=StateChoices.WALLET_SUBMIT_SUCCESS.value + # ).update( + # state=StateChoices.FAILED.value, + # ) raise Exception('Failed to verify payment in wallet') to_pay_success = PaymentRequest.objects.filter( diff --git a/apps/pg/views.py b/apps/pg/views.py index 1451db6..c2c2a26 100644 --- a/apps/pg/views.py +++ b/apps/pg/views.py @@ -9,6 +9,7 @@ from rest_framework import generics from rest_framework.response import Response from rest_framework.views import APIView from drf_spectacular.utils import extend_schema +from django.shortcuts import render from utils.commons import calculate_pna_commission from .constans import StateChoices @@ -79,6 +80,11 @@ class PaymentRequestView(UpdateView): charge_request.save_commission() tool = charge_request.get_gateway_tools() tool.make_request() + charge_request.refresh_from_db() + if charge_request.state == StateChoices.FAILED: + return render(request, 'pg/payment_failure.html', { + 'object': charge_request + }) redirect_url = tool.get_pg_page_url() return HttpResponseRedirect(redirect_url) @@ -88,6 +94,11 @@ class PaymentRequestView(UpdateView): charge_request.set_gateway({'pna': True}) tool = charge_request.get_gateway_tools() tool.make_request() + charge_request.refresh_from_db() + if charge_request.state == StateChoices.FAILED: + return render(request, 'pg/payment_failure.html', { + 'object': charge_request + }) redirect_url = tool.get_pg_page_url() return HttpResponseRedirect(redirect_url) diff --git a/static/image/pg/fail.png b/static/image/pg/fail.png new file mode 100644 index 0000000..ec72d92 Binary files /dev/null and b/static/image/pg/fail.png differ diff --git a/static/image/pg/tik.png b/static/image/pg/tik.png new file mode 100644 index 0000000..c6beb97 Binary files /dev/null and b/static/image/pg/tik.png differ diff --git a/templates/pg/payment-confirm.html b/templates/pg/payment-confirm.html new file mode 100644 index 0000000..3e87bfc --- /dev/null +++ b/templates/pg/payment-confirm.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} +{% load static %} +{% load crispy_forms_tags %} +{% load jalali_tags %} + +{% block title %}بازگشت{% endblock %} +{% block page_title %}بازگشت{% endblock %} + + +{% block content %} + مبلغ {{ object.amount }} ریال با وضعیت {{ object.get_state_display }}
+
+ {% csrf_token %} +
+
+ {#
#} + {#
#} + {{ form|crispy }} + {#
#} + {#
#} +
+
بازگشت به برنامه
+
+
+ +
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/pg/payment_confirm.html b/templates/pg/payment_failure.html similarity index 88% rename from templates/pg/payment_confirm.html rename to templates/pg/payment_failure.html index 926cfab..1559144 100644 --- a/templates/pg/payment_confirm.html +++ b/templates/pg/payment_failure.html @@ -1,179 +1,168 @@ -{% load static %} -{% load crispy_forms_tags %} -{% load jalali_tags %} - - - - - - - - Payment Unsuccessful - - - - - - - - - -
-
- -
-
!
- {% if message %} -

{{ message }}

- {% else %} -

پرداخت شما ناموفق بود

- {% endif %} -
-
-

کد پیگیری تراکنش شما: {{ object.reference_number }}

-

در صورت کسر از موجودی، مبلغ پرداختی طی یک تا 72 ساعت آینده به حساب شما بازگردانده خواهد شد.

-
- وینسو -
- -
-
- {% csrf_token %} - {{ form|crispy }} - -
-
-
-
- - +{% load static %} +{% load crispy_forms_tags %} +{% load jalali_tags %} + + + + + + + + Payment Unsuccessful + + + + + + + + + +
+
+ +
+
fail
+ {% if message %} +

{{ message }}

+ {% else %} +

پرداخت ناموفق

+ {% endif %} +
+
+

کد پیگیری تراکنش شما: {{ object.reference_number }}

+

در صورت کسر از موجودی، مبلغ پرداختی طی یک تا 72 ساعت آینده به حساب شما بازگردانده خواهد شد.

+
+ winsoo +
+ +
+
+ {% csrf_token %} + {{ form|crispy }} + +
+
+
+
+ + \ No newline at end of file diff --git a/templates/pg/payment_success.html b/templates/pg/payment_success.html index fa011f1..fd9844e 100644 --- a/templates/pg/payment_success.html +++ b/templates/pg/payment_success.html @@ -24,18 +24,6 @@ min-height: 100vh; } - - .mobile-frame { - width: 100vh; - height: 100vh; - background-color: #ffffff; - box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); - padding: 30px; - box-sizing: border-box; - display: flex; - flex-direction: column; - } - .screen-content { flex-grow: 1; display: flex; @@ -125,7 +113,7 @@ width: 100%; padding: 15px; border: none; - border-radius: 20px; + border-radius: 8px; font-size: 1.1rem; font-weight: bold; font-family: 'Vazirmatn', sans-serif; @@ -134,12 +122,12 @@ } .btn-primary { - background-color: #6931c9; + background-color: #3B604B; color: #ffffff; } .btn-primary:hover { - background-color: #7745ce; + background-color: #3B604B; } @@ -149,24 +137,24 @@
-
✓
+
success

پرداخت موفق

-

پرداخت با موفقیت انجام شد.


- مقدار پرداخت شده: - {{ object.amount }} ریال + مبلغ شارژ + {{ object.amount }} تومان
- وینسو + winsoo
{% csrf_token %} {{ form|crispy }} - +
+