-
Notifications
You must be signed in to change notification settings - Fork 739
/
currency.go
42 lines (34 loc) · 1.57 KB
/
currency.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package currency
import (
"github.com/prebid/prebid-server/v2/openrtb_ext"
)
func GetAuctionCurrencyRates(currencyConverter *RateConverter, requestRates *openrtb_ext.ExtRequestCurrency) Conversions {
if currencyConverter == nil && requestRates == nil {
return nil
}
if requestRates == nil {
// No bidRequest.ext.currency field was found, use PBS rates as usual
return currencyConverter.Rates()
}
// currencyConverter will never be nil, refer main.serve(), adding this check for future usecases
if currencyConverter == nil {
return NewRates(requestRates.ConversionRates)
}
// If bidRequest.ext.currency.usepbsrates is nil, we understand its value as true. It will be false
// only if it's explicitly set to false
usePbsRates := requestRates.UsePBSRates == nil || *requestRates.UsePBSRates
if !usePbsRates {
// At this point, we can safely assume the ConversionRates map is not empty because
// validateCustomRates(bidReqCurrencyRates *openrtb_ext.ExtRequestCurrency) would have
// thrown an error under such conditions.
return NewRates(requestRates.ConversionRates)
}
// Both PBS and custom rates can be used, check if ConversionRates is not empty
if len(requestRates.ConversionRates) == 0 {
// Custom rates map is empty, use PBS rates only
return currencyConverter.Rates()
}
// Return an AggregateConversions object that includes both custom and PBS currency rates but will
// prioritize custom rates over PBS rates whenever a currency rate is found in both
return NewAggregateConversions(NewRates(requestRates.ConversionRates), currencyConverter.Rates())
}