-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manual-payments): Add manual payments
- Loading branch information
1 parent
974cf8a
commit e12c1c7
Showing
13 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import List, Optional | ||
|
||
from ..base_model import BaseModel, BaseResponseModel | ||
|
||
|
||
class Payment(BaseModel): | ||
invoice_id: str | ||
amount_cents: int | ||
reference: str | ||
paid_at: Optional[str] | ||
|
||
|
||
class PaymentResponse(BaseResponseModel): | ||
lago_id: str | ||
invoice_ids: List[str] | ||
amount_cents: int | ||
amount_currency: str | ||
payment_status: str | ||
type: str | ||
reference: str | ||
external_payment_id: Optional[str] | ||
created_at: str | ||
|
||
|
||
class PaymentsResponse(BaseResponseModel): | ||
__root__: List[PaymentResponse] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import ClassVar, Type | ||
|
||
from ..base_client import BaseClient | ||
from ..mixins import CreateCommandMixin, FindAllCommandMixin, FindCommandMixin | ||
from ..models.payment import PaymentResponse | ||
|
||
|
||
class PaymentClient( | ||
CreateCommandMixin[PaymentResponse], | ||
FindAllCommandMixin[PaymentResponse], | ||
FindCommandMixin[PaymentResponse], | ||
BaseClient, | ||
): | ||
API_RESOURCE: ClassVar[str] = "payments" | ||
RESPONSE_MODEL: ClassVar[Type[PaymentResponse]] = PaymentResponse | ||
ROOT_NAME: ClassVar[str] = "payment" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"payment": { | ||
"lago_id": "8e5d5ec2-bdc7-4c43-a944-5ababae775d4", | ||
"invoice_ids": ["f8e194df-5d90-4382-b146-c881d2c67f28"], | ||
"amount_cents": 100, | ||
"amount_currency": "USD", | ||
"payment_status": "succeeded", | ||
"type": "manual", | ||
"reference": "123", | ||
"external_payment_id": null, | ||
"created_at": "2025-02-18T18:31:13Z" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"payments": [ | ||
{ | ||
"lago_id": "8e5d5ec2-bdc7-4c43-a944-5ababae775d4", | ||
"invoice_ids": [ | ||
"ed267c66-8170-4d23-83e8-6d6e4fc735ef" | ||
], | ||
"amount_cents": 100, | ||
"amount_currency": "USD", | ||
"payment_status": "succeeded", | ||
"type": "manual", | ||
"reference": "123", | ||
"external_payment_id": null, | ||
"created_at": "2025-02-18T18:31:13Z" | ||
} | ||
], | ||
"meta": { | ||
"current_page": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import os | ||
|
||
import pytest | ||
from pytest_httpx import HTTPXMock | ||
|
||
from lago_python_client.client import Client | ||
from lago_python_client.exceptions import LagoApiError | ||
from lago_python_client.models import Payment | ||
|
||
|
||
def payment_object(): | ||
return Payment( | ||
amount_cents=100, | ||
reference="ref1", | ||
invoice_id="f8e194df-5d90-4382-b146-c881d2c67f28", | ||
paid_at="2025-01-01T13:00:00Z" | ||
) | ||
|
||
|
||
def mock_response(): | ||
this_dir = os.path.dirname(os.path.abspath(__file__)) | ||
data_path = os.path.join(this_dir, "fixtures/payment.json") | ||
|
||
with open(data_path, "rb") as payment_response: | ||
return payment_response.read() | ||
|
||
|
||
def mock_collection_response(): | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
data_path = os.path.join(current_dir, "fixtures/payment_index.json") | ||
|
||
with open(data_path, "rb") as payments_response: | ||
return payments_response.read() | ||
|
||
|
||
def test_valid_find_all_payments_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") | ||
|
||
httpx_mock.add_response( | ||
method="GET", | ||
url="https://api.getlago.com/api/v1/payments", | ||
content=mock_collection_response(), | ||
) | ||
response = client.payments.find_all() | ||
|
||
assert response["payments"][0].lago_id == "8e5d5ec2-bdc7-4c43-a944-5ababae775d4" | ||
assert response["meta"]["current_page"] == 1 | ||
|
||
|
||
def test_valid_find_all_payments_request_with_options(httpx_mock: HTTPXMock): | ||
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") | ||
|
||
httpx_mock.add_response( | ||
method="GET", | ||
url="https://api.getlago.com/api/v1/payments?per_page=2&page=1", | ||
content=mock_collection_response(), | ||
) | ||
response = client.payments.find_all({"per_page": 2, "page": 1}) | ||
|
||
assert response["payments"][0].lago_id == "8e5d5ec2-bdc7-4c43-a944-5ababae775d4" | ||
assert response["meta"]["current_page"] == 1 | ||
|
||
|
||
def test_invalid_find_all_payment_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key="invalid") | ||
|
||
httpx_mock.add_response( | ||
method="GET", | ||
url="https://api.getlago.com/api/v1/payments", | ||
status_code=404, | ||
content=b"", | ||
) | ||
|
||
with pytest.raises(LagoApiError): | ||
client.payments.find_all() | ||
|
||
|
||
def test_valid_create_payment_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") | ||
|
||
httpx_mock.add_response( | ||
method="POST", | ||
url="https://api.getlago.com/api/v1/payments", | ||
content=mock_response(), | ||
) | ||
response = client.payments.create(payment_object()) | ||
|
||
assert response is not None | ||
assert response.lago_id == "8e5d5ec2-bdc7-4c43-a944-5ababae775d4" | ||
assert response.amount_cents == 100 | ||
assert response.amount_currency == "USD" | ||
assert response.payment_status == "succeeded" | ||
assert len(response.invoice_ids) == 1 | ||
assert response.invoice_ids[0] == "f8e194df-5d90-4382-b146-c881d2c67f28" | ||
|
||
|
||
def test_invalid_create_payment_request(httpx_mock: HTTPXMock): | ||
client = Client(api_key="invalid") | ||
|
||
httpx_mock.add_response( | ||
method="POST", | ||
url="https://api.getlago.com/api/v1/payments", | ||
status_code=401, | ||
content=b"", | ||
) | ||
|
||
with pytest.raises(LagoApiError): | ||
client.payments.create(payment_object()) |