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_message = ft.Text("")
self.payment_redirect_button = ft.ElevatedButton(
"Finalizeaza plata",
visible=False,
)
self.error_message = ft.Text(
color=ft.Colors.RED
)
@@ -206,6 +210,7 @@ class Cart:
weight=ft.FontWeight.BOLD
),
self.payment_message,
self.payment_redirect_button,
ft.Row([self.error_message],alignment=ft.MainAxisAlignment.CENTER),
ft.Row(
[
@@ -276,7 +281,7 @@ class Cart:
def get_order_products(self, id):
products = self.orders_manager.get_order_products(id)
total = 0
total = 17
all_products = []
for product in products:
@@ -624,35 +629,49 @@ class Cart:
p = self.productsDB.get(prod['prdouct_id'])
order_products.append(
{
'name':p['name'],
'code':p['id'],
'category':p['category_id'],
'price':p['price'],
'vat':0,
'name': p['name'],
'code': p['id'],
'category': p['category_id'],
'price': p['price'],
'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)
response = start_card_payment(
order_id=order_id,
amount=self.pret_total.value.split(": ")[1],
amount=total_amount,
currency='RON',
description="Comanda noua",
customer={
'email':self.email.value,
'phone':self.phone.value,
'firstName':self.first_name.value,
'lastName':self.last_name.value,
'city':self.city.value,
'email': self.email.value,
'phone': self.phone.value,
'firstName': self.first_name.value,
'lastName': self.last_name.value,
'city': self.city.value,
'country': 642,
'address':self.address.value,
'county':'',
'zipCode':''
'address': self.address.value,
'county': '',
'zipCode': ''
},
products=order_products
)
print(type(response))
print(response)
# Extract URL & ntpID from SDK response
payment_url = response.payment['paymentURL']
ntp_id = response.payment['ntpID']
@@ -661,12 +680,16 @@ class Cart:
if ntp_id:
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:
self.page.launch_url(payment_url)
#self.page.go("/payment/redirect") # your UX page
self.payment_redirect_button.url = payment_url
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:
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()
def on_confim_btn_click(self, e):