chore: refactor settings
This commit is contained in:
+22
-7
@@ -43,11 +43,15 @@ class RedsysClient:
|
||||
def get_currency_code(self) -> str:
|
||||
return settings.REDSYS_CURRENCY_CODE
|
||||
|
||||
def get_merchant_url_ok_for_transaction(self, transaction: PaymentTransaction) -> str:
|
||||
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_transaction(self, transaction: PaymentTransaction) -> str:
|
||||
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}"
|
||||
|
||||
@@ -63,7 +67,9 @@ class RedsysClient:
|
||||
return compute_signature(str(hash), payload, key).decode()
|
||||
|
||||
def get_merchant_parameters_for_transaction(
|
||||
self, transaction: PaymentTransaction, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
self,
|
||||
transaction: PaymentTransaction,
|
||||
transaction_type: int = TransactionTypes.AUTHORIZATION,
|
||||
) -> dict:
|
||||
merchant_code = self.get_merchant_code()
|
||||
|
||||
@@ -71,7 +77,10 @@ class RedsysClient:
|
||||
"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_transaction(transaction), # Webhook
|
||||
# Webhook
|
||||
"DS_MERCHANT_MERCHANTURL": self.get_webhook_url_for_transaction(
|
||||
transaction
|
||||
),
|
||||
"DS_MERCHANT_ORDER": transaction.hash.hex,
|
||||
"DS_MERCHANT_TERMINAL": self.get_terminal(),
|
||||
"DS_MERCHANT_TRANSACTIONTYPE": transaction_type,
|
||||
@@ -82,14 +91,20 @@ class RedsysClient:
|
||||
}
|
||||
|
||||
def get_encoded_merchant_parameters_for_transaction(
|
||||
self, transaction: PaymentTransaction, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
self,
|
||||
transaction: PaymentTransaction,
|
||||
transaction_type: int = TransactionTypes.AUTHORIZATION,
|
||||
) -> str:
|
||||
body = self.get_merchant_parameters_for_transaction(transaction, 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_transaction(
|
||||
self, transaction: PaymentTransaction, transaction_type: int = TransactionTypes.AUTHORIZATION
|
||||
self,
|
||||
transaction: PaymentTransaction,
|
||||
transaction_type: int = TransactionTypes.AUTHORIZATION,
|
||||
) -> dict:
|
||||
merchant_parameters = self.get_encoded_merchant_parameters_for_transaction(
|
||||
transaction, transaction_type
|
||||
|
||||
Reference in New Issue
Block a user