This commit is contained in:
45
capture.go
Normal file
45
capture.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type CaptureData struct {
|
||||||
|
CapturedAmount int `json:"captured_amount"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
OrderLines []struct {
|
||||||
|
ImageURL string `json:"image_url"`
|
||||||
|
MerchantData string `json:"merchant_data"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ProductIdentifiers struct {
|
||||||
|
Brand string `json:"brand"`
|
||||||
|
CategoryPath string `json:"category_path"`
|
||||||
|
Color string `json:"color"`
|
||||||
|
GlobalTradeItemNumber string `json:"global_trade_item_number"`
|
||||||
|
ManufacturerPartNumber string `json:"manufacturer_part_number"`
|
||||||
|
Size string `json:"size"`
|
||||||
|
} `json:"product_identifiers"`
|
||||||
|
ProductURL string `json:"product_url"`
|
||||||
|
Quantity int `json:"quantity"`
|
||||||
|
QuantityUnit string `json:"quantity_unit"`
|
||||||
|
Reference string `json:"reference"`
|
||||||
|
Subscription struct {
|
||||||
|
Interval string `json:"interval"`
|
||||||
|
IntervalCount int `json:"interval_count"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"subscription"`
|
||||||
|
TaxRate int `json:"tax_rate"`
|
||||||
|
TotalAmount int `json:"total_amount"`
|
||||||
|
TotalDiscountAmount int `json:"total_discount_amount"`
|
||||||
|
TotalTaxAmount int `json:"total_tax_amount"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
UnitPrice int `json:"unit_price"`
|
||||||
|
} `json:"order_lines"`
|
||||||
|
Reference string `json:"reference"`
|
||||||
|
ShippingDelay int `json:"shipping_delay"`
|
||||||
|
ShippingInfo []struct {
|
||||||
|
ReturnShippingCompany string `json:"return_shipping_company"`
|
||||||
|
ReturnTrackingNumber string `json:"return_tracking_number"`
|
||||||
|
ReturnTrackingURI string `json:"return_tracking_uri"`
|
||||||
|
ShippingCompany string `json:"shipping_company"`
|
||||||
|
ShippingMethod string `json:"shipping_method"`
|
||||||
|
TrackingNumber string `json:"tracking_number"`
|
||||||
|
TrackingURI string `json:"tracking_uri"`
|
||||||
|
} `json:"shipping_info"`
|
||||||
|
}
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: klarna-api-credentials
|
||||||
|
data:
|
||||||
|
username: ZjQzZDY3YjEtNzA2Yy00NTk2LTliNTgtYjg1YjU2NDEwZTUw
|
||||||
|
password: a2xhcm5hX3Rlc3RfYXBpX0trUWhWVE5yYVZsV2FsTnhTRVp3Y1ZSSFF5UkVNRmxyY25Kd1AxSndQMGdzWmpRelpEWTNZakV0TnpBMll5MDBOVGsyTFRsaU5UZ3RZamcxWWpVMk5ERXdaVFV3TERFc2JUUkNjRFpWU1RsTllsSk1aMlEyVEc4MmRVODNZMkozUlRaaFdEZDViV3AwYkhGV1JqTjVNQzlaYXow
|
||||||
|
type: Opaque
|
||||||
---
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -7,7 +15,7 @@ metadata:
|
|||||||
arch: arm64
|
arch: arm64
|
||||||
name: order-manager-arm64
|
name: order-manager-arm64
|
||||||
spec:
|
spec:
|
||||||
replicas: 0
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: order-manager
|
app: order-manager
|
||||||
@@ -38,7 +46,6 @@ spec:
|
|||||||
server: 10.10.1.10
|
server: 10.10.1.10
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: regcred
|
- name: regcred
|
||||||
serviceAccountName: default
|
|
||||||
containers:
|
containers:
|
||||||
- image: registry.knatofs.se/go-order-manager:latest
|
- image: registry.knatofs.se/go-order-manager:latest
|
||||||
name: order-manager-arm64
|
name: order-manager-arm64
|
||||||
|
|||||||
42
main.go
42
main.go
@@ -59,6 +59,17 @@ func (h *PersistingOrderHandler) Load() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *PersistingOrderHandler) GetById(id string) (*Order, bool) {
|
||||||
|
h.mu.RLock()
|
||||||
|
defer h.mu.RUnlock()
|
||||||
|
for _, curr := range h.Orders {
|
||||||
|
if curr.ID == id {
|
||||||
|
return &curr, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
func (h *PersistingOrderHandler) Save() error {
|
func (h *PersistingOrderHandler) Save() error {
|
||||||
file, err := os.Create(h.fileName + ".tmp")
|
file, err := os.Create(h.fileName + ".tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -84,6 +95,12 @@ func (h *PersistingOrderHandler) Save() error {
|
|||||||
return os.Rename(h.fileName+".tmp", h.fileName)
|
return os.Rename(h.fileName+".tmp", h.fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *PersistingOrderHandler) GetLatest() []Order {
|
||||||
|
h.mu.RLock()
|
||||||
|
defer h.mu.RUnlock()
|
||||||
|
return h.Orders
|
||||||
|
}
|
||||||
|
|
||||||
func (h *PersistingOrderHandler) OrderPlaced(order Order) {
|
func (h *PersistingOrderHandler) OrderPlaced(order Order) {
|
||||||
// Here you would implement the logic to persist the order
|
// Here you would implement the logic to persist the order
|
||||||
log.Printf("Order placed: %s", order.ID)
|
log.Printf("Order placed: %s", order.ID)
|
||||||
@@ -122,12 +139,29 @@ func main() {
|
|||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("GET /orders", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("GET /api/orders", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
handler.mu.RLock()
|
json.NewEncoder(w).Encode(handler.GetLatest())
|
||||||
defer handler.mu.RUnlock()
|
})
|
||||||
json.NewEncoder(w).Encode(handler.Orders)
|
mux.HandleFunc("GET /api/orders/{id}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
order_id := r.PathValue("id")
|
||||||
|
|
||||||
|
order, ok := handler.GetById(order_id)
|
||||||
|
if !ok {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode(order)
|
||||||
|
})
|
||||||
|
mux.HandleFunc("POST /api/orders/{id}/capture", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
order_id := r.PathValue("id")
|
||||||
|
capture := &CaptureData{}
|
||||||
|
json.NewDecoder(r.Body).Decode(capture)
|
||||||
|
w.WriteHeader(http.StatusNotImplemented)
|
||||||
|
w.Write([]byte(order_id))
|
||||||
})
|
})
|
||||||
if err := http.ListenAndServe(":8080", mux); err != nil {
|
if err := http.ListenAndServe(":8080", mux); err != nil {
|
||||||
log.Fatalf("Failed to start server: %v", err)
|
log.Fatalf("Failed to start server: %v", err)
|
||||||
|
|||||||
2
order.go
2
order.go
@@ -17,7 +17,6 @@ type (
|
|||||||
OrderLines []*Line `json:"order_lines"`
|
OrderLines []*Line `json:"order_lines"`
|
||||||
Customer *CheckoutCustomer `json:"customer,omitempty"`
|
Customer *CheckoutCustomer `json:"customer,omitempty"`
|
||||||
MerchantURLS *CheckoutMerchantURLS `json:"merchant_urls"`
|
MerchantURLS *CheckoutMerchantURLS `json:"merchant_urls"`
|
||||||
HTMLSnippet string `json:"html_snippet,omitempty"`
|
|
||||||
MerchantReference1 string `json:"merchant_reference1,omitempty"`
|
MerchantReference1 string `json:"merchant_reference1,omitempty"`
|
||||||
MerchantReference2 string `json:"merchant_reference2,omitempty"`
|
MerchantReference2 string `json:"merchant_reference2,omitempty"`
|
||||||
StartedAt string `json:"started_at,omitempty"`
|
StartedAt string `json:"started_at,omitempty"`
|
||||||
@@ -35,6 +34,7 @@ type (
|
|||||||
SelectedShippingOption *ShippingOption `json:"selected_shipping_option,omitempty"`
|
SelectedShippingOption *ShippingOption `json:"selected_shipping_option,omitempty"`
|
||||||
ErrorCode string `json:"error_code,omitempty"`
|
ErrorCode string `json:"error_code,omitempty"`
|
||||||
ErrorMessages []string `json:"error_messages,omitempty"`
|
ErrorMessages []string `json:"error_messages,omitempty"`
|
||||||
|
//HTMLSnippet string `json:"html_snippet,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GUI type wraps the GUI options
|
// GUI type wraps the GUI options
|
||||||
|
|||||||
Reference in New Issue
Block a user