Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Feb 20, 2023
1 parent 0c5952f commit 7dfac1f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions kkiapay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


class Kkiapay(KkiapayBase):
def __init__(self, public_key: str, private_key: str, secret: str, sandbox=False) -> None:
def __init__(
self, public_key: str, private_key: str, secret: str, sandbox=False
) -> None:
r"""Initialize Kkiapay client.
:param public_key: Public key from https://app.kkiapay.me/dashboard/developers/keys.
:param private_key: Provate key from https://app.kkiapay.me/dashboard/developers/keys.
Expand All @@ -11,14 +13,12 @@ def __init__(self, public_key: str, private_key: str, secret: str, sandbox=False
"""
self._initialize_credentials(public_key, private_key, secret, sandbox)


def verify_transaction(self, transaction_id: str) -> dict:
r"""Verify a transaction.
:param transaction_id: transaction ID
"""
return self._verify_transaction(transaction_id)


def refund_transaction(self, transaction_id: str) -> dict:
r"""Refund a specific transaction.
:param transaction_id: transaction ID
Expand Down
18 changes: 11 additions & 7 deletions kkiapay/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@


class KkiapayBase:
def _initialize_credentials(self, public_key: str, private_key: str, secret: str, sandbox: bool) -> None:
self.public_key = public_key
self.private_key = private_key
self.secret = secret
def _initialize_credentials(
self, public_key: str, private_key: str, secret: str, sandbox: bool
) -> None:
self.public_key = public_key
self.private_key = private_key
self.secret = secret
self.is_sandbox_environment = sandbox

def _build_request_headers(self) -> dict:
Expand All @@ -20,21 +22,23 @@ def _build_request_headers(self) -> dict:
}

def _build_request_url(self, path: str) -> str:
BASE_URL = SANDBOX_BASE_URL if self.is_sandbox_environment else PRODUCTION_BASE_URL
BASE_URL = (
SANDBOX_BASE_URL if self.is_sandbox_environment else PRODUCTION_BASE_URL
)
return f"{BASE_URL}/{path}"

def _verify_transaction(self, transaction_id: str):
return make_request(
"post",
self._build_request_url("api/v1/transactions/status"),
json={"transactionId": transaction_id},
headers=self._build_request_headers()
headers=self._build_request_headers(),
)

def _refund_transaction(self, transaction_id: str):
return make_request(
"post",
self._build_request_url("api/v1/transactions/revert"),
json={"transactionId": transaction_id},
headers=self._build_request_headers()
headers=self._build_request_headers(),
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import setuptools

with open('requirements.txt') as f:
with open("requirements.txt") as f:
required = f.read().splitlines()

with open("README.md", "r") as fh:
Expand Down
17 changes: 14 additions & 3 deletions tests/test_kkiapay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,34 @@ def test_verify_transaction():
responses.add(
responses.POST,
"https://api-sandbox.kkiapay.me/api/v1/transactions/status",
json={'performed_at': '2023-02-20T17:44:47.842Z', 'received_at': 1676915100302, 'type': 'DEBIT', 'status': 'SUCCESS', 'source': 'MOBILE_MONEY'},
json={
"performed_at": "2023-02-20T17:44:47.842Z",
"received_at": 1676915100302,
"type": "DEBIT",
"status": "SUCCESS",
"source": "MOBILE_MONEY",
},
)

k = Kkiapay("public_key", "private_key", "secret", True)

response = k.verify_transaction("123")
assert response["type"] == "DEBIT"


@responses.activate
def test_refund_transaction():
responses.add(
responses.POST,
"https://api-sandbox.kkiapay.me/api/v1/transactions/revert",
json={'code': 'SUCCESS', 'description': 'REVERTED', 'transactionId': '123'},
json={"code": "SUCCESS", "description": "REVERTED", "transactionId": "123"},
)

k = Kkiapay("public_key", "private_key", "secret", True)

response = k.refund_transaction("123")
assert response == {'code': 'SUCCESS', 'description': 'REVERTED', 'transactionId': '123'}
assert response == {
"code": "SUCCESS",
"description": "REVERTED",
"transactionId": "123",
}

0 comments on commit 7dfac1f

Please sign in to comment.