method get instead of post for confirm
This commit is contained in:
parent
243b34d4a3
commit
58c9416d16
10 changed files with 95 additions and 61 deletions
|
|
@ -3,6 +3,6 @@ from .models import ChargeRequest
|
|||
|
||||
|
||||
class ChargeRequestAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
list_display = ['uuid', 'id']
|
||||
|
||||
admin.site.register(ChargeRequest, ChargeRequestAdmin)
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
import urllib.parse
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from oauth2_provider.settings import oauth2_settings
|
||||
|
||||
from apps.core.models import BaseModel
|
||||
|
|
@ -49,8 +52,11 @@ class ChargeRequest(models.Model):
|
|||
|
||||
def request_sale(self):
|
||||
pna_client = PNAClient()
|
||||
|
||||
description = 'from addwin ipg'
|
||||
pna_callback_url = f'https://ipg.addwin.ir/page/pna_callback/{self.uuid}/'
|
||||
pna_callback_url = urllib.parse.urljoin(
|
||||
settings.IPG_BASE_PUBLIC_URL,
|
||||
reverse("pg:charge-confirm-view", kwargs={"uuid": self.uuid}))
|
||||
response = pna_client.request_normal_sale(self.amount, description, pna_callback_url, order_id=self.id)
|
||||
|
||||
self.pna_status_code = response['status']
|
||||
|
|
@ -70,6 +76,8 @@ class ChargeRequest(models.Model):
|
|||
pna_client = PNAClient()
|
||||
description = 'from addwin ipg'
|
||||
response = pna_client.request_normal_sale_confirm(self.pna_token)
|
||||
# response = {'status': 0, 'cardNumberMasked': '504172******9210', 'rrn': 511629210215, 'appToken': 4101434578524, 'token': 'NDEwMTQzNDU3ODUyNA=='}
|
||||
|
||||
if response['status'] == 0:
|
||||
self.pna_status = StateChoices.SUCCESS.value
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ class ChargeRequestView(UpdateView):
|
|||
slug_url_kwarg = 'uuid'
|
||||
|
||||
def get_queryset(self):
|
||||
return ChargeRequest.objects.all()
|
||||
# return ChargeRequest.objects.all()
|
||||
# return Charge.objects.filter(state__in=[StateChoices.CREATED.value, StateChoices.SUCCESS.value])
|
||||
return ChargeRequest.objects.filter(state__in=[StateChoices.CREATED.value])
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save()
|
||||
|
|
@ -57,35 +58,13 @@ class ChargeRequestView(UpdateView):
|
|||
# TODO: redirect to error page
|
||||
return HttpResponseRedirect(reverse('pg:charge-request-view', kwargs={'uuid': charge_request.uuid}))
|
||||
|
||||
charge_request.charge_wallet_balance()
|
||||
# transaction = Transaction.objects.create(
|
||||
# uuid=charge.uuid,
|
||||
# payee_id=charge.user.pk,
|
||||
# payee_type=1,
|
||||
# payer_id=payer_pk,
|
||||
# payer_type=2,
|
||||
# amount=amount,
|
||||
# details={'description': 'شارژ مجازی کیف پول'}
|
||||
# )
|
||||
# transaction.submit()
|
||||
# transaction.verify()
|
||||
# charge.change_state(from_state=StateChoices.PENDING.value, to_state=StateChoices.SUCCESS.value)
|
||||
messages.success(self.request, 'شارژ انجام شد')
|
||||
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# messages.error(self.request, 'خطایی رخ داده است')
|
||||
# charge_request.change_state(from_state=StateChoices.PENDING.value, to_state=StateChoices.EXPECTED_FAILURE.value)
|
||||
#
|
||||
# return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
def get_success_url(self):
|
||||
return self.object.callback_url
|
||||
# return reverse('pg:charge-request-view', kwargs={'pk': self.object.pk})
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
class ChargeConfirmView(UpdateView):
|
||||
template_name = 'pg/charge-request.html'
|
||||
template_name = 'pg/charge-confirm.html'
|
||||
form_class = ChargeRequestForm
|
||||
# pk_url_kwarg = 'uuid'
|
||||
slug_field = 'uuid'
|
||||
|
|
@ -97,16 +76,11 @@ class ChargeConfirmView(UpdateView):
|
|||
|
||||
def get(self, request, *args, **kwargs):
|
||||
print('get')
|
||||
|
||||
print(args)
|
||||
print(kwargs)
|
||||
|
||||
self.object = self.get_object()
|
||||
charge_request: ChargeRequest = self.get_object()
|
||||
charge_request.charge_wallet_balance()
|
||||
charge_request.confirm_sale()
|
||||
context = self.get_context_data(object=self.object)
|
||||
messages.success(self.request, 'شارژ انجام شد')
|
||||
context = self.get_context_data()
|
||||
messages.info(self.request, 'در پردازش صفحه خطایی وجود دارد.')
|
||||
|
||||
return self.render_to_response(context)
|
||||
|
||||
|
|
@ -118,13 +92,25 @@ class ChargeConfirmView(UpdateView):
|
|||
|
||||
# post = <QueryDict: {'Token': ['NDEwMTI0Nzc0MDMzMA=='], 'OrderId': ['7'], 'TerminalNo': ['31127029'], 'RRN': ['511629156251'], 'status': ['0'], 'TspToken': ['00000000-0000-0000-0000-000000000000'], 'HashCardNumber': ['6008617E6BAB76997499446356F5C8B60288445650DD551FDF32007BCF2B14AF'], 'Amount': ['21,000'], 'SwAmount': [''], 'STraceNo': ['123232']}>
|
||||
|
||||
self.object = self.get_object()
|
||||
charge_request: ChargeRequest = self.get_object()
|
||||
charge_request.charge_wallet_balance()
|
||||
charge_request.confirm_sale()
|
||||
context = self.get_context_data(object=self.object)
|
||||
messages.success(self.request, 'شارژ انجام شد')
|
||||
return self.render_to_response(context)
|
||||
if 'redirect-to-app' in request.POST:
|
||||
return super().post(request, *args, **kwargs)
|
||||
else:
|
||||
self.object = self.get_object()
|
||||
|
||||
# post = <QueryDict: {'Token': ['NDEwMTI0Nzc0MDMzMA=='], 'OrderId': ['7'], 'TerminalNo': ['31127029'], 'RRN': ['511629156251'], 'status': ['0'], 'TspToken': ['00000000-0000-0000-0000-000000000000'], 'HashCardNumber': ['6008617E6BAB76997499446356F5C8B60288445650DD551FDF32007BCF2B14AF'], 'Amount': ['21,000'], 'SwAmount': [''], 'STraceNo': ['123232']}>
|
||||
if request.POST.get('status') == 0:
|
||||
try:
|
||||
charge_request: ChargeRequest = self.get_object()
|
||||
charge_request.charge_wallet_balance()
|
||||
charge_request.confirm_sale()
|
||||
messages.success(self.request, 'شارژ انجام شد')
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
messages.success(self.request, str(e))
|
||||
|
||||
context = self.get_context_data(object=self.object)
|
||||
return self.render_to_response(context)
|
||||
|
||||
|
||||
# def form_valid(self, form):
|
||||
|
|
@ -152,6 +138,5 @@ class ChargeConfirmView(UpdateView):
|
|||
#
|
||||
# return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
# def get_success_url(self):
|
||||
# return self.object.callback_url
|
||||
# return reverse('pg:charge-request-view', kwargs={'pk': self.object.pk})
|
||||
def get_success_url(self):
|
||||
return self.object.callback_url
|
||||
|
|
|
|||
|
|
@ -244,4 +244,6 @@ CACHES = {
|
|||
}
|
||||
}
|
||||
|
||||
PNA_CORPORATION_PIN = config('PNA_CORPORATION_PIN')
|
||||
PNA_CORPORATION_PIN = config('PNA_CORPORATION_PIN')
|
||||
WALLET_BASE_PUBLIC_URL = config('WALLET_BASE_PUBLIC_URL')
|
||||
IPG_BASE_PUBLIC_URL = config('IPG_BASE_PUBLIC_URL')
|
||||
|
|
|
|||
BIN
static/image/icon.png
Normal file
BIN
static/image/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
static/image/pna.png
Normal file
BIN
static/image/pna.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
|
|
@ -63,14 +63,14 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="grid">
|
||||
<div class="d-flex justify-content-end mt-2">
|
||||
{% block page_action %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{# <div class="col">#}
|
||||
{# <div class="grid">#}
|
||||
{# <div class="d-flex justify-content-end mt-2">#}
|
||||
{# {% block page_action %}#}
|
||||
{# {% endblock %}#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
|
|
|||
33
templates/pg/charge-confirm.html
Normal file
33
templates/pg/charge-confirm.html
Normal file
|
|
@ -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 }}<br>
|
||||
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="row g-3">
|
||||
<div class="col-md-12 col-lg-12" id="formset">
|
||||
{# <div class="card">#}
|
||||
{# <div class="card-body">#}
|
||||
{{ form|crispy }}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
</div>
|
||||
<h6 class="h6">بازگشت به برنامه</h6>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button type="submit" name="redirect-to-app" value="true" class="btn mx-auto d-block">
|
||||
<img class="img-thumbnail" width="128" height="128" src="{% static "image/icon.png" %}"/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -8,19 +8,24 @@
|
|||
|
||||
|
||||
{% block content %}
|
||||
مبلغ {{ object.amount }} ریال با وضعیت {{ object.get_state_display }}<br>
|
||||
مبلغ {{ object.amount }} ریال <br>
|
||||
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="row g-3">
|
||||
<div class="col-md-12 col-lg-12" id="formset">
|
||||
{# <div class="card">#}
|
||||
{# <div class="card-body">#}
|
||||
{{ form|crispy }}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# <div class="card">#}
|
||||
{# <div class="card-body">#}
|
||||
{{ form|crispy }}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<input class="w-100 btn btn-primary btn-lg" type="submit" value="ثبت" name="save"/>
|
||||
<h6 class="h6">پرداخت با:</h6>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn mx-auto d-block">
|
||||
<img class="img-thumbnail" width="128" height="128" src="{% static "image/pna.png" %}"/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from gooyal_wallet_client.api.wallet import (wallet_api_application_deposit_crea
|
|||
wallet_api_application_withdraw_verify_retrieve)
|
||||
from gooyal_wallet_client.types import Response
|
||||
|
||||
from django.conf import Settings
|
||||
|
||||
class ContentTypeChoices(models.IntegerChoices):
|
||||
IMAGE = 1, 'image'
|
||||
|
|
@ -66,7 +67,7 @@ def log_response(response):
|
|||
|
||||
def get_client():
|
||||
access_token = login_as_client_credentials()['access_token']
|
||||
client = AuthenticatedClient(base_url="https://wallet.gooyal.com", token=access_token,
|
||||
client = AuthenticatedClient(base_url=settings.WALLET_BASE_PUBLIC_URL, token=access_token,
|
||||
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
|
||||
)
|
||||
return client
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue