Merge pull request #4 from Selly-Modules/global-care-car-insurance

update global care - integrate car insurance
This commit is contained in:
Sinh Luu 2022-10-04 15:38:23 +07:00 committed by GitHub
commit c8868f34b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 35 deletions

View File

@ -20,19 +20,33 @@ const (
) )
const ( const (
VehicleTypeID50ccAbove = 1 MotorbikeProductCode = "bbxm"
VehicleTypeID50ccBelow = 2 MotorbikeProviderID = 4
VehicleTypeIDElectricBike = 3 MotorbikeProductID = 18
CarProductCode = "bbot"
CarProviderID = 10
CarProductID = 35
NumOfSeatsMinValue = 25
) )
const ( type InsuranceConfig struct {
CarOccupantAccidentInsurance0 = 1 ProductCode string
CarOccupantAccidentInsurance10m = 2 ProviderID int
CarOccupantAccidentInsurance20m = 3 ProductID int
) }
const ( var (
productCodeDefault = "bbxm" CarConfig = InsuranceConfig{
providerIDDefault = 4 ProductCode: CarProductCode,
productIDDefault = 18 ProviderID: CarProviderID,
ProductID: CarProductID,
}
MotorbikeConfig = InsuranceConfig{
ProductCode: MotorbikeProductCode,
ProviderID: MotorbikeProviderID,
ProductID: MotorbikeProductID,
}
) )

View File

@ -54,17 +54,8 @@ func NewClient(env ENV, privateKey, publicKey string, natsClient natsio.Server)
} }
// CreateOrder ... // CreateOrder ...
func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded, error) { func (c *Client) CreateOrder(data CreateOrderPayload) (*CreateOrderResponseDecoded, error) {
url := c.getBaseURL() + apiPathCreateOrder 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)) dataString := base64.Encode(pjson.ToBytes(data))
sign, err := c.signData(dataString) sign, err := c.signData(dataString)
if err != nil { if err != nil {

View File

@ -1,6 +1,9 @@
package globalcare package globalcare
import "time" import (
"encoding/json"
"time"
)
// CommonRequestBody ... // CommonRequestBody ...
type CommonRequestBody struct { type CommonRequestBody struct {
@ -10,12 +13,6 @@ type CommonRequestBody struct {
// CreateOrderPayload ... // CreateOrderPayload ...
type CreateOrderPayload struct { type CreateOrderPayload struct {
PartnerOrderCode string `json:"partnerOrderCode"`
VehicleInfo VehicleInfo `json:"vehicleInfo"`
InsuredInfo InsuredInfo `json:"insuredInfo"`
}
type createOrderData struct {
ProductCode string `json:"productCode"` ProductCode string `json:"productCode"`
ProviderID int `json:"providerId"` ProviderID int `json:"providerId"`
ProductID int `json:"productId"` ProductID int `json:"productId"`
@ -28,10 +25,36 @@ type createOrderData struct {
type VehicleInfo struct { type VehicleInfo struct {
TypeID int `json:"typeId"` TypeID int `json:"typeId"`
TypeName string `json:"typeName"` TypeName string `json:"typeName"`
CarOccupantAccidentInsurance int `json:"carOccupantAccidentInsurance"`
License string `json:"license"` License string `json:"license"`
Chassis string `json:"chassis"` Chassis string `json:"chassis"`
Engine string `json:"engine"` 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 ... // InsuredInfo ...