From 34035447654e1a91ba11095c25c9d67cb51200d7 Mon Sep 17 00:00:00 2001
From: PGAMSSP <142323401+PGAMSSP@users.noreply.github.com>
Date: Mon, 4 Nov 2024 23:30:59 +0200
Subject: [PATCH] PgamSSP: Add currency converter (#3907)
---
adapters/pgamssp/pgamssp.go | 12 ++
.../exemplary/convert_currency.json | 154 ++++++++++++++++++
2 files changed, 166 insertions(+)
create mode 100644 adapters/pgamssp/pgamssptest/exemplary/convert_currency.json
diff --git a/adapters/pgamssp/pgamssp.go b/adapters/pgamssp/pgamssp.go
index 1b96edd5597..6ddf21159e0 100644
--- a/adapters/pgamssp/pgamssp.go
+++ b/adapters/pgamssp/pgamssp.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "strings"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
@@ -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
diff --git a/adapters/pgamssp/pgamssptest/exemplary/convert_currency.json b/adapters/pgamssp/pgamssptest/exemplary/convert_currency.json
new file mode 100644
index 00000000000..bdb2027714b
--- /dev/null
+++ b/adapters/pgamssp/pgamssptest/exemplary/convert_currency.json
@@ -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": "",
+ "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": "",
+ "cid": "test_cid",
+ "crid": "test_crid",
+ "dealid": "test_dealid",
+ "w": 300,
+ "h": 250,
+ "mtype": 1
+ },
+ "type": "banner"
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file