add transport to total

This commit is contained in:
2025-11-23 12:41:02 +02:00
parent 8f70947214
commit 05328d64fe

View File

@@ -59,6 +59,10 @@ class Cart:
) )
self.payment.value = 'ramburs' if self.user['email'] != 'user_de_test@gmail.com' else None self.payment.value = 'ramburs' if self.user['email'] != 'user_de_test@gmail.com' else None
self.payment_message = ft.Text("") self.payment_message = ft.Text("")
self.payment_redirect_button = ft.ElevatedButton(
"Finalizeaza plata",
visible=False,
)
self.error_message = ft.Text( self.error_message = ft.Text(
color=ft.Colors.RED color=ft.Colors.RED
) )
@@ -206,6 +210,7 @@ class Cart:
weight=ft.FontWeight.BOLD weight=ft.FontWeight.BOLD
), ),
self.payment_message, self.payment_message,
self.payment_redirect_button,
ft.Row([self.error_message],alignment=ft.MainAxisAlignment.CENTER), ft.Row([self.error_message],alignment=ft.MainAxisAlignment.CENTER),
ft.Row( ft.Row(
[ [
@@ -276,7 +281,7 @@ class Cart:
def get_order_products(self, id): def get_order_products(self, id):
products = self.orders_manager.get_order_products(id) products = self.orders_manager.get_order_products(id)
total = 0 total = 17
all_products = [] all_products = []
for product in products: for product in products:
@@ -631,10 +636,24 @@ class Cart:
'vat': 0, 'vat': 0,
} }
) )
# Add transport (courier) cost as a separate product
shipping_cost = 17.0
order_products.append(
{
'name': 'Transport curier',
'code': 'transport',
'category': 'transport',
'price': shipping_cost,
'vat': 0,
}
)
# Calculate total amount including transport
total_amount = sum(float(p['price']) for p in order_products)
print(order_products) print(order_products)
response = start_card_payment( response = start_card_payment(
order_id=order_id, order_id=order_id,
amount=self.pret_total.value.split(": ")[1], amount=total_amount,
currency='RON', currency='RON',
description="Comanda noua", description="Comanda noua",
customer={ customer={
@@ -661,12 +680,16 @@ class Cart:
if ntp_id: if ntp_id:
self.save_order_ntp_id(order_id, ntp_id) # implement in your DB layer self.save_order_ntp_id(order_id, ntp_id) # implement in your DB layer
# 2) Open hosted payment page # 2) Show a button that opens the hosted payment page (iOS-safe)
if payment_url: if payment_url:
self.page.launch_url(payment_url) self.payment_redirect_button.url = payment_url
#self.page.go("/payment/redirect") # your UX page self.payment_redirect_button.visible = True
self.payment_redirect_button.text = "Finalizeaza plata"
self.payment_message.value = "Pentru a finaliza plata, apasati butonul de mai jos."
self.payment_message.update()
self.payment_redirect_button.update()
else: else:
self.error_message.text('Nu am primit URL-ul de plată.') self.error_message.value = "Nu am primit URL-ul de plata."
self.error_message.update() self.error_message.update()
def on_confim_btn_click(self, e): def on_confim_btn_click(self, e):