integrate-onpoint #5

Merged
sinhluu merged 15 commits from integrate-onpoint into master 2022-10-31 09:36:25 +00:00
5 changed files with 40 additions and 87 deletions
Showing only changes of commit d3a7fe684b - Show all commits

View File

@ -15,6 +15,8 @@ const (
webhookEventUpdateOrderStatus = "update_order_status"
webhookEventUpdateInventory = "update_inventory"
CodeSuccess = "SUCCESS"
)
var (

View File

@ -1,14 +1,25 @@
package onpoint
import "fmt"
import (
"fmt"
"strings"
)
// Error ...
type Error struct {
Message string `json:"message"`
Status string `json:"status"`
Code string `json:"code"`
Errors map[string][]string `json:"errors"`
}
// Error ...
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
}

View File

@ -12,23 +12,14 @@ import (
// CreateOrderRequest ...
type CreateOrderRequest struct {
PartnerOrderCode string `json:"partner_order_code"`
OrderCode string `json:"order_code"`
OrderDate time.Time `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"`
DistrictCode string `json:"district_code"`
WardCode string `json:"ward_code"`
ProvinceCode string `json:"province_code"`
PickupLocationCode string `json:"pickup_location_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"`
}
@ -39,12 +30,13 @@ type OrderItem struct {
Uom string `json:"uom"`
Amount int `json:"amount"`
Name string `json:"name"`
PartnerSku string `json:"partner_sku"`
PartnerSku string `json:"sku"`
DiscountPrice int `json:"discount_price"`
}
// UpdateOrderDeliveryRequest ...
type UpdateOrderDeliveryRequest struct {
OrderNo string `json:"order_no"` // required
OrderCode string `json:"order_code"` // required
DeliveryPlatform string `json:"delivery_platform"` // required
DeliveryTrackingNumber string `json:"delivery_tracking_number"`
ShippingLabel string `json:"shipping_label"`
@ -52,7 +44,7 @@ type UpdateOrderDeliveryRequest struct {
// CancelOrderRequest ...
type CancelOrderRequest struct {
OrderNo string `json:"order_no"`
OrderNo string `json:"order_code"`
}
/**

View File

@ -1,34 +1,18 @@
package onpoint
import "time"
// CreateOrderResponse ...
type CreateOrderResponse struct {
PartnerOrderCode string `json:"partner_order_code"`
OrderNo string `json:"order_no"`
OrderDate time.Time `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"`
OrderCode string `json:"order_code"`
OnpointOrderCode string `json:"onpoint_order_code"`
OrderDate string `json:"order_date"`
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"`
Status string `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
InsertedAt time.Time `json:"inserted_at"`
UpdatedAt string `json:"updated_at"`
Items []OrderItem `json:"items"`
}

View File

@ -51,6 +51,7 @@ func (c *Client) CreateOrder(p CreateOrderRequest) (*CreateOrderResponse, error)
r model.CommunicationHttpResponse
errRes Error
dataRes struct {
Code string `json:"code"`
Data CreateOrderResponse `json:"data"`
}
)
@ -150,43 +151,6 @@ func (c *Client) CancelOrder(p CancelOrderRequest) (*CancelOrderResponse, error)
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 {
ec, err := c.natsClient.NewJSONEncodedConn()
if err != nil {