Skip to content

Commit

Permalink
* Modifies behavior to pass bid floor as is when it cannot be convert…
Browse files Browse the repository at this point in the history
…ed to USD;

* Removes rounding of bid floor when converting its currency to USD;
  • Loading branch information
lshishkov committed Oct 2, 2024
1 parent ff11c0c commit 638c39e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
19 changes: 6 additions & 13 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,19 @@ export const spec = {
registerBidder(spec);

const convertBidFloorCurrency = (imp) => {
const omitBidFloor = () => {
delete imp.bidfloor;
delete imp.bidfloorcur;
logWarn('Cannot convert bid floor currency. Omitting bid floor from request.');
};

try {
imp.bidfloor = parseFloat(convertCurrency(
const bidFloor = convertCurrency(
imp.bidfloor,
imp.bidfloorcur.toUpperCase(),
DEFAULT_CURRENCY,
false,
).toFixed(2));
imp.bidfloorcur = DEFAULT_CURRENCY;

if (isNaN(imp.bidfloor)) {
omitBidFloor();
);
if (typeof bidFloor === 'number' && !isNaN(bidFloor)) {
imp.bidfloor = bidFloor;
imp.bidfloorcur = DEFAULT_CURRENCY;
}
} catch (err) {
omitBidFloor();
logWarn(`Failed to convert bid floor to ${DEFAULT_CURRENCY}. Passing floor price in its original currency.`, err);
}
};

Expand Down
8 changes: 4 additions & 4 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,17 @@ describe('Improve Digital Adapter Tests', function () {
expect(payload.imp[0].bidfloor).to.equal(0.05);
expect(payload.imp[0].bidfloorcur).to.equal('USD');

// Floor price omitted when currency cannot be converted to default bid adapter currency
// Floor price sent as is when currency cannot be converted to default bid adapter currency
bidRequest.params.bidFloorCur = 'UAH';
bidRequest.params.bidFloor = 0.05;
payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data);
expect(payload.imp[0].bidfloor).to.be.undefined;
expect(payload.imp[0].bidfloorcur).to.not.exist;
expect(payload.imp[0].bidfloor).to.equal(0.05);
expect(payload.imp[0].bidfloorcur).to.equal('UAH');

// Floor price currency converted to default bid adapter currency
bidRequest.params.bidFloorCur = 'eUR';
payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data);
expect(payload.imp[0].bidfloor).to.equal(0.09);
expect(payload.imp[0].bidfloor).to.equal(0.08750000000000001);
expect(payload.imp[0].bidfloorcur).to.equal('USD');

// getFloor defined -> use it over bidFloor
Expand Down

0 comments on commit 638c39e

Please sign in to comment.