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:
@@ -624,29 +629,43 @@ class Cart:
p = self.productsDB.get(prod['prdouct_id']) p = self.productsDB.get(prod['prdouct_id'])
order_products.append( order_products.append(
{ {
'name':p['name'], 'name': p['name'],
'code':p['id'], 'code': p['id'],
'category':p['category_id'], 'category': p['category_id'],
'price':p['price'], 'price': p['price'],
'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={
'email':self.email.value, 'email': self.email.value,
'phone':self.phone.value, 'phone': self.phone.value,
'firstName':self.first_name.value, 'firstName': self.first_name.value,
'lastName':self.last_name.value, 'lastName': self.last_name.value,
'city':self.city.value, 'city': self.city.value,
'country': 642, 'country': 642,
'address':self.address.value, 'address': self.address.value,
'county':'', 'county': '',
'zipCode':'' 'zipCode': ''
}, },
products=order_products products=order_products
) )
@@ -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):