feature/pubsub #7
@@ -13,12 +13,13 @@ import (
|
|||||||
// Klarna CheckoutOrder from a CartGrain snapshot. It deliberately excludes
|
// Klarna CheckoutOrder from a CartGrain snapshot. It deliberately excludes
|
||||||
// any Klarna-specific response fields (HTML snippet, client token, etc.).
|
// any Klarna-specific response fields (HTML snippet, client token, etc.).
|
||||||
type CheckoutMeta struct {
|
type CheckoutMeta struct {
|
||||||
Terms string
|
SiteUrl string
|
||||||
Checkout string
|
// Terms string
|
||||||
Confirmation string
|
// Checkout string
|
||||||
Country string
|
// Confirmation string
|
||||||
Currency string // optional override (defaults to "SEK" if empty)
|
Country string
|
||||||
Locale string // optional override (defaults to "sv-se" if empty)
|
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
|
// BuildCheckoutOrderPayload converts the current cart grain + meta information
|
||||||
@@ -104,9 +105,9 @@ func BuildCheckoutOrderPayload(grain *cart.CartGrain, meta *CheckoutMeta) ([]byt
|
|||||||
OrderLines: lines,
|
OrderLines: lines,
|
||||||
MerchantReference1: grain.Id.String(),
|
MerchantReference1: grain.Id.String(),
|
||||||
MerchantURLS: &CheckoutMerchantURLS{
|
MerchantURLS: &CheckoutMerchantURLS{
|
||||||
Terms: meta.Terms,
|
Terms: fmt.Sprintf("%s/terms", meta.SiteUrl),
|
||||||
Checkout: meta.Checkout,
|
Checkout: fmt.Sprintf("%s/checkout?order_id={checkout.order.id}", meta.SiteUrl),
|
||||||
Confirmation: meta.Confirmation,
|
Confirmation: fmt.Sprintf("%s/confirmation/{checkout.order.id}", meta.SiteUrl),
|
||||||
Notification: "https://cart.k6n.net/notification",
|
Notification: "https://cart.k6n.net/notification",
|
||||||
Validation: "https://cart.k6n.net/validate",
|
Validation: "https://cart.k6n.net/validate",
|
||||||
Push: "https://cart.k6n.net/push?order_id={checkout.order.id}",
|
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)),
|
Quantity: common.PtrInt64(int64(it.Quantity)),
|
||||||
AmountIncludingTax: common.PtrInt64(it.TotalPrice.IncVat),
|
AmountIncludingTax: common.PtrInt64(it.TotalPrice.IncVat),
|
||||||
Description: common.PtrString(it.Meta.Name),
|
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),
|
Quantity: common.PtrInt64(1),
|
||||||
AmountIncludingTax: common.PtrInt64(d.Price.IncVat),
|
AmountIncludingTax: common.PtrInt64(d.Price.IncVat),
|
||||||
Description: common.PtrString("Delivery"),
|
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),
|
CountryCode: common.PtrString(country),
|
||||||
MerchantAccount: "ElgigantenECOM",
|
MerchantAccount: "ElgigantenECOM",
|
||||||
Channel: common.PtrString("Web"),
|
Channel: common.PtrString("Web"),
|
||||||
ReturnUrl: meta.Checkout,
|
ReturnUrl: fmt.Sprintf("%s/adyen-return", meta.SiteUrl),
|
||||||
LineItems: lineItems,
|
LineItems: lineItems,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
|
|||||||
@@ -370,12 +370,10 @@ func (s *PoolServer) CreateOrUpdateCheckout(r *http.Request, id cart.CartId) (*C
|
|||||||
host := getOriginalHost(r)
|
host := getOriginalHost(r)
|
||||||
country := getCountryFromHost(host)
|
country := getCountryFromHost(host)
|
||||||
meta := &CheckoutMeta{
|
meta := &CheckoutMeta{
|
||||||
Terms: fmt.Sprintf("https://%s/terms", host),
|
SiteUrl: fmt.Sprintf("https://%s", host),
|
||||||
Checkout: fmt.Sprintf("https://%s/checkout?order_id={checkout.order.id}", host),
|
Country: country,
|
||||||
Confirmation: fmt.Sprintf("https://%s/confirmation/{checkout.order.id}", host),
|
Currency: getCurrency(country),
|
||||||
Country: country,
|
Locale: getLocale(country),
|
||||||
Currency: getCurrency(country),
|
|
||||||
Locale: getLocale(country),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current grain state (may be local or remote)
|
// 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)
|
host := getOriginalHost(r)
|
||||||
country := getCountryFromHost(host)
|
country := getCountryFromHost(host)
|
||||||
meta := &CheckoutMeta{
|
meta := &CheckoutMeta{
|
||||||
Terms: fmt.Sprintf("https://%s/terms", host),
|
SiteUrl: fmt.Sprintf("https://%s", host),
|
||||||
Checkout: fmt.Sprintf("https://%s/checkout?order_id={checkout.order.id}", host),
|
Country: country,
|
||||||
Confirmation: fmt.Sprintf("https://%s/confirmation/{checkout.order.id}", host),
|
Currency: getCurrency(country),
|
||||||
Country: country,
|
Locale: getLocale(country),
|
||||||
Currency: getCurrency(country),
|
|
||||||
Locale: getLocale(country),
|
|
||||||
}
|
}
|
||||||
sessionData, err := BuildAdyenCheckoutSession(grain, meta)
|
sessionData, err := BuildAdyenCheckoutSession(grain, meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user