push endpoint
This commit is contained in:
@@ -60,15 +60,18 @@ type CartDelivery struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CartGrain struct {
|
type CartGrain struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
lastItemId int
|
lastItemId int
|
||||||
lastDeliveryId int
|
lastDeliveryId int
|
||||||
storageMessages []Message
|
storageMessages []Message
|
||||||
Id CartId `json:"id"`
|
Id CartId `json:"id"`
|
||||||
Items []*CartItem `json:"items"`
|
Items []*CartItem `json:"items"`
|
||||||
TotalPrice int64 `json:"totalPrice"`
|
TotalPrice int64 `json:"totalPrice"`
|
||||||
Deliveries []*CartDelivery `json:"deliveries,omitempty"`
|
Deliveries []*CartDelivery `json:"deliveries,omitempty"`
|
||||||
Processing bool `json:"processing"`
|
Processing bool `json:"processing"`
|
||||||
|
PaymentInProgress bool `json:"paymentInProgress"`
|
||||||
|
OrderReference string `json:"orderReference,omitempty"`
|
||||||
|
PaymentReference string `json:"paymentReference,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Grain interface {
|
type Grain interface {
|
||||||
@@ -413,6 +416,8 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*FrameWithPa
|
|||||||
} else {
|
} else {
|
||||||
orderLines := make([]*klarna.Line, 0, len(c.Items))
|
orderLines := make([]*klarna.Line, 0, len(c.Items))
|
||||||
totalTax := 0
|
totalTax := 0
|
||||||
|
c.PaymentInProgress = true
|
||||||
|
c.Processing = true
|
||||||
for _, item := range c.Items {
|
for _, item := range c.Items {
|
||||||
total := int(item.Price) * item.Quantity
|
total := int(item.Price) * item.Quantity
|
||||||
taxAmount := GetTaxAmount(total, item.Tax)
|
taxAmount := GetTaxAmount(total, item.Tax)
|
||||||
|
|||||||
135
klarna-push-type.go
Normal file
135
klarna-push-type.go
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type OrderValidationBody struct {
|
||||||
|
PurchaseCountry string `json:"purchase_country"`
|
||||||
|
PurchaseCurrency string `json:"purchase_currency"`
|
||||||
|
Locale string `json:"locale"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
BillingAddress struct {
|
||||||
|
GivenName string `json:"given_name"`
|
||||||
|
FamilyName string `json:"family_name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
StreetAddress string `json:"street_address"`
|
||||||
|
StreetAddress2 string `json:"street_address2"`
|
||||||
|
StreetName string `json:"street_name"`
|
||||||
|
StreetNumber string `json:"street_number"`
|
||||||
|
HouseExtension string `json:"house_extension"`
|
||||||
|
PostalCode string `json:"postal_code"`
|
||||||
|
City string `json:"city"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
Phone string `json:"phone"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
CareOf string `json:"care_of"`
|
||||||
|
} `json:"billing_address"`
|
||||||
|
ShippingAddress struct {
|
||||||
|
GivenName string `json:"given_name"`
|
||||||
|
FamilyName string `json:"family_name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
StreetAddress string `json:"street_address"`
|
||||||
|
StreetAddress2 string `json:"street_address2"`
|
||||||
|
StreetName string `json:"street_name"`
|
||||||
|
StreetNumber string `json:"street_number"`
|
||||||
|
HouseExtension string `json:"house_extension"`
|
||||||
|
PostalCode string `json:"postal_code"`
|
||||||
|
City string `json:"city"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
Phone string `json:"phone"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
CareOf string `json:"care_of"`
|
||||||
|
} `json:"shipping_address"`
|
||||||
|
OrderAmount int `json:"order_amount"`
|
||||||
|
OrderTaxAmount int `json:"order_tax_amount"`
|
||||||
|
OrderLines []struct {
|
||||||
|
} `json:"order_lines"`
|
||||||
|
Customer struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Gender string `json:"gender"`
|
||||||
|
DateOfBirth string `json:"date_of_birth"`
|
||||||
|
OrganizationRegistrationID string `json:"organization_registration_id"`
|
||||||
|
VatID string `json:"vat_id"`
|
||||||
|
} `json:"customer"`
|
||||||
|
MerchantUrls struct {
|
||||||
|
Terms string `json:"terms"`
|
||||||
|
Checkout string `json:"checkout"`
|
||||||
|
Confirmation string `json:"confirmation"`
|
||||||
|
Push string `json:"push"`
|
||||||
|
Validation string `json:"validation"`
|
||||||
|
Notification string `json:"notification"`
|
||||||
|
CancellationTerms string `json:"cancellation_terms"`
|
||||||
|
ShippingOptionUpdate string `json:"shipping_option_update"`
|
||||||
|
AddressUpdate string `json:"address_update"`
|
||||||
|
CountryChange string `json:"country_change"`
|
||||||
|
} `json:"merchant_urls"`
|
||||||
|
MerchantReference1 string `json:"merchant_reference1"`
|
||||||
|
MerchantReference2 string `json:"merchant_reference2"`
|
||||||
|
Options struct {
|
||||||
|
RequireValidateCallbackSuccess bool `json:"require_validate_callback_success"`
|
||||||
|
AcquiringChannel string `json:"acquiring_channel"`
|
||||||
|
VatRemoved bool `json:"vat_removed"`
|
||||||
|
AllowSeparateShippingAddress bool `json:"allow_separate_shipping_address"`
|
||||||
|
ColorButton string `json:"color_button"`
|
||||||
|
ColorButtonText string `json:"color_button_text"`
|
||||||
|
ColorCheckbox string `json:"color_checkbox"`
|
||||||
|
ColorCheckboxCheckmark string `json:"color_checkbox_checkmark"`
|
||||||
|
ColorHeader string `json:"color_header"`
|
||||||
|
ColorLink string `json:"color_link"`
|
||||||
|
DateOfBirthMandatory bool `json:"date_of_birth_mandatory"`
|
||||||
|
ShippingDetails string `json:"shipping_details"`
|
||||||
|
TitleMandatory bool `json:"title_mandatory"`
|
||||||
|
AdditionalCheckbox struct {
|
||||||
|
} `json:"additional_checkbox"`
|
||||||
|
NationalIdentificationNumberMandatory bool `json:"national_identification_number_mandatory"`
|
||||||
|
AdditionalMerchantTerms string `json:"additional_merchant_terms"`
|
||||||
|
PhoneMandatory bool `json:"phone_mandatory"`
|
||||||
|
RadiusBorder string `json:"radius_border"`
|
||||||
|
AllowedCustomerTypes []interface{} `json:"allowed_customer_types"`
|
||||||
|
ShowSubtotalDetail bool `json:"show_subtotal_detail"`
|
||||||
|
AdditionalCheckboxes []interface{} `json:"additional_checkboxes"`
|
||||||
|
VerifyNationalIdentificationNumber bool `json:"verify_national_identification_number"`
|
||||||
|
AutoCapture bool `json:"auto_capture"`
|
||||||
|
RequireClientValidation bool `json:"require_client_validation"`
|
||||||
|
EnableDiscountModule bool `json:"enable_discount_module"`
|
||||||
|
ShowVatRegistrationNumberField bool `json:"show_vat_registration_number_field"`
|
||||||
|
} `json:"options"`
|
||||||
|
Attachment struct {
|
||||||
|
Body time.Time `json:"body"`
|
||||||
|
ContentType string `json:"content_type"`
|
||||||
|
} `json:"attachment"`
|
||||||
|
ExternalPaymentMethods []struct {
|
||||||
|
} `json:"external_payment_methods"`
|
||||||
|
ExternalCheckouts []struct {
|
||||||
|
} `json:"external_checkouts"`
|
||||||
|
ShippingCountries []string `json:"shipping_countries"`
|
||||||
|
ShippingOptions []struct {
|
||||||
|
} `json:"shipping_options"`
|
||||||
|
MerchantData string `json:"merchant_data"`
|
||||||
|
Gui struct {
|
||||||
|
Options []interface{} `json:"options"`
|
||||||
|
} `json:"gui"`
|
||||||
|
MerchantRequested struct {
|
||||||
|
} `json:"merchant_requested"`
|
||||||
|
SelectedShippingOption struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Promo string `json:"promo"`
|
||||||
|
Price int `json:"price"`
|
||||||
|
Preselected bool `json:"preselected"`
|
||||||
|
TaxAmount int `json:"tax_amount"`
|
||||||
|
TaxRate int `json:"tax_rate"`
|
||||||
|
ShippingMethod string `json:"shipping_method"`
|
||||||
|
DeliveryDetails struct {
|
||||||
|
} `json:"delivery_details"`
|
||||||
|
TmsReference string `json:"tms_reference"`
|
||||||
|
SelectedAddons []interface{} `json:"selected_addons"`
|
||||||
|
} `json:"selected_shipping_option"`
|
||||||
|
Recurring bool `json:"recurring"`
|
||||||
|
BillingCountries []string `json:"billing_countries"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
|
DiscountLines []struct {
|
||||||
|
} `json:"discount_lines"`
|
||||||
|
}
|
||||||
17
main.go
17
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@@ -181,7 +182,21 @@ func main() {
|
|||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/push", func(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Print(r.Body)
|
log.Printf("KLARNA PUSH: search %v, body %s", r.URL.Query(), r.Body)
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var data OrderValidationBody
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&data)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error decoding body: %v\n", err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cartId := data.MerchantReference1
|
||||||
|
log.Printf("Received push for cart %s, status: %s", cartId, data.Status)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|||||||
Reference in New Issue
Block a user