fake charge
This commit is contained in:
parent
1c437c49c6
commit
e54e4ae829
2 changed files with 20 additions and 11 deletions
|
|
@ -12,6 +12,7 @@ from rest_framework.views import APIView
|
||||||
from apps.core.forms import ChargeForm
|
from apps.core.forms import ChargeForm
|
||||||
from apps.core.models import Charge
|
from apps.core.models import Charge
|
||||||
from apps.core.serializers import ChargeSerializer
|
from apps.core.serializers import ChargeSerializer
|
||||||
|
from apps.wallet.constans import StateChoices
|
||||||
from apps.wallet.models import Transaction
|
from apps.wallet.models import Transaction
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -38,29 +39,32 @@ class ChargeView(UpdateView):
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Charge.objects.all()
|
return Charge.objects.all()
|
||||||
|
# return Charge.objects.filter(state__in=[StateChoices.CREATED.value, StateChoices.SUCCESS.value])
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
self.object = form.save()
|
self.object = form.save()
|
||||||
amount = form.cleaned_data['amount']
|
amount = form.cleaned_data['amount']
|
||||||
payer_pk = 'a95557d6-4f21-4717-99c2-354db85f940e'
|
payer_pk = 'a95557d6-4f21-4717-99c2-354db85f940e'
|
||||||
charge = self.get_object()
|
charge: Charge = self.get_object()
|
||||||
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': 'شارژ مجازی کیف پول'}
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
charge.change_state(from_state=StateChoices.CREATED.value, to_state=StateChoices.PENDING.value)
|
||||||
|
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.submit()
|
||||||
transaction.verify()
|
transaction.verify()
|
||||||
|
charge.change_state(from_state=StateChoices.PENDING.value, to_state=StateChoices.SUCCESS.value)
|
||||||
messages.success(self.request, 'شارژ انجام شد')
|
messages.success(self.request, 'شارژ انجام شد')
|
||||||
|
|
||||||
except:
|
except:
|
||||||
messages.error(self.request, 'خطایی رخ داده است')
|
messages.error(self.request, 'خطایی رخ داده است')
|
||||||
|
charge.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())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if object.state in '1' %}
|
||||||
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data">
|
<form action="{{ request.get_full_path }}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="row g-3">
|
<div class="row g-3">
|
||||||
|
|
@ -23,5 +24,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{% else %}
|
||||||
|
{{ object.amount }} in state {{ object.get_state_display }}<br>
|
||||||
|
back to application
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Loading…
Add table
Reference in a new issue