3pl/partnerapi/onpoint/model_request.go

120 lines
3.3 KiB
Go
Raw Normal View History

2022-09-16 10:43:13 +00:00
package onpoint
2022-09-19 07:34:55 +00:00
import (
"time"
2022-10-13 09:45:04 +00:00
"git.selly.red/Selly-Modules/3pl/util/pjson"
2022-09-19 07:34:55 +00:00
)
2022-09-16 10:43:13 +00:00
/*
* Request payload
*/
// CreateOrderRequest ...
type CreateOrderRequest struct {
2023-12-01 07:39:56 +00:00
StoreCode string `json:"store_code"`
DeliveryPlatform string `json:"delivery_platform"`
2022-10-04 08:45:29 +00:00
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"`
2022-09-16 10:43:13 +00:00
}
// OrderItem ...
type OrderItem struct {
2023-12-08 02:10:20 +00:00
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"`
2022-09-16 10:43:13 +00:00
}
// UpdateOrderDeliveryRequest ...
type UpdateOrderDeliveryRequest struct {
2022-10-04 08:45:29 +00:00
OrderCode string `json:"order_code"` // required
2022-09-16 10:43:13 +00:00
DeliveryPlatform string `json:"delivery_platform"` // required
DeliveryTrackingNumber string `json:"delivery_tracking_number"`
2022-10-18 07:58:48 +00:00
DeliveryStatus string `json:"delivery_status"`
2022-09-16 10:43:13 +00:00
ShippingLabel string `json:"shipping_label"`
}
// CancelOrderRequest ...
type CancelOrderRequest struct {
2022-10-04 08:45:29 +00:00
OrderNo string `json:"order_code"`
2022-09-16 10:43:13 +00:00
}
2024-04-08 08:38:20 +00:00
type ListInventoriesReq struct {
UpdatedFrom time.Time
UpdatedTo time.Time
SKUList []string
Size int
Page int
}
2022-09-16 10:43:13 +00:00
/**
* WEBHOOK ONPOINT
*/
// WebhookDataUpdateInventory ...
type WebhookDataUpdateInventory struct {
2022-10-14 07:39:57 +00:00
Sku string `json:"sku"`
PartnerSku string `json:"partner_sku"`
WarehouseCode string `json:"warehouse_code"`
AvailableQuantity int `json:"available_quantity"`
CommittedQuantity int `json:"committed_quantity"`
TotalQuantity int `json:"total_quantity"`
UpdatedAt string `json:"updated_at"`
2022-09-16 10:43:13 +00:00
}
// WebhookDataUpdateOrderStatus ...
type WebhookDataUpdateOrderStatus struct {
2022-10-14 07:39:57 +00:00
OrderCode string `json:"order_code"`
OnpointOrderCode string `json:"onpoint_order_code"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
2022-09-16 10:43:13 +00:00
}
2022-09-19 07:34:55 +00:00
// WebhookPayload ...
type WebhookPayload struct {
Event string `json:"event"`
RequestedAt time.Time `json:"requested_at"`
2022-10-17 09:48:53 +00:00
Payload interface{} `json:"payload"`
2022-09-19 07:34:55 +00:00
}
// GetDataEventUpdateOrderStatus ...
func (p WebhookPayload) GetDataEventUpdateOrderStatus() (data *WebhookDataUpdateOrderStatus, ok bool) {
if p.Event != webhookEventUpdateOrderStatus {
return nil, false
}
2022-10-17 09:48:53 +00:00
b, err := pjson.Marshal(p.Payload)
2022-09-19 07:34:55 +00:00
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
}
2022-10-17 09:48:53 +00:00
b, err := pjson.Marshal(p.Payload)
2022-09-19 07:34:55 +00:00
if err != nil {
return nil, false
}
if err = pjson.Unmarshal(b, &data); err != nil {
return nil, false
}
return data, true
}