update onpoint payload
This commit is contained in:
parent
590bbe2076
commit
d3a7fe684b
|
@ -15,6 +15,8 @@ const (
|
||||||
|
|
||||||
webhookEventUpdateOrderStatus = "update_order_status"
|
webhookEventUpdateOrderStatus = "update_order_status"
|
||||||
webhookEventUpdateInventory = "update_inventory"
|
webhookEventUpdateInventory = "update_inventory"
|
||||||
|
|
||||||
|
CodeSuccess = "SUCCESS"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -1,14 +1,25 @@
|
||||||
package onpoint
|
package onpoint
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// Error ...
|
// Error ...
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Status string `json:"status"`
|
Code string `json:"code"`
|
||||||
|
Errors map[string][]string `json:"errors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error ...
|
// Error ...
|
||||||
func (e Error) Error() string {
|
func (e Error) Error() string {
|
||||||
return fmt.Sprintf("onpoint_err: status %s, message: %s", e.Status, e.Message)
|
msg := fmt.Sprintf("onpoint_err: code %s, message: %s", e.Code, e.Message)
|
||||||
|
if len(e.Errors) > 0 {
|
||||||
|
msg += "\ndetail: "
|
||||||
|
for k, v := range e.Errors {
|
||||||
|
msg += fmt.Sprintf("field %s - error %s", k, strings.Join(v, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,39 +12,31 @@ import (
|
||||||
|
|
||||||
// CreateOrderRequest ...
|
// CreateOrderRequest ...
|
||||||
type CreateOrderRequest struct {
|
type CreateOrderRequest struct {
|
||||||
PartnerOrderCode string `json:"partner_order_code"`
|
OrderCode string `json:"order_code"`
|
||||||
OrderDate time.Time `json:"order_date"`
|
OrderDate time.Time `json:"order_date"`
|
||||||
ChannelCode string `json:"channel_code"`
|
PickupLocationCode string `json:"pickup_location_code"`
|
||||||
FullName string `json:"full_name"`
|
Note string `json:"note"`
|
||||||
Email string `json:"email"`
|
SubtotalPrice int `json:"subtotal_price"`
|
||||||
Phone string `json:"phone"`
|
TotalDiscounts int `json:"total_discounts"`
|
||||||
Address string `json:"address"`
|
TotalPrice int `json:"total_price"`
|
||||||
DistrictCode string `json:"district_code"`
|
PaymentMethod string `json:"payment_method"`
|
||||||
WardCode string `json:"ward_code"`
|
Items []OrderItem `json:"items"`
|
||||||
ProvinceCode string `json:"province_code"`
|
|
||||||
Note string `json:"note"`
|
|
||||||
SubtotalPrice int `json:"subtotal_price"`
|
|
||||||
ShippingFee int `json:"shipping_fee"`
|
|
||||||
TotalDiscounts int `json:"total_discounts"`
|
|
||||||
TotalPrice int `json:"total_price"`
|
|
||||||
PaymentMethod string `json:"payment_method"`
|
|
||||||
DeliveryPlatform string `json:"delivery_platform"`
|
|
||||||
Items []OrderItem `json:"items"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderItem ...
|
// OrderItem ...
|
||||||
type OrderItem struct {
|
type OrderItem struct {
|
||||||
SellingPrice int `json:"selling_price"`
|
SellingPrice int `json:"selling_price"`
|
||||||
Quantity int `json:"quantity"`
|
Quantity int `json:"quantity"`
|
||||||
Uom string `json:"uom"`
|
Uom string `json:"uom"`
|
||||||
Amount int `json:"amount"`
|
Amount int `json:"amount"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PartnerSku string `json:"partner_sku"`
|
PartnerSku string `json:"sku"`
|
||||||
|
DiscountPrice int `json:"discount_price"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateOrderDeliveryRequest ...
|
// UpdateOrderDeliveryRequest ...
|
||||||
type UpdateOrderDeliveryRequest struct {
|
type UpdateOrderDeliveryRequest struct {
|
||||||
OrderNo string `json:"order_no"` // required
|
OrderCode string `json:"order_code"` // required
|
||||||
DeliveryPlatform string `json:"delivery_platform"` // required
|
DeliveryPlatform string `json:"delivery_platform"` // required
|
||||||
DeliveryTrackingNumber string `json:"delivery_tracking_number"`
|
DeliveryTrackingNumber string `json:"delivery_tracking_number"`
|
||||||
ShippingLabel string `json:"shipping_label"`
|
ShippingLabel string `json:"shipping_label"`
|
||||||
|
@ -52,7 +44,7 @@ type UpdateOrderDeliveryRequest struct {
|
||||||
|
|
||||||
// CancelOrderRequest ...
|
// CancelOrderRequest ...
|
||||||
type CancelOrderRequest struct {
|
type CancelOrderRequest struct {
|
||||||
OrderNo string `json:"order_no"`
|
OrderNo string `json:"order_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,34 +1,18 @@
|
||||||
package onpoint
|
package onpoint
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// CreateOrderResponse ...
|
// CreateOrderResponse ...
|
||||||
type CreateOrderResponse struct {
|
type CreateOrderResponse struct {
|
||||||
PartnerOrderCode string `json:"partner_order_code"`
|
OrderCode string `json:"order_code"`
|
||||||
OrderNo string `json:"order_no"`
|
OnpointOrderCode string `json:"onpoint_order_code"`
|
||||||
OrderDate time.Time `json:"order_date"`
|
OrderDate string `json:"order_date"`
|
||||||
ChannelCode string `json:"channel_code"`
|
|
||||||
FullName string `json:"full_name"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
Phone string `json:"phone"`
|
|
||||||
Address string `json:"address"`
|
|
||||||
FullAddress string `json:"full_address"`
|
|
||||||
District string `json:"district"`
|
|
||||||
Ward string `json:"ward"`
|
|
||||||
Province string `json:"province"`
|
|
||||||
DistrictCode string `json:"district_code"`
|
|
||||||
WardCode string `json:"ward_code"`
|
|
||||||
ProvinceCode string `json:"province_code"`
|
|
||||||
Note string `json:"note"`
|
Note string `json:"note"`
|
||||||
SubtotalPrice int `json:"subtotal_price"`
|
SubtotalPrice int `json:"subtotal_price"`
|
||||||
ShippingFee int `json:"shipping_fee"`
|
|
||||||
TotalDiscounts int `json:"total_discounts"`
|
TotalDiscounts int `json:"total_discounts"`
|
||||||
TotalPrice int `json:"total_price"`
|
TotalPrice int `json:"total_price"`
|
||||||
PaymentMethod string `json:"payment_method"`
|
PaymentMethod string `json:"payment_method"`
|
||||||
DeliveryPlatform string `json:"delivery_platform"`
|
DeliveryPlatform string `json:"delivery_platform"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt string `json:"updated_at"`
|
||||||
InsertedAt time.Time `json:"inserted_at"`
|
|
||||||
Items []OrderItem `json:"items"`
|
Items []OrderItem `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ func (c *Client) CreateOrder(p CreateOrderRequest) (*CreateOrderResponse, error)
|
||||||
r model.CommunicationHttpResponse
|
r model.CommunicationHttpResponse
|
||||||
errRes Error
|
errRes Error
|
||||||
dataRes struct {
|
dataRes struct {
|
||||||
|
Code string `json:"code"`
|
||||||
Data CreateOrderResponse `json:"data"`
|
Data CreateOrderResponse `json:"data"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -150,43 +151,6 @@ func (c *Client) CancelOrder(p CancelOrderRequest) (*CancelOrderResponse, error)
|
||||||
return &dataRes.Data, nil
|
return &dataRes.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChannels ...
|
|
||||||
func (c *Client) GetChannels() ([]ChannelResponse, error) {
|
|
||||||
url := c.getBaseURL() + apiPathGetChannels
|
|
||||||
natsPayload := model.CommunicationRequestHttp{
|
|
||||||
ResponseImmediately: true,
|
|
||||||
Payload: model.HttpRequest{
|
|
||||||
URL: url,
|
|
||||||
Method: http.MethodGet,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
r model.CommunicationHttpResponse
|
|
||||||
errRes Error
|
|
||||||
dataRes struct {
|
|
||||||
Data []ChannelResponse `json:"data"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if err := c.requestHttpViaNats(natsPayload, &r); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res := r.Response
|
|
||||||
if res == nil {
|
|
||||||
return nil, fmt.Errorf("onpoint.Client.GetChannels: empty_response")
|
|
||||||
}
|
|
||||||
if res.StatusCode >= http.StatusBadRequest {
|
|
||||||
if err := r.ParseResponseData(&errRes); err != nil {
|
|
||||||
return nil, fmt.Errorf("onpoint.Client.GetChannels: parse_response_err: %v", err)
|
|
||||||
}
|
|
||||||
return nil, errRes
|
|
||||||
}
|
|
||||||
if err := r.ParseResponseData(&dataRes); err != nil {
|
|
||||||
return nil, fmt.Errorf("onpoint.Client.GetChannels: parse_response_data: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataRes.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) requestHttpViaNats(data model.CommunicationRequestHttp, res interface{}) error {
|
func (c *Client) requestHttpViaNats(data model.CommunicationRequestHttp, res interface{}) error {
|
||||||
ec, err := c.natsClient.NewJSONEncodedConn()
|
ec, err := c.natsClient.NewJSONEncodedConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue