diff --git a/src/routing.go b/src/routing.go index 2fa7f5b..d2f5621 100644 --- a/src/routing.go +++ b/src/routing.go @@ -683,34 +683,62 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string { mb += "\n" for k, v := range dataOrder.Items { mb += fmt.Sprintf( - "%d. %s %v x %s\n", + "%d. %s", k+1, v.Name, - v.Quantity.Value, - getLocalizedTemplateMessage( - "cost_currency", - map[string]interface{}{ - "Amount": v.Price.Value, - "Currency": currency[strings.ToLower(v.Price.Currency)], - }, - ), ) + + if v.Quantity != nil { + if v.Quantity.Value != 0 { + mb += fmt.Sprintf( + " %v", + v.Quantity.Value, + ) + } + } + + if v.Price != nil { + if val, ok := currency[strings.ToLower(v.Price.Currency)]; ok { + mb += fmt.Sprintf( + " x %s\n", + getLocalizedTemplateMessage( + "cost_currency", + map[string]interface{}{ + "Amount": v.Price.Value, + "Currency": val, + }, + ), + ) + } + } else { + mb += "\n" + } } } if dataOrder.Delivery != nil { - mb += fmt.Sprintf( - "\n%s:\n%s; %s", - getLocalizedMessage("delivery"), - dataOrder.Delivery.Name, - getLocalizedTemplateMessage( - "cost_currency", - map[string]interface{}{ - "Amount": dataOrder.Delivery.Amount.Value, - "Currency": currency[strings.ToLower(dataOrder.Delivery.Amount.Currency)], - }, - ), - ) + if dataOrder.Delivery.Name != "" { + mb += fmt.Sprintf( + "\n%s:\n%s", + getLocalizedMessage("delivery"), + dataOrder.Delivery.Name, + ) + } + + if dataOrder.Delivery.Amount != nil { + if val, ok := currency[strings.ToLower(dataOrder.Delivery.Amount.Currency)]; ok && dataOrder.Delivery.Amount.Value != 0 { + mb += fmt.Sprintf( + "; %s", + getLocalizedTemplateMessage( + "cost_currency", + map[string]interface{}{ + "Amount": dataOrder.Delivery.Amount.Value, + "Currency": val, + }, + ), + ) + } + } if dataOrder.Delivery.Address != "" { mb += ";\n" + dataOrder.Delivery.Address @@ -725,17 +753,22 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string { getLocalizedMessage("payment"), ) for _, v := range dataOrder.Payments { - mb += fmt.Sprintf( - "%s; %s", - v.Name, - getLocalizedTemplateMessage( - "cost_currency", - map[string]interface{}{ - "Amount": v.Amount.Value, - "Currency": currency[strings.ToLower(v.Amount.Currency)], - }, - ), - ) + mb += v.Name + + if v.Amount != nil { + if val, ok := currency[strings.ToLower(v.Amount.Currency)]; ok && v.Amount.Value != 0 { + mb += fmt.Sprintf( + "; %s", + getLocalizedTemplateMessage( + "cost_currency", + map[string]interface{}{ + "Amount": v.Amount.Value, + "Currency": val, + }, + ), + ) + } + } if v.Status != nil && v.Status.Name != "" { mb += fmt.Sprintf( @@ -748,18 +781,20 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string { } } - if dataOrder.Cost != nil && dataOrder.Cost.Value != 0 { - mb += fmt.Sprintf( - "\n%s: %s", - getLocalizedMessage("cost"), - getLocalizedTemplateMessage( - "cost_currency", - map[string]interface{}{ - "Amount": dataOrder.Cost.Value, - "Currency": currency[strings.ToLower(dataOrder.Cost.Currency)], - }, - ), - ) + if dataOrder.Cost != nil { + if val, ok := currency[strings.ToLower(dataOrder.Cost.Currency)]; ok && dataOrder.Cost.Value != 0 { + mb += fmt.Sprintf( + "\n%s: %s", + getLocalizedMessage("order_total"), + getLocalizedTemplateMessage( + "cost_currency", + map[string]interface{}{ + "Amount": dataOrder.Cost.Value, + "Currency": val, + }, + ), + ) + } } return mb diff --git a/translate/translate.en.yml b/translate/translate.en.yml index 8f6def4..b160a5c 100644 --- a/translate/translate.en.yml +++ b/translate/translate.en.yml @@ -47,5 +47,5 @@ item_cost: "Cost" order: "Order" delivery: "Delivery" payment: "Payment" -cost: "Amount" +order_total: "Order total" cost_currency: "{{.Amount}} {{.Currency}}" diff --git a/translate/translate.es.yml b/translate/translate.es.yml index a3aa4e1..9ad7caf 100644 --- a/translate/translate.es.yml +++ b/translate/translate.es.yml @@ -43,9 +43,9 @@ voice: "[mensaje de voz]" photo: "[foto]" other: "[formato indefinido de mensaje]" -item_cost: "Costo" -order: "Orden" +item_cost: "Precio" +order: "Pedido" delivery: "Entrega" payment: "Pago" -cost: "Monto" +order_total: "Total pedido" cost_currency: "{{.Amount}} {{.Currency}}" diff --git a/translate/translate.ru.yml b/translate/translate.ru.yml index d5ab951..5b14854 100644 --- a/translate/translate.ru.yml +++ b/translate/translate.ru.yml @@ -47,5 +47,5 @@ item_cost: "Цена" order: "Заказ" delivery: "Доставка" payment: "Оплата" -cost: "Сумма" +order_total: "Сумма" cost_currency: "{{.Amount}} {{.Currency}}"