Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ build-backend = "setuptools.build_meta"

[project]
name = "transfa"
version = "0.2.3"
version = "0.2.4"
dynamic = ["description", "readme", "optional-dependencies", "dependencies", "classifiers", "authors", "license"]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.3
current_version = 0.2.4
commit = True
tag = True

Expand Down
10 changes: 4 additions & 6 deletions tests/test_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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,
}
)
Expand Down Expand Up @@ -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,
}
),
Expand Down Expand Up @@ -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,
}
)
Expand Down
51 changes: 33 additions & 18 deletions tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand Down
2 changes: 0 additions & 2 deletions transfa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions transfa/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

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


class TransfaAPIClient:
_base_url = api_base
auth_header_prefix = default_auth_header_bearer
__version__ = VERSION

def __init__(
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions transfa/api_resources/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion transfa/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.2.3"
VERSION = "0.2.4"
9 changes: 2 additions & 7 deletions transfa/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand Down