From e3d781e496c4e7db850bddbaeedec346fd6503e8 Mon Sep 17 00:00:00 2001 From: ademianenko Date: Mon, 28 Apr 2025 13:15:23 +0300 Subject: [PATCH] [PAY-5624] - added $exchange_rate --- Sift/Schema/ComplexTypes/booking.json | 6 + Sift/Schema/ComplexTypes/discount.json | 6 + Sift/Schema/ComplexTypes/exchange_rate.json | 18 ++ Sift/Schema/ComplexTypes/item.json | 6 + Sift/Schema/create_order.json | 6 + Sift/Schema/transaction.json | 6 + Sift/Schema/update_order.json | 6 + Sift/Schema/wager.json | 6 + Sift/Sift.csproj | 4 +- Test.Integration.Net7/EventsAPI/Order.cs | 21 ++- .../EventsAPI/Transactions.cs | 7 +- Test.Integration.Net7/EventsAPI/Wagers.cs | 7 +- Test.Integration.NetFx48/EventsAPI/Order.cs | 21 ++- .../EventsAPI/Transactions.cs | 7 +- Test.Integration.NetFx48/EventsAPI/Wagers.cs | 7 +- Test/Test.cs | 158 +++++++++++++++++- 16 files changed, 278 insertions(+), 14 deletions(-) create mode 100644 Sift/Schema/ComplexTypes/exchange_rate.json diff --git a/Sift/Schema/ComplexTypes/booking.json b/Sift/Schema/ComplexTypes/booking.json index 3d3252fb..74e969bb 100644 --- a/Sift/Schema/ComplexTypes/booking.json +++ b/Sift/Schema/ComplexTypes/booking.json @@ -25,6 +25,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "exchange_rate.json" }, + { "type": "null" } + ] + }, "$iata_carrier_code": { "type": [ "string", "null" ] }, diff --git a/Sift/Schema/ComplexTypes/discount.json b/Sift/Schema/ComplexTypes/discount.json index 3cecbcaf..1c650d83 100644 --- a/Sift/Schema/ComplexTypes/discount.json +++ b/Sift/Schema/ComplexTypes/discount.json @@ -13,6 +13,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "exchange_rate.json" }, + { "type": "null" } + ] + }, "$minimum_purchase_amount": { "type": [ "integer", "null" ], "format": "long" diff --git a/Sift/Schema/ComplexTypes/exchange_rate.json b/Sift/Schema/ComplexTypes/exchange_rate.json new file mode 100644 index 00000000..ac74dd34 --- /dev/null +++ b/Sift/Schema/ComplexTypes/exchange_rate.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema", + "title": "ExchangeRate", + "type": "object", + "required": [ + "$quote_currency_code", + "$rate" + ], + "properties": { + "$quote_currency_code": { + "type": [ "string", "null" ] + }, + "$rate": { + "type": [ "number", "null" ], + "format": "float" + } + } +} \ No newline at end of file diff --git a/Sift/Schema/ComplexTypes/item.json b/Sift/Schema/ComplexTypes/item.json index d8ef4daa..901d86d7 100644 --- a/Sift/Schema/ComplexTypes/item.json +++ b/Sift/Schema/ComplexTypes/item.json @@ -16,6 +16,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "exchange_rate.json" }, + { "type": "null" } + ] + }, "$quantity": { "type": [ "integer", "null" ] }, diff --git a/Sift/Schema/create_order.json b/Sift/Schema/create_order.json index 8bb59197..985bd32d 100644 --- a/Sift/Schema/create_order.json +++ b/Sift/Schema/create_order.json @@ -27,6 +27,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "ComplexTypes/exchange_rate.json" }, + { "type": "null" } + ] + }, "$billing_address": { "oneOf": [ { "$ref": "ComplexTypes/address.json" }, diff --git a/Sift/Schema/transaction.json b/Sift/Schema/transaction.json index bceb3b9b..d8155b89 100644 --- a/Sift/Schema/transaction.json +++ b/Sift/Schema/transaction.json @@ -30,6 +30,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "ComplexTypes/exchange_rate.json" }, + { "type": "null" } + ] + }, "$order_id": { "type": [ "string", "null" ] }, diff --git a/Sift/Schema/update_order.json b/Sift/Schema/update_order.json index 9ea3089a..e55464ba 100644 --- a/Sift/Schema/update_order.json +++ b/Sift/Schema/update_order.json @@ -27,6 +27,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "ComplexTypes/exchange_rate.json" }, + { "type": "null" } + ] + }, "$billing_address": { "oneOf": [ { "$ref": "ComplexTypes/address.json" }, diff --git a/Sift/Schema/wager.json b/Sift/Schema/wager.json index db88bd24..ff0a996b 100644 --- a/Sift/Schema/wager.json +++ b/Sift/Schema/wager.json @@ -27,6 +27,12 @@ "$currency_code": { "type": [ "string", "null" ] }, + "$exchange_rate": { + "oneOf": [ + { "$ref": "ComplexTypes/exchange_rate.json" }, + { "type": "null" } + ] + }, "$wager_event_type": { "type": [ "string", "null" ] }, diff --git a/Sift/Sift.csproj b/Sift/Sift.csproj index 4c16f532..927b0abd 100644 --- a/Sift/Sift.csproj +++ b/Sift/Sift.csproj @@ -4,8 +4,8 @@ Sift Sift Sift - 1.5.0 - Release 1.5.0 + 1.6.0 + Release 1.6.0 netstandard2.0 Sift sift;siftscience;client;api;client;async diff --git a/Test.Integration.Net7/EventsAPI/Order.cs b/Test.Integration.Net7/EventsAPI/Order.cs index 002c57ee..6d71395c 100644 --- a/Test.Integration.Net7/EventsAPI/Order.cs +++ b/Test.Integration.Net7/EventsAPI/Order.cs @@ -56,7 +56,12 @@ private EventResponse CreateOrder(Client sift) order_id = OrderId, user_email = UserEmail, amount = 115940000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, billing_address = new Address() { name = "Bill Jones", @@ -122,7 +127,12 @@ private EventResponse CreateOrder(Client sift) item_id = ItemId, product_title = "Microwavable Kettle Corn: Original Flavor", price = 4990000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, upc = "097564307560", sku = "03586005", isbn = "0446576220", @@ -149,7 +159,12 @@ private EventResponse CreateOrder(Client sift) discount = new Discount() { amount = 5000000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, minimum_purchase_amount = 25000000 } } diff --git a/Test.Integration.Net7/EventsAPI/Transactions.cs b/Test.Integration.Net7/EventsAPI/Transactions.cs index 42c90f9b..14485d24 100644 --- a/Test.Integration.Net7/EventsAPI/Transactions.cs +++ b/Test.Integration.Net7/EventsAPI/Transactions.cs @@ -43,7 +43,12 @@ public void TransactionTest() transaction_type = "$sale", transaction_status = "$failure", amount = 506790000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, order_id = OrderId, transaction_id = TransactionId, billing_address = new Address() diff --git a/Test.Integration.Net7/EventsAPI/Wagers.cs b/Test.Integration.Net7/EventsAPI/Wagers.cs index 22ffa679..56cb0f3d 100644 --- a/Test.Integration.Net7/EventsAPI/Wagers.cs +++ b/Test.Integration.Net7/EventsAPI/Wagers.cs @@ -34,7 +34,12 @@ public void WagerTest() wager_type = "$parlay", wager_status = "$accept", amount = 5000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, minimum_wager_amount = 100L, wager_event_type = "NBA", wager_event_name = "Bulls-Lakers", diff --git a/Test.Integration.NetFx48/EventsAPI/Order.cs b/Test.Integration.NetFx48/EventsAPI/Order.cs index 75d8622b..2b7ef686 100644 --- a/Test.Integration.NetFx48/EventsAPI/Order.cs +++ b/Test.Integration.NetFx48/EventsAPI/Order.cs @@ -40,7 +40,12 @@ public void CreateOrder() order_id = OrderId, user_email = UserEmail, amount = 115940000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, billing_address = new Address() { name = "Bill Jones", @@ -106,7 +111,12 @@ public void CreateOrder() item_id = ItemId, product_title = "Microwavable Kettle Corn: Original Flavor", price = 4990000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, upc = "097564307560", sku = "03586005", isbn = "0446576220", @@ -133,7 +143,12 @@ public void CreateOrder() discount = new Discount() { amount = 5000000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, minimum_purchase_amount = 25000000 } } diff --git a/Test.Integration.NetFx48/EventsAPI/Transactions.cs b/Test.Integration.NetFx48/EventsAPI/Transactions.cs index 1d4bcc72..43647c26 100644 --- a/Test.Integration.NetFx48/EventsAPI/Transactions.cs +++ b/Test.Integration.NetFx48/EventsAPI/Transactions.cs @@ -39,7 +39,12 @@ public void TransactionTest() transaction_type = "$sale", transaction_status = "$failure", amount = 506790000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, order_id = OrderId, transaction_id = TransactionId, billing_address = new Address() diff --git a/Test.Integration.NetFx48/EventsAPI/Wagers.cs b/Test.Integration.NetFx48/EventsAPI/Wagers.cs index a9cff6db..013ded80 100644 --- a/Test.Integration.NetFx48/EventsAPI/Wagers.cs +++ b/Test.Integration.NetFx48/EventsAPI/Wagers.cs @@ -34,7 +34,12 @@ public void WagerTest() wager_type = "$parlay", wager_status = "$accept", amount = 5000, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, minimum_wager_amount = 100L, wager_event_type = "NBA", wager_event_name = "Bulls-Lakers", diff --git a/Test/Test.cs b/Test/Test.cs index 8d31f0b1..3546cfca 100644 --- a/Test/Test.cs +++ b/Test/Test.cs @@ -2763,7 +2763,12 @@ public void TestWagerEvent() wager_type = "$parlay", wager_status = "$accept", amount = 5000L, - currency_code = "USD", + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, wager_event_type = "NFL", wager_event_name = "Example Game", wager_event_id = "event456", @@ -2777,7 +2782,11 @@ public void TestWagerEvent() "\"$wager_type\":\"$parlay\"," + "\"$wager_status\":\"$accept\"," + "\"$amount\":5000," + - "\"$currency_code\":\"USD\"," + + "\"$currency_code\":\"EUR\"," + + "\"$exchange_rate\":{" + + "\"$quote_currency_code\":\"USD\"," + + "\"$rate\":1.14" + + "}," + "\"$wager_event_type\":\"NFL\"," + "\"$wager_event_name\":\"Example Game\"," + "\"$wager_event_id\":\"event456\"," + @@ -2801,6 +2810,151 @@ public void TestWagerEvent() Assert.Equal("https://api.sift.com/v205/events?abuse_types=legacy,payment_abuse&return_score=true", Uri.UnescapeDataString(eventRequest.Request.RequestUri!.ToString())); } + + [Fact] + public void TestTransactionEventWithExchangeRate() + { + //Please provide the valid session id in place of 'sessionId' + var sessionId = "sessionId"; + var transaction = new Transaction + { + user_id = "test_dotnet_transaction_event", + amount = 100000000L, + currency_code = "EUR", + session_id = sessionId, + transaction_type = "$deposit", + transaction_status = "$failure", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + }, + }; + + Assert.Equal("{" + + "\"$type\":\"$transaction\"," + + "\"$user_id\":\"test_dotnet_transaction_event\"," + + "\"$session_id\":\"sessionId\"," + + "\"$transaction_type\":\"$deposit\"," + + "\"$transaction_status\":\"$failure\"," + + "\"$amount\":100000000," + + "\"$currency_code\":\"EUR\"," + + "\"$exchange_rate\":{" + + "\"$quote_currency_code\":\"USD\"," + + "\"$rate\":1.14" + + "}" + + "}", transaction.ToJson()); + + EventRequest eventRequest = new EventRequest + { + Event = transaction + }; + + Assert.Equal("https://api.sift.com/v205/events", eventRequest.Request.RequestUri!.ToString()); + + eventRequest = new EventRequest + { + Event = transaction, + AbuseTypes = { "legacy", "payment_abuse" }, + ReturnScore = true + }; + + Assert.Equal("https://api.sift.com/v205/events?abuse_types=legacy,payment_abuse&return_score=true", + Uri.UnescapeDataString(eventRequest.Request.RequestUri!.ToString())); + } + + [Fact] + public void TestCreateOrderWithExchangeRate() + { + //Please provide the valid session id in place of 'sessionId' + var sessionId = "sessionId"; + var createOrder = new CreateOrder + { + user_id = "test_dotnet_order_with_all_exchange_rate_fields", + order_id = "oid", + amount = 1000000000000L, + currency_code = "EUR", + session_id = sessionId, + user_email = "bill@gmail.com", + bookings = new ObservableCollection() + { + new Booking() + { + booking_type = "$flight", + title = "SFO - LAS, 2 Adults", + start_time= 2038412903, + end_time= 2038412903, + price = 49900000, + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + } + } + }, + promotions = new ObservableCollection() + { + new Promotion() + { + discount = new Discount() + { + percentage_off = 0.2, + amount = 5000000, + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + } + } + } + }, + items = new ObservableCollection() + { + new Item() + { + item_id = "12344321", + price = 4990000, + currency_code = "EUR", + exchange_rate = new ExchangeRate + { + quote_currency_code = "USD", + rate = 1.14 + } + } + }, + }; + + // Augment with custom fields + Assert.Equal("{\"$type\":\"$create_order\",\"$user_id\":\"test_dotnet_order_with_all_exchange_rate_fields\"," + + "\"$session_id\":\"sessionId\",\"$order_id\":\"oid\",\"$user_email\":\"bill@gmail.com\",\"$amount\":1000000000000," + + "\"$currency_code\":\"EUR\",\"$items\":[{\"$item_id\":\"12344321\",\"$price\":4990000,\"$currency_code\":\"EUR\"," + + "\"$exchange_rate\":{\"$quote_currency_code\":\"USD\",\"$rate\":1.14}}],\"$bookings\":[{\"$booking_type\":\"$flight\"," + + "\"$title\":\"SFO - LAS, 2 Adults\",\"$start_time\":2038412903,\"$end_time\":2038412903,\"$price\":49900000," + + "\"$currency_code\":\"EUR\",\"$exchange_rate\":{\"$quote_currency_code\":\"USD\",\"$rate\":1.14}}],\"$promotions\":" + + "[{\"$discount\":{\"$percentage_off\":0.2,\"$amount\":5000000,\"$currency_code\":\"EUR\",\"$exchange_rate\":" + + "{\"$quote_currency_code\":\"USD\",\"$rate\":1.14}}}]}", createOrder.ToJson()); + + + EventRequest eventRequest = new EventRequest + { + Event = createOrder + }; + + Assert.Equal("https://api.sift.com/v205/events", eventRequest.Request.RequestUri!.ToString()); + + eventRequest = new EventRequest + { + Event = createOrder, + AbuseTypes = { "legacy", "payment_abuse" }, + ReturnScore = true, + ReturnRouteInfo = true + }; + + Assert.Equal("https://api.sift.com/v205/events?abuse_types=legacy,payment_abuse&return_score=true&return_route_info=true", + Uri.UnescapeDataString(eventRequest.Request.RequestUri!.ToString())); + } } }