payments/pricing/pricing_pfm63.go

92 lines
2.3 KiB
Go

package pricing
import (
"slices"
"github.com/rs/zerolog/log"
)
const (
PFM63_CC_CHAVAILLON_COMBAILLES_VOLCANS = "200071215"
PFM63_CC_DOMES_SANCY_ARTENSE = "200069169"
PFM63_CC_AMBERT_LIVRADOIS_FOREZ = "200070761"
PFM63_COM_CLERMONT = "63113"
PFM63_COM_USSEL = "19275"
PFM63_COM_AUBUSSON = "23008"
PFM63_COM_RIOM = "63300"
)
type PFM63PricingService struct{}
func NewPFM63PricingService() (*PFM63PricingService, error) {
return &PFM63PricingService{}, nil
}
func (s *PFM63PricingService) Prices(params PricingParams) (map[string]Price, error) {
log.Debug().Any("params", params).Msg("get price")
free_trips := 0
fixedCityPrices := []string{}
switch params.Beneficiary.Address.IntercommunalityCode {
case PFM63_CC_CHAVAILLON_COMBAILLES_VOLCANS:
fixedCityPrices = []string{PFM63_COM_CLERMONT, PFM63_COM_AUBUSSON, PFM63_COM_RIOM, PFM63_COM_USSEL}
case PFM63_CC_DOMES_SANCY_ARTENSE:
fixedCityPrices = []string{PFM63_COM_CLERMONT, PFM63_COM_USSEL}
case PFM63_CC_AMBERT_LIVRADOIS_FOREZ:
free_trips = 1
}
passenger_distance := params.SharedMobility.PassengerDistance
pricing := 0.0
if params.Beneficiary.History < free_trips {
pricing = 0
} else if params.Beneficiary.Priority && params.Beneficiary.History <= 5 {
pricing = 0
} else if slices.Contains(fixedCityPrices, params.SharedMobility.Destination.CityCode) {
if params.SharedMobility.OutwardOnly {
pricing = 5
} else {
pricing = 10
}
} else if passenger_distance < 15 {
pricing = 2
} else if passenger_distance < 30 {
pricing = 4
} else if passenger_distance < 45 {
pricing = 6
} else if passenger_distance < 60 {
pricing = 7
} else if passenger_distance < 75 {
pricing = 9
} else if passenger_distance < 90 {
pricing = 10
} else if passenger_distance < 105 {
pricing = 12
} else if passenger_distance < 120 {
pricing = 15
} else if passenger_distance < 140 {
pricing = 17
} else {
pricing = 17
log.Error().Msg("no pricing case found")
}
kmCompensation := 0.22
if params.MobilityType == "carpool" {
kmCompensation = 0.09
}
return map[string]Price{
"passenger": {
Amount: pricing,
Currency: "EUR/2",
},
"driver": {
Amount: kmCompensation * float64(params.SharedMobility.DriverDistance),
Currency: "EUR/2",
},
}, nil
}