From ed37e02fdf64cdc039f84a5c5f435b721f1c9fc9 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 28 Sep 2022 08:58:24 +0700 Subject: [PATCH] update global care - integrate car insurance --- partnerapi/globalcare/const.go | 38 +++++++++++++------- partnerapi/globalcare/globale_care.go | 11 +----- partnerapi/globalcare/model_request.go | 49 +++++++++++++++++++------- 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/partnerapi/globalcare/const.go b/partnerapi/globalcare/const.go index 00d6aeb..cec8416 100644 --- a/partnerapi/globalcare/const.go +++ b/partnerapi/globalcare/const.go @@ -20,19 +20,33 @@ const ( ) const ( - VehicleTypeID50ccAbove = 1 - VehicleTypeID50ccBelow = 2 - VehicleTypeIDElectricBike = 3 + MotorbikeProductCode = "bbxm" + MotorbikeProviderID = 4 + MotorbikeProductID = 18 + + CarProductCode = "bbot" + CarProviderID = 10 + CarProductID = 35 + + NumOfSeatsMinValue = 25 ) -const ( - CarOccupantAccidentInsurance0 = 1 - CarOccupantAccidentInsurance10m = 2 - CarOccupantAccidentInsurance20m = 3 -) +type InsuranceConfig struct { + ProductCode string + ProviderID int + ProductID int +} -const ( - productCodeDefault = "bbxm" - providerIDDefault = 4 - productIDDefault = 18 +var ( + CarConfig = InsuranceConfig{ + ProductCode: CarProductCode, + ProviderID: CarProviderID, + ProductID: CarProductID, + } + + MotorbikeConfig = InsuranceConfig{ + ProductCode: MotorbikeProductCode, + ProviderID: MotorbikeProviderID, + ProductID: MotorbikeProductID, + } ) diff --git a/partnerapi/globalcare/globale_care.go b/partnerapi/globalcare/globale_care.go index 13bc995..3a2ab0c 100644 --- a/partnerapi/globalcare/globale_care.go +++ b/partnerapi/globalcare/globale_care.go @@ -54,17 +54,8 @@ func NewClient(env ENV, privateKey, publicKey string, natsClient natsio.Server) } // CreateOrder ... -func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded, error) { +func (c *Client) CreateOrder(data CreateOrderPayload) (*CreateOrderResponseDecoded, error) { url := c.getBaseURL() + apiPathCreateOrder - data := createOrderData{ - ProductCode: productCodeDefault, - ProviderID: providerIDDefault, - ProductID: productIDDefault, - PartnerID: p.PartnerOrderCode, - VehicleInfo: p.VehicleInfo, - InsuredInfo: p.InsuredInfo, - } - dataString := base64.Encode(pjson.ToBytes(data)) sign, err := c.signData(dataString) if err != nil { diff --git a/partnerapi/globalcare/model_request.go b/partnerapi/globalcare/model_request.go index 154d44a..2da031f 100644 --- a/partnerapi/globalcare/model_request.go +++ b/partnerapi/globalcare/model_request.go @@ -1,6 +1,9 @@ package globalcare -import "time" +import ( + "encoding/json" + "time" +) // CommonRequestBody ... type CommonRequestBody struct { @@ -10,12 +13,6 @@ type CommonRequestBody struct { // CreateOrderPayload ... type CreateOrderPayload struct { - PartnerOrderCode string `json:"partnerOrderCode"` - VehicleInfo VehicleInfo `json:"vehicleInfo"` - InsuredInfo InsuredInfo `json:"insuredInfo"` -} - -type createOrderData struct { ProductCode string `json:"productCode"` ProviderID int `json:"providerId"` ProductID int `json:"productId"` @@ -26,12 +23,38 @@ type createOrderData struct { // VehicleInfo ... type VehicleInfo struct { - TypeID int `json:"typeId"` - TypeName string `json:"typeName"` - CarOccupantAccidentInsurance int `json:"carOccupantAccidentInsurance"` - License string `json:"license"` - Chassis string `json:"chassis"` - Engine string `json:"engine"` + TypeID int `json:"typeId"` + TypeName string `json:"typeName"` + License string `json:"license"` + Chassis string `json:"chassis"` + Engine string `json:"engine"` + + // V2 = true if TypeID = 1 and insurance type is car + V2 bool `json:"v2,omitempty"` + // CarOccupantAccidentInsurance type int for motorbike, type CarOccupantAccidentInsuranceObj for car insurance + CarOccupantAccidentInsurance interface{} `json:"carOccupantAccidentInsurance"` + NumberOfSeatsOver25 int `json:"numberOfSeatsOver25"` + NumberOfSeatsOrTonnageName string `json:"numberOfSeatsOrTonnageName"` + NumberOfSeatsOrTonnage int `json:"numberOfSeatsOrTonnage"` +} + +// CarOccupantAccidentInsuranceObj ... +type CarOccupantAccidentInsuranceObj struct { + NumberOfSeats int `json:"numberOfSeats"` +} + +func (c *CarOccupantAccidentInsuranceObj) MarshalJSON() ([]byte, error) { + buy := 1 + if c.NumberOfSeats <= 0 { + buy = 2 + } + return json.Marshal(&struct { + Buy int `json:"buy"` + NumberOfSeats int `json:"numberOfSeats"` + }{ + Buy: buy, + NumberOfSeats: c.NumberOfSeats, + }) } // InsuredInfo ...