update global care - integrate car insurance

This commit is contained in:
Sinh 2022-09-28 08:58:24 +07:00
parent b627377b17
commit ed37e02fdf
3 changed files with 63 additions and 35 deletions

View File

@ -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,
}
)

View File

@ -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 {

View File

@ -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 ...