chore: rename model
This commit is contained in:
+24
-26
@@ -3,7 +3,7 @@ import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from tpv.models import PaymentTPV
|
||||
from tpv.models import PaymentTransaction
|
||||
from tpv.utils import compute_signature
|
||||
|
||||
|
||||
@@ -43,16 +43,16 @@ class RedsysClient:
|
||||
def get_currency_code(self) -> str:
|
||||
return settings.REDSYS_CURRENCY_CODE
|
||||
|
||||
def get_merchant_url_ok_for_order(self, order: PaymentTPV) -> str:
|
||||
path = reverse("tpv:ok", kwargs={"order": order.hash})
|
||||
def get_merchant_url_ok_for_transaction(self, transaction: PaymentTransaction) -> str:
|
||||
path = reverse("tpv:ok", kwargs={"transaction": transaction.hash})
|
||||
return f"{settings.REDSYS_TPV_DOMAIN}{path}"
|
||||
|
||||
def get_merchant_url_ko_for_order(self, order: PaymentTPV) -> str:
|
||||
path = reverse("tpv:ko", kwargs={"order": order.hash})
|
||||
def get_merchant_url_ko_for_transaction(self, transaction: PaymentTransaction) -> str:
|
||||
path = reverse("tpv:ko", kwargs={"transaction": transaction.hash})
|
||||
return f"{settings.REDSYS_TPV_DOMAIN}{path}"
|
||||
|
||||
def get_webhook_url_for_order(self, order: PaymentTPV) -> str:
|
||||
path = reverse("tpv:webhook", kwargs={"order": order.hash})
|
||||
def get_webhook_url_for_transaction(self, transaction: PaymentTransaction) -> str:
|
||||
path = reverse("tpv:webhook", kwargs={"transaction": transaction.hash})
|
||||
return f"{settings.REDSYS_TPV_DOMAIN}{path}"
|
||||
|
||||
def get_shared_secret(self) -> str:
|
||||
@@ -62,41 +62,39 @@ class RedsysClient:
|
||||
key = self.get_shared_secret()
|
||||
return compute_signature(str(hash), payload, key).decode()
|
||||
|
||||
def get_merchant_parameters_for_order(
|
||||
self, order: PaymentTPV, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
def get_merchant_parameters_for_transaction(
|
||||
self, transaction: PaymentTransaction, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
) -> dict:
|
||||
merchant_code = self.get_merchant_code()
|
||||
|
||||
return {
|
||||
"DS_MERCHANT_AMOUNT": str(order.amount_integer),
|
||||
"DS_MERCHANT_AMOUNT": str(transaction.amount_integer),
|
||||
"DS_MERCHANT_CURRENCY": self.get_currency_code(),
|
||||
"DS_MERCHANT_MERCHANTCODE": merchant_code,
|
||||
"DS_MERCHANT_MERCHANTURL": self.get_webhook_url_for_order(order), # Webhook
|
||||
"DS_MERCHANT_ORDER": order.hash.hex,
|
||||
"DS_MERCHANT_MERCHANTURL": self.get_webhook_url_for_transaction(transaction), # Webhook
|
||||
"DS_MERCHANT_ORDER": transaction.hash.hex,
|
||||
"DS_MERCHANT_TERMINAL": self.get_terminal(),
|
||||
"DS_MERCHANT_TRANSACTIONTYPE": transaction_type,
|
||||
"DS_MERCHANT_URLKO": self.get_merchant_url_ko_for_order(
|
||||
order
|
||||
), # Página informativa al usuario - Pago erróneo
|
||||
"DS_MERCHANT_URLOK": self.get_merchant_url_ok_for_order(
|
||||
order
|
||||
), # Página informativa al usuario - Pago confirmado
|
||||
# Página informativa al usuario - Pago erróneo
|
||||
"DS_MERCHANT_URLKO": self.get_merchant_url_ko_for_transaction(transaction),
|
||||
# Página informativa al usuario - Pago confirmado
|
||||
"DS_MERCHANT_URLOK": self.get_merchant_url_ok_for_transaction(transaction),
|
||||
}
|
||||
|
||||
def get_encoded_merchant_parameters_for_order(
|
||||
self, order: PaymentTPV, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
def get_encoded_merchant_parameters_for_transaction(
|
||||
self, transaction: PaymentTransaction, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
) -> str:
|
||||
body = self.get_merchant_parameters_for_order(order, transaction_type)
|
||||
body = self.get_merchant_parameters_for_transaction(transaction, transaction_type)
|
||||
stringified_body = json.dumps(body)
|
||||
return base64.b64encode(stringified_body.encode()).decode("utf-8")
|
||||
|
||||
def get_body_for_order(
|
||||
self, order: PaymentTPV, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
def get_body_for_transaction(
|
||||
self, transaction: PaymentTransaction, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
) -> dict:
|
||||
merchant_parameters = self.get_encoded_merchant_parameters_for_order(
|
||||
order, transaction_type
|
||||
merchant_parameters = self.get_encoded_merchant_parameters_for_transaction(
|
||||
transaction, transaction_type
|
||||
)
|
||||
signature = self.get_signature(order.hash.hex, merchant_parameters)
|
||||
signature = self.get_signature(transaction.hash.hex, merchant_parameters)
|
||||
|
||||
return {
|
||||
"Ds_MerchantParameters": merchant_parameters,
|
||||
|
||||
Reference in New Issue
Block a user