From 1382e5700355bf48150b447508bb23624aeaeee4 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 24 Aug 2022 14:17:45 +0700 Subject: [PATCH 01/11] define tnc error code --- partnerapi/tnc/const.go | 4 ++++ partnerapi/tnc/error.go | 22 ++++++++++++++++++++++ partnerapi/tnc/model_response.go | 14 ++++---------- partnerapi/tnc/tnc.go | 22 +++++++++++----------- 4 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 partnerapi/tnc/error.go diff --git a/partnerapi/tnc/const.go b/partnerapi/tnc/const.go index fd3bbf6..fd6a860 100644 --- a/partnerapi/tnc/const.go +++ b/partnerapi/tnc/const.go @@ -37,6 +37,10 @@ const ( baseURLProd = "https://ext-api.tnclog.vn" ) +const ( + ErrCodeExistPartnerCode = "exist_partner_code" +) + var ( baseURLENVMapping = map[ENV]string{ EnvProd: baseURLProd, diff --git a/partnerapi/tnc/error.go b/partnerapi/tnc/error.go new file mode 100644 index 0000000..ec41b58 --- /dev/null +++ b/partnerapi/tnc/error.go @@ -0,0 +1,22 @@ +package tnc + +import ( + "fmt" +) + +// Error ... +type Error struct { + Code string `json:"code"` + Message string `json:"errorMessage"` +} + +// Error ... +func (e Error) Error() string { + return fmt.Sprintf("tnc_err: code %s, messsage %s", e.Code, e.Message) +} + +// IsErrExistPartnerCode ... +func IsErrExistPartnerCode(err error) bool { + e, ok := err.(Error) + return ok && e.Code == ErrCodeExistPartnerCode +} diff --git a/partnerapi/tnc/model_response.go b/partnerapi/tnc/model_response.go index a13dec4..5d3843d 100644 --- a/partnerapi/tnc/model_response.go +++ b/partnerapi/tnc/model_response.go @@ -2,16 +2,10 @@ package tnc // OutboundRequestRes ... type OutboundRequestRes struct { - OrID int `json:"orId"` - OrCode string `json:"orCode"` - PartnerORCode string `json:"partnerORCode"` - Error *ErrRes `json:"error"` -} - -// ErrRes ... -type ErrRes struct { - Code string `json:"code"` - ErrorMessage string `json:"errorMessage"` + OrID int `json:"orId"` + OrCode string `json:"orCode"` + PartnerORCode string `json:"partnerORCode"` + Error *Error `json:"error"` } type authRes struct { diff --git a/partnerapi/tnc/tnc.go b/partnerapi/tnc/tnc.go index a9a5971..17e83fd 100644 --- a/partnerapi/tnc/tnc.go +++ b/partnerapi/tnc/tnc.go @@ -66,7 +66,7 @@ func (c *Client) CreateOutboundRequest(p OutboundRequestPayload) (*OutboundReque } var ( r model.CommunicationHttpResponse - errRes ErrRes + errRes Error dataRes []OutboundRequestRes ) if err = pjson.Unmarshal(msg.Data, &r); err != nil { @@ -80,7 +80,7 @@ func (c *Client) CreateOutboundRequest(p OutboundRequestPayload) (*OutboundReque if err = r.ParseResponseData(&errRes); err != nil { return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: parse_response_err: %v", err) } - return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: failed code %s, message %s", errRes.Code, errRes.ErrorMessage) + return nil, errRes } if err = r.ParseResponseData(&dataRes); err != nil { return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: parse_response_data: %v", err) @@ -91,7 +91,7 @@ func (c *Client) CreateOutboundRequest(p OutboundRequestPayload) (*OutboundReque item := &dataRes[0] e := item.Error if e != nil { - return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: failed, code %s - message %s", e.Code, e.ErrorMessage) + return nil, errRes } return item, err @@ -119,7 +119,7 @@ func (c *Client) UpdateOutboundRequestLogisticInfo(p UpdateORLogisticInfoPayload } var ( r model.CommunicationHttpResponse - errRes ErrRes + errRes Error ) if err = pjson.Unmarshal(msg.Data, &r); err != nil { return fmt.Errorf("tnc.Client.UpdateOutboundRequestLogisticInfo: parse_data %v", err) @@ -132,7 +132,7 @@ func (c *Client) UpdateOutboundRequestLogisticInfo(p UpdateORLogisticInfoPayload if err = r.ParseResponseData(&errRes); err != nil { return fmt.Errorf("tnc.Client.UpdateOutboundRequestLogisticInfo: parse_response_err: %v", err) } - return fmt.Errorf("tnc.Client.UpdateOutboundRequestLogisticInfo: failed code %s, message %s", errRes.Code, errRes.ErrorMessage) + return errRes } return nil } @@ -158,7 +158,7 @@ func (c *Client) GetOutboundRequestByID(requestID int) (*OutboundRequestInfo, er } var ( r model.CommunicationHttpResponse - errRes ErrRes + errRes Error outboundRequest OutboundRequestInfo ) if err = pjson.Unmarshal(msg.Data, &r); err != nil { @@ -172,7 +172,7 @@ func (c *Client) GetOutboundRequestByID(requestID int) (*OutboundRequestInfo, er if err = r.ParseResponseData(&errRes); err != nil { return nil, fmt.Errorf("tnc.Client.GetOutboundRequestByID: parse_response_err: %v", err) } - return nil, fmt.Errorf("tnc.Client.GetOutboundRequestByID: failed code %s, message %s", errRes.Code, errRes.ErrorMessage) + return nil, errRes } if err = r.ParseResponseData(&outboundRequest); err != nil { return nil, fmt.Errorf("tnc.Client.GetOutboundRequestByID: parse_response_data: %v", err) @@ -203,7 +203,7 @@ func (c *Client) CancelOutboundRequest(requestID int, note string) error { } var ( r model.CommunicationHttpResponse - errRes ErrRes + errRes Error ) if err = pjson.Unmarshal(msg.Data, &r); err != nil { return fmt.Errorf("tnc.Client.CancelOutboundRequest: parse_data %v", err) @@ -216,7 +216,7 @@ func (c *Client) CancelOutboundRequest(requestID int, note string) error { if err = r.ParseResponseData(&errRes); err != nil { return fmt.Errorf("tnc.Client.CancelOutboundRequest: parse_response_err: %v", err) } - return fmt.Errorf("tnc.Client.CancelOutboundRequest: failed code %s, message %s", errRes.Code, errRes.ErrorMessage) + return errRes } return nil } @@ -252,7 +252,7 @@ func (c *Client) auth() (*authRes, error) { } var ( r model.CommunicationHttpResponse - errRes ErrRes + errRes Error data authRes ) if err = pjson.Unmarshal(msg.Data, &r); err != nil { @@ -266,7 +266,7 @@ func (c *Client) auth() (*authRes, error) { if err = r.ParseResponseData(&errRes); err != nil { return nil, fmt.Errorf("tnc.Client.auth: parse_response_err: %v", err) } - return nil, fmt.Errorf("tnc.Client.auth: failed code %s, message %s", errRes.Code, errRes.ErrorMessage) + return nil, errRes } if err = r.ParseResponseData(&data); err != nil { return nil, fmt.Errorf("tnc.Client.auth: parse_response_data: %v", err) -- 2.34.1 From e7f2ec779cba2783c7c54d0f2b196ccd1f61978b Mon Sep 17 00:00:00 2001 From: Sinh Date: Sun, 28 Aug 2022 14:16:27 +0700 Subject: [PATCH 02/11] update --- constant/natsio.go | 9 --- go.mod | 2 + partnerapi/globalcare/globale_care.go | 85 +++++++++++++++++++++---- partnerapi/globalcare/model_response.go | 85 ++++++++++++++++++++++++- partnerapi/tnc/tnc.go | 4 +- 5 files changed, 159 insertions(+), 26 deletions(-) delete mode 100644 constant/natsio.go diff --git a/constant/natsio.go b/constant/natsio.go deleted file mode 100644 index d730e74..0000000 --- a/constant/natsio.go +++ /dev/null @@ -1,9 +0,0 @@ -package constant - -const natsCommunicationPrefix = "communication_" - -const ( - NatsCommunicationSubjectRequestHTTP = natsCommunicationPrefix + "request_http" - NatsCommunicationSubjectResponseHTTP = natsCommunicationPrefix + "response_http" - NatsCommunicationSubjectWebhookTNC = natsCommunicationPrefix + "webhook_tnc" -) diff --git a/go.mod b/go.mod index aed1d01..98b1f93 100644 --- a/go.mod +++ b/go.mod @@ -36,3 +36,5 @@ require ( golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect ) + +//replace github.com/Selly-Modules/natsio => /Users/sinh/Documents/dev/selly-module/natsio diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index 56ed5fd..41f7ef7 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -1,17 +1,21 @@ package globalcare import ( + "crypto" + "crypto/rand" "crypto/rsa" + "crypto/sha256" + "errors" "fmt" "net/http" "github.com/Selly-Modules/logger" "github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" "github.com/nats-io/nats.go" "github.com/thoas/go-funk" - "github.com/Selly-Modules/3pl/constant" "github.com/Selly-Modules/3pl/util/base64" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -27,7 +31,7 @@ type Client struct { // NewClient generate Client // using privateKey to decrypt data from Global Care // using publicKey to encrypt data before send to Global Care -func NewClient(env ENV, privateKey, publicKey string) (*Client, error) { +func NewClient(env ENV, privateKey, publicKey string, natsClient natsio.Server) (*Client, error) { validENVs := []ENV{EnvProd, EnvDev, EnvStaging} if !funk.Contains(validENVs, env) { return nil, fmt.Errorf("globalcare.NewClient - invalid_env: %s", env) @@ -43,11 +47,13 @@ func NewClient(env ENV, privateKey, publicKey string) (*Client, error) { return &Client{ privateKey: privKey, publicKey: pubKey, + env: env, + natsClient: natsClient, }, nil } // CreateOrder ... -func (c *Client) CreateOrder(p CreateOrderPayload) (*CommonResponse, error) { +func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded, error) { url := c.getBaseURL() + apiPathCreateOrder data := createOrderData{ ProductCode: productCodeDefault, @@ -58,9 +64,14 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CommonResponse, error) { InsuredInfo: p.InsuredInfo, } + dataString := base64.Encode(pjson.ToBytes(data)) + sign, err := c.signData(dataString) + if err != nil { + return nil, fmt.Errorf("globalcare.Client.CreateOrder - sign_err %v", err) + } body := CommonRequestBody{ - Signature: "", // TODO:implement - Data: base64.Encode(pjson.ToBytes(data)), + Signature: sign, + Data: dataString, } natsPayload := model.CommunicationRequestHttp{ ResponseImmediately: true, @@ -70,7 +81,7 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CommonResponse, error) { Data: pjson.ToJSONString(body), }, } - msg, err := c.requestNats(constant.NatsCommunicationSubjectRequestHTTP, natsPayload) + msg, err := c.requestNats(subject.Communication.RequestHTTP, natsPayload) if err != nil { logger.Error("globalcare.Client.CreateOrder", logger.LogData{ "err": err.Error(), @@ -85,12 +96,30 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CommonResponse, error) { if err = pjson.Unmarshal(msg.Data, &r); err != nil { return nil, err } - err = r.ParseResponseData(&res) - return &res, err + if err = r.ParseResponseData(&res); err != nil { + return nil, err + } + if r.Response == nil { + return nil, fmt.Errorf("globalcare.Client.CreateOrder create_order_empty_response") + } + + if r.Response.StatusCode >= http.StatusBadRequest { + info, err := res.DecodeError() + if err != nil { + return nil, err + } + return nil, errors.New(info.Message) + } + info, err := res.DecodeCreateOrderSuccess() + if err != nil { + return nil, err + } + + return &info, err } // GetOrder ... -func (c *Client) GetOrder(orderCode string) (*CommonResponse, error) { +func (c *Client) GetOrder(orderCode string) (*GetOrderResponseDecoded, error) { url := c.getBaseURL() + fmt.Sprintf(apiPathGetOrder, orderCode) natsPayload := model.CommunicationRequestHttp{ ResponseImmediately: true, @@ -99,7 +128,7 @@ func (c *Client) GetOrder(orderCode string) (*CommonResponse, error) { Method: http.MethodGet, }, } - msg, err := c.requestNats(constant.NatsCommunicationSubjectRequestHTTP, natsPayload) + msg, err := c.requestNats(subject.Communication.RequestHTTP, natsPayload) if err != nil { logger.Error("globalcare.Client.GetOrder", logger.LogData{ "err": err.Error(), @@ -114,8 +143,25 @@ func (c *Client) GetOrder(orderCode string) (*CommonResponse, error) { if err = pjson.Unmarshal(msg.Data, &r); err != nil { return nil, err } - err = r.ParseResponseData(&res) - return &res, err + if err = r.ParseResponseData(&res); err != nil { + return nil, err + } + if r.Response == nil { + return nil, fmt.Errorf("globalcare.Client.GetOrder get_order_empty_response") + } + + if r.Response.StatusCode >= http.StatusBadRequest { + info, err := res.DecodeError() + if err != nil { + return nil, err + } + return nil, errors.New(info.Message) + } + info, err := res.DecodeGetOrderSuccess() + if err != nil { + return nil, err + } + return &info, err } func (c *Client) requestNats(subject string, data interface{}) (*nats.Msg, error) { @@ -126,3 +172,18 @@ func (c *Client) requestNats(subject string, data interface{}) (*nats.Msg, error func (c *Client) getBaseURL() string { return baseURLENVMapping[c.env] } + +func (c *Client) signData(s string) (string, error) { + msgHash := sha256.New() + _, err := msgHash.Write([]byte(s)) + if err != nil { + return "", err + } + msgHashSum := msgHash.Sum(nil) + signature, err := rsa.SignPKCS1v15(rand.Reader, c.privateKey, crypto.SHA256, msgHashSum) + if err != nil { + return "", err + } + + return base64.Encode(signature), nil +} diff --git a/partnerapi/globalcare/model_response.go b/partnerapi/globalcare/model_response.go index ae17dff..8bf04b1 100644 --- a/partnerapi/globalcare/model_response.go +++ b/partnerapi/globalcare/model_response.go @@ -1,8 +1,87 @@ package globalcare +import "encoding/json" + // CommonResponse ... type CommonResponse struct { - StatusCode int `json:"statusCode"` - Message string `json:"message"` - Result interface{} `json:"result"` + Data string `json:"data"` + Signature string `json:"signature"` +} + +// DecodeCreateOrderSuccess ... +func (r *CommonResponse) DecodeCreateOrderSuccess() (res CreateOrderResponseDecoded, err error) { + err = r.Decode(res) + return res, err +} + +// DecodeGetOrderSuccess ... +func (r *CommonResponse) DecodeGetOrderSuccess() (res GetOrderResponseDecoded, err error) { + err = r.Decode(res) + return res, err +} + +// DecodeError ... +func (r *CommonResponse) DecodeError() (res ResponseError, err error) { + err = r.Decode(res) + return res, err +} + +// Decode ... +func (r *CommonResponse) Decode(resultPointer interface{}) error { + return json.Unmarshal([]byte(r.Data), resultPointer) +} + +// CreateOrderResponseDecoded ... +type CreateOrderResponseDecoded struct { + StatusCode int `json:"statusCode"` + Result CreateOrderResult `json:"result"` +} + +// CreateOrderResult ... +type CreateOrderResult struct { + OrderCode string `json:"orderCode"` + PaymentLink string `json:"paymentLink"` + Fees int `json:"fees"` + StatusId int `json:"statusId"` +} + +// ResponseError ... +type ResponseError struct { + StatusCode int `json:"statusCode"` + Message string `json:"message"` +} + +// GetOrderResponseDecoded ... +type GetOrderResponseDecoded struct { + StatusCode int `json:"statusCode"` + Result GetOrderResult `json:"result"` +} + +// GetOrderResult ... +type GetOrderResult struct { + ProviderTitle string `json:"providerTitle"` + BeginDate string `json:"beginDate"` + EndDate string `json:"endDate"` + Amount string `json:"amount"` + CertLink string `json:"certLink"` + StatusId int `json:"statusId"` + StatusTitle string `json:"statusTitle"` + Buyer BuyerInfo `json:"buyer"` + InsuredInfo InsuranceInfo `json:"insuredInfo"` +} + +// InsuranceInfo ... +type InsuranceInfo struct { + TypeId int `json:"typeId"` + TypeName string `json:"typeName"` + CarOccupantAccidentInsurance int `json:"carOccupantAccidentInsurance"` +} + +// BuyerInfo ... +type BuyerInfo struct { + BuyerName string `json:"buyerName"` + BuyerPrivateId interface{} `json:"buyerPrivateId"` + BuyerPhone string `json:"buyerPhone"` + BuyerAddress string `json:"buyerAddress"` + BuyerEmail string `json:"buyerEmail"` } diff --git a/partnerapi/tnc/tnc.go b/partnerapi/tnc/tnc.go index a9a5971..0d0b867 100644 --- a/partnerapi/tnc/tnc.go +++ b/partnerapi/tnc/tnc.go @@ -9,9 +9,9 @@ import ( "github.com/Selly-Modules/logger" "github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" "github.com/nats-io/nats.go" - "github.com/Selly-Modules/3pl/constant" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -288,7 +288,7 @@ func (c *Client) getRequestHeader() map[string]string { } func (c *Client) requestHttpViaNats(data model.CommunicationRequestHttp) (*nats.Msg, error) { - s := constant.NatsCommunicationSubjectRequestHTTP + s := subject.Communication.RequestHTTP b := pjson.ToBytes(data) return c.natsClient.Request(s, b) } -- 2.34.1 From 4f0da1a456666fd7a4cfc02bc7158175d490e174 Mon Sep 17 00:00:00 2001 From: Sinh Date: Sun, 28 Aug 2022 14:18:46 +0700 Subject: [PATCH 03/11] update nats module --- constant/natsio.go | 9 --------- go.mod | 7 +++---- go.sum | 7 ++----- partnerapi/globalcare/globale_care.go | 6 +++--- partnerapi/tnc/tnc.go | 5 ++--- 5 files changed, 10 insertions(+), 24 deletions(-) delete mode 100644 constant/natsio.go diff --git a/constant/natsio.go b/constant/natsio.go deleted file mode 100644 index d730e74..0000000 --- a/constant/natsio.go +++ /dev/null @@ -1,9 +0,0 @@ -package constant - -const natsCommunicationPrefix = "communication_" - -const ( - NatsCommunicationSubjectRequestHTTP = natsCommunicationPrefix + "request_http" - NatsCommunicationSubjectResponseHTTP = natsCommunicationPrefix + "response_http" - NatsCommunicationSubjectWebhookTNC = natsCommunicationPrefix + "webhook_tnc" -) diff --git a/go.mod b/go.mod index aed1d01..f602b02 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,9 @@ go 1.17 require ( github.com/Selly-Modules/logger v0.0.1 - github.com/Selly-Modules/natsio v1.0.1-0.20220818104747-572120c26a1d + github.com/Selly-Modules/natsio v1.0.1 + github.com/nats-io/nats.go v1.13.0 + github.com/thoas/go-funk v0.9.1 ) require ( @@ -14,14 +16,11 @@ require ( github.com/elastic/go-windows v1.0.0 // indirect github.com/jcchavezs/porto v0.1.0 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect - github.com/logrusorgru/aurora v2.0.3+incompatible // indirect - github.com/nats-io/nats.go v1.13.0 // indirect github.com/nats-io/nkeys v0.3.0 // indirect github.com/nats-io/nuid v1.0.1 // indirect github.com/pkg/errors v0.8.1 // indirect github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 // indirect github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect - github.com/thoas/go-funk v0.9.1 // indirect go.elastic.co/apm v1.13.1 // indirect go.elastic.co/apm/module/apmzap v1.13.1 // indirect go.elastic.co/fastjson v1.1.0 // indirect diff --git a/go.sum b/go.sum index bf59b4e..f9468d2 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ github.com/Selly-Modules/logger v0.0.1 h1:dwLLtW53FfVBlklhdtFRB63eP0ofIh0IUQ/Gjgi0r5k= github.com/Selly-Modules/logger v0.0.1/go.mod h1:RWhSQ3F01an8KD00VjzRBZOMcE5eV2Cy0/l4ZkeieyU= -github.com/Selly-Modules/natsio v1.0.0 h1:2GHm7upYn0CmqKPwfg2AXNmaAHuL7V9l36M4BgOmQ4M= -github.com/Selly-Modules/natsio v1.0.0/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ= -github.com/Selly-Modules/natsio v1.0.1-0.20220818104747-572120c26a1d h1:NnRejDZPFqvtphr2rtfwi0rGx+oN8yD8RwttViVddjY= -github.com/Selly-Modules/natsio v1.0.1-0.20220818104747-572120c26a1d/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ= +github.com/Selly-Modules/natsio v1.0.1 h1:0HoP00hP0Fz5h03p23Al3aARZwg+JSKpOrBo5Oh7pwY= +github.com/Selly-Modules/natsio v1.0.1/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= @@ -42,7 +40,6 @@ github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index 56ed5fd..8d53362 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -8,10 +8,10 @@ import ( "github.com/Selly-Modules/logger" "github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" "github.com/nats-io/nats.go" "github.com/thoas/go-funk" - "github.com/Selly-Modules/3pl/constant" "github.com/Selly-Modules/3pl/util/base64" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -70,7 +70,7 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CommonResponse, error) { Data: pjson.ToJSONString(body), }, } - msg, err := c.requestNats(constant.NatsCommunicationSubjectRequestHTTP, natsPayload) + msg, err := c.requestNats(subject.Communication.RequestHTTP, natsPayload) if err != nil { logger.Error("globalcare.Client.CreateOrder", logger.LogData{ "err": err.Error(), @@ -99,7 +99,7 @@ func (c *Client) GetOrder(orderCode string) (*CommonResponse, error) { Method: http.MethodGet, }, } - msg, err := c.requestNats(constant.NatsCommunicationSubjectRequestHTTP, natsPayload) + msg, err := c.requestNats(subject.Communication.RequestHTTP, natsPayload) if err != nil { logger.Error("globalcare.Client.GetOrder", logger.LogData{ "err": err.Error(), diff --git a/partnerapi/tnc/tnc.go b/partnerapi/tnc/tnc.go index 17e83fd..de2c7e0 100644 --- a/partnerapi/tnc/tnc.go +++ b/partnerapi/tnc/tnc.go @@ -9,9 +9,9 @@ import ( "github.com/Selly-Modules/logger" "github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" "github.com/nats-io/nats.go" - "github.com/Selly-Modules/3pl/constant" "github.com/Selly-Modules/3pl/util/pjson" ) @@ -288,9 +288,8 @@ func (c *Client) getRequestHeader() map[string]string { } func (c *Client) requestHttpViaNats(data model.CommunicationRequestHttp) (*nats.Msg, error) { - s := constant.NatsCommunicationSubjectRequestHTTP b := pjson.ToBytes(data) - return c.natsClient.Request(s, b) + return c.natsClient.Request(subject.Communication.RequestHTTP, b) } func (c *Client) getBaseURL() string { -- 2.34.1 From a0f382fd9c47e01f4c37f3cfd2e4484c65cd3fc1 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 29 Aug 2022 09:28:32 +0700 Subject: [PATCH 04/11] update nats module --- go.mod | 14 ++++++-------- go.sum | 35 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 98b1f93..881b3a0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,9 @@ go 1.17 require ( github.com/Selly-Modules/logger v0.0.1 - github.com/Selly-Modules/natsio v1.0.1-0.20220818104747-572120c26a1d + github.com/Selly-Modules/natsio v1.0.2-0.20220826163751-df340fefda0a + github.com/nats-io/nats.go v1.13.0 + github.com/thoas/go-funk v0.9.1 ) require ( @@ -14,21 +16,19 @@ require ( github.com/elastic/go-windows v1.0.0 // indirect github.com/jcchavezs/porto v0.1.0 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect - github.com/logrusorgru/aurora v2.0.3+incompatible // indirect - github.com/nats-io/nats.go v1.13.0 // indirect github.com/nats-io/nkeys v0.3.0 // indirect github.com/nats-io/nuid v1.0.1 // indirect - github.com/pkg/errors v0.8.1 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 // indirect github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect - github.com/thoas/go-funk v0.9.1 // indirect go.elastic.co/apm v1.13.1 // indirect go.elastic.co/apm/module/apmzap v1.13.1 // indirect go.elastic.co/fastjson v1.1.0 // indirect + go.mongodb.org/mongo-driver v1.10.1 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.18.1 // indirect - golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect + golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect golang.org/x/mod v0.3.0 // indirect golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect @@ -36,5 +36,3 @@ require ( golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect ) - -//replace github.com/Selly-Modules/natsio => /Users/sinh/Documents/dev/selly-module/natsio diff --git a/go.sum b/go.sum index bf59b4e..bb59017 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ github.com/Selly-Modules/logger v0.0.1 h1:dwLLtW53FfVBlklhdtFRB63eP0ofIh0IUQ/Gjgi0r5k= github.com/Selly-Modules/logger v0.0.1/go.mod h1:RWhSQ3F01an8KD00VjzRBZOMcE5eV2Cy0/l4ZkeieyU= -github.com/Selly-Modules/natsio v1.0.0 h1:2GHm7upYn0CmqKPwfg2AXNmaAHuL7V9l36M4BgOmQ4M= -github.com/Selly-Modules/natsio v1.0.0/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ= -github.com/Selly-Modules/natsio v1.0.1-0.20220818104747-572120c26a1d h1:NnRejDZPFqvtphr2rtfwi0rGx+oN8yD8RwttViVddjY= -github.com/Selly-Modules/natsio v1.0.1-0.20220818104747-572120c26a1d/go.mod h1:NG55g9ip18nvN5tfP6PcSEKec10/lOeIOZC8HqBVNlQ= +github.com/Selly-Modules/natsio v1.0.2-0.20220826163751-df340fefda0a h1:QmJ8iqksbU+1vUa2SijsAMSLnw1C5X4R8PYjuNPNCCE= +github.com/Selly-Modules/natsio v1.0.2-0.20220826163751-df340fefda0a/go.mod h1:q9dqmiMyl9MUVYZsvAWDI85083rnLEGAEFfYajLOLUU= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= @@ -26,10 +24,12 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/jcchavezs/porto v0.1.0 h1:Xmxxn25zQMmgE7/yHYmh19KcItG81hIwfbEEFnd6w/Q= @@ -37,15 +37,15 @@ github.com/jcchavezs/porto v0.1.0/go.mod h1:fESH0gzDHiutHRdX2hv27ojnOVFco37hg1W6 github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= -github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= -github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU= github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= github.com/nats-io/jwt/v2 v2.0.3 h1:i/O6cmIsjpcQyWDYNcq2JyZ3/VTF8SJ4JWluI5OhpvI= @@ -61,8 +61,9 @@ github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 h1:c8R11WC8m7KNMkTv/0+Be8vvwo4I3/Ut9AC2FW8fX3U= @@ -77,6 +78,11 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.elastic.co/apm v1.13.1 h1:ICIcUcQOImg/bve9mQVyLCvm1cSUZ1afdwK6ACnxczU= go.elastic.co/apm v1.13.1/go.mod h1:dylGv2HKR0tiCV+wliJz1KHtDyuD8SPe69oV7VyK6WY= @@ -84,6 +90,8 @@ go.elastic.co/apm/module/apmzap v1.13.1 h1:Soa4vNYYabPvOW1vm1A00C0UcEmfEzcx3YBjA go.elastic.co/apm/module/apmzap v1.13.1/go.mod h1:Tu8/TwffpBoNGmI05VcL1Ye2AC8oXrlMKNaKD1TIQy0= go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= +go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4= +go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= @@ -99,8 +107,9 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= @@ -113,20 +122,25 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -157,7 +171,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M= howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= -- 2.34.1 From fb104bb0bd2bd669a019ac703d735d2c2e6f7898 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 31 Aug 2022 14:21:43 +0700 Subject: [PATCH 05/11] define webhook global care --- partnerapi/globalcare/model_request.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/partnerapi/globalcare/model_request.go b/partnerapi/globalcare/model_request.go index a520bb7..d991ba0 100644 --- a/partnerapi/globalcare/model_request.go +++ b/partnerapi/globalcare/model_request.go @@ -1,5 +1,7 @@ package globalcare +import "time" + // CommonRequestBody ... type CommonRequestBody struct { Signature string `json:"signature"` @@ -41,3 +43,11 @@ type InsuredInfo struct { YearsOfInsurance string `json:"yearsOfInsurance"` BeginDate string `json:"beginDate"` } + +// Webhook ... +type Webhook struct { + Status int `json:"status"` + OrderCode string `json:"orderCode"` + UpdatedAt time.Time `json:"updatedAt"` + Note string `json:"note"` +} -- 2.34.1 From e354f157a0541f92b8553a4725bb51b92432f1d6 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 31 Aug 2022 17:52:52 +0700 Subject: [PATCH 06/11] add header content type for GC --- partnerapi/globalcare/globale_care.go | 3 +++ partnerapi/globalcare/nats.go | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 partnerapi/globalcare/nats.go diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index 41f7ef7..d7f08eb 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -79,6 +79,9 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded, URL: url, Method: http.MethodPost, Data: pjson.ToJSONString(body), + Header: map[string]string{ + "Content-Type": "application/json", + }, }, } msg, err := c.requestNats(subject.Communication.RequestHTTP, natsPayload) diff --git a/partnerapi/globalcare/nats.go b/partnerapi/globalcare/nats.go deleted file mode 100644 index 7ae04ff..0000000 --- a/partnerapi/globalcare/nats.go +++ /dev/null @@ -1 +0,0 @@ -package globalcare -- 2.34.1 From bc3db15466e86497cf030d97301b17e1d8b720fe Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 5 Sep 2022 14:18:01 +0700 Subject: [PATCH 07/11] add debug log --- partnerapi/globalcare/globale_care.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index d7f08eb..1056a71 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -7,6 +7,7 @@ import ( "crypto/sha256" "errors" "fmt" + "log" "net/http" "github.com/Selly-Modules/logger" @@ -97,24 +98,30 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded, res CommonResponse ) if err = pjson.Unmarshal(msg.Data, &r); err != nil { + log.Printf("globalcare.Client.CreateOrder - pjson.Unmarshal %v, %s\n", err, string(msg.Data)) return nil, err } if err = r.ParseResponseData(&res); err != nil { + log.Printf("globalcare.Client.CreateOrder - ParseResponseData %v, %s\n", err, string(msg.Data)) return nil, err } if r.Response == nil { + log.Println("globalcare.Client.CreateOrder - nil response") return nil, fmt.Errorf("globalcare.Client.CreateOrder create_order_empty_response") } if r.Response.StatusCode >= http.StatusBadRequest { + log.Println("globalcare.Client.CreateOrder - bad request", res) info, err := res.DecodeError() if err != nil { + log.Println("globalcare.Client.CreateOrder - decode err", err) return nil, err } return nil, errors.New(info.Message) } info, err := res.DecodeCreateOrderSuccess() if err != nil { + log.Println("globalcare.Client.CreateOrder - DecodeCreateOrderSuccess err:", err) return nil, err } -- 2.34.1 From f9046088ea74452974d14ddefb1bb9de293aeccb Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 5 Sep 2022 14:33:39 +0700 Subject: [PATCH 08/11] add debug log --- partnerapi/globalcare/globale_care.go | 2 +- partnerapi/globalcare/model_response.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index 1056a71..13bc995 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -121,7 +121,7 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded, } info, err := res.DecodeCreateOrderSuccess() if err != nil { - log.Println("globalcare.Client.CreateOrder - DecodeCreateOrderSuccess err:", err) + log.Println("globalcare.Client.CreateOrder - DecodeCreateOrderSuccess err:", err, string(msg.Data)) return nil, err } diff --git a/partnerapi/globalcare/model_response.go b/partnerapi/globalcare/model_response.go index 8bf04b1..0e035a5 100644 --- a/partnerapi/globalcare/model_response.go +++ b/partnerapi/globalcare/model_response.go @@ -10,19 +10,19 @@ type CommonResponse struct { // DecodeCreateOrderSuccess ... func (r *CommonResponse) DecodeCreateOrderSuccess() (res CreateOrderResponseDecoded, err error) { - err = r.Decode(res) + err = r.Decode(&res) return res, err } // DecodeGetOrderSuccess ... func (r *CommonResponse) DecodeGetOrderSuccess() (res GetOrderResponseDecoded, err error) { - err = r.Decode(res) + err = r.Decode(&res) return res, err } // DecodeError ... func (r *CommonResponse) DecodeError() (res ResponseError, err error) { - err = r.Decode(res) + err = r.Decode(&res) return res, err } -- 2.34.1 From 68fe77da6cbd02b7131ab3a0fcf4e552529afe49 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 5 Sep 2022 15:07:26 +0700 Subject: [PATCH 09/11] fix GC parse data --- partnerapi/globalcare/model_response.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/partnerapi/globalcare/model_response.go b/partnerapi/globalcare/model_response.go index 0e035a5..1da624c 100644 --- a/partnerapi/globalcare/model_response.go +++ b/partnerapi/globalcare/model_response.go @@ -1,6 +1,10 @@ package globalcare -import "encoding/json" +import ( + "encoding/json" + + "github.com/Selly-Modules/3pl/util/base64" +) // CommonResponse ... type CommonResponse struct { @@ -28,7 +32,8 @@ func (r *CommonResponse) DecodeError() (res ResponseError, err error) { // Decode ... func (r *CommonResponse) Decode(resultPointer interface{}) error { - return json.Unmarshal([]byte(r.Data), resultPointer) + b := base64.Decode(r.Data) + return json.Unmarshal(b, resultPointer) } // CreateOrderResponseDecoded ... -- 2.34.1 From dcb2bb5d7351e0f765526b25589a4c93e2677bc1 Mon Sep 17 00:00:00 2001 From: Sinh Date: Tue, 6 Sep 2022 11:08:35 +0700 Subject: [PATCH 10/11] update order OR model --- partnerapi/globalcare/model_request.go | 1 + 1 file changed, 1 insertion(+) diff --git a/partnerapi/globalcare/model_request.go b/partnerapi/globalcare/model_request.go index d991ba0..eb595c8 100644 --- a/partnerapi/globalcare/model_request.go +++ b/partnerapi/globalcare/model_request.go @@ -50,4 +50,5 @@ type Webhook struct { OrderCode string `json:"orderCode"` UpdatedAt time.Time `json:"updatedAt"` Note string `json:"note"` + CertLink string `json:"certLink"` } -- 2.34.1 From ab895e78cbd64a1c387b40eae1c15f99efa7a1a1 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 9 Sep 2022 09:47:24 +0700 Subject: [PATCH 11/11] update GC webhook model --- partnerapi/globalcare/model_request.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/partnerapi/globalcare/model_request.go b/partnerapi/globalcare/model_request.go index eb595c8..154d44a 100644 --- a/partnerapi/globalcare/model_request.go +++ b/partnerapi/globalcare/model_request.go @@ -46,9 +46,10 @@ type InsuredInfo struct { // Webhook ... type Webhook struct { - Status int `json:"status"` - OrderCode string `json:"orderCode"` - UpdatedAt time.Time `json:"updatedAt"` - Note string `json:"note"` - CertLink string `json:"certLink"` + Status int `json:"status"` + OrderCode string `json:"orderCode"` + UpdatedAt time.Time `json:"updatedAt"` + Note string `json:"note"` + CertLink string `json:"certLink"` + PartnerOrderCode string `json:"partnerOrderCode"` } -- 2.34.1