refactor klarna stuff
Some checks failed
Build and Publish / BuildAndDeploy (push) Successful in 3m42s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled

This commit is contained in:
matst80
2025-04-18 20:41:25 +02:00
parent b51fc78dd5
commit 6c2328495b
8 changed files with 302 additions and 145 deletions

View File

@@ -9,7 +9,6 @@ import (
"time"
messages "git.tornberg.me/go-cart-actor/proto"
klarna "github.com/Flaconi/go-klarna"
)
type CartId [16]byte
@@ -430,7 +429,7 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
err = fmt.Errorf("expected CreateCheckoutOrder")
} else {
orderLines := make([]*klarna.Line, 0, len(c.Items))
orderLines := make([]*Line, 0, len(c.Items))
totalTax := 0
c.PaymentInProgress = true
c.Processing = true
@@ -438,7 +437,7 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
total := int(item.Price) * item.Quantity
taxAmount := GetTaxAmount(total, item.Tax)
totalTax += taxAmount
orderLines = append(orderLines, &klarna.Line{
orderLines = append(orderLines, &Line{
Type: "physical",
Reference: item.Sku,
Name: item.Name,
@@ -448,10 +447,10 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
QuantityUnit: "st",
TotalAmount: total,
TotalTaxAmount: taxAmount,
ImageURL: item.Image,
ImageURL: fmt.Sprintf("https://www.elgiganten.se%s", item.Image),
})
}
order := klarna.CheckoutOrder{
order := CheckoutOrder{
PurchaseCountry: "SE",
PurchaseCurrency: "SEK",
Locale: "sv-se",
@@ -459,7 +458,7 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
OrderTaxAmount: totalTax,
OrderLines: orderLines,
MerchantReference1: c.Id.String(),
MerchantURLS: &klarna.CheckoutMerchantURLS{
MerchantURLS: &CheckoutMerchantURLS{
Terms: msg.Terms,
Checkout: msg.Checkout,
Confirmation: msg.Confirmation,