3pl/partnerapi/onpoint/model_request.go

117 lines
3.2 KiB
Go

package onpoint
import (
"time"
"git.selly.red/Selly-Modules/3pl/util/pjson"
)
/*
* Request payload
*/
// CreateOrderRequest ...
type CreateOrderRequest struct {
StoreCode string `json:"store_code"`
DeliveryPlatform string `json:"delivery_platform"`
OrderCode string `json:"order_code"`
OrderDate time.Time `json:"order_date"`
PickupLocationCode string `json:"pickup_location_code"`
Note string `json:"note"`
SubtotalPrice int `json:"subtotal_price"`
TotalDiscounts int `json:"total_discounts"`
TotalPrice int `json:"total_price"`
PaymentMethod string `json:"payment_method"`
Items []OrderItem `json:"items"`
}
// OrderItem ...
type OrderItem struct {
SellingPrice int `json:"selling_price"`
Quantity int `json:"quantity"`
Uom string `json:"uom"`
Amount int `json:"amount"`
Name string `json:"name"`
PartnerSku string `json:"sku"`
DiscountedPrice int `json:"discounted_price"`
}
// UpdateOrderDeliveryRequest ...
type UpdateOrderDeliveryRequest struct {
OrderCode string `json:"order_code"` // required
DeliveryPlatform string `json:"delivery_platform"` // required
DeliveryTrackingNumber string `json:"delivery_tracking_number"`
DeliveryStatus string `json:"delivery_status"`
ShippingLabel string `json:"shipping_label"`
}
// CancelOrderRequest ...
type CancelOrderRequest struct {
OrderNo string `json:"order_code"`
}
type ListInventoriesReq struct {
UpdatedFrom time.Time
UpdatedTo time.Time
SKUList []string
Size int
Page int
}
/**
* WEBHOOK ONPOINT
*/
// WebhookDataUpdateInventory ...
type WebhookDataUpdateInventory struct {
Sku string `json:"sku"`
AvailableQuantity int `json:"available_quantity"`
PickupLocationCode string `json:"pickup_location_code"`
UpdatedAt time.Time `json:"updated_at"`
}
// WebhookDataUpdateOrderStatus ...
type WebhookDataUpdateOrderStatus struct {
OrderCode string `json:"order_code"`
OnpointOrderCode string `json:"onpoint_order_code"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
}
// WebhookPayload ...
type WebhookPayload struct {
Event string `json:"event"`
RequestedAt time.Time `json:"requested_at"`
Payload interface{} `json:"payload"`
}
// GetDataEventUpdateOrderStatus ...
func (p WebhookPayload) GetDataEventUpdateOrderStatus() (data *WebhookDataUpdateOrderStatus, ok bool) {
if p.Event != webhookEventUpdateOrderStatus {
return nil, false
}
b, err := pjson.Marshal(p.Payload)
if err != nil {
return nil, false
}
if err = pjson.Unmarshal(b, &data); err != nil {
return nil, false
}
return data, true
}
// GetDataEventUpdateInventory ...
func (p WebhookPayload) GetDataEventUpdateInventory() (data *WebhookDataUpdateInventory, ok bool) {
if p.Event != webhookEventUpdateInventory {
return nil, false
}
b, err := pjson.Marshal(p.Payload)
if err != nil {
return nil, false
}
if err = pjson.Unmarshal(b, &data); err != nil {
return nil, false
}
return data, true
}