Skip to content

Commit

Permalink
PgamSSP: Add currency converter (#3907)
Browse files Browse the repository at this point in the history
  • Loading branch information
PGAMSSP authored Nov 4, 2024
1 parent a788661 commit 3403544
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
12 changes: 12 additions & 0 deletions adapters/pgamssp/pgamssp.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/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
Expand Down Expand Up @@ -39,6 +40,17 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E

reqCopy := *request
for _, imp := range request.Imp {

// Check if imp comes with bid floor amount defined in a foreign currency
if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
// Convert to US dollars
convertedValue, err := reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err == nil {
imp.BidFloorCur = "USD"
imp.BidFloor = convertedValue
}
}

reqCopy.Imp = []openrtb2.Imp{imp}

var bidderExt adapters.ExtImpBidder
Expand Down
154 changes: 154 additions & 0 deletions adapters/pgamssp/pgamssptest/exemplary/convert_currency.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"mockBidRequest": {
"id": "test-request-id",
"device": {
"ip": "123.123.123.123",
"ua": "iPad"
},
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"imp": [
{
"id": "test-imp-id",
"tagid": "test",
"bidfloor": 1,
"bidfloorcur": "GBP",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"placementId": "test"
}
}
}
],
"ext": {
"prebid": {
"currency": {
"rates": {
"GBP": {
"USD": 0.05
}
}
}
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://test.com/pserver",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"tagid": "test",
"bidfloor": 0.05,
"bidfloorcur": "USD",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"placementId": "test",
"type": "publisher"
}
}
}
],
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"device": {
"ip": "123.123.123.123",
"ua": "iPad"
},
"ext": {
"prebid": {
"currency": {
"rates": {
"GBP": {
"USD": 0.05
}
}
}
}
}
},
"impIDs": [
"test-imp-id"
]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"bid": [
{
"id": "test_bid_id",
"impid": "test-imp-id",
"price": 0.27543,
"adm": "<iframe id=\"adm-banner-16\" width=\"300\" height=\"250\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"{overflow:hidden}\" src=\"http://test.com/pserver&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1
}
],
"seat": "pgamssp"
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "test_bid_id",
"impid": "test-imp-id",
"price": 0.27543,
"adm": "<iframe id=\"adm-banner-16\" width=\"300\" height=\"250\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"{overflow:hidden}\" src=\"http://test.com/pserver&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"mtype": 1
},
"type": "banner"
}
]
}
]
}

0 comments on commit 3403544

Please sign in to comment.