diff --git a/cmd/cart/checkout_builder.go b/cmd/cart/checkout_builder.go index 3e4c48a..226ed3c 100644 --- a/cmd/cart/checkout_builder.go +++ b/cmd/cart/checkout_builder.go @@ -13,12 +13,13 @@ import ( // Klarna CheckoutOrder from a CartGrain snapshot. It deliberately excludes // any Klarna-specific response fields (HTML snippet, client token, etc.). type CheckoutMeta struct { - Terms string - Checkout string - Confirmation string - Country string - Currency string // optional override (defaults to "SEK" if empty) - Locale string // optional override (defaults to "sv-se" if empty) + SiteUrl string + // Terms string + // Checkout string + // Confirmation string + Country string + Currency string // optional override (defaults to "SEK" if empty) + Locale string // optional override (defaults to "sv-se" if empty) } // BuildCheckoutOrderPayload converts the current cart grain + meta information @@ -104,9 +105,9 @@ func BuildCheckoutOrderPayload(grain *cart.CartGrain, meta *CheckoutMeta) ([]byt OrderLines: lines, MerchantReference1: grain.Id.String(), MerchantURLS: &CheckoutMerchantURLS{ - Terms: meta.Terms, - Checkout: meta.Checkout, - Confirmation: meta.Confirmation, + Terms: fmt.Sprintf("%s/terms", meta.SiteUrl), + Checkout: fmt.Sprintf("%s/checkout?order_id={checkout.order.id}", meta.SiteUrl), + Confirmation: fmt.Sprintf("%s/confirmation/{checkout.order.id}", meta.SiteUrl), Notification: "https://cart.k6n.net/notification", Validation: "https://cart.k6n.net/validate", Push: "https://cart.k6n.net/push?order_id={checkout.order.id}", @@ -149,6 +150,8 @@ func BuildAdyenCheckoutSession(grain *cart.CartGrain, meta *CheckoutMeta) (*chec Quantity: common.PtrInt64(int64(it.Quantity)), AmountIncludingTax: common.PtrInt64(it.TotalPrice.IncVat), Description: common.PtrString(it.Meta.Name), + AmountExcludingTax: common.PtrInt64(it.TotalPrice.ValueExVat()), + TaxPercentage: common.PtrInt64(int64(it.Tax)), }) } @@ -161,6 +164,8 @@ func BuildAdyenCheckoutSession(grain *cart.CartGrain, meta *CheckoutMeta) (*chec Quantity: common.PtrInt64(1), AmountIncludingTax: common.PtrInt64(d.Price.IncVat), Description: common.PtrString("Delivery"), + AmountExcludingTax: common.PtrInt64(d.Price.ValueExVat()), + TaxPercentage: common.PtrInt64(25), }) } @@ -173,7 +178,7 @@ func BuildAdyenCheckoutSession(grain *cart.CartGrain, meta *CheckoutMeta) (*chec CountryCode: common.PtrString(country), MerchantAccount: "ElgigantenECOM", Channel: common.PtrString("Web"), - ReturnUrl: meta.Checkout, + ReturnUrl: fmt.Sprintf("%s/adyen-return", meta.SiteUrl), LineItems: lineItems, }, nil diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index 37ffa7c..dd44355 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -370,12 +370,10 @@ func (s *PoolServer) CreateOrUpdateCheckout(r *http.Request, id cart.CartId) (*C host := getOriginalHost(r) country := getCountryFromHost(host) meta := &CheckoutMeta{ - Terms: fmt.Sprintf("https://%s/terms", host), - Checkout: fmt.Sprintf("https://%s/checkout?order_id={checkout.order.id}", host), - Confirmation: fmt.Sprintf("https://%s/confirmation/{checkout.order.id}", host), - Country: country, - Currency: getCurrency(country), - Locale: getLocale(country), + SiteUrl: fmt.Sprintf("https://%s", host), + Country: country, + Currency: getCurrency(country), + Locale: getLocale(country), } // Get current grain state (may be local or remote) @@ -731,12 +729,10 @@ func (s *PoolServer) AdyenSessionHandler(w http.ResponseWriter, r *http.Request, host := getOriginalHost(r) country := getCountryFromHost(host) meta := &CheckoutMeta{ - Terms: fmt.Sprintf("https://%s/terms", host), - Checkout: fmt.Sprintf("https://%s/checkout?order_id={checkout.order.id}", host), - Confirmation: fmt.Sprintf("https://%s/confirmation/{checkout.order.id}", host), - Country: country, - Currency: getCurrency(country), - Locale: getLocale(country), + SiteUrl: fmt.Sprintf("https://%s", host), + Country: country, + Currency: getCurrency(country), + Locale: getLocale(country), } sessionData, err := BuildAdyenCheckoutSession(grain, meta) if err != nil {