Skip to content
Open
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
1 change: 1 addition & 0 deletions assets/translations/ru/utils.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ gateway-type = { $gateway_type ->
[CRYPTOMUS] Cryptomus
[HELEKET] Heleket
[URLPAY] UrlPay
[PLATEGA] Platega
*[OTHER] { $gateway_type }
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class PaymentGatewayType(UpperStrEnum):
HELEKET = auto()
CRYPTOPAY = auto()
ROBOKASSA = auto()
PLATEGA = auto()


class Currency(UpperStrEnum):
Expand Down Expand Up @@ -254,6 +255,7 @@ def from_gateway_type(cls, gateway_type: PaymentGatewayType) -> "Currency":
PaymentGatewayType.CRYPTOMUS: cls.USD,
PaymentGatewayType.HELEKET: cls.USD,
PaymentGatewayType.CRYPTOPAY: cls.USD,
PaymentGatewayType.PLATEGA: cls.RUB
}

try:
Expand Down
230 changes: 115 additions & 115 deletions src/infrastructure/database/migrations/versions/0001_create_enums.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
from typing import Sequence, Union

from alembic import op

revision: str = "0001"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.execute("""
CREATE TYPE payment_gateway_type AS ENUM (
'TELEGRAM_STARS',
'YOOKASSA',
'YOOMONEY',
'CRYPTOMUS',
'HELEKET',
'URLPAY'
)
""")

op.execute("""
CREATE TYPE currency AS ENUM ('USD', 'XTR', 'RUB')
""")

op.execute("""
CREATE TYPE plan_type AS ENUM (
'TRAFFIC',
'DEVICES',
'BOTH',
'UNLIMITED'
)
""")

op.execute("""
CREATE TYPE plan_availability AS ENUM (
'ALL',
'NEW',
'EXISTING',
'INVITED',
'ALLOWED',
'TRIAL'
)
""")

op.execute("""
CREATE TYPE promocode_reward_type AS ENUM (
'DURATION',
'TRAFFIC',
'SUBSCRIPTION',
'PERSONAL_DISCOUNT',
'PURCHASE_DISCOUNT'
)
""")

op.execute("""
CREATE TYPE access_mode AS ENUM (
'ALL',
'INVITED',
'PURCHASE',
'BLOCKED'
)
""")

op.execute("""
CREATE TYPE subscription_status AS ENUM (
'ACTIVE',
'DISABLED',
'LIMITED',
'EXPIRED',
'DELETED'
)
""")

op.execute("""
CREATE TYPE user_role AS ENUM ('DEV', 'ADMIN', 'USER')
""")

op.execute("""
CREATE TYPE locale AS ENUM (
'AR', 'AZ', 'BE', 'CS', 'DE', 'EN', 'ES', 'FA',
'FR', 'HE', 'HI', 'ID', 'IT', 'JA', 'KK', 'KO',
'MS', 'NL', 'PL', 'PT', 'RO', 'RU', 'SR', 'TR',
'UK', 'UZ', 'VI'
)
""")

op.execute("""
CREATE TYPE transaction_status AS ENUM (
'PENDING',
'COMPLETED',
'CANCELED',
'REFUNDED',
'FAILED'
)
""")

op.execute("""
CREATE TYPE purchasetype AS ENUM ('NEW', 'RENEW', 'CHANGE')
""")


def downgrade() -> None:
op.execute("DROP TYPE IF EXISTS purchasetype")
op.execute("DROP TYPE IF EXISTS transaction_status")
op.execute("DROP TYPE IF EXISTS locale")
op.execute("DROP TYPE IF EXISTS user_role")
op.execute("DROP TYPE IF EXISTS subscription_status")
op.execute("DROP TYPE IF EXISTS access_mode")
op.execute("DROP TYPE IF EXISTS promocode_reward_type")
op.execute("DROP TYPE IF EXISTS plan_availability")
op.execute("DROP TYPE IF EXISTS plan_type")
op.execute("DROP TYPE IF EXISTS currency")
op.execute("DROP TYPE IF EXISTS payment_gateway_type")
from typing import Sequence, Union
from alembic import op
revision: str = "0001"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.execute("""
CREATE TYPE payment_gateway_type AS ENUM (
'TELEGRAM_STARS',
'YOOKASSA',
'YOOMONEY',
'CRYPTOMUS',
'HELEKET',
'URLPAY'
)
""")
op.execute("""
CREATE TYPE currency AS ENUM ('USD', 'XTR', 'RUB')
""")
op.execute("""
CREATE TYPE plan_type AS ENUM (
'TRAFFIC',
'DEVICES',
'BOTH',
'UNLIMITED'
)
""")
op.execute("""
CREATE TYPE plan_availability AS ENUM (
'ALL',
'NEW',
'EXISTING',
'INVITED',
'ALLOWED',
'TRIAL'
)
""")
op.execute("""
CREATE TYPE promocode_reward_type AS ENUM (
'DURATION',
'TRAFFIC',
'SUBSCRIPTION',
'PERSONAL_DISCOUNT',
'PURCHASE_DISCOUNT'
)
""")
op.execute("""
CREATE TYPE access_mode AS ENUM (
'ALL',
'INVITED',
'PURCHASE',
'BLOCKED'
)
""")
op.execute("""
CREATE TYPE subscription_status AS ENUM (
'ACTIVE',
'DISABLED',
'LIMITED',
'EXPIRED',
'DELETED'
)
""")
op.execute("""
CREATE TYPE user_role AS ENUM ('DEV', 'ADMIN', 'USER')
""")
op.execute("""
CREATE TYPE locale AS ENUM (
'AR', 'AZ', 'BE', 'CS', 'DE', 'EN', 'ES', 'FA',
'FR', 'HE', 'HI', 'ID', 'IT', 'JA', 'KK', 'KO',
'MS', 'NL', 'PL', 'PT', 'RO', 'RU', 'SR', 'TR',
'UK', 'UZ', 'VI'
)
""")
op.execute("""
CREATE TYPE transaction_status AS ENUM (
'PENDING',
'COMPLETED',
'CANCELED',
'REFUNDED',
'FAILED'
)
""")
op.execute("""
CREATE TYPE purchasetype AS ENUM ('NEW', 'RENEW', 'CHANGE')
""")
def downgrade() -> None:
op.execute("DROP TYPE IF EXISTS purchasetype")
op.execute("DROP TYPE IF EXISTS transaction_status")
op.execute("DROP TYPE IF EXISTS locale")
op.execute("DROP TYPE IF EXISTS user_role")
op.execute("DROP TYPE IF EXISTS subscription_status")
op.execute("DROP TYPE IF EXISTS access_mode")
op.execute("DROP TYPE IF EXISTS promocode_reward_type")
op.execute("DROP TYPE IF EXISTS plan_availability")
op.execute("DROP TYPE IF EXISTS plan_type")
op.execute("DROP TYPE IF EXISTS currency")
op.execute("DROP TYPE IF EXISTS payment_gateway_type")
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Sequence, Union

from alembic import op

revision: str = "0018"
down_revision: Union[str, None] = "0017"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.execute("""
ALTER TYPE payment_gateway_type ADD VALUE 'PLATEGA'
""")


def downgrade() -> None:
op.execute("""
CREATE TYPE payment_gateway_type_backup AS ENUM (
'TELEGRAM_STARS',
'YOOKASSA',
'YOOMONEY',
'CRYPTOMUS',
'HELEKET',
'URLPAY'
)
""")
op.execute("""
ALTER TABLE payment_gateways ALTER COLUMN type
TYPE payment_gateway_type_backup
USING type::text::payment_gateway_type_backup
""")
op.execute("DROP TYPE payment_gateway_type")
op.execute("ALTER TYPE payment_gateway_type_backup RENAME TO payment_gateway_type")
2 changes: 2 additions & 0 deletions src/infrastructure/database/models/dto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
RobokassaGatewaySettingsDto,
YookassaGatewaySettingsDto,
YoomoneyGatewaySettingsDto,
PlategaGatewaySettingsDto,
)
from .plan import PlanDto, PlanDurationDto, PlanPriceDto, PlanSnapshotDto
from .promocode import PromocodeActivationDto, PromocodeDto
Expand Down Expand Up @@ -39,6 +40,7 @@
"CryptomusGatewaySettingsDto",
"CryptopayGatewaySettingsDto",
"HeleketGatewaySettingsDto",
"PlategaGatewaySettingsDto",
"PaymentGatewayDto",
"PaymentResult",
"RobokassaGatewaySettingsDto",
Expand Down
7 changes: 7 additions & 0 deletions src/infrastructure/database/models/dto/payment_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class CryptopayGatewaySettingsDto(GatewaySettingsDto):
secret_key: Optional[SecretStr] = None


class PlategaGatewaySettingsDto(GatewaySettingsDto):
type: Literal[PaymentGatewayType.PLATEGA] = PaymentGatewayType.PLATEGA
merchant_id: Optional[str] = None
api_key: Optional[SecretStr] = None


class RobokassaGatewaySettingsDto(GatewaySettingsDto):
type: Literal[PaymentGatewayType.ROBOKASSA] = PaymentGatewayType.ROBOKASSA
shop_id: Optional[str] = None
Expand All @@ -98,6 +104,7 @@ class RobokassaGatewaySettingsDto(GatewaySettingsDto):
HeleketGatewaySettingsDto,
CryptopayGatewaySettingsDto,
RobokassaGatewaySettingsDto,
PlategaGatewaySettingsDto,
],
Field(discriminator="type"),
]
2 changes: 2 additions & 0 deletions src/infrastructure/di/providers/payment_gateways.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
TelegramStarsGateway,
YookassaGateway,
YoomoneyGateway,
PlategaGateway
)

GATEWAY_MAP: dict[PaymentGatewayType, Type[BasePaymentGateway]] = {
Expand All @@ -25,6 +26,7 @@
PaymentGatewayType.YOOMONEY: YoomoneyGateway,
PaymentGatewayType.CRYPTOMUS: CryptomusGateway,
PaymentGatewayType.HELEKET: HeleketGateway,
PaymentGatewayType.PLATEGA: PlategaGateway
# PaymentGatewayType.URLPAY: UrlpayGateway,
}

Expand Down
2 changes: 2 additions & 0 deletions src/infrastructure/payment_gateways/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .telegram_stars import TelegramStarsGateway
from .yookassa import YookassaGateway
from .yoomoney import YoomoneyGateway
from .platega import PlategaGateway

__all__ = [
"BasePaymentGateway",
Expand All @@ -13,4 +14,5 @@
"YoomoneyGateway",
"CryptomusGateway",
"HeleketGateway",
"PlategaGateway"
]
Loading