diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ef37f..476e0f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Changelog [Unreleased] ------------ +[v0.2.4] - 2024-02-05 +------------------ + +- Remove prefix for requests + [v0.2.3] - 2023-04-21 ------------------ - Fix Webhook's Header Identifier bug diff --git a/pyproject.toml b/pyproject.toml index bc3b797..f5469c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,4 +6,5 @@ build-backend = "setuptools.build_meta" [project] name = "transfa" -version = "0.2.3" \ No newline at end of file +version = "0.2.4" +dynamic = ["description", "readme", "optional-dependencies", "dependencies", "classifiers", "authors", "license"] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index bfd14ba..fdb6f4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.3 +current_version = 0.2.4 commit = True tag = True diff --git a/tests/test_payment.py b/tests/test_payment.py index 4bd1a80..ef13526 100644 --- a/tests/test_payment.py +++ b/tests/test_payment.py @@ -4,8 +4,6 @@ import responses from responses import matchers -from transfa import default_auth_header_bearer - from transfa.api_client import client from transfa.version import VERSION @@ -32,7 +30,7 @@ def test_request_payment(payment): match=[ matchers.header_matcher( { - "Authorization": f"{default_auth_header_bearer} {client.api_key}", + "Authorization": f"{client.api_key}", "accept": "application/json", "content-type": "application/json;charset=utf-8", "Idempotency-Key": idempotency_key, @@ -68,7 +66,7 @@ def test_list_payments(payments): match=[ matchers.header_matcher( { - "Authorization": f"{default_auth_header_bearer} {client.api_key}", + "Authorization": f"{client.api_key}", "user-agent": "Transfa API SDK-Python/%s" % VERSION, } ) @@ -97,7 +95,7 @@ def test_retrieve_payment(payment): match=[ matchers.header_matcher( { - "Authorization": f"{default_auth_header_bearer} {client.api_key}", + "Authorization": f"{client.api_key}", "user-agent": "Transfa API SDK-Python/%s" % VERSION, } ), @@ -127,7 +125,7 @@ def test_refund_payment(payment): match=[ matchers.header_matcher( { - "Authorization": f"{default_auth_header_bearer} {client.api_key}", + "Authorization": f"{client.api_key}", "user-agent": "Transfa API SDK-Python/%s" % VERSION, } ) diff --git a/tests/test_webhook.py b/tests/test_webhook.py index 9e529f5..d003fcd 100644 --- a/tests/test_webhook.py +++ b/tests/test_webhook.py @@ -7,7 +7,6 @@ class WebhookData: - def __init__(self): self.valid_webhook_token = get_random_string(64) self.invalid_webhook_token = get_random_string(64) @@ -26,11 +25,15 @@ def generate_signature(self, body, webhook_token, algorithm=hashlib.sha512): def test_valid_webhook_signature(valid_webhook_payload): webhook_data = WebhookData() - signature = webhook_data.generate_signature(valid_webhook_payload, webhook_data.valid_webhook_token) + signature = webhook_data.generate_signature( + valid_webhook_payload, webhook_data.valid_webhook_token + ) - webhook = Webhook(webhook_token=webhook_data.valid_webhook_token, body=valid_webhook_payload, headers={ - "X-Webhook-Transfa-Signature": signature - }) + webhook = Webhook( + webhook_token=webhook_data.valid_webhook_token, + body=valid_webhook_payload, + headers={"X-Webhook-Transfa-Signature": signature}, + ) verified = webhook.verify() @@ -39,11 +42,15 @@ def test_valid_webhook_signature(valid_webhook_payload): def test_invalid_webhook_signature(valid_webhook_payload, invalid_webhook_payload): webhook_data = WebhookData() - invalid_signature = webhook_data.generate_signature(invalid_webhook_payload, webhook_data.valid_webhook_token) + invalid_signature = webhook_data.generate_signature( + invalid_webhook_payload, webhook_data.valid_webhook_token + ) - webhook = Webhook(webhook_token=webhook_data.valid_webhook_token, body=valid_webhook_payload, headers={ - "X-Webhook-Transfa-Signature": invalid_signature - }) + webhook = Webhook( + webhook_token=webhook_data.valid_webhook_token, + body=valid_webhook_payload, + headers={"X-Webhook-Transfa-Signature": invalid_signature}, + ) verified = webhook.verify() @@ -52,11 +59,15 @@ def test_invalid_webhook_signature(valid_webhook_payload, invalid_webhook_payloa def test_valid_webhook_token(valid_webhook_payload): webhook_data = WebhookData() - valid_signature = webhook_data.generate_signature(valid_webhook_payload, webhook_data.valid_webhook_token) + valid_signature = webhook_data.generate_signature( + valid_webhook_payload, webhook_data.valid_webhook_token + ) - webhook = Webhook(webhook_token=webhook_data.valid_webhook_token, body=valid_webhook_payload, headers={ - "X-Webhook-Transfa-Signature": valid_signature - }) + webhook = Webhook( + webhook_token=webhook_data.valid_webhook_token, + body=valid_webhook_payload, + headers={"X-Webhook-Transfa-Signature": valid_signature}, + ) verified = webhook.verify() @@ -65,11 +76,15 @@ def test_valid_webhook_token(valid_webhook_payload): def test_invalid_webhook_token(valid_webhook_payload): webhook_data = WebhookData() - valid_signature = webhook_data.generate_signature(valid_webhook_payload, webhook_data.valid_webhook_token) - - webhook = Webhook(webhook_token=webhook_data.invalid_webhook_token, body=valid_webhook_payload, headers={ - "X-Webhook-Transfa-Signature": valid_signature - }) + valid_signature = webhook_data.generate_signature( + valid_webhook_payload, webhook_data.valid_webhook_token + ) + + webhook = Webhook( + webhook_token=webhook_data.invalid_webhook_token, + body=valid_webhook_payload, + headers={"X-Webhook-Transfa-Signature": valid_signature}, + ) verified = webhook.verify() diff --git a/transfa/__init__.py b/transfa/__init__.py index e5858af..0643795 100644 --- a/transfa/__init__.py +++ b/transfa/__init__.py @@ -10,8 +10,6 @@ private_secret = None api_base = "https://api.transfapp.com" verify_ssl = True -default_auth_header_bearer = "Api-Transfa-Key" - # API Resources diff --git a/transfa/api_client.py b/transfa/api_client.py index 83c6d97..b288012 100644 --- a/transfa/api_client.py +++ b/transfa/api_client.py @@ -2,7 +2,7 @@ from requests import request -from transfa import api_key, api_base, default_auth_header_bearer +from transfa import api_key, api_base from transfa.api_resources.payments import PaymentResource from transfa.version import VERSION @@ -10,7 +10,6 @@ class TransfaAPIClient: _base_url = api_base - auth_header_prefix = default_auth_header_bearer __version__ = VERSION def __init__( @@ -44,7 +43,7 @@ def _request(self, method, endpoint, data=None, params=None, **kwargs): headers = { "user-agent": "Transfa API SDK-Python/%s" % self.__version__, "accept": "application/json", - "Authorization": f"{self.auth_header_prefix} {self.api_key}", + "Authorization": f"{self.api_key}", } if "headers" in kwargs: diff --git a/transfa/api_resources/payments.py b/transfa/api_resources/payments.py index 25acdf6..9df6d06 100644 --- a/transfa/api_resources/payments.py +++ b/transfa/api_resources/payments.py @@ -78,8 +78,8 @@ def status(self, payment_id): status_data = { "status": response_data.get("status"), - "financial_status": response_data.get("financial_status") - } + "financial_status": response_data.get("financial_status"), + } return status_data diff --git a/transfa/version.py b/transfa/version.py index ae50f1f..4b51ef6 100644 --- a/transfa/version.py +++ b/transfa/version.py @@ -1 +1 @@ -VERSION = "0.2.3" +VERSION = "0.2.4" diff --git a/transfa/webhook.py b/transfa/webhook.py index 42dfd93..0e705dc 100644 --- a/transfa/webhook.py +++ b/transfa/webhook.py @@ -14,14 +14,10 @@ def __init__(self, webhook_token=private_secret, body=None, headers=None): ) if body is None: - raise NotImplementedError( - "Can't work without the body of the request." - ) + raise NotImplementedError("Can't work without the body of the request.") if headers is None: - raise NotImplementedError( - "Can't work without the headers." - ) + raise NotImplementedError("Can't work without the headers.") if isinstance(body, bytes): body = body.decode("utf-8") @@ -42,7 +38,6 @@ def sign_body(self, body, algorithm=hashlib.sha512): return signature.hexdigest() def has_data_not_tempered(self, body, transfa_api_signature): - if isinstance(body, dict): body = json.dumps(body)