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
Binary file removed branta/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file removed branta/__pycache__/enums.cpython-313.pyc
Binary file not shown.
Binary file removed branta/__pycache__/exceptions.cpython-313.pyc
Binary file not shown.
Binary file removed branta/__pycache__/extensions.cpython-313.pyc
Binary file not shown.
Binary file removed branta/__pycache__/models.cpython-313.pyc
Binary file not shown.
Binary file removed branta/__pycache__/options.cpython-313.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions branta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Payment:
platform_logo_url: Optional[str] = None
platform_logo_light_url: Optional[str] = None
parent_platform: Optional[Platform] = None
child_platform: Optional[Platform] = None
btc_pay_server_plugin_version: Optional[str] = None
is_metadata_decrypted: Optional[bool] = None

Expand Down
Binary file removed branta/v2/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/builder.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/client.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/encryption.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/parser.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/secret_generator.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/serialization.cpython-313.pyc
Binary file not shown.
Binary file removed branta/v2/__pycache__/service.cpython-313.pyc
Binary file not shown.
11 changes: 10 additions & 1 deletion branta/v2/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Optional

from branta.enums import DestinationType
from branta.models import Destination, Payment
from branta.models import Destination, Payment, Platform


class PaymentBuilder:
Expand Down Expand Up @@ -44,5 +44,14 @@ def set_platform_logo_url(self, platform_logo_url: str) -> "PaymentBuilder":
self._payment.platform_logo_url = platform_logo_url
return self

def set_child_platform(
self,
name: str,
logo_url: Optional[str] = None,
logo_light_url: Optional[str] = None,
) -> "PaymentBuilder":
self._payment.child_platform = Platform(name=name, logo_url=logo_url, logo_light_url=logo_light_url)
return self

def build(self) -> Payment:
return self._payment
9 changes: 9 additions & 0 deletions branta/v2/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def payment_to_api(payment: Payment) -> Dict[str, Any]:
result["platform_logo_url"] = payment.platform_logo_url
if payment.platform_logo_light_url is not None:
result["platform_logo_light_url"] = payment.platform_logo_light_url
if payment.child_platform is not None:
cp: Dict[str, Any] = {}
if payment.child_platform.name is not None:
cp["name"] = payment.child_platform.name
if payment.child_platform.logo_url is not None:
cp["logo_url"] = payment.child_platform.logo_url
if payment.child_platform.logo_light_url is not None:
cp["logo_light_url"] = payment.child_platform.logo_light_url
result["child_platform"] = cp
if payment.btc_pay_server_plugin_version is not None:
result["btc_pay_server_plugin_version"] = payment.btc_pay_server_plugin_version
return result
Expand Down
Binary file removed tests/__pycache__/__init__.cpython-313.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 43 additions & 0 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,49 @@ def test_add_destination_without_type_type_is_none(self):
payment = PaymentBuilder().add_destination("bc1qtest").build()
assert payment.destinations[0].type is None

def test_set_child_platform_sets_name(self):
payment = PaymentBuilder().add_destination("bc1qtest").set_child_platform("Acme").build()
assert payment.child_platform.name == "Acme"

def test_set_child_platform_optional_urls_default_none(self):
payment = PaymentBuilder().add_destination("bc1qtest").set_child_platform("Acme").build()
assert payment.child_platform.logo_url is None
assert payment.child_platform.logo_light_url is None

def test_set_child_platform_with_urls(self):
payment = (
PaymentBuilder()
.add_destination("bc1qtest")
.set_child_platform("Acme", logo_url="https://example.com/logo.png", logo_light_url="https://example.com/logo-light.png")
.build()
)
assert payment.child_platform.logo_url == "https://example.com/logo.png"
assert payment.child_platform.logo_light_url == "https://example.com/logo-light.png"

def test_set_child_platform_returns_builder(self):
builder = PaymentBuilder()
result = builder.set_child_platform("Acme")
assert result is builder

def test_child_platform_serializes_to_api(self):
from branta.v2.serialization import payment_to_api
payment = (
PaymentBuilder()
.add_destination("bc1qtest")
.set_child_platform("Acme", logo_url="https://example.com/logo.png")
.build()
)
api = payment_to_api(payment)
assert api["child_platform"]["name"] == "Acme"
assert api["child_platform"]["logo_url"] == "https://example.com/logo.png"
assert "logo_light_url" not in api["child_platform"]

def test_no_child_platform_omitted_from_api(self):
from branta.v2.serialization import payment_to_api
payment = PaymentBuilder().add_destination("bc1qtest").build()
api = payment_to_api(payment)
assert "child_platform" not in api


class TestSerializationDestinationType:
@pytest.mark.parametrize("dest_type,expected", [
Expand Down
Loading