FEATURE(pg):check success again
check success again
This commit is contained in:
parent
fe1f535ee6
commit
64368eb188
1 changed files with 43 additions and 2 deletions
|
|
@ -2,10 +2,14 @@ import io
|
|||
|
||||
import jdatetime
|
||||
import xlsxwriter
|
||||
from django.contrib import admin
|
||||
from django.contrib import admin, messages
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpResponse
|
||||
from django.utils import timezone
|
||||
from django.utils.html import format_html
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import path
|
||||
from utils.wallet_client import deposit_to_user_wallet_verify
|
||||
|
||||
from .constans import StateChoices
|
||||
from .models import PaymentRequest, PNA, Fake
|
||||
|
|
@ -61,7 +65,7 @@ def change_to_failed(model_admin, request, queryset):
|
|||
|
||||
|
||||
class PaymentRequestAdmin(admin.ModelAdmin):
|
||||
list_display = ['state', 'uuid', 'splited_amount', 'user_id', 'jajali_datetime', 'created_at', 'application', 'gateway']
|
||||
list_display = ['state', 'check_success_again', 'uuid', 'splited_amount', 'user_id', 'jajali_datetime', 'created_at', 'application', 'gateway']
|
||||
search_fields = ['application__uuid','application__client_id', 'amount', 'user__uuid']
|
||||
list_filter = ['application', 'state', 'gateway']
|
||||
actions = [export_exel, change_to_success, change_to_failed]
|
||||
|
|
@ -78,6 +82,43 @@ class PaymentRequestAdmin(admin.ModelAdmin):
|
|||
extra_context['totals'] = totals
|
||||
return super().changelist_view(request, extra_context=extra_context)
|
||||
|
||||
def check_success_again(self, obj):
|
||||
if obj.state == StateChoices.WALLET_SUBMIT_SUCCESS:
|
||||
return format_html(
|
||||
'<a class="button" href="{}">بررسی دوباره موفقیت</a>',
|
||||
f'{obj.uuid}/check_success_again/'
|
||||
)
|
||||
return ''
|
||||
|
||||
def get_urls(self):
|
||||
urls = super().get_urls()
|
||||
custom_urls = [
|
||||
path('<uuid:payment_request_uuid>/check_success_again/', self.admin_site.admin_view(self.check_success_again_view))
|
||||
]
|
||||
return custom_urls + urls
|
||||
|
||||
def check_success_again_view(self, request, payment_request_uuid):
|
||||
verify_response = deposit_to_user_wallet_verify(payment_request_uuid)
|
||||
if not verify_response:
|
||||
self.message_user(request, "خطای استعلام", level=messages.ERROR)
|
||||
else:
|
||||
if not verify_response.uuid or verify_response.state != 5:
|
||||
to_pay_failed = PaymentRequest.objects.filter(
|
||||
pk=payment_request_uuid,
|
||||
state=StateChoices.WALLET_SUBMIT_SUCCESS.value
|
||||
).update(
|
||||
state=StateChoices.FAILED.value,
|
||||
)
|
||||
else:
|
||||
to_pay_success = PaymentRequest.objects.filter(
|
||||
pk=payment_request_uuid,
|
||||
state=StateChoices.WALLET_SUBMIT_SUCCESS.value
|
||||
).update(
|
||||
state=StateChoices.SUCCESS.value,
|
||||
)
|
||||
self.message_user(request, f"درخواست {payment_request_uuid} بررسی شد ✅")
|
||||
return redirect(request.META.get("HTTP_REFERER", ".."))
|
||||
|
||||
|
||||
class FakeAdmin(admin.ModelAdmin):
|
||||
list_display = [ 'created_at']
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue