Skip to content

Commit

Permalink
Conversant: Make requests in USD (#3611)
Browse files Browse the repository at this point in the history
Co-authored-by: johwier <john.wier@epsilon.com>
  • Loading branch information
johnwier and johwier authored Apr 25, 2024
1 parent 440ba5c commit 5e7c824
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
23 changes: 21 additions & 2 deletions adapters/conversant/conversant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/prebid/openrtb/v20/adcom1"
"github.com/prebid/openrtb/v20/openrtb2"
Expand All @@ -18,6 +19,10 @@ type ConversantAdapter struct {
}

func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
//Backend needs USD or it will reject the request
if len(request.Cur) > 0 && request.Cur[0] != "USD" {
request.Cur = []string{"USD"}
}
for i := 0; i < len(request.Imp); i++ {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(request.Imp[i].Ext, &bidderExt); err != nil {
Expand Down Expand Up @@ -50,7 +55,10 @@ func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *
request.App.ID = cnvrExt.SiteID
}
}
parseCnvrParams(&request.Imp[i], cnvrExt)
err := parseCnvrParams(&request.Imp[i], cnvrExt, reqInfo)
if err != nil {
return nil, err
}
}

//create the request body
Expand All @@ -73,7 +81,7 @@ func (c *ConversantAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *
}}, nil
}

func parseCnvrParams(imp *openrtb2.Imp, cnvrExt openrtb_ext.ExtImpConversant) {
func parseCnvrParams(imp *openrtb2.Imp, cnvrExt openrtb_ext.ExtImpConversant, reqInfo *adapters.ExtraRequestInfo) []error {
imp.DisplayManager = "prebid-s2s"
imp.DisplayManagerVer = "2.0.0"

Expand Down Expand Up @@ -131,6 +139,17 @@ func parseCnvrParams(imp *openrtb2.Imp, cnvrExt openrtb_ext.ExtImpConversant) {
imp.Video.MaxDuration = *cnvrExt.MaxDuration
}
}
if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
floor, err := reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err != nil {
return []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unable to convert provided bid floor currency from %s to USD", imp.BidFloorCur),
}}
}
imp.BidFloorCur = "USD"
imp.BidFloor = floor
}
return nil
}

func (c *ConversantAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down
27 changes: 24 additions & 3 deletions adapters/conversant/conversanttest/exemplary/video.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"mockBidRequest": {
"id": "testauction",
"cur": ["EUR"],
"imp": [
{
"id": "1",
"video": {
"w": 300,
"h": 250
},
"bidfloor": 2.00,
"bidfloorcur": "EUR",
"ext": {
"bidder": {
"site_id": "108060",
"bidfloor": 0.01,
"tag_id": "mytag",
"secure": 1,
"mimes": ["video/mp4", "video/x-flv"],
Expand All @@ -31,6 +33,15 @@
},
"site": {
"domain": "www.mypage.com"
},
"ext": {
"prebid": {
"currency": {
"rates": {
"USD": {"EUR": 0.08}
}
}
}
}
},
"httpCalls": [
Expand All @@ -39,6 +50,7 @@
"uri": "",
"body": {
"id": "testauction",
"cur": ["USD"],
"site": {
"id": "108060",
"domain": "www.mypage.com"
Expand All @@ -48,7 +60,8 @@
"id": "1",
"tagid": "mytag",
"secure": 1,
"bidfloor": 0.01,
"bidfloor": 25.0,
"bidfloorcur": "USD",
"displaymanager": "prebid-s2s",
"displaymanagerver": "2.0.0",
"video": {
Expand All @@ -66,7 +79,6 @@
"ext": {
"bidder": {
"site_id": "108060",
"bidfloor": 0.01,
"tag_id": "mytag",
"secure": 1,
"mimes": [
Expand All @@ -86,6 +98,15 @@
"ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36",
"ip": "192.168.1.1",
"dnt": 1
},
"ext": {
"prebid": {
"currency": {
"rates": {
"USD": {"EUR": 0.08}
}
}
}
}
},
"impIDs":["1"]
Expand Down

0 comments on commit 5e7c824

Please sign in to comment.