Skip to content

Commit 0a06689

Browse files
authored
feat: Implement Google Pay (#154)
1 parent d78ee07 commit 0a06689

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ classifiers = [
3131
"Operating System :: OS Independent",
3232
"Programming Language :: Python :: 3.11",
3333
"Programming Language :: Python :: 3.12",
34+
"Programming Language :: Python :: 3.13",
3435
"Topic :: Software Development :: Libraries :: Python Modules",
3536
]
3637

@@ -39,7 +40,7 @@ version = { attr = "viur.shop.version.__version__" }
3940

4041
[project.optional-dependencies]
4142
unzer = [
42-
"unzer~=1.0",
43+
"unzer~=1.1",
4344
]
4445

4546
[tool.setuptools.packages.find]
@@ -49,4 +50,4 @@ where = ["src"]
4950
Documentation = "https://viur-shop.readthedocs.io"
5051
Repository = "https://github.com/viur-framework/viur-shop.git"
5152
"Bug Tracker" = "https://github.com/viur-framework/viur-shop/issues"
52-
#TODO: Changelog = "https://github.com/viur-framework/viur-shop/blob/main/CHANGELOG.md"
53+
Changelog = "https://github.com/viur-framework/viur-shop/releases"

src/viur/shop/data/translations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"_default_text": "Sofort via Unzer",
7676
"_hint": "viur-shop payment provider: unzer-sofort",
7777
},
78+
"viur.shop.payment_provider.unzer-googlepay": {
79+
"_default_text": "Google Pay via Unzer",
80+
"_hint": "viur-shop payment provider: unzer-googlepay",
81+
},
7882
"viur.shop.payment_provider.prepayment": {
7983
"_default_text": "Prepayment",
8084
"_hint": "viur-shop Prepayment",

src/viur/shop/payment_providers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .unzer_abstract import UnzerAbstract
1515
from .unzer_bancontact import UnzerBancontact
1616
from .unzer_card import UnzerCard
17+
from .unzer_googlepay import UnzerGooglepay
1718
from .unzer_ideal import UnzerIdeal
1819
from .unzer_paypal import UnzerPayPal
1920
from .unzer_sofort import UnzerSofort
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import typing as t
2+
3+
import unzer
4+
from unzer.model import PaymentType
5+
6+
from viur.core.skeleton import SkeletonInstance
7+
from .unzer_abstract import UnzerAbstract
8+
from ..globals import SHOP_LOGGER
9+
10+
logger = SHOP_LOGGER.getChild(__name__)
11+
12+
13+
class UnzerGooglepay(UnzerAbstract):
14+
"""
15+
Unzer Google Pay payment method integration for the ViUR Shop.
16+
17+
Enables customers to pay Google Pay through the Unzer payment gateway.
18+
"""
19+
20+
name: t.Final[str] = "unzer-googlepay"
21+
22+
def __init__(
23+
self,
24+
*,
25+
merchant_id: str | t.Callable[[], str],
26+
merchant_name: str | t.Callable[[], str],
27+
allow_credit_cards: bool = True,
28+
allow_prepaid_cards: bool = True,
29+
**kwargs: t.Any,
30+
) -> None:
31+
super().__init__(**kwargs)
32+
self._merchant_id = merchant_id
33+
self._merchant_name = merchant_name
34+
self.allow_credit_cards = allow_credit_cards
35+
self.allow_prepaid_cards = allow_prepaid_cards
36+
37+
@property
38+
def merchant_id(self) -> str:
39+
if callable(self._merchant_id):
40+
return self._merchant_id()
41+
return self._merchant_id
42+
43+
@property
44+
def merchant_name(self) -> str:
45+
if callable(self._merchant_name):
46+
return self._merchant_name()
47+
return self._merchant_name
48+
49+
def get_payment_type(
50+
self,
51+
order_skel: SkeletonInstance,
52+
) -> PaymentType:
53+
type_id = order_skel["payment"]["payments"][-1]["type_id"]
54+
return unzer.Googlepay(key=type_id)
55+
56+
def get_checkout_start_data(
57+
self,
58+
order_skel: SkeletonInstance,
59+
) -> t.Any:
60+
res = super().get_checkout_start_data(order_skel)
61+
configuration = unzer.Googlepay(client=self.client).get_configuration()["supports"][0]
62+
return res | {
63+
"sandbox": self.sandbox,
64+
"brands": configuration["brands"],
65+
"channel": configuration["channel"],
66+
"merchant_id": self.merchant_id,
67+
"merchant_name": self.merchant_name,
68+
"allow_credit_cards": self.allow_credit_cards,
69+
"allow_prepaid_cards": self.allow_prepaid_cards,
70+
}

0 commit comments

Comments
 (0)