feat: lots of changes

This commit is contained in:
2024-05-05 00:04:51 +02:00
parent d5643bbf5f
commit d148cc9c61
32 changed files with 509 additions and 61 deletions
+38 -5
View File
@@ -8,10 +8,12 @@ import re
from decimal import Decimal
from django.utils.text import gettext_lazy as _
from django.utils import timezone
from tpv.exceptions import RedsysValidationException, RedsysPaymentException
from tpv.models import PaymentTransaction
from tpv.settings import ERROR_CODES
from tpv.signals import redsys_payment_accepted
def compute_signature(salt, payload, key):
@@ -64,10 +66,6 @@ def validate_payment_for_transaction(
'Ds_ECI': '05',
'Ds_Response_Description': 'OPERACION AUTORIZADA'
}
:param request:
:param transaction:
:return:
"""
data = request.POST
@@ -78,7 +76,7 @@ def validate_payment_for_transaction(
_("No se ha recibido ningún valor para Ds_MerchantParameters")
)
merchant_params = base64.b64decode(merchant_parameters).decode()
merchant_params = decode_b64_string(merchant_parameters)
result = json.loads(merchant_params)
transaction_hex = result.get("Ds_Order")
@@ -96,6 +94,41 @@ def validate_payment_for_transaction(
return amount
def validate_expiry_date(expiry_date: str):
if len(expiry_date) != 4:
return False
month, year = int(expiry_date[2:4]), int(expiry_date[:2])
if month < 1 or month > 12:
return False
current_year = int(str(timezone.now().year)[2:])
current_month = timezone.now().month
if year < current_year:
return False
if year == current_year and month > current_month:
return False
return True
def pay_transaction(transaction: PaymentTransaction, amount_paid: Decimal):
transaction.status = PaymentTransaction.StatusChoices.PAID
transaction.save()
redsys_payment_accepted.send_robust(
PaymentTransaction.__class__,
hash=transaction.hash,
amount=amount_paid,
)
def decode_b64_string(value: str):
return base64.b64decode(value).decode()
def decode_b64_dict(value: str):
return json.loads(decode_b64_string(value))