|
34 | 34 | CreateTunnelRequest, |
35 | 35 | CreateTunnelResponse, |
36 | 36 | ExtensionSettings, |
| 37 | + PublicTopupRequest, |
37 | 38 | ) |
38 | 39 |
|
39 | 40 | async def get_settings(user_id: str) -> ExtensionSettings: |
@@ -559,18 +560,31 @@ def _remove_authorized_key(settings: ExtensionSettings, proxy: Proxies) -> None: |
559 | 560 |
|
560 | 561 | async def payment_request_for_payments( |
561 | 562 | proxies_id: str, |
562 | | - data: CreatePayments, |
| 563 | + data: CreatePayments | PublicTopupRequest, |
563 | 564 | ) -> PaymentsPaymentRequest: |
564 | 565 | proxies = await get_proxies_by_id(proxies_id) |
565 | 566 | if not proxies: |
566 | 567 | raise ValueError("Invalid proxies ID.") |
567 | 568 |
|
568 | | - payments = await create_payments(proxies_id, data) |
| 569 | + settings = await get_settings(proxies.user_id) |
569 | 570 |
|
570 | | - amount = getattr(payments, "amount", 0) |
| 571 | + # derive amount from days when provided |
| 572 | + amount = getattr(data, "amount", 0) |
| 573 | + if hasattr(data, "days"): |
| 574 | + amount = getattr(data, "days", 0) * settings.price_per_day_sats |
571 | 575 | if not amount or amount <= 0: |
572 | 576 | raise ValueError("The amount must be greater than zero to create a payment request.") |
573 | 577 |
|
| 578 | + payments = await create_payments( |
| 579 | + proxies_id, |
| 580 | + CreatePayments( |
| 581 | + tunnel_id=proxies_id, |
| 582 | + invoice_id="", |
| 583 | + amount=amount, |
| 584 | + paid=False, |
| 585 | + ), |
| 586 | + ) |
| 587 | + |
574 | 588 | proxies_name = getattr(proxies, "", "Unknown") |
575 | 589 | payment: Payment = await create_invoice( |
576 | 590 | wallet_id=getattr(proxies, "wallet", "no_wallet_id"), |
|
0 commit comments