From e4c607c66b478abb07e493ee522356148021fc60 Mon Sep 17 00:00:00 2001 From: Haneesh Date: Thu, 3 Aug 2023 13:50:42 +0530 Subject: [PATCH 01/11] Integration testing files --- examples/reserved_events/test_event.py | 1 + .../verification_api/test_verification_api.py | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 examples/reserved_events/test_event.py create mode 100644 examples/verification_api/test_verification_api.py diff --git a/examples/reserved_events/test_event.py b/examples/reserved_events/test_event.py new file mode 100644 index 0000000..03f49e2 --- /dev/null +++ b/examples/reserved_events/test_event.py @@ -0,0 +1 @@ +import sift \ No newline at end of file diff --git a/examples/verification_api/test_verification_api.py b/examples/verification_api/test_verification_api.py new file mode 100644 index 0000000..1a422ef --- /dev/null +++ b/examples/verification_api/test_verification_api.py @@ -0,0 +1,60 @@ +import sift + +from os import environ as env + +# Get the value of API_KEY from environment variable +api_key = env['API_KEY'] + +client = sift.Client(api_key = api_key, account_id = 'ACCT') + +def test_verification_send(): + sendProperties = { + '$user_id': 'haneeshv@exalture.com', + '$send_to': 'haneeshv@exalture.com', + '$verification_type': '$email', + '$brand_name': 'MyTopBrand', + '$language': 'en', + '$site_country': 'IN', + '$event': { + '$session_id': 'SOME_SESSION_ID', + '$verified_event': '$login', + '$verified_entity_id': 'SOME_SESSION_ID', + '$reason': '$automated_rule', + '$ip': '192.168.1.1', + '$browser': { + '$user_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', + '$accept_language': 'en-US', + '$content_language': 'en-GB' + } + } + } + + response = client.verification_send(sendProperties) + print(response) + +def test_verification_resend(): + resendProperties = { + '$user_id': 'haneeshv@exalture.com', + '$verified_event': '$login', + '$verified_entity_id': 'SOME_SESSION_ID' + } + + response = client.verification_resend(resendProperties) + print(response) + +def test_verification_check(): + checkProperties = { + '$user_id': 'haneeshv@exalture.com', + '$code': '354290', + '$verified_event': '$login', + '$verified_entity_id': "SOME_SESSION_ID" + } + + response = client.verification_check(checkProperties) + print(response) + +# test_verification_send() + +# test_verification_resend() + +test_verification_check() \ No newline at end of file From 3dc9a4c9a361028119043ae1056984f6344b6c32 Mon Sep 17 00:00:00 2001 From: Haneesh Date: Fri, 4 Aug 2023 14:58:03 +0530 Subject: [PATCH 02/11] Testing App folder structure updated --- examples/reserved_events/test_event.py | 1 - test_client_library.py | 54 +++++++++++++++++++ .../decisions_api/__init__.py | 0 test_integration_app/events_api/__init__.py | 0 test_integration_app/events_api/test_event.py | 0 test_integration_app/labels_api/__init__.py | 0 test_integration_app/main.py | 16 ++++++ test_integration_app/score_api/__init__.py | 0 .../verifications_api/__init__.py | 1 + .../test_verification_api.py | 31 ++++++----- .../workflows_api/__init__.py | 0 11 files changed, 86 insertions(+), 17 deletions(-) delete mode 100644 examples/reserved_events/test_event.py create mode 100644 test_client_library.py create mode 100644 test_integration_app/decisions_api/__init__.py create mode 100644 test_integration_app/events_api/__init__.py create mode 100644 test_integration_app/events_api/test_event.py create mode 100644 test_integration_app/labels_api/__init__.py create mode 100644 test_integration_app/main.py create mode 100644 test_integration_app/score_api/__init__.py create mode 100644 test_integration_app/verifications_api/__init__.py rename {examples/verification_api => test_integration_app/verifications_api}/test_verification_api.py (66%) create mode 100644 test_integration_app/workflows_api/__init__.py diff --git a/examples/reserved_events/test_event.py b/examples/reserved_events/test_event.py deleted file mode 100644 index 03f49e2..0000000 --- a/examples/reserved_events/test_event.py +++ /dev/null @@ -1 +0,0 @@ -import sift \ No newline at end of file diff --git a/test_client_library.py b/test_client_library.py new file mode 100644 index 0000000..3932e7a --- /dev/null +++ b/test_client_library.py @@ -0,0 +1,54 @@ +from decimal import Decimal +import sift +import sys +from os import environ as env + +if sys.version_info[0] < 3: + import six.moves.urllib as urllib +else: + import urllib.parse + +def response_with_data_header(): + return { + 'content-type': 'application/json; charset=UTF-8' + } + +# Get the value of API_KEY from environment variable +api_key = env['API_KEY'] + +def test_add_item_to_cart(): + add_item_to_cart_properties = { + # Required Fields + "$user_id" : "haneeshv@exalture.com", + + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$item" : { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$currency_code" : "USD", + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 16 + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + client = sift.Client(api_key=api_key, account_id='ACCT') + response = client.track("$add_item_to_cart", add_item_to_cart_properties) + print(response) + +test_add_item_to_cart() \ No newline at end of file diff --git a/test_integration_app/decisions_api/__init__.py b/test_integration_app/decisions_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_integration_app/events_api/__init__.py b/test_integration_app/events_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_integration_app/events_api/test_event.py b/test_integration_app/events_api/test_event.py new file mode 100644 index 0000000..e69de29 diff --git a/test_integration_app/labels_api/__init__.py b/test_integration_app/labels_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_integration_app/main.py b/test_integration_app/main.py new file mode 100644 index 0000000..da2a284 --- /dev/null +++ b/test_integration_app/main.py @@ -0,0 +1,16 @@ +from verifications_api import test_verification_api + +def test_send(): + test_verification_api.test_verification_send() + +def test_resend(): + test_verification_api.test_verification_resend() + +def test_check(code): + test_verification_api.test_verification_check(code) + +test_send() + +# test_resend() + +# test_check(329311) \ No newline at end of file diff --git a/test_integration_app/score_api/__init__.py b/test_integration_app/score_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_integration_app/verifications_api/__init__.py b/test_integration_app/verifications_api/__init__.py new file mode 100644 index 0000000..192aad0 --- /dev/null +++ b/test_integration_app/verifications_api/__init__.py @@ -0,0 +1 @@ +from verifications_api import test_verification_api \ No newline at end of file diff --git a/examples/verification_api/test_verification_api.py b/test_integration_app/verifications_api/test_verification_api.py similarity index 66% rename from examples/verification_api/test_verification_api.py rename to test_integration_app/verifications_api/test_verification_api.py index 1a422ef..f38c727 100644 --- a/examples/verification_api/test_verification_api.py +++ b/test_integration_app/verifications_api/test_verification_api.py @@ -1,11 +1,10 @@ import sift from os import environ as env - -# Get the value of API_KEY from environment variable + # Get the value of API_KEY from environment variable api_key = env['API_KEY'] +client = sift.Client(api_key = api_key) -client = sift.Client(api_key = api_key, account_id = 'ACCT') def test_verification_send(): sendProperties = { @@ -30,9 +29,11 @@ def test_verification_send(): } response = client.verification_send(sendProperties) - print(response) - -def test_verification_resend(): + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def test_verification_resend(): resendProperties = { '$user_id': 'haneeshv@exalture.com', '$verified_event': '$login', @@ -40,21 +41,19 @@ def test_verification_resend(): } response = client.verification_resend(resendProperties) - print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" -def test_verification_check(): +def test_verification_check(code): checkProperties = { '$user_id': 'haneeshv@exalture.com', - '$code': '354290', + '$code': code, '$verified_event': '$login', '$verified_entity_id': "SOME_SESSION_ID" } response = client.verification_check(checkProperties) - print(response) - -# test_verification_send() - -# test_verification_resend() - -test_verification_check() \ No newline at end of file + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" diff --git a/test_integration_app/workflows_api/__init__.py b/test_integration_app/workflows_api/__init__.py new file mode 100644 index 0000000..e69de29 From a5a5a70ad5286b77c8eb3da5af441315a150b26e Mon Sep 17 00:00:00 2001 From: haneeshv <135820493+haneeshv@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:00:25 +0530 Subject: [PATCH 03/11] Delete test_client_library.py --- test_client_library.py | 54 ------------------------------------------ 1 file changed, 54 deletions(-) delete mode 100644 test_client_library.py diff --git a/test_client_library.py b/test_client_library.py deleted file mode 100644 index 3932e7a..0000000 --- a/test_client_library.py +++ /dev/null @@ -1,54 +0,0 @@ -from decimal import Decimal -import sift -import sys -from os import environ as env - -if sys.version_info[0] < 3: - import six.moves.urllib as urllib -else: - import urllib.parse - -def response_with_data_header(): - return { - 'content-type': 'application/json; charset=UTF-8' - } - -# Get the value of API_KEY from environment variable -api_key = env['API_KEY'] - -def test_add_item_to_cart(): - add_item_to_cart_properties = { - # Required Fields - "$user_id" : "haneeshv@exalture.com", - - # Supported Fields - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$item" : { - "$item_id" : "B004834GQO", - "$product_title" : "The Slanket Blanket-Texas Tea", - "$price" : 39990000, # $39.99 - "$currency_code" : "USD", - "$upc" : "6786211451001", - "$sku" : "004834GQ", - "$brand" : "Slanket", - "$manufacturer" : "Slanket", - "$category" : "Blankets & Throws", - "$tags" : ["Awesome", "Wintertime specials"], - "$color" : "Texas Tea", - "$quantity" : 16 - }, - "$brand_name" : "sift", - "$site_domain" : "sift.com", - "$site_country" : "US", - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - client = sift.Client(api_key=api_key, account_id='ACCT') - response = client.track("$add_item_to_cart", add_item_to_cart_properties) - print(response) - -test_add_item_to_cart() \ No newline at end of file From 5a7efabcb950f33199b52f4dfc3386b31aa29ec7 Mon Sep 17 00:00:00 2001 From: Haneesh Date: Tue, 22 Aug 2023 15:35:01 +0530 Subject: [PATCH 04/11] Integration files added --- .../decisions_api/__init__.py | 1 + .../decisions_api/test_decisions_api.py | 93 ++ test_integration_app/events_api/__init__.py | 1 + test_integration_app/events_api/test_event.py | 0 .../events_api/test_events_api.py | 1408 +++++++++++++++++ test_integration_app/labels_api/__init__.py | 1 + .../labels_api/test_labels_api.py | 26 + test_integration_app/main.py | 131 +- .../psp_merchant_api/__init__.py | 1 + .../psp_merchant_api/test_psp_merchant_api.py | 76 + test_integration_app/score_api/__init__.py | 1 + .../score_api/test_score_api.py | 150 ++ .../test_verification_api.py | 6 +- .../workflows_api/__init__.py | 1 + .../workflows_api/test_workflows_api.py | 14 + test_sift_verification_apis.py | 66 + tests/test_client.py | 2 +- tests/test_client_v203.py | 2 +- 18 files changed, 1966 insertions(+), 14 deletions(-) create mode 100644 test_integration_app/decisions_api/test_decisions_api.py delete mode 100644 test_integration_app/events_api/test_event.py create mode 100644 test_integration_app/events_api/test_events_api.py create mode 100644 test_integration_app/labels_api/test_labels_api.py create mode 100644 test_integration_app/psp_merchant_api/__init__.py create mode 100644 test_integration_app/psp_merchant_api/test_psp_merchant_api.py create mode 100644 test_integration_app/score_api/test_score_api.py create mode 100644 test_integration_app/workflows_api/test_workflows_api.py create mode 100644 test_sift_verification_apis.py diff --git a/test_integration_app/decisions_api/__init__.py b/test_integration_app/decisions_api/__init__.py index e69de29..5ead333 100644 --- a/test_integration_app/decisions_api/__init__.py +++ b/test_integration_app/decisions_api/__init__.py @@ -0,0 +1 @@ +from decisions_api import test_decisions_api \ No newline at end of file diff --git a/test_integration_app/decisions_api/test_decisions_api.py b/test_integration_app/decisions_api/test_decisions_api.py new file mode 100644 index 0000000..406fece --- /dev/null +++ b/test_integration_app/decisions_api/test_decisions_api.py @@ -0,0 +1,93 @@ +import sift + +from os import environ as env + # Get the value of API_KEY from environment variable +api_key = env['API_KEY'] +account_id = env['ACCT'] +client = sift.Client(api_key = api_key, account_id = account_id) + + +def apply_user_decision(): + applyDecisionRequest = { + "decision_id" : "block_user_payment_abuse", + "source" : "MANUAL_REVIEW", + "analyst" : "haneeshv@exalture.com", + "description" : "User linked to three other payment abusers and ordering high value items" + } + + response = client.apply_user_decision("haneeshv@exalture.com", applyDecisionRequest) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def apply_order_decision(): + applyOrderDecisionRequest = { + "decision_id" : "block_order_payment_abuse", + "source" : "AUTOMATED_RULE", + "description" : "Auto block pending order as score exceeded risk threshold of 90" + } + + response = client.apply_order_decision("haneeshv@exalture.com", "ORDER-1234567", applyOrderDecisionRequest) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def apply_session_decision(): + applySessionDecisionRequest = { + "decision_id" : "session_looks_fraud_account_takover", + "source" : "MANUAL_REVIEW", + "analyst" : "analyst@example.com", + "description" : "compromised account reported to customer service" + } + + response = client.apply_session_decision('haneeshv@exalture.com', "session_id", applySessionDecisionRequest) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def apply_content_decision(): + applyContentDecisionRequest = { + "decision_id" : "content_looks_fraud_content_abuse", + "source" : "MANUAL_REVIEW", + "analyst" : "analyst@example.com", + "description" : "fraudulent listing" + } + + response = client.apply_content_decision('haneeshv@exalture.com', "content_id", applyContentDecisionRequest) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_user_decisions(): + response = client.get_user_decisions("haneeshv@exalture.com") + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_order_decisions(): + response = client.get_order_decisions("ORDER-1234567") + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_content_decisions(): + response = client.get_content_decisions("haneeshv@exalture.com", "CONTENT_ID") + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_session_decisions(): + response = client.get_session_decisions("haneeshv@exalture.com", "SESSION_ID") + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_decisions(entityType): + response = client.get_decisions(entityType) + print(response) + assert(response.is_ok()) + assert response.http_status_code == 200, "api_status should be 200" diff --git a/test_integration_app/events_api/__init__.py b/test_integration_app/events_api/__init__.py index e69de29..12b0d31 100644 --- a/test_integration_app/events_api/__init__.py +++ b/test_integration_app/events_api/__init__.py @@ -0,0 +1 @@ +from events_api import test_events_api \ No newline at end of file diff --git a/test_integration_app/events_api/test_event.py b/test_integration_app/events_api/test_event.py deleted file mode 100644 index e69de29..0000000 diff --git a/test_integration_app/events_api/test_events_api.py b/test_integration_app/events_api/test_events_api.py new file mode 100644 index 0000000..5dfeeac --- /dev/null +++ b/test_integration_app/events_api/test_events_api.py @@ -0,0 +1,1408 @@ +import sift + +from os import environ as env + # Get the value of API_KEY from environment variable +api_key = env['API_KEY'] +client = sift.Client(api_key = api_key) + +def add_item_to_cart(): + add_item_to_cart_properties = { + # Required Fields + "$user_id" : "haneeshv@exalture.com", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$item" : { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$currency_code" : "USD", + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 16 + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$add_item_to_cart", add_item_to_cart_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def add_promotion(): + add_promotion_properties = { + # Required fields. + "$user_id" : "haneeshv@exalture.com", + # Supported fields. + "$promotions" : [ + # Example of a promotion for monetary discounts off good or services + { + "$promotion_id" : "NewRideDiscountMay2016", + "$status" : "$success", + "$description" : "$5 off your first 5 rides", + "$referrer_user_id" : "elon-m93903", + "$discount" : { + "$amount" : 5000000, # $5 + "$currency_code" : "USD" + } + } + ], + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$add_promotion", add_promotion_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def chargeback(): + # Sample $chargeback event + chargeback_properties = { + # Required Fields + "$order_id" : "ORDER-123124124", + "$transaction_id" : "719637215", + # Recommended Fields + "$user_id" : "billy_jones_301", + "$chargeback_state" : "$lost", + "$chargeback_reason" : "$duplicate" + } + response = client.track("$chargeback", chargeback_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def content_status(): + # Sample $content_status event + content_status_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$content_id" : "9671500641", + "$status" : "$paused", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$content_status", content_status_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_account(): + # Sample $create_account event + create_account_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$referrer_user_id" : "janejane101", + "$payment_methods" : [ + { + "$payment_type" : "$credit_card", + "$card_bin" : "542486", + "$card_last4" : "4444" + } + ], + "$billing_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$shipping_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$promotions" : [ + { + "$promotion_id" : "FriendReferral", + "$status" : "$success", + "$referrer_user_id" : "janejane102", + "$credit_point" : { + "$amount" : 100, + "$credit_point_type" : "account karma" + } + } + ], + "$social_sign_on_type" : "$twitter", + "$account_types" : ["merchant", "premium"], + + # Suggested Custom Fields + "twitter_handle" : "billyjones", + "work_phone" : "1-347-555-5921", + "location" : "New London, NH", + "referral_code" : "MIKEFRIENDS", + "email_confirmed_status" : "$pending", + "phone_confirmed_status" : "$pending", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$create_account", create_account_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_content_comment(): + # Sample $create_content event for comments + comment_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "comment-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $comment object + "$comment" : { + "$body" : "Congrats on the new role!", + "$contact_email" : "alex_301@domain.com", + "$parent_comment_id" : "comment-23407", + "$root_content_id" : "listing-12923213", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "An old picture" + } + ] + }, + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$create_content", comment_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_content_listing(): + # Sample $create_content event for listings + listing_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "listing-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $listing object + "$listing" : { + "$subject" : "2 Bedroom Apartment for Rent", + "$body" : "Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$listed_items" : [ + { + "$price" : 2950000000, # $2950.00 + "$currency_code" : "USD", + "$tags" : ["heat", "washer/dryer"] + } + ], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Billy's picture" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$create_content", listing_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_content_message(): + # Sample $create_content event for messages + message_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "message-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $message object + "$message" : { + "$body" : "Let’s meet at 5pm", + "$contact_email" : "alex_301@domain.com", + "$recipient_user_ids" : ["fy9h989sjphh71"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "My hike today!" + } + ] + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$create_content", message_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_content_post(): + # Sample $create_content event for posts + post_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "post-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $post object + "$post" : { + "$subject" : "My new apartment!", + "$body" : "Moved into my new apartment yesterday.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$categories" : ["Personal"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "View from the window!" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$create_content", post_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_content_profile(): + # Sample $create_content event for reviews + profile_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "profile-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $profile object + "$profile" : { + "$body" : "Hi! My name is Alex and I just moved to New London!", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Alex Smith", + "$phone" : "1-415-555-6041", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Alex's picture" + } + ], + "$categories" : [ + "Friends", + "Long-term dating" + ] + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$create_content", profile_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_content_review(): + # Sample $create_content event for reviews + review_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "review-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $review object + "$review" : { + "$subject" : "Amazing Tacos!", + "$body" : "I ate the tacos.", + "$contact_email" : "alex_301@domain.com", + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$reviewed_content_id" : "listing-234234", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Calamari tacos." + } + ], + "$rating" : 4.5 + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$create_content", review_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def create_order(): + # Sample $create_order event + order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$order_id" : "ORDER-28168441", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$amount" : 115940000, # $115.94 + "$currency_code" : "USD", + "$billing_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$payment_methods" : [ + { + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" + } + ], + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$shipping_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$expedited_shipping" : True, + "$shipping_method" : "$physical", + "$shipping_carrier" : "UPS", + "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], + "$items" : [ + { + "$item_id" : "12344321", + "$product_title" : "Microwavable Kettle Corn: Original Flavor", + "$price" : 4990000, # $4.99 + "$upc" : "097564307560", + "$sku" : "03586005", + "$brand" : "Peters Kettle Corn", + "$manufacturer" : "Peters Kettle Corn", + "$category" : "Food and Grocery", + "$tags" : ["Popcorn", "Snacks", "On Sale"], + "$quantity" : 4 + }, + { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 2 + } + ], + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", + + "$promotions" : [ + { + "$promotion_id" : "FirstTimeBuyer", + "$status" : "$success", + "$description" : "$5 off", + "$discount" : { + "$amount" : 5000000, # $5.00 + "$currency_code" : "USD", + "$minimum_purchase_amount" : 25000000 # $25.00 + } + } + ], + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$create_order", order_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def flag_content(): + # Sample $flag_content event + flag_content_properties = { + # Required Fields + "$user_id" : "billy_jones_301", # content creator + "$content_id" : "9671500641", + + # Supported Fields + "$flagged_by" : "jamieli89" + } + response = client.track("$flag_content", flag_content_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def link_session_to_user(): + # Sample $link_session_to_user event + link_session_to_user_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il" + } + response = client.track("$link_session_to_user", link_session_to_user_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def login(): + # Sample $login event + login_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$login_status" : "$failure", + + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$ip" : "128.148.1.135", + + # Optional Fields + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$failure_reason" : "$wrong_password", + "$username" : "billjones1@example.com", + "$account_types" : ["merchant", "premium"], + "$social_sign_on_type" : "$linkedin", + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + + # Send this information with a login from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$login", login_properties) + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def logout(): + # Sample $logout event + logout_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$logout", logout_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def order_status(): + # Sample $order_status event + order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$order_id" : "ORDER-28168441", + "$order_status" : "$canceled", + + # Optional Fields + "$reason" : "$payment_risk", + "$source" : "$manual_review", + "$analyst" : "someone@your-site.com", + "$webhook_id" : "3ff1082a4aea8d0c58e3643ddb7a5bb87ffffeb2492dca33", + "$description" : "Canceling because multiple fraudulent users on device", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$order_status", order_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def remove_item_from_cart(): + # Sample $remove_item_from_cart event + remove_item_from_cart_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$item" : { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$currency_code" : "USD", + "$quantity" : 2, + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea" + }, + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$remove_item_from_cart", remove_item_from_cart_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def security_notification(): + # Sample $security_notification event + security_notification_properties = { + # Required Fields + "$type" : "$security_notification", + "$api_key" : "YOUR_API_KEY", + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$notification_status" : "$sent", + # Optional fields if applicable + "$notification_type" : "$email", + "$notified_value" : "billy123@domain.com", + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$security_notification", security_notification_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def transaction(): + # Sample $transaction event + transaction_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$amount" : 506790000, # $506.79 + "$currency_code" : "USD", + # Supported Fields + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$transaction_type" : "$sale", + "$transaction_status" : "$failure", + "$decline_category" : "$bank_decline", + "$order_id" : "ORDER-123124124", + "$transaction_id" : "719637215", + "$billing_address" : { # or "$sent_address" # or "$received_address" + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + # Credit card example + "$payment_method" : { + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" + }, + + # Bank account example + # "$payment_method" : { + # "$payment_type" : "$electronic_fund_transfer", + # "$routing_number" : "021001088" + #}, + # See other payment method options in the field description + + # Supported fields for 3DS + "$status_3ds" : "$attempted", + "$triggered_3ds" : "$processor", + "$merchant_initiated_transaction" : False, + + # Supported Fields + "$shipping_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$session_id" : "gigtleqddo84l8cm15qe4il", + + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + response = client.track("$transaction", transaction_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_account(): + # Sample $update_account event + update_account_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + + # Supported Fields + "$changed_password" : True, + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$referrer_user_id" : "janejane102", + "$payment_methods" : [ + { + "$payment_type" : "$credit_card", + "$card_bin" : "542486", + "$card_last4" : "4444" + } + ], + "$billing_address" : + { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$shipping_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + + "$social_sign_on_type" : "$twitter", + "$account_types" : ["merchant", "premium"], + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$update_account", update_account_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_content_comment(): + # Sample $update_content event for comments + update_content_comment_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "comment-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $comment object + "$comment" : { + "$body" : "Congrats on the new role!", + "$contact_email" : "alex_301@domain.com", + "$parent_comment_id" : "comment-23407", + "$root_content_id" : "listing-12923213", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "An old picture" + } + ] + }, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + response = client.track("$update_content", update_content_comment_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_content_listing(): + # Sample $update_content event for listings + update_content_listing_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "listing-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $listing object + "$listing" : { + "$subject" : "2 Bedroom Apartment for Rent", + "$body" : "Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$listed_items" : [ + { + "$price" : 2950000000, # $2950.00 + "$currency_code" : "USD", + "$tags" : ["heat", "washer/dryer"] + } + ], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Billy's picture" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + response = client.track("$update_content", update_content_listing_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_content_message(): + # Sample $update_content event for messages + update_content_message_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "message-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $message object + "$message" : { + "$body" : "Lets meet at 5pm", + "$contact_email" : "alex_301@domain.com", + "$recipient_user_ids" : ["fy9h989sjphh71"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "My hike today!" + } + ] + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$update_content", update_content_message_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_content_post(): + # Sample $update_content event for posts + update_content_post_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "post-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $post object + "$post" : { + "$subject" : "My new apartment!", + "$body" : "Moved into my new apartment yesterday.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$categories" : ["Personal"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "View from the window!" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } +} + + response = client.track("$update_content", update_content_post_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_content_profile(): + # Sample $update_content event for reviews + update_content_profile_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "profile-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $profile object + "$profile" : { + "$body" : "Hi! My name is Alex and I just moved to New London!", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Alex Smith", + "$phone" : "1-415-555-6041", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Alex's picture" + } + ], + "$categories" : [ + "Friends", + "Long-term dating" + ] + }, + # ========================================= + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + + response = client.track("$update_content", update_content_profile_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_content_review(): + # Sample $update_content event for reviews + update_content_review_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "review-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $review object + "$review" : { + "$subject" : "Amazing Tacos!", + "$body" : "I ate the tacos.", + "$contact_email" : "alex_301@domain.com", + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$reviewed_content_id" : "listing-234234", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Calamari tacos." + } + ], + "$rating" : 4.5 + }, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + + response = client.track("$update_content", update_content_review_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_order(): + # Sample $update_order event + update_order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$order_id" : "ORDER-28168441", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$amount" : 115940000, # $115.94 + "$currency_code" : "USD", + "$billing_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$payment_methods" : [ + { + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" + } + ], + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + "$shipping_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$expedited_shipping" : True, + "$shipping_method" : "$physical", + "$shipping_carrier" : "UPS", + "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], + "$items" : [ + { + "$item_id" : "12344321", + "$product_title" : "Microwavable Kettle Corn: Original Flavor", + "$price" : 4990000, # $4.99 + "$upc" : "097564307560", + "$sku" : "03586005", + "$brand" : "Peters Kettle Corn", + "$manufacturer" : "Peters Kettle Corn", + "$category" : "Food and Grocery", + "$tags" : ["Popcorn", "Snacks", "On Sale"], + "$quantity" : 4 + }, + { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 2 + } + ], + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", + + "$promotions" : [ + { + "$promotion_id" : "FirstTimeBuyer", + "$status" : "$success", + "$description" : "$5 off", + "$discount" : { + "$amount" : 5000000, # $5.00 + "$currency_code" : "USD", + "$minimum_purchase_amount" : 25000000 # $25.00 + } + } + ], + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + + response = client.track("$update_order", update_order_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def update_password(): + # Sample $update_password event + update_password_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$status" : "$success", + "$reason" : "$forced_reset", + "$ip" : "128.148.1.135", # IP of the user that entered the new password after the old password was reset + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + + response = client.track("$update_password", update_password_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def verification(): + # Sample $verification event + verification_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$status" : "$pending", + + # Optional fields if applicable + "$verified_event" : "$login", + "$reason" : "$automated_rule", + "$verification_type" : "$sms", + "$verified_value" : "14155551212" + } + response = client.track("$verification", verification_properties) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" \ No newline at end of file diff --git a/test_integration_app/labels_api/__init__.py b/test_integration_app/labels_api/__init__.py index e69de29..124289c 100644 --- a/test_integration_app/labels_api/__init__.py +++ b/test_integration_app/labels_api/__init__.py @@ -0,0 +1 @@ +from labels_api import test_labels_api \ No newline at end of file diff --git a/test_integration_app/labels_api/test_labels_api.py b/test_integration_app/labels_api/test_labels_api.py new file mode 100644 index 0000000..e9c07cf --- /dev/null +++ b/test_integration_app/labels_api/test_labels_api.py @@ -0,0 +1,26 @@ +import sift + +from os import environ as env + # Get the value of API_KEY from environment variable +api_key = env['API_KEY'] +client = sift.Client(api_key = api_key) + +def user_label(): + properties = { + "$is_fraud" : True, # ... or False; Required + "$abuse_type" : "payment_abuse", # Required + "$description" : "The user was testing cards repeatedly for a valid card", # Optional + "$source" : "manual review", # Optional + "$analyst" : "someone@your-site.com" # Optional + } + response = client.label("haneeshv@exalture.com", properties) + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def user_unlabel(): + response = client.unlabel("haneeshv@exalture.com", abuse_type = "payment_abuse") + print(response) + assert(response.is_ok()) + assert response.http_status_code == 204, "api_status should be 204" diff --git a/test_integration_app/main.py b/test_integration_app/main.py index da2a284..083c39e 100644 --- a/test_integration_app/main.py +++ b/test_integration_app/main.py @@ -1,16 +1,129 @@ +from events_api import test_events_api +from decisions_api import test_decisions_api +from workflows_api import test_workflows_api +from score_api import test_score_api from verifications_api import test_verification_api +from labels_api import test_labels_api +from psp_merchant_api import test_psp_merchant_api -def test_send(): - test_verification_api.test_verification_send() +#Events APIs -def test_resend(): - test_verification_api.test_verification_resend() +# test_events_api.add_item_to_cart() -def test_check(code): - test_verification_api.test_verification_check(code) +# test_events_api.add_promotion() -test_send() +# test_events_api.chargeback() -# test_resend() +# test_events_api.content_status() -# test_check(329311) \ No newline at end of file +# test_events_api.create_account() + +# test_events_api.create_content_comment() + +# test_events_api.create_content_listing() + +# test_events_api.create_content_message() + +# test_events_api.create_content_post() + +# test_events_api.create_content_profile() + +# test_events_api.create_content_review() + +# test_events_api.create_order() + +# test_events_api.flag_content() + +# test_events_api.link_session_to_user() + +# test_events_api.login() + +# test_events_api.logout() + +# test_events_api.order_status() + +# test_events_api.remove_item_from_cart() + +# test_events_api.security_notification() + +# test_events_api.transaction() + +# test_events_api.update_account() + +# test_events_api.update_content_comment() + +# test_events_api.update_content_listing() + +# test_events_api.update_content_message() + +# test_events_api.update_content_post() + +# test_events_api.update_content_profile() + +# test_events_api.update_content_review() + +# test_events_api.update_order() + +# test_events_api.update_password() + +# test_events_api.verification() + +# Decision APIs + +# test_decisions_api.apply_user_decision_request() + +# test_decisions_api.apply_order_decision_request() + +# test_decisions_api.apply_session_decision() + +# test_decisions_api.apply_content_decision() + +# test_decisions_api.get_user_decisions() + +# test_decisions_api.get_order_decisions() + +# test_decisions_api.get_content_decisions() + +# test_decisions_api.get_session_decisions() + +# test_decisions_api.get_decisions("session") #user, order, content, session + +# Workflows APIs + +# test_workflows_api.get_workflow_status("workflow_run_id") + +# Score APIs + +# test_score_api.create_order_with_return_score() + +# test_score_api.get_score() + +# test_score_api.get_user_score() + +# test_score_api.rescore_user() + +# Labeling + +# test_labels_api.user_label() + +# test_labels_api.user_unlabel() + +# Verification APIs + +# test_verification_api.send() + +# test_verification_api.resend() + +# test_verification_api.check("271571") + +# PSP Merchant APIs + +# test_psp_merchant_api.create_merchant() + +# test_psp_merchant_api.edit_merchant() + +# test_psp_merchant_api.get_a_merchant_profile() + +# test_psp_merchant_api.get_merchant_profiles() + +test_psp_merchant_api.get_merchant_profiles(batch_size=2, batch_token="64d0a6a5afb931525995e75b") \ No newline at end of file diff --git a/test_integration_app/psp_merchant_api/__init__.py b/test_integration_app/psp_merchant_api/__init__.py new file mode 100644 index 0000000..8cc869d --- /dev/null +++ b/test_integration_app/psp_merchant_api/__init__.py @@ -0,0 +1 @@ +from psp_merchant_api import test_psp_merchant_api \ No newline at end of file diff --git a/test_integration_app/psp_merchant_api/test_psp_merchant_api.py b/test_integration_app/psp_merchant_api/test_psp_merchant_api.py new file mode 100644 index 0000000..1a09536 --- /dev/null +++ b/test_integration_app/psp_merchant_api/test_psp_merchant_api.py @@ -0,0 +1,76 @@ +import sift + +from os import environ as env + # Get the value of API_KEY from environment variable +api_key = env['API_KEY'] +account_id = env['ACCT'] +client = sift.Client(api_key = api_key, account_id = account_id) + +def create_merchant(): + merchantProperties={ + "id": "merchant_id_01013", + "name": "Wonderful Payments Inc.13", + "description": "Wonderful Payments payment provider.", + "address": { + "name": "Alany", + "address_1": "Big Payment blvd, 22", + "address_2": "apt, 8", + "city": "New Orleans", + "region": "NA", + "country": "US", + "zipcode": "76830", + "phone": "0394888320" + }, + "category": "1002", + "service_level": "Platinum", + "status": "active", + "risk_profile": { + "level": "low", + "score": 10 + } + } + response = client.create_psp_merchant_profile(merchantProperties) + print(response) + assert response.http_status_code == 201, "api_status should be 201" + +def edit_merchant(): + merchantProperties={ + "id": "merchant_id_01013", + "name": "Wonderful Payments Inc.13 edit", + "description": "Wonderful Payments payment provider. edit", + "address": { + "name": "Alany", + "address_1": "Big Payment blvd, 22", + "address_2": "apt, 8", + "city": "New Orleans", + "region": "NA", + "country": "US", + "zipcode": "76830", + "phone": "0394888320" + }, + "category": "1002", + "service_level": "Platinum", + "status": "active", + "risk_profile": { + "level": "low", + "score": 10 + } + } + response = client.update_psp_merchant_profile("merchant_id_01013", merchantProperties) + print(response) + assert response.http_status_code == 200, "api_status should be 200" + +def get_a_merchant_profile(): + response = client.get_a_psp_merchant_profile("merchant_id_01013") + print(response) + assert response.http_status_code == 200, "api_status should be 200" + +def get_merchant_profiles(): + response = client.get_psp_merchant_profiles() + print(response) + assert response.http_status_code == 200, "api_status should be 200" + +def get_merchant_profiles(batch_token = None, batch_size = None): + response = client.get_psp_merchant_profiles(batch_token, batch_size) + print(response) + assert response.http_status_code == 200, "api_status should be 200" \ No newline at end of file diff --git a/test_integration_app/score_api/__init__.py b/test_integration_app/score_api/__init__.py index e69de29..c6e1b23 100644 --- a/test_integration_app/score_api/__init__.py +++ b/test_integration_app/score_api/__init__.py @@ -0,0 +1 @@ +from score_api import test_score_api \ No newline at end of file diff --git a/test_integration_app/score_api/test_score_api.py b/test_integration_app/score_api/test_score_api.py new file mode 100644 index 0000000..d254b63 --- /dev/null +++ b/test_integration_app/score_api/test_score_api.py @@ -0,0 +1,150 @@ +import sift + +from os import environ as env + # Get the value of API_KEY from environment variable +api_key = env['API_KEY'] +client = sift.Client(api_key = api_key) + +def create_order_with_return_score(): + # Sample $create_order event + order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$order_id" : "ORDER-28168441", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$amount" : 115940000, # $115.94 + "$currency_code" : "USD", + "$billing_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$payment_methods" : [ + { + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" + } + ], + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$shipping_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$expedited_shipping" : True, + "$shipping_method" : "$physical", + "$shipping_carrier" : "UPS", + "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], + "$items" : [ + { + "$item_id" : "12344321", + "$product_title" : "Microwavable Kettle Corn: Original Flavor", + "$price" : 4990000, # $4.99 + "$upc" : "097564307560", + "$sku" : "03586005", + "$brand" : "Peters Kettle Corn", + "$manufacturer" : "Peters Kettle Corn", + "$category" : "Food and Grocery", + "$tags" : ["Popcorn", "Snacks", "On Sale"], + "$quantity" : 4 + }, + { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 2 + } + ], + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", + + "$promotions" : [ + { + "$promotion_id" : "FirstTimeBuyer", + "$status" : "$success", + "$description" : "$5 off", + "$discount" : { + "$amount" : 5000000, # $5.00 + "$currency_code" : "USD", + "$minimum_purchase_amount" : 25000000 # $25.00 + } + } + ], + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + + response = client.track("$create_order", order_properties, return_score= True, abuse_types=['payment_abuse', 'promotion_abuse']) + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_score(): + response = client.score("haneeshv@exalture.com") + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def get_user_score(): + response = client.get_user_score("haneeshv@exalture.com") + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + +def rescore_user(): + response = client.rescore_user("haneeshv@exalture.com", abuse_types=['payment_abuse', 'account_abuse']) + print(response) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" \ No newline at end of file diff --git a/test_integration_app/verifications_api/test_verification_api.py b/test_integration_app/verifications_api/test_verification_api.py index f38c727..d5dfc2c 100644 --- a/test_integration_app/verifications_api/test_verification_api.py +++ b/test_integration_app/verifications_api/test_verification_api.py @@ -6,7 +6,7 @@ client = sift.Client(api_key = api_key) -def test_verification_send(): +def send(): sendProperties = { '$user_id': 'haneeshv@exalture.com', '$send_to': 'haneeshv@exalture.com', @@ -33,7 +33,7 @@ def test_verification_send(): assert response.api_status == 0, "api_status should be 0" assert response.api_error_message == "OK", "api_error_message should be OK" -def test_verification_resend(): +def resend(): resendProperties = { '$user_id': 'haneeshv@exalture.com', '$verified_event': '$login', @@ -45,7 +45,7 @@ def test_verification_resend(): assert response.api_status == 0, "api_status should be 0" assert response.api_error_message == "OK", "api_error_message should be OK" -def test_verification_check(code): +def check(code): checkProperties = { '$user_id': 'haneeshv@exalture.com', '$code': code, diff --git a/test_integration_app/workflows_api/__init__.py b/test_integration_app/workflows_api/__init__.py index e69de29..b04f380 100644 --- a/test_integration_app/workflows_api/__init__.py +++ b/test_integration_app/workflows_api/__init__.py @@ -0,0 +1 @@ +from workflows_api import test_workflows_api \ No newline at end of file diff --git a/test_integration_app/workflows_api/test_workflows_api.py b/test_integration_app/workflows_api/test_workflows_api.py new file mode 100644 index 0000000..abd4cb6 --- /dev/null +++ b/test_integration_app/workflows_api/test_workflows_api.py @@ -0,0 +1,14 @@ +import sift + +from os import environ as env + # Get the value of API_KEY from environment variable +api_key = env['API_KEY'] +client = sift.Client(api_key = api_key) + +def get_workflow_status(workflow_run_id): + response = client.get_workflow_status(workflow_run_id) + assert(response.is_ok()) + assert response.api_status == 0, "api_status should be 0" + assert response.api_error_message == "OK", "api_error_message should be OK" + + diff --git a/test_sift_verification_apis.py b/test_sift_verification_apis.py new file mode 100644 index 0000000..4540127 --- /dev/null +++ b/test_sift_verification_apis.py @@ -0,0 +1,66 @@ +from decimal import Decimal +import sift +import sys + +if sys.version_info[0] < 3: + import six.moves.urllib as urllib +else: + import urllib.parse + +def response_with_data_header(): + return { + 'content-type': 'application/json; charset=UTF-8' + } + +sendProperties = { + '$user_id' : 'haneeshv@exalture.com', + '$send_to' : 'haneeshv@exalture.com', + '$verification_type': '$email', + '$brand_name' : 'MyTopBrand', + '$language' : 'en', + "$site_country": "IN", + '$event': { + '$session_id': 'SOME_SESSION_ID', + # '$verified_event': '$login', + '$verified_entity_id': 'SOME_SESSION_ID', + '$reason': '$automated_rule', + '$ip': '192.168.1.1', + '$browser': { + '$user_agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' + } + } +} + +resendProperties = { + '$user_id' : 'haneeshv@exalture.com', + '$verified_event': '$login', + '$verified_entity_id': 'SOME_SESSION_ID' +} + +checkProperties = { + '$user_id' : 'haneeshv@exalture.com', + '$code' : '636068', + '$verified_event': '$login', + '$verified_entity_id' : "SOME_SESSION_ID" +} + +def test_verification_send(): + client = sift.Client(api_key='ccd68efbe25809bc', account_id='ACCT') + response = client.verification_send(sendProperties) + print(response) + +def test_verification_resend(): + client = sift.Client(api_key='ccd68efbe25809bc', account_id='ACCT') + response = client.verification_resend(resendProperties) + print(response) + +def test_verification_check(): + client = sift.Client(api_key='ccd68efbe25809bc', account_id='ACCT') + response = client.verification_check(checkProperties) + print(response) + +test_verification_send() + +# test_verification_resend() + +# test_verification_check() \ No newline at end of file diff --git a/tests/test_client.py b/tests/test_client.py index adca48e..330a120 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -22,7 +22,7 @@ def valid_transaction_properties(): '$seller_user_id': '654321', '$amount': Decimal('1253200.0'), '$currency_code': 'USD', - '$time': int(datetime.datetime.now().strftime('%s')), + '$time': int(datetime.datetime.now().strftime('%S')), '$transaction_id': 'my_transaction_id', '$billing_name': 'Mike Snow', '$billing_bin': '411111', diff --git a/tests/test_client_v203.py b/tests/test_client_v203.py index a7af5b8..d1fa5a1 100644 --- a/tests/test_client_v203.py +++ b/tests/test_client_v203.py @@ -19,7 +19,7 @@ def valid_transaction_properties(): '$seller_user_id': '654321', '$amount': Decimal('1253200.0'), '$currency_code': 'USD', - '$time': int(datetime.datetime.now().strftime('%s')), + '$time': int(datetime.datetime.now().strftime('%S')), '$transaction_id': 'my_transaction_id', '$billing_name': 'Mike Snow', '$billing_bin': '411111', From fb8d503d09b19e49a94eeb9785744dd7e9bd0414 Mon Sep 17 00:00:00 2001 From: haneeshv <135820493+haneeshv@users.noreply.github.com> Date: Tue, 22 Aug 2023 15:40:26 +0530 Subject: [PATCH 05/11] Update test_sift_verification_apis.py --- test_sift_verification_apis.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test_sift_verification_apis.py b/test_sift_verification_apis.py index 4540127..5b2ab9c 100644 --- a/test_sift_verification_apis.py +++ b/test_sift_verification_apis.py @@ -45,17 +45,17 @@ def response_with_data_header(): } def test_verification_send(): - client = sift.Client(api_key='ccd68efbe25809bc', account_id='ACCT') + client = sift.Client(api_key='valid-api-key', account_id='ACCT') response = client.verification_send(sendProperties) print(response) def test_verification_resend(): - client = sift.Client(api_key='ccd68efbe25809bc', account_id='ACCT') + client = sift.Client(api_key='valid-api-key', account_id='ACCT') response = client.verification_resend(resendProperties) print(response) def test_verification_check(): - client = sift.Client(api_key='ccd68efbe25809bc', account_id='ACCT') + client = sift.Client(api_key='valid-api-key', account_id='ACCT') response = client.verification_check(checkProperties) print(response) @@ -63,4 +63,4 @@ def test_verification_check(): # test_verification_resend() -# test_verification_check() \ No newline at end of file +# test_verification_check() From d30dedf6ba94ea4bc07c4d1e9e7bde08e39c3aa2 Mon Sep 17 00:00:00 2001 From: Haneesh Date: Mon, 25 Sep 2023 15:39:42 +0530 Subject: [PATCH 06/11] code fine tuning --- .../decisions_api/__init__.py | 3 +- .../decisions_api/test_decisions_api.py | 133 +- test_integration_app/events_api/__init__.py | 3 +- .../events_api/test_events_api.py | 2365 ++++++++--------- test_integration_app/labels_api/__init__.py | 1 - .../labels_api/test_labels_api.py | 26 - test_integration_app/main.py | 206 +- .../psp_merchant_api/__init__.py | 3 +- .../psp_merchant_api/test_psp_merchant_api.py | 132 +- test_integration_app/score_api/__init__.py | 3 +- .../score_api/test_score_api.py | 152 +- .../verifications_api/__init__.py | 3 +- .../test_verification_api.py | 92 +- .../workflows_api/__init__.py | 3 +- .../workflows_api/test_workflows_api.py | 23 +- 15 files changed, 1406 insertions(+), 1742 deletions(-) delete mode 100644 test_integration_app/labels_api/__init__.py delete mode 100644 test_integration_app/labels_api/test_labels_api.py diff --git a/test_integration_app/decisions_api/__init__.py b/test_integration_app/decisions_api/__init__.py index 5ead333..993fb27 100644 --- a/test_integration_app/decisions_api/__init__.py +++ b/test_integration_app/decisions_api/__init__.py @@ -1 +1,2 @@ -from decisions_api import test_decisions_api \ No newline at end of file +from decisions_api import test_decisions_api + diff --git a/test_integration_app/decisions_api/test_decisions_api.py b/test_integration_app/decisions_api/test_decisions_api.py index 406fece..1f604b1 100644 --- a/test_integration_app/decisions_api/test_decisions_api.py +++ b/test_integration_app/decisions_api/test_decisions_api.py @@ -1,93 +1,64 @@ import sift from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -account_id = env['ACCT'] -client = sift.Client(api_key = api_key, account_id = account_id) +class DecisionAPI(): + # Get the value of API_KEY from environment variable + api_key = env['API_KEY'] + account_id = env['ACCT'] + client = sift.Client(api_key = api_key, account_id = account_id) -def apply_user_decision(): - applyDecisionRequest = { - "decision_id" : "block_user_payment_abuse", - "source" : "MANUAL_REVIEW", - "analyst" : "haneeshv@exalture.com", - "description" : "User linked to three other payment abusers and ordering high value items" - } - - response = client.apply_user_decision("haneeshv@exalture.com", applyDecisionRequest) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def apply_user_decision(self): + applyDecisionRequest = { + "decision_id" : "block_user_payment_abuse", + "source" : "MANUAL_REVIEW", + "analyst" : "analyst@example.com", + "description" : "User linked to three other payment abusers and ordering high value items" + } + + return self.client.apply_user_decision("billy_jones_301", applyDecisionRequest) -def apply_order_decision(): - applyOrderDecisionRequest = { - "decision_id" : "block_order_payment_abuse", - "source" : "AUTOMATED_RULE", - "description" : "Auto block pending order as score exceeded risk threshold of 90" - } - - response = client.apply_order_decision("haneeshv@exalture.com", "ORDER-1234567", applyOrderDecisionRequest) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def apply_order_decision(self): + applyOrderDecisionRequest = { + "decision_id" : "block_order_payment_abuse", + "source" : "AUTOMATED_RULE", + "description" : "Auto block pending order as score exceeded risk threshold of 90" + } + + return self.client.apply_order_decision("billy_jones_301", "ORDER-1234567", applyOrderDecisionRequest) -def apply_session_decision(): - applySessionDecisionRequest = { - "decision_id" : "session_looks_fraud_account_takover", - "source" : "MANUAL_REVIEW", - "analyst" : "analyst@example.com", - "description" : "compromised account reported to customer service" - } - - response = client.apply_session_decision('haneeshv@exalture.com', "session_id", applySessionDecisionRequest) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def apply_session_decision(self): + applySessionDecisionRequest = { + "decision_id" : "session_looks_fraud_account_takover", + "source" : "MANUAL_REVIEW", + "analyst" : "analyst@example.com", + "description" : "compromised account reported to customer service" + } + + return self.client.apply_session_decision('billy_jones_301', "session_id", applySessionDecisionRequest) -def apply_content_decision(): - applyContentDecisionRequest = { - "decision_id" : "content_looks_fraud_content_abuse", - "source" : "MANUAL_REVIEW", - "analyst" : "analyst@example.com", - "description" : "fraudulent listing" - } - - response = client.apply_content_decision('haneeshv@exalture.com', "content_id", applyContentDecisionRequest) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def apply_content_decision(self): + applyContentDecisionRequest = { + "decision_id" : "content_looks_fraud_content_abuse", + "source" : "MANUAL_REVIEW", + "analyst" : "analyst@example.com", + "description" : "fraudulent listing" + } + + return self.client.apply_content_decision('billy_jones_301', "content_id", applyContentDecisionRequest) -def get_user_decisions(): - response = client.get_user_decisions("haneeshv@exalture.com") - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def get_user_decisions(self): + return self.client.get_user_decisions("billy_jones_301") -def get_order_decisions(): - response = client.get_order_decisions("ORDER-1234567") - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def get_order_decisions(self): + return self.client.get_order_decisions("ORDER-1234567") -def get_content_decisions(): - response = client.get_content_decisions("haneeshv@exalture.com", "CONTENT_ID") - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + def get_content_decisions(self): + return self.client.get_content_decisions("billy_jones_301", "CONTENT_ID") + + def get_session_decisions(self): + return self.client.get_session_decisions("billy_jones_301", "SESSION_ID") + + def get_decisions(self): + return self.client.get_decisions(entity_type='user', limit=10, start_from=5, abuse_types='legacy,payment_abuse') -def get_session_decisions(): - response = client.get_session_decisions("haneeshv@exalture.com", "SESSION_ID") - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def get_decisions(entityType): - response = client.get_decisions(entityType) - print(response) - assert(response.is_ok()) - assert response.http_status_code == 200, "api_status should be 200" diff --git a/test_integration_app/events_api/__init__.py b/test_integration_app/events_api/__init__.py index 12b0d31..2a42a7a 100644 --- a/test_integration_app/events_api/__init__.py +++ b/test_integration_app/events_api/__init__.py @@ -1 +1,2 @@ -from events_api import test_events_api \ No newline at end of file +from events_api import test_events_api + diff --git a/test_integration_app/events_api/test_events_api.py b/test_integration_app/events_api/test_events_api.py index 5dfeeac..57aceb7 100644 --- a/test_integration_app/events_api/test_events_api.py +++ b/test_integration_app/events_api/test_events_api.py @@ -1,131 +1,123 @@ import sift from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -client = sift.Client(api_key = api_key) - -def add_item_to_cart(): - add_item_to_cart_properties = { - # Required Fields - "$user_id" : "haneeshv@exalture.com", + + +class EventsAPI(): + # Get the value of API_KEY from environment variable + api_key = env['API_KEY'] + client = sift.Client(api_key = api_key) + + def add_item_to_cart(self): + add_item_to_cart_properties = { + # Required Fields + "$user_id" : "billy_jones_301", # Supported Fields "$session_id" : "gigtleqddo84l8cm15qe4il", "$item" : { - "$item_id" : "B004834GQO", - "$product_title" : "The Slanket Blanket-Texas Tea", - "$price" : 39990000, # $39.99 - "$currency_code" : "USD", - "$upc" : "6786211451001", - "$sku" : "004834GQ", - "$brand" : "Slanket", - "$manufacturer" : "Slanket", - "$category" : "Blankets & Throws", - "$tags" : ["Awesome", "Wintertime specials"], - "$color" : "Texas Tea", - "$quantity" : 16 + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$currency_code" : "USD", + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 16 }, "$brand_name" : "sift", "$site_domain" : "sift.com", "$site_country" : "US", # Send this information from a BROWSER client. "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" } - } - response = client.track("$add_item_to_cart", add_item_to_cart_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def add_promotion(): - add_promotion_properties = { - # Required fields. - "$user_id" : "haneeshv@exalture.com", - # Supported fields. - "$promotions" : [ - # Example of a promotion for monetary discounts off good or services - { - "$promotion_id" : "NewRideDiscountMay2016", - "$status" : "$success", - "$description" : "$5 off your first 5 rides", - "$referrer_user_id" : "elon-m93903", - "$discount" : { - "$amount" : 5000000, # $5 - "$currency_code" : "USD" + } + return self.client.track("$add_item_to_cart", add_item_to_cart_properties) + + + def add_promotion(self): + add_promotion_properties = { + # Required fields. + "$user_id" : "billy_jones_301", + # Supported fields. + "$promotions" : [ + # Example of a promotion for monetary discounts off good or services + { + "$promotion_id" : "NewRideDiscountMay2016", + "$status" : "$success", + "$description" : "$5 off your first 5 rides", + "$referrer_user_id" : "elon-m93903", + "$discount" : { + "$amount" : 5000000, # $5 + "$currency_code" : "USD" + } } + ], + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - ], - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + return self.client.track("$add_promotion", add_promotion_properties) + + def chargeback(self): + # Sample $chargeback event + chargeback_properties = { + # Required Fields + "$order_id" : "ORDER-123124124", + "$transaction_id" : "719637215", + # Recommended Fields + "$user_id" : "billy_jones_301", + "$chargeback_state" : "$lost", + "$chargeback_reason" : "$duplicate" } - } - response = client.track("$add_promotion", add_promotion_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def chargeback(): - # Sample $chargeback event - chargeback_properties = { - # Required Fields - "$order_id" : "ORDER-123124124", - "$transaction_id" : "719637215", - # Recommended Fields - "$user_id" : "billy_jones_301", - "$chargeback_state" : "$lost", - "$chargeback_reason" : "$duplicate" - } - response = client.track("$chargeback", chargeback_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def content_status(): - # Sample $content_status event - content_status_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$content_id" : "9671500641", - "$status" : "$paused", - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + return self.client.track("$chargeback", chargeback_properties) + + def content_status(self): + # Sample $content_status event + content_status_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$content_id" : "9671500641", + "$status" : "$paused", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - } - response = client.track("$content_status", content_status_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_account(): - # Sample $create_account event - create_account_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - # Supported Fields - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$name" : "Bill Jones", - "$phone" : "1-415-555-6040", - "$referrer_user_id" : "janejane101", - "$payment_methods" : [ + return self.client.track("$content_status", content_status_properties) + + def create_account(self): + # Sample $create_account event + create_account_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$referrer_user_id" : "janejane101", + "$payment_methods" : [ { - "$payment_type" : "$credit_card", - "$card_bin" : "542486", - "$card_last4" : "4444" + "$payment_type" : "$credit_card", + "$card_bin" : "542486", + "$card_last4" : "4444" } - ], - "$billing_address" : { + ], + "$billing_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6040", "$address_1" : "2100 Main Street", @@ -134,8 +126,8 @@ def create_account(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$shipping_address" : { + }, + "$shipping_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -144,346 +136,323 @@ def create_account(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$promotions" : [ - { - "$promotion_id" : "FriendReferral", - "$status" : "$success", - "$referrer_user_id" : "janejane102", - "$credit_point" : { - "$amount" : 100, - "$credit_point_type" : "account karma" - } - } - ], - "$social_sign_on_type" : "$twitter", - "$account_types" : ["merchant", "premium"], - - # Suggested Custom Fields - "twitter_handle" : "billyjones", - "work_phone" : "1-347-555-5921", - "location" : "New London, NH", - "referral_code" : "MIKEFRIENDS", - "email_confirmed_status" : "$pending", - "phone_confirmed_status" : "$pending", - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - response = client.track("$create_account", create_account_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_content_comment(): - # Sample $create_content event for comments - comment_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "comment-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $comment object - "$comment" : { - "$body" : "Congrats on the new role!", - "$contact_email" : "alex_301@domain.com", - "$parent_comment_id" : "comment-23407", - "$root_content_id" : "listing-12923213", - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "An old picture" - } - ] - }, - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - response = client.track("$create_content", comment_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_content_listing(): - # Sample $create_content event for listings - listing_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "listing-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $listing object - "$listing" : { - "$subject" : "2 Bedroom Apartment for Rent", - "$body" : "Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.", - "$contact_email" : "alex_301@domain.com", - "$contact_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6041", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" }, - "$locations" : [ - { - "$city" : "Seattle", - "$region" : "Washington", - "$country" : "US", - "$zipcode" : "98112" - } - ], - "$listed_items" : [ - { - "$price" : 2950000000, # $2950.00 - "$currency_code" : "USD", - "$tags" : ["heat", "washer/dryer"] - } - ], - "$images" : [ + "$promotions" : [ { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "Billy's picture" + "$promotion_id" : "FriendReferral", + "$status" : "$success", + "$referrer_user_id" : "janejane102", + "$credit_point" : { + "$amount" : 100, + "$credit_point_type" : "account karma" + } } ], - "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds - }, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - response = client.track("$create_content", listing_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + "$social_sign_on_type" : "$twitter", + "$account_types" : ["merchant", "premium"], -def create_content_message(): - # Sample $create_content event for messages - message_properties = { + # Suggested Custom Fields + "twitter_handle" : "billyjones", + "work_phone" : "1-347-555-5921", + "location" : "New London, NH", + "referral_code" : "MIKEFRIENDS", + "email_confirmed_status" : "$pending", + "phone_confirmed_status" : "$pending", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$create_account", create_account_properties) + + def create_content_comment(self): + # Sample $create_content event for comments + comment_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "message-23412", + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "comment-23412", # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $message object - "$message" : { - "$body" : "Let’s meet at 5pm", - "$contact_email" : "alex_301@domain.com", - "$recipient_user_ids" : ["fy9h989sjphh71"], - "$images" : [ + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $comment object + "$comment" : { + "$body" : "Congrats on the new role!", + "$contact_email" : "alex_301@domain.com", + "$parent_comment_id" : "comment-23407", + "$root_content_id" : "listing-12923213", + "$images" : [ { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "My hike today!" + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "An old picture" } ] }, + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$create_content", comment_properties) + + def create_content_listing(self): + # Sample $create_content event for listings + listing_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "listing-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $listing object + "$listing" : { + "$subject" : "2 Bedroom Apartment for Rent", + "$body" : "Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$listed_items" : [ + { + "$price" : 2950000000, # $2950.00 + "$currency_code" : "USD", + "$tags" : ["heat", "washer/dryer"] + } + ], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Billy's picture" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, # Send this information from a BROWSER client. "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$create_content", listing_properties) + + def create_content_message(self): + # Sample $create_content event for messages + message_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "message-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $message object + "$message" : { + "$body" : "Let’s meet at 5pm", + "$contact_email" : "alex_301@domain.com", + "$recipient_user_ids" : ["fy9h989sjphh71"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "My hike today!" + } + ] + }, + + # Send this information from a BROWSER client. + "$browser" : { "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", "$accept_language" : "en-US", "$content_language" : "en-GB" - } - } - response = client.track("$create_content", message_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_content_post(): - # Sample $create_content event for posts - post_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "post-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $post object - "$post" : { - "$subject" : "My new apartment!", - "$body" : "Moved into my new apartment yesterday.", - "$contact_email" : "alex_301@domain.com", - "$contact_address" : { - "$name" : "Bill Jones", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - }, - "$locations" : [ - { - "$city" : "Seattle", - "$region" : "Washington", - "$country" : "US", - "$zipcode" : "98112" - } - ], - "$categories" : ["Personal"], - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "View from the window!" } - ], - "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds - }, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" } - } - response = client.track("$create_content", post_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_content_profile(): - # Sample $create_content event for reviews - profile_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "profile-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $profile object - "$profile" : { - "$body" : "Hi! My name is Alex and I just moved to New London!", - "$contact_email" : "alex_301@domain.com", - "$contact_address" : { + return self.client.track("$create_content", message_properties) + + def create_content_post(self): + # Sample $create_content event for posts + post_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "post-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $post object + "$post" : { + "$subject" : "My new apartment!", + "$body" : "Moved into my new apartment yesterday.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$categories" : ["Personal"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "View from the window!" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$create_content", post_properties) + + def create_content_profile(self): + # Sample $create_content event for reviews + profile_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "profile-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $profile object + "$profile" : { + "$body" : "Hi! My name is Alex and I just moved to New London!", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { "$name" : "Alex Smith", "$phone" : "1-415-555-6041", "$city" : "New London", "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" + }, + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Alex's picture" + } + ], + "$categories" : [ + "Friends", + "Long-term dating" + ] }, - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "Alex's picture" - } - ], - "$categories" : [ - "Friends", - "Long-term dating" - ] - }, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - } - - response = client.track("$create_content", profile_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_content_review(): - # Sample $create_content event for reviews - review_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "review-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $review object - "$review" : { - "$subject" : "Amazing Tacos!", - "$body" : "I ate the tacos.", - "$contact_email" : "alex_301@domain.com", - "$locations" : [ - { - "$city" : "Seattle", - "$region" : "Washington", - "$country" : "US", - "$zipcode" : "98112" - } - ], - "$reviewed_content_id" : "listing-234234", - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "Calamari tacos." - } - ], - "$rating" : 4.5 - }, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + return self.client.track("$create_content", profile_properties) + + def create_content_review(self): + # Sample $create_content event for reviews + review_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "review-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $review object + "$review" : { + "$subject" : "Amazing Tacos!", + "$body" : "I ate the tacos.", + "$contact_email" : "alex_301@domain.com", + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$reviewed_content_id" : "listing-234234", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Calamari tacos." + } + ], + "$rating" : 4.5 + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - } - - response = client.track("$create_content", review_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def create_order(): - # Sample $create_order event - order_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - # Supported Fields - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$order_id" : "ORDER-28168441", - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$amount" : 115940000, # $115.94 - "$currency_code" : "USD", - "$billing_address" : { + return self.client.track("$create_content", review_properties) + + def create_order(self): + # Sample $create_order event + order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$order_id" : "ORDER-28168441", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$amount" : 115940000, # $115.94 + "$currency_code" : "USD", + "$billing_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -492,32 +461,32 @@ def create_order(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$payment_methods" : [ + }, + "$payment_methods" : [ { - "$payment_type" : "$credit_card", - "$payment_gateway" : "$braintree", - "$card_bin" : "542486", - "$card_last4" : "4444" + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" } - ], - "$ordered_from" : { - "$store_id" : "123", - "$store_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6040", - "$address_1" : "2100 Main Street", - "$address_2" : "Apt 3B", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - } - }, - "$brand_name" : "sift", - "$site_domain" : "sift.com", - "$site_country" : "US", - "$shipping_address" : { + ], + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$shipping_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -526,255 +495,226 @@ def create_order(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$expedited_shipping" : True, - "$shipping_method" : "$physical", - "$shipping_carrier" : "UPS", - "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], - "$items" : [ - { - "$item_id" : "12344321", - "$product_title" : "Microwavable Kettle Corn: Original Flavor", - "$price" : 4990000, # $4.99 - "$upc" : "097564307560", - "$sku" : "03586005", - "$brand" : "Peters Kettle Corn", - "$manufacturer" : "Peters Kettle Corn", - "$category" : "Food and Grocery", - "$tags" : ["Popcorn", "Snacks", "On Sale"], - "$quantity" : 4 }, - { + "$expedited_shipping" : True, + "$shipping_method" : "$physical", + "$shipping_carrier" : "UPS", + "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], + "$items" : [ + { + "$item_id" : "12344321", + "$product_title" : "Microwavable Kettle Corn: Original Flavor", + "$price" : 4990000, # $4.99 + "$upc" : "097564307560", + "$sku" : "03586005", + "$brand" : "Peters Kettle Corn", + "$manufacturer" : "Peters Kettle Corn", + "$category" : "Food and Grocery", + "$tags" : ["Popcorn", "Snacks", "On Sale"], + "$quantity" : 4 + }, + { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 2 + } + ], + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", + + "$promotions" : [ + { + "$promotion_id" : "FirstTimeBuyer", + "$status" : "$success", + "$description" : "$5 off", + "$discount" : { + "$amount" : 5000000, # $5.00 + "$currency_code" : "USD", + "$minimum_purchase_amount" : 25000000 # $25.00 + } + } + ], + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$create_order", order_properties) + + def flag_content(self): + # Sample $flag_content event + flag_content_properties = { + # Required Fields + "$user_id" : "billy_jones_301", # content creator + "$content_id" : "9671500641", + + # Supported Fields + "$flagged_by" : "jamieli89" + } + return self.client.track("$flag_content", flag_content_properties) + + def link_session_to_user(self): + # Sample $link_session_to_user event + link_session_to_user_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il" + } + return self.client.track("$link_session_to_user", link_session_to_user_properties) + + def login(self): + # Sample $login event + login_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$login_status" : "$failure", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$ip" : "128.148.1.135", + + # Optional Fields + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$failure_reason" : "$wrong_password", + "$username" : "billjones1@example.com", + "$account_types" : ["merchant", "premium"], + "$social_sign_on_type" : "$linkedin", + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + + # Send this information with a login from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$login", login_properties) + + def logout(self): + # Sample $logout event + logout_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$logout", logout_properties) + + def order_status(self): + # Sample $order_status event + order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$order_id" : "ORDER-28168441", + "$order_status" : "$canceled", + + # Optional Fields + "$reason" : "$payment_risk", + "$source" : "$manual_review", + "$analyst" : "someone@your-site.com", + "$webhook_id" : "3ff1082a4aea8d0c58e3643ddb7a5bb87ffffeb2492dca33", + "$description" : "Canceling because multiple fraudulent users on device", + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } + } + return self.client.track("$order_status", order_properties) + + def remove_item_from_cart(self): + # Sample $remove_item_from_cart event + remove_item_from_cart_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$item" : { "$item_id" : "B004834GQO", "$product_title" : "The Slanket Blanket-Texas Tea", "$price" : 39990000, # $39.99 + "$currency_code" : "USD", + "$quantity" : 2, "$upc" : "6786211451001", "$sku" : "004834GQ", "$brand" : "Slanket", "$manufacturer" : "Slanket", "$category" : "Blankets & Throws", "$tags" : ["Awesome", "Wintertime specials"], - "$color" : "Texas Tea", - "$quantity" : 2 + "$color" : "Texas Tea" + }, + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" } - ], - # For marketplaces, use $seller_user_id to identify the seller - "$seller_user_id" : "slinkys_emporium", + } - "$promotions" : [ - { - "$promotion_id" : "FirstTimeBuyer", - "$status" : "$success", - "$description" : "$5 off", - "$discount" : { - "$amount" : 5000000, # $5.00 - "$currency_code" : "USD", - "$minimum_purchase_amount" : 25000000 # $25.00 - } + return self.client.track("$remove_item_from_cart", remove_item_from_cart_properties) + + def security_notification(self): + # Sample $security_notification event + security_notification_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$notification_status" : "$sent", + # Optional fields if applicable + "$notification_type" : "$email", + "$notified_value" : "billy123@domain.com", + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" } - ], - - # Sample Custom Fields - "digital_wallet" : "apple_pay", # "google_wallet", etc. - "coupon_code" : "dollarMadness", - "shipping_choice" : "FedEx Ground Courier", - "is_first_time_buyer" : False, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" } - } - response = client.track("$create_order", order_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def flag_content(): - # Sample $flag_content event - flag_content_properties = { - # Required Fields - "$user_id" : "billy_jones_301", # content creator - "$content_id" : "9671500641", - - # Supported Fields - "$flagged_by" : "jamieli89" - } - response = client.track("$flag_content", flag_content_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def link_session_to_user(): - # Sample $link_session_to_user event - link_session_to_user_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$session_id" : "gigtleqddo84l8cm15qe4il" - } - response = client.track("$link_session_to_user", link_session_to_user_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def login(): - # Sample $login event - login_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$login_status" : "$failure", - - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$ip" : "128.148.1.135", - - # Optional Fields - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$failure_reason" : "$wrong_password", - "$username" : "billjones1@example.com", - "$account_types" : ["merchant", "premium"], - "$social_sign_on_type" : "$linkedin", - "$brand_name" : "sift", - "$site_domain" : "sift.com", - "$site_country" : "US", - - # Send this information with a login from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - response = client.track("$login", login_properties) - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def logout(): - # Sample $logout event - logout_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - response = client.track("$logout", logout_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def order_status(): - # Sample $order_status event - order_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$order_id" : "ORDER-28168441", - "$order_status" : "$canceled", - - # Optional Fields - "$reason" : "$payment_risk", - "$source" : "$manual_review", - "$analyst" : "someone@your-site.com", - "$webhook_id" : "3ff1082a4aea8d0c58e3643ddb7a5bb87ffffeb2492dca33", - "$description" : "Canceling because multiple fraudulent users on device", - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - response = client.track("$order_status", order_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def remove_item_from_cart(): - # Sample $remove_item_from_cart event - remove_item_from_cart_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - - # Supported Fields - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$item" : { - "$item_id" : "B004834GQO", - "$product_title" : "The Slanket Blanket-Texas Tea", - "$price" : 39990000, # $39.99 - "$currency_code" : "USD", - "$quantity" : 2, - "$upc" : "6786211451001", - "$sku" : "004834GQ", - "$brand" : "Slanket", - "$manufacturer" : "Slanket", - "$category" : "Blankets & Throws", - "$tags" : ["Awesome", "Wintertime specials"], - "$color" : "Texas Tea" - }, - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } + return self.client.track("$security_notification", security_notification_properties) - response = client.track("$remove_item_from_cart", remove_item_from_cart_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def security_notification(): - # Sample $security_notification event - security_notification_properties = { - # Required Fields - "$type" : "$security_notification", - "$api_key" : "YOUR_API_KEY", - "$user_id" : "billy_jones_301", - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$notification_status" : "$sent", - # Optional fields if applicable - "$notification_type" : "$email", - "$notified_value" : "billy123@domain.com", - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - - response = client.track("$security_notification", security_notification_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def transaction(): - # Sample $transaction event - transaction_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$amount" : 506790000, # $506.79 - "$currency_code" : "USD", - # Supported Fields - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$transaction_type" : "$sale", - "$transaction_status" : "$failure", - "$decline_category" : "$bank_decline", - "$order_id" : "ORDER-123124124", - "$transaction_id" : "719637215", - "$billing_address" : { # or "$sent_address" # or "$received_address" + def transaction(self): + # Sample $transaction event + transaction_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$amount" : 506790000, # $506.79 + "$currency_code" : "USD", + # Supported Fields + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$transaction_type" : "$sale", + "$transaction_status" : "$failure", + "$decline_category" : "$bank_decline", + "$order_id" : "ORDER-123124124", + "$transaction_id" : "719637215", + "$billing_address" : { # or "$sent_address" # or "$received_address" "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -783,45 +723,38 @@ def transaction(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$brand_name" : "sift", - "$site_domain" : "sift.com", - "$site_country" : "US", - "$ordered_from" : { - "$store_id" : "123", - "$store_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6040", - "$address_1" : "2100 Main Street", - "$address_2" : "Apt 3B", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - } - }, - # Credit card example - "$payment_method" : { - "$payment_type" : "$credit_card", - "$payment_gateway" : "$braintree", - "$card_bin" : "542486", - "$card_last4" : "4444" - }, - - # Bank account example - # "$payment_method" : { - # "$payment_type" : "$electronic_fund_transfer", - # "$routing_number" : "021001088" - #}, - # See other payment method options in the field description - - # Supported fields for 3DS - "$status_3ds" : "$attempted", - "$triggered_3ds" : "$processor", - "$merchant_initiated_transaction" : False, - - # Supported Fields - "$shipping_address" : { + }, + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + # Credit card example + "$payment_method" : { + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" + }, + + # Supported fields for 3DS + "$status_3ds" : "$attempted", + "$triggered_3ds" : "$processor", + "$merchant_initiated_transaction" : False, + + # Supported Fields + "$shipping_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -830,52 +763,49 @@ def transaction(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$session_id" : "gigtleqddo84l8cm15qe4il", - - # For marketplaces, use $seller_user_id to identify the seller - "$seller_user_id" : "slinkys_emporium", - - # Sample Custom Fields - "digital_wallet" : "apple_pay", # "google_wallet", etc. - "coupon_code" : "dollarMadness", - "shipping_choice" : "FedEx Ground Courier", - "is_first_time_buyer" : False, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + }, + "$session_id" : "gigtleqddo84l8cm15qe4il", + + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - } - response = client.track("$transaction", transaction_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_account(): - # Sample $update_account event - update_account_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - - # Supported Fields - "$changed_password" : True, - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$name" : "Bill Jones", - "$phone" : "1-415-555-6040", - "$referrer_user_id" : "janejane102", - "$payment_methods" : [ + return self.client.track("$transaction", transaction_properties) + + def update_account(self): + # Sample $update_account event + update_account_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + + # Supported Fields + "$changed_password" : True, + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$referrer_user_id" : "janejane102", + "$payment_methods" : [ { - "$payment_type" : "$credit_card", - "$card_bin" : "542486", - "$card_last4" : "4444" + "$payment_type" : "$credit_card", + "$card_bin" : "542486", + "$card_last4" : "4444" } - ], - "$billing_address" : - { + ], + "$billing_address" : + { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -884,8 +814,8 @@ def update_account(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$shipping_address" : { + }, + "$shipping_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -894,358 +824,334 @@ def update_account(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, + }, - "$social_sign_on_type" : "$twitter", - "$account_types" : ["merchant", "premium"], + "$social_sign_on_type" : "$twitter", + "$account_types" : ["merchant", "premium"], - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - - response = client.track("$update_account", update_account_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_content_comment(): - # Sample $update_content event for comments - update_content_comment_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "comment-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $comment object - "$comment" : { - "$body" : "Congrats on the new role!", - "$contact_email" : "alex_301@domain.com", - "$parent_comment_id" : "comment-23407", - "$root_content_id" : "listing-12923213", - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "An old picture" - } - ] - }, - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - } - response = client.track("$update_content", update_content_comment_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_content_listing(): - # Sample $update_content event for listings - update_content_listing_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "listing-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $listing object - "$listing" : { - "$subject" : "2 Bedroom Apartment for Rent", - "$body" : "Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.", - "$contact_email" : "alex_301@domain.com", - "$contact_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6041", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" + + return self.client.track("$update_account", update_account_properties) + + def update_content_comment(self): + # Sample $update_content event for comments + update_content_comment_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "comment-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $comment object + "$comment" : { + "$body" : "Congrats on the new role!", + "$contact_email" : "alex_301@domain.com", + "$parent_comment_id" : "comment-23407", + "$root_content_id" : "listing-12923213", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "An old picture" + } + ] }, - "$locations" : [ - { - "$city" : "Seattle", - "$region" : "Washington", + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + return self.client.track("$update_content", update_content_comment_properties) + + def update_content_listing(self): + # Sample $update_content event for listings + update_content_listing_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "listing-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $listing object + "$listing" : { + "$subject" : "2 Bedroom Apartment for Rent", + "$body" : "Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6041", + "$city" : "New London", + "$region" : "New Hampshire", "$country" : "US", - "$zipcode" : "98112" - } - ], - "$listed_items" : [ - { - "$price" : 2950000000, # $2950.00 - "$currency_code" : "USD", - "$tags" : ["heat", "washer/dryer"] - } - ], - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "Billy's picture" - } - ], - "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds - }, - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$listed_items" : [ + { + "$price" : 2950000000, # $2950.00 + "$currency_code" : "USD", + "$tags" : ["heat", "washer/dryer"] + } + ], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Billy's picture" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } } - } - response = client.track("$update_content", update_content_listing_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_content_message(): - # Sample $update_content event for messages - update_content_message_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "message-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $message object - "$message" : { - "$body" : "Lets meet at 5pm", - "$contact_email" : "alex_301@domain.com", - "$recipient_user_ids" : ["fy9h989sjphh71"], - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "My hike today!" - } - ] - }, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" + return self.client.track("$update_content", update_content_listing_properties) + + def update_content_message(self): + # Sample $update_content event for messages + update_content_message_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "message-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $message object + "$message" : { + "$body" : "Lets meet at 5pm", + "$contact_email" : "alex_301@domain.com", + "$recipient_user_ids" : ["fy9h989sjphh71"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "My hike today!" + } + ] + }, + + # Send this information from a BROWSER client. + "$browser" : { + "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + "$accept_language" : "en-US", + "$content_language" : "en-GB" + } } - } - response = client.track("$update_content", update_content_message_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_content_post(): - # Sample $update_content event for posts - update_content_post_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "post-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $post object - "$post" : { - "$subject" : "My new apartment!", - "$body" : "Moved into my new apartment yesterday.", - "$contact_email" : "alex_301@domain.com", - "$contact_address" : { - "$name" : "Bill Jones", + return self.client.track("$update_content", update_content_message_properties) + + def update_content_post(self): + # Sample $update_content event for posts + update_content_post_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "post-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $post object + "$post" : { + "$subject" : "My new apartment!", + "$body" : "Moved into my new apartment yesterday.", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Bill Jones", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + }, + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$categories" : ["Personal"], + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "View from the window!" + } + ], + "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds + }, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + return self.client.track("$update_content", update_content_post_properties) + + def update_content_profile(self): + # Sample $update_content event for reviews + update_content_profile_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "profile-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $profile object + "$profile" : { + "$body" : "Hi! My name is Alex and I just moved to New London!", + "$contact_email" : "alex_301@domain.com", + "$contact_address" : { + "$name" : "Alex Smith", + "$phone" : "1-415-555-6041", "$city" : "New London", "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" + }, + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Alex's picture" + } + ], + "$categories" : [ + "Friends", + "Long-term dating" + ] }, - "$locations" : [ - { - "$city" : "Seattle", - "$region" : "Washington", - "$country" : "US", - "$zipcode" : "98112" - } - ], - "$categories" : ["Personal"], - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "View from the window!" - } - ], - "$expiration_time" : 1549063157000 # UNIX timestamp in milliseconds - }, - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" + # ========================================= + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } } -} - - response = client.track("$update_content", update_content_post_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_content_profile(): - # Sample $update_content event for reviews - update_content_profile_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "profile-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $profile object - "$profile" : { - "$body" : "Hi! My name is Alex and I just moved to New London!", - "$contact_email" : "alex_301@domain.com", - "$contact_address" : { - "$name" : "Alex Smith", - "$phone" : "1-415-555-6041", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" + return self.client.track("$update_content", update_content_profile_properties) + + def update_content_review(self): + # Sample $update_content event for reviews + update_content_review_properties = { + # Required fields + "$user_id" : "fyw3989sjpqr71", + "$content_id" : "review-23412", + + # Recommended fields + "$session_id" : "a234ksjfgn435sfg", + "$status" : "$active", + "$ip" : "255.255.255.0", + + # Required $review object + "$review" : { + "$subject" : "Amazing Tacos!", + "$body" : "I ate the tacos.", + "$contact_email" : "alex_301@domain.com", + "$locations" : [ + { + "$city" : "Seattle", + "$region" : "Washington", + "$country" : "US", + "$zipcode" : "98112" + } + ], + "$reviewed_content_id" : "listing-234234", + "$images" : [ + { + "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", + "$link" : "https://www.domain.com/file.png", + "$description" : "Calamari tacos." + } + ], + "$rating" : 4.5 }, - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "Alex's picture" - } - ], - "$categories" : [ - "Friends", - "Long-term dating" - ] - }, - # ========================================= - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } } - } + return self.client.track("$update_content", update_content_review_properties) - response = client.track("$update_content", update_content_profile_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_content_review(): - # Sample $update_content event for reviews - update_content_review_properties = { - # Required fields - "$user_id" : "fyw3989sjpqr71", - "$content_id" : "review-23412", - - # Recommended fields - "$session_id" : "a234ksjfgn435sfg", - "$status" : "$active", - "$ip" : "255.255.255.0", - - # Required $review object - "$review" : { - "$subject" : "Amazing Tacos!", - "$body" : "I ate the tacos.", - "$contact_email" : "alex_301@domain.com", - "$locations" : [ - { - "$city" : "Seattle", - "$region" : "Washington", - "$country" : "US", - "$zipcode" : "98112" - } - ], - "$reviewed_content_id" : "listing-234234", - "$images" : [ - { - "$md5_hash" : "0cc175b9c0f1b6a831c399e269772661", - "$link" : "https://www.domain.com/file.png", - "$description" : "Calamari tacos." - } - ], - "$rating" : 4.5 - }, - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" - } - } - - response = client.track("$update_content", update_content_review_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_order(): - # Sample $update_order event - update_order_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - # Supported Fields - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$order_id" : "ORDER-28168441", - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$amount" : 115940000, # $115.94 - "$currency_code" : "USD", - "$billing_address" : { + def update_order(self): + # Sample $update_order event + update_order_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + # Supported Fields + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$order_id" : "ORDER-28168441", + "$user_email" : "billjones1@example.com", + "$verification_phone_number" : "+123456789012", + "$amount" : 115940000, # $115.94 + "$currency_code" : "USD", + "$billing_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -1254,32 +1160,32 @@ def update_order(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$payment_methods" : [ + }, + "$payment_methods" : [ { - "$payment_type" : "$credit_card", - "$payment_gateway" : "$braintree", - "$card_bin" : "542486", - "$card_last4" : "4444" + "$payment_type" : "$credit_card", + "$payment_gateway" : "$braintree", + "$card_bin" : "542486", + "$card_last4" : "4444" } - ], - "$brand_name" : "sift", - "$site_domain" : "sift.com", - "$site_country" : "US", - "$ordered_from" : { - "$store_id" : "123", - "$store_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6040", - "$address_1" : "2100 Main Street", - "$address_2" : "Apt 3B", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - } - }, - "$shipping_address" : { + ], + "$brand_name" : "sift", + "$site_domain" : "sift.com", + "$site_country" : "US", + "$ordered_from" : { + "$store_id" : "123", + "$store_address" : { + "$name" : "Bill Jones", + "$phone" : "1-415-555-6040", + "$address_1" : "2100 Main Street", + "$address_2" : "Apt 3B", + "$city" : "New London", + "$region" : "New Hampshire", + "$country" : "US", + "$zipcode" : "03257" + } + }, + "$shipping_address" : { "$name" : "Bill Jones", "$phone" : "1-415-555-6041", "$address_1" : "2100 Main Street", @@ -1288,121 +1194,112 @@ def update_order(): "$region" : "New Hampshire", "$country" : "US", "$zipcode" : "03257" - }, - "$expedited_shipping" : True, - "$shipping_method" : "$physical", - "$shipping_carrier" : "UPS", - "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], - "$items" : [ - { - "$item_id" : "12344321", - "$product_title" : "Microwavable Kettle Corn: Original Flavor", - "$price" : 4990000, # $4.99 - "$upc" : "097564307560", - "$sku" : "03586005", - "$brand" : "Peters Kettle Corn", - "$manufacturer" : "Peters Kettle Corn", - "$category" : "Food and Grocery", - "$tags" : ["Popcorn", "Snacks", "On Sale"], - "$quantity" : 4 }, - { - "$item_id" : "B004834GQO", - "$product_title" : "The Slanket Blanket-Texas Tea", - "$price" : 39990000, # $39.99 - "$upc" : "6786211451001", - "$sku" : "004834GQ", - "$brand" : "Slanket", - "$manufacturer" : "Slanket", - "$category" : "Blankets & Throws", - "$tags" : ["Awesome", "Wintertime specials"], - "$color" : "Texas Tea", - "$quantity" : 2 - } - ], - # For marketplaces, use $seller_user_id to identify the seller - "$seller_user_id" : "slinkys_emporium", + "$expedited_shipping" : True, + "$shipping_method" : "$physical", + "$shipping_carrier" : "UPS", + "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], + "$items" : [ + { + "$item_id" : "12344321", + "$product_title" : "Microwavable Kettle Corn: Original Flavor", + "$price" : 4990000, # $4.99 + "$upc" : "097564307560", + "$sku" : "03586005", + "$brand" : "Peters Kettle Corn", + "$manufacturer" : "Peters Kettle Corn", + "$category" : "Food and Grocery", + "$tags" : ["Popcorn", "Snacks", "On Sale"], + "$quantity" : 4 + }, + { + "$item_id" : "B004834GQO", + "$product_title" : "The Slanket Blanket-Texas Tea", + "$price" : 39990000, # $39.99 + "$upc" : "6786211451001", + "$sku" : "004834GQ", + "$brand" : "Slanket", + "$manufacturer" : "Slanket", + "$category" : "Blankets & Throws", + "$tags" : ["Awesome", "Wintertime specials"], + "$color" : "Texas Tea", + "$quantity" : 2 + } + ], + # For marketplaces, use $seller_user_id to identify the seller + "$seller_user_id" : "slinkys_emporium", - "$promotions" : [ - { - "$promotion_id" : "FirstTimeBuyer", - "$status" : "$success", - "$description" : "$5 off", - "$discount" : { - "$amount" : 5000000, # $5.00 - "$currency_code" : "USD", - "$minimum_purchase_amount" : 25000000 # $25.00 + "$promotions" : [ + { + "$promotion_id" : "FirstTimeBuyer", + "$status" : "$success", + "$description" : "$5 off", + "$discount" : { + "$amount" : 5000000, # $5.00 + "$currency_code" : "USD", + "$minimum_purchase_amount" : 25000000 # $25.00 + } } + ], + + # Sample Custom Fields + "digital_wallet" : "apple_pay", # "google_wallet", etc. + "coupon_code" : "dollarMadness", + "shipping_choice" : "FedEx Ground Courier", + "is_first_time_buyer" : False, + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" } - ], - - # Sample Custom Fields - "digital_wallet" : "apple_pay", # "google_wallet", etc. - "coupon_code" : "dollarMadness", - "shipping_choice" : "FedEx Ground Courier", - "is_first_time_buyer" : False, - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" } - } - - response = client.track("$update_order", update_order_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def update_password(): - # Sample $update_password event - update_password_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$status" : "$success", - "$reason" : "$forced_reset", - "$ip" : "128.148.1.135", # IP of the user that entered the new password after the old password was reset - # Send this information from an APP client. - "$app" : { - # Example for the iOS Calculator app. - "$os" : "iOS", - "$os_version" : "10.1.3", - "$device_manufacturer" : "Apple", - "$device_model" : "iPhone 4,2", - "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", - "$app_name" : "Calculator", - "$app_version" : "3.2.7", - "$client_language" : "en-US" + return self.client.track("$update_order", update_order_properties) + + def update_password(self): + # Sample $update_password event + update_password_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$status" : "$success", + "$reason" : "$forced_reset", + "$ip" : "128.148.1.135", # IP of the user that entered the new password after the old password was reset + # Send this information from an APP client. + "$app" : { + # Example for the iOS Calculator app. + "$os" : "iOS", + "$os_version" : "10.1.3", + "$device_manufacturer" : "Apple", + "$device_model" : "iPhone 4,2", + "$device_unique_id" : "A3D261E4-DE0A-470B-9E4A-720F3D3D22E6", + "$app_name" : "Calculator", + "$app_version" : "3.2.7", + "$client_language" : "en-US" + } + } + return self.client.track("$update_password", update_password_properties) + + def verification(self): + # Sample $verification event + verification_properties = { + # Required Fields + "$user_id" : "billy_jones_301", + "$session_id" : "gigtleqddo84l8cm15qe4il", + "$status" : "$pending", + + # Optional fields if applicable + "$verified_event" : "$login", + "$reason" : "$automated_rule", + "$verification_type" : "$sms", + "$verified_value" : "14155551212" } - } - - response = client.track("$update_password", update_password_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def verification(): - # Sample $verification event - verification_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$status" : "$pending", - - # Optional fields if applicable - "$verified_event" : "$login", - "$reason" : "$automated_rule", - "$verification_type" : "$sms", - "$verified_value" : "14155551212" - } - response = client.track("$verification", verification_properties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" \ No newline at end of file + return self.client.track("$verification", verification_properties) + + \ No newline at end of file diff --git a/test_integration_app/labels_api/__init__.py b/test_integration_app/labels_api/__init__.py deleted file mode 100644 index 124289c..0000000 --- a/test_integration_app/labels_api/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from labels_api import test_labels_api \ No newline at end of file diff --git a/test_integration_app/labels_api/test_labels_api.py b/test_integration_app/labels_api/test_labels_api.py deleted file mode 100644 index e9c07cf..0000000 --- a/test_integration_app/labels_api/test_labels_api.py +++ /dev/null @@ -1,26 +0,0 @@ -import sift - -from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -client = sift.Client(api_key = api_key) - -def user_label(): - properties = { - "$is_fraud" : True, # ... or False; Required - "$abuse_type" : "payment_abuse", # Required - "$description" : "The user was testing cards repeatedly for a valid card", # Optional - "$source" : "manual review", # Optional - "$analyst" : "someone@your-site.com" # Optional - } - response = client.label("haneeshv@exalture.com", properties) - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def user_unlabel(): - response = client.unlabel("haneeshv@exalture.com", abuse_type = "payment_abuse") - print(response) - assert(response.is_ok()) - assert response.http_status_code == 204, "api_status should be 204" diff --git a/test_integration_app/main.py b/test_integration_app/main.py index 083c39e..4ce0a6a 100644 --- a/test_integration_app/main.py +++ b/test_integration_app/main.py @@ -3,127 +3,91 @@ from workflows_api import test_workflows_api from score_api import test_score_api from verifications_api import test_verification_api -from labels_api import test_labels_api from psp_merchant_api import test_psp_merchant_api -#Events APIs +class Utils: + def isOK(self, response): + if(hasattr(response, 'status')): + return ((response.status == 0) and ((response.http_status_code == 200) or (response.http_status_code == 201))) + else: + return ((response.http_status_code == 200) or (response.http_status_code == 201)) + +def runAllMethods(): + objUtils = Utils() + objEvents = test_events_api.EventsAPI() + ObjDecision = test_decisions_api.DecisionAPI() + objScore = test_score_api.ScoreAPI() + objWorkflow = test_workflows_api.WorkflowsAPI() + objVerification = test_verification_api.VerificationAPI() + objPSPMerchant = test_psp_merchant_api.PSPMerchantAPI() + + #Events APIs + + assert (objUtils.isOK(objEvents.add_item_to_cart()) == True) + assert (objUtils.isOK(objEvents.add_promotion()) == True) + assert (objUtils.isOK(objEvents.chargeback()) == True) + assert (objUtils.isOK(objEvents.content_status()) == True) + assert (objUtils.isOK(objEvents.create_account()) == True) + assert (objUtils.isOK(objEvents.create_content_comment()) == True) + assert (objUtils.isOK(objEvents.create_content_listing()) == True) + assert (objUtils.isOK(objEvents.create_content_message()) == True) + assert (objUtils.isOK(objEvents.create_content_post()) == True) + assert (objUtils.isOK(objEvents.create_content_profile()) == True) + assert (objUtils.isOK(objEvents.create_content_review()) == True) + assert (objUtils.isOK(objEvents.create_order()) == True) + assert (objUtils.isOK(objEvents.flag_content()) == True) + assert (objUtils.isOK(objEvents.link_session_to_user()) == True) + assert (objUtils.isOK(objEvents.login()) == True) + assert (objUtils.isOK(objEvents.logout()) == True) + assert (objUtils.isOK(objEvents.order_status()) == True) + assert (objUtils.isOK(objEvents.remove_item_from_cart()) == True) + assert (objUtils.isOK(objEvents.security_notification()) == True) + assert (objUtils.isOK(objEvents.transaction()) == True) + assert (objUtils.isOK(objEvents.update_account()) == True) + assert (objUtils.isOK(objEvents.update_content_comment()) == True) + assert (objUtils.isOK(objEvents.update_content_listing()) == True) + assert (objUtils.isOK(objEvents.update_content_message()) == True) + assert (objUtils.isOK(objEvents.update_content_post()) == True) + assert (objUtils.isOK(objEvents.update_content_profile()) == True) + assert (objUtils.isOK(objEvents.update_content_review()) == True) + assert (objUtils.isOK(objEvents.update_order()) == True) + assert (objUtils.isOK(objEvents.update_password()) == True) + assert (objUtils.isOK(objEvents.verification()) == True) + + # Decision APIs + + assert (objUtils.isOK(ObjDecision.apply_user_decision()) == False) + assert (objUtils.isOK(ObjDecision.apply_order_decision()) == False) + assert (objUtils.isOK(ObjDecision.apply_session_decision()) == False) + assert (objUtils.isOK(ObjDecision.apply_content_decision()) == False) + assert (objUtils.isOK(ObjDecision.get_user_decisions()) == True) + assert (objUtils.isOK(ObjDecision.get_order_decisions()) == True) + assert (objUtils.isOK(ObjDecision.get_content_decisions()) == True) + assert (objUtils.isOK(ObjDecision.get_session_decisions()) == True) + assert (objUtils.isOK(ObjDecision.get_decisions()) == True) + + # Workflows APIs + + assert (objUtils.isOK(objWorkflow.synchronous_workflows()) == True) + + # Score APIs + + assert (objUtils.isOK(objScore.get_user_score()) == False) + + # Verification APIs + + assert (objUtils.isOK(objVerification.send()) == True) + assert (objUtils.isOK(objVerification.resend()) == True) + assert (objUtils.isOK(objVerification.check()) == True) + + # PSP Merchant APIs + + assert (objUtils.isOK(objPSPMerchant.create_merchant()) == True) + assert (objUtils.isOK(objPSPMerchant.edit_merchant()) == True) + assert (objUtils.isOK(objPSPMerchant.get_a_merchant_profile()) == True) + assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles()) == True) + assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles(batch_size=10, batch_token=None)) == True) + + +runAllMethods() -# test_events_api.add_item_to_cart() - -# test_events_api.add_promotion() - -# test_events_api.chargeback() - -# test_events_api.content_status() - -# test_events_api.create_account() - -# test_events_api.create_content_comment() - -# test_events_api.create_content_listing() - -# test_events_api.create_content_message() - -# test_events_api.create_content_post() - -# test_events_api.create_content_profile() - -# test_events_api.create_content_review() - -# test_events_api.create_order() - -# test_events_api.flag_content() - -# test_events_api.link_session_to_user() - -# test_events_api.login() - -# test_events_api.logout() - -# test_events_api.order_status() - -# test_events_api.remove_item_from_cart() - -# test_events_api.security_notification() - -# test_events_api.transaction() - -# test_events_api.update_account() - -# test_events_api.update_content_comment() - -# test_events_api.update_content_listing() - -# test_events_api.update_content_message() - -# test_events_api.update_content_post() - -# test_events_api.update_content_profile() - -# test_events_api.update_content_review() - -# test_events_api.update_order() - -# test_events_api.update_password() - -# test_events_api.verification() - -# Decision APIs - -# test_decisions_api.apply_user_decision_request() - -# test_decisions_api.apply_order_decision_request() - -# test_decisions_api.apply_session_decision() - -# test_decisions_api.apply_content_decision() - -# test_decisions_api.get_user_decisions() - -# test_decisions_api.get_order_decisions() - -# test_decisions_api.get_content_decisions() - -# test_decisions_api.get_session_decisions() - -# test_decisions_api.get_decisions("session") #user, order, content, session - -# Workflows APIs - -# test_workflows_api.get_workflow_status("workflow_run_id") - -# Score APIs - -# test_score_api.create_order_with_return_score() - -# test_score_api.get_score() - -# test_score_api.get_user_score() - -# test_score_api.rescore_user() - -# Labeling - -# test_labels_api.user_label() - -# test_labels_api.user_unlabel() - -# Verification APIs - -# test_verification_api.send() - -# test_verification_api.resend() - -# test_verification_api.check("271571") - -# PSP Merchant APIs - -# test_psp_merchant_api.create_merchant() - -# test_psp_merchant_api.edit_merchant() - -# test_psp_merchant_api.get_a_merchant_profile() - -# test_psp_merchant_api.get_merchant_profiles() - -test_psp_merchant_api.get_merchant_profiles(batch_size=2, batch_token="64d0a6a5afb931525995e75b") \ No newline at end of file diff --git a/test_integration_app/psp_merchant_api/__init__.py b/test_integration_app/psp_merchant_api/__init__.py index 8cc869d..5aa1905 100644 --- a/test_integration_app/psp_merchant_api/__init__.py +++ b/test_integration_app/psp_merchant_api/__init__.py @@ -1 +1,2 @@ -from psp_merchant_api import test_psp_merchant_api \ No newline at end of file +from psp_merchant_api import test_psp_merchant_api + diff --git a/test_integration_app/psp_merchant_api/test_psp_merchant_api.py b/test_integration_app/psp_merchant_api/test_psp_merchant_api.py index 1a09536..4570cb6 100644 --- a/test_integration_app/psp_merchant_api/test_psp_merchant_api.py +++ b/test_integration_app/psp_merchant_api/test_psp_merchant_api.py @@ -1,76 +1,72 @@ import sift +import string +import random # define the random module from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -account_id = env['ACCT'] -client = sift.Client(api_key = api_key, account_id = account_id) -def create_merchant(): - merchantProperties={ - "id": "merchant_id_01013", - "name": "Wonderful Payments Inc.13", - "description": "Wonderful Payments payment provider.", - "address": { - "name": "Alany", - "address_1": "Big Payment blvd, 22", - "address_2": "apt, 8", - "city": "New Orleans", - "region": "NA", - "country": "US", - "zipcode": "76830", - "phone": "0394888320" - }, - "category": "1002", - "service_level": "Platinum", - "status": "active", - "risk_profile": { - "level": "low", - "score": 10 - } - } - response = client.create_psp_merchant_profile(merchantProperties) - print(response) - assert response.http_status_code == 201, "api_status should be 201" + +class PSPMerchantAPI(): + # Get the value of API_KEY and ACCOUNT_ID from environment variable + api_key = env['API_KEY'] + account_id = env['ACCT'] + + client = sift.Client(api_key = api_key, account_id = account_id) -def edit_merchant(): - merchantProperties={ - "id": "merchant_id_01013", - "name": "Wonderful Payments Inc.13 edit", - "description": "Wonderful Payments payment provider. edit", - "address": { - "name": "Alany", - "address_1": "Big Payment blvd, 22", - "address_2": "apt, 8", - "city": "New Orleans", - "region": "NA", - "country": "US", - "zipcode": "76830", - "phone": "0394888320" - }, - "category": "1002", - "service_level": "Platinum", - "status": "active", - "risk_profile": { - "level": "low", - "score": 10 + def create_merchant(self): + merchant_id = ''.join(random.choices(string.digits, k = 7)) + merchantProperties={ + "id": 'merchant_id_' + merchant_id, + "name": "Wonderful Payments Inc.13", + "description": "Wonderful Payments payment provider.", + "address": { + "name": "Alany", + "address_1": "Big Payment blvd, 22", + "address_2": "apt, 8", + "city": "New Orleans", + "region": "NA", + "country": "US", + "zipcode": "76830", + "phone": "0394888320" + }, + "category": "1002", + "service_level": "Platinum", + "status": "active", + "risk_profile": { + "level": "low", + "score": 10 + } } - } - response = client.update_psp_merchant_profile("merchant_id_01013", merchantProperties) - print(response) - assert response.http_status_code == 200, "api_status should be 200" - -def get_a_merchant_profile(): - response = client.get_a_psp_merchant_profile("merchant_id_01013") - print(response) - assert response.http_status_code == 200, "api_status should be 200" + return self.client.create_psp_merchant_profile(merchantProperties) + + def edit_merchant(self): + merchantProperties={ + "id": "merchant_id_01013", + "name": "Wonderful Payments Inc.13 edit", + "description": "Wonderful Payments payment provider. edit", + "address": { + "name": "Alany", + "address_1": "Big Payment blvd, 22", + "address_2": "apt, 8", + "city": "New Orleans", + "region": "NA", + "country": "US", + "zipcode": "76830", + "phone": "0394888320" + }, + "category": "1002", + "service_level": "Platinum", + "status": "active", + "risk_profile": { + "level": "low", + "score": 10 + } + } + return self.client.update_psp_merchant_profile("merchant_id_01013", merchantProperties) -def get_merchant_profiles(): - response = client.get_psp_merchant_profiles() - print(response) - assert response.http_status_code == 200, "api_status should be 200" + def get_a_merchant_profile(self): + return self.client.get_a_psp_merchant_profile("merchant_id_01013") -def get_merchant_profiles(batch_token = None, batch_size = None): - response = client.get_psp_merchant_profiles(batch_token, batch_size) - print(response) - assert response.http_status_code == 200, "api_status should be 200" \ No newline at end of file + def get_merchant_profiles(self, batch_token = None, batch_size = None): + return self.client.get_psp_merchant_profiles(batch_token, batch_size) + + \ No newline at end of file diff --git a/test_integration_app/score_api/__init__.py b/test_integration_app/score_api/__init__.py index c6e1b23..4ab0dee 100644 --- a/test_integration_app/score_api/__init__.py +++ b/test_integration_app/score_api/__init__.py @@ -1 +1,2 @@ -from score_api import test_score_api \ No newline at end of file +from score_api import test_score_api + diff --git a/test_integration_app/score_api/test_score_api.py b/test_integration_app/score_api/test_score_api.py index d254b63..f8b55c6 100644 --- a/test_integration_app/score_api/test_score_api.py +++ b/test_integration_app/score_api/test_score_api.py @@ -1,150 +1,12 @@ import sift from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -client = sift.Client(api_key = api_key) -def create_order_with_return_score(): - # Sample $create_order event - order_properties = { - # Required Fields - "$user_id" : "billy_jones_301", - # Supported Fields - "$session_id" : "gigtleqddo84l8cm15qe4il", - "$order_id" : "ORDER-28168441", - "$user_email" : "billjones1@example.com", - "$verification_phone_number" : "+123456789012", - "$amount" : 115940000, # $115.94 - "$currency_code" : "USD", - "$billing_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6041", - "$address_1" : "2100 Main Street", - "$address_2" : "Apt 3B", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - }, - "$payment_methods" : [ - { - "$payment_type" : "$credit_card", - "$payment_gateway" : "$braintree", - "$card_bin" : "542486", - "$card_last4" : "4444" - } - ], - "$ordered_from" : { - "$store_id" : "123", - "$store_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6040", - "$address_1" : "2100 Main Street", - "$address_2" : "Apt 3B", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - } - }, - "$brand_name" : "sift", - "$site_domain" : "sift.com", - "$site_country" : "US", - "$shipping_address" : { - "$name" : "Bill Jones", - "$phone" : "1-415-555-6041", - "$address_1" : "2100 Main Street", - "$address_2" : "Apt 3B", - "$city" : "New London", - "$region" : "New Hampshire", - "$country" : "US", - "$zipcode" : "03257" - }, - "$expedited_shipping" : True, - "$shipping_method" : "$physical", - "$shipping_carrier" : "UPS", - "$shipping_tracking_numbers": ["1Z204E380338943508", "1Z204E380338943509"], - "$items" : [ - { - "$item_id" : "12344321", - "$product_title" : "Microwavable Kettle Corn: Original Flavor", - "$price" : 4990000, # $4.99 - "$upc" : "097564307560", - "$sku" : "03586005", - "$brand" : "Peters Kettle Corn", - "$manufacturer" : "Peters Kettle Corn", - "$category" : "Food and Grocery", - "$tags" : ["Popcorn", "Snacks", "On Sale"], - "$quantity" : 4 - }, - { - "$item_id" : "B004834GQO", - "$product_title" : "The Slanket Blanket-Texas Tea", - "$price" : 39990000, # $39.99 - "$upc" : "6786211451001", - "$sku" : "004834GQ", - "$brand" : "Slanket", - "$manufacturer" : "Slanket", - "$category" : "Blankets & Throws", - "$tags" : ["Awesome", "Wintertime specials"], - "$color" : "Texas Tea", - "$quantity" : 2 - } - ], - # For marketplaces, use $seller_user_id to identify the seller - "$seller_user_id" : "slinkys_emporium", +class ScoreAPI(): + # Get the value of API_KEY from environment variable + api_key = env['API_KEY'] + client = sift.Client(api_key = api_key) + + def get_user_score(self): + return self.client.get_user_score(user_id = "billy_jones_301", abuse_types=["payment_abuse", "promotion_abuse"]) - "$promotions" : [ - { - "$promotion_id" : "FirstTimeBuyer", - "$status" : "$success", - "$description" : "$5 off", - "$discount" : { - "$amount" : 5000000, # $5.00 - "$currency_code" : "USD", - "$minimum_purchase_amount" : 25000000 # $25.00 - } - } - ], - - # Sample Custom Fields - "digital_wallet" : "apple_pay", # "google_wallet", etc. - "coupon_code" : "dollarMadness", - "shipping_choice" : "FedEx Ground Courier", - "is_first_time_buyer" : False, - - # Send this information from a BROWSER client. - "$browser" : { - "$user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", - "$accept_language" : "en-US", - "$content_language" : "en-GB" - } - } - - response = client.track("$create_order", order_properties, return_score= True, abuse_types=['payment_abuse', 'promotion_abuse']) - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def get_score(): - response = client.score("haneeshv@exalture.com") - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def get_user_score(): - response = client.get_user_score("haneeshv@exalture.com") - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def rescore_user(): - response = client.rescore_user("haneeshv@exalture.com", abuse_types=['payment_abuse', 'account_abuse']) - print(response) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" \ No newline at end of file diff --git a/test_integration_app/verifications_api/__init__.py b/test_integration_app/verifications_api/__init__.py index 192aad0..1985889 100644 --- a/test_integration_app/verifications_api/__init__.py +++ b/test_integration_app/verifications_api/__init__.py @@ -1 +1,2 @@ -from verifications_api import test_verification_api \ No newline at end of file +from verifications_api import test_verification_api + diff --git a/test_integration_app/verifications_api/test_verification_api.py b/test_integration_app/verifications_api/test_verification_api.py index d5dfc2c..0fd0cde 100644 --- a/test_integration_app/verifications_api/test_verification_api.py +++ b/test_integration_app/verifications_api/test_verification_api.py @@ -1,59 +1,49 @@ import sift from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -client = sift.Client(api_key = api_key) +class VerificationAPI(): + # Get the value of API_KEY from environment variable + api_key = env['API_KEY'] + client = sift.Client(api_key = api_key) + + def send(self): + sendProperties = { + '$user_id': 'billy_jones_301', + '$send_to': 'billy_jones_301@gmail.com', + '$verification_type': '$email', + '$brand_name': 'MyTopBrand', + '$language': 'en', + '$site_country': 'IN', + '$event': { + '$session_id': 'SOME_SESSION_ID', + '$verified_event': '$login', + '$verified_entity_id': 'SOME_SESSION_ID', + '$reason': '$automated_rule', + '$ip': '192.168.1.1', + '$browser': { + '$user_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', + '$accept_language': 'en-US', + '$content_language': 'en-GB' + } + } + } + return self.client.verification_send(sendProperties) + + def resend(self): + resendProperties = { + '$user_id': 'billy_jones_301', + '$verified_event': '$login', + '$verified_entity_id': 'SOME_SESSION_ID' + } + return self.client.verification_resend(resendProperties) -def send(): - sendProperties = { - '$user_id': 'haneeshv@exalture.com', - '$send_to': 'haneeshv@exalture.com', - '$verification_type': '$email', - '$brand_name': 'MyTopBrand', - '$language': 'en', - '$site_country': 'IN', - '$event': { - '$session_id': 'SOME_SESSION_ID', + def check(self): + checkProperties = { + '$user_id': 'billy_jones_301', + '$code': '123456', '$verified_event': '$login', - '$verified_entity_id': 'SOME_SESSION_ID', - '$reason': '$automated_rule', - '$ip': '192.168.1.1', - '$browser': { - '$user_agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', - '$accept_language': 'en-US', - '$content_language': 'en-GB' - } + '$verified_entity_id': "SOME_SESSION_ID" } - } - - response = client.verification_send(sendProperties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def resend(): - resendProperties = { - '$user_id': 'haneeshv@exalture.com', - '$verified_event': '$login', - '$verified_entity_id': 'SOME_SESSION_ID' - } - - response = client.verification_resend(resendProperties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" - -def check(code): - checkProperties = { - '$user_id': 'haneeshv@exalture.com', - '$code': code, - '$verified_event': '$login', - '$verified_entity_id': "SOME_SESSION_ID" - } + return self.client.verification_check(checkProperties) - response = client.verification_check(checkProperties) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" diff --git a/test_integration_app/workflows_api/__init__.py b/test_integration_app/workflows_api/__init__.py index b04f380..353cd25 100644 --- a/test_integration_app/workflows_api/__init__.py +++ b/test_integration_app/workflows_api/__init__.py @@ -1 +1,2 @@ -from workflows_api import test_workflows_api \ No newline at end of file +from workflows_api import test_workflows_api + diff --git a/test_integration_app/workflows_api/test_workflows_api.py b/test_integration_app/workflows_api/test_workflows_api.py index abd4cb6..62f9a85 100644 --- a/test_integration_app/workflows_api/test_workflows_api.py +++ b/test_integration_app/workflows_api/test_workflows_api.py @@ -1,14 +1,19 @@ import sift from os import environ as env - # Get the value of API_KEY from environment variable -api_key = env['API_KEY'] -client = sift.Client(api_key = api_key) - -def get_workflow_status(workflow_run_id): - response = client.get_workflow_status(workflow_run_id) - assert(response.is_ok()) - assert response.api_status == 0, "api_status should be 0" - assert response.api_error_message == "OK", "api_error_message should be OK" + + +class WorkflowsAPI(): + # Get the value of API_KEY from environment variable + api_key = env['API_KEY'] + client = sift.Client(api_key = api_key) + + def synchronous_workflows(self): + properties = { + '$user_id' : 'test_user', + '$user_email' : 'sample_user@gmail.com' + } + return self.client.track('$create_order', properties, return_workflow_status=True, + return_route_info=True, abuse_types=['promo_abuse', 'content_abuse', 'payment_abuse']) From 0dd0faf65b2129460964702cac9db5522fcbf229 Mon Sep 17 00:00:00 2001 From: haneeshv <135820493+haneeshv@users.noreply.github.com> Date: Mon, 25 Sep 2023 15:46:50 +0530 Subject: [PATCH 07/11] Delete test_sift_verification_apis.py Not required, created for testing purpose --- test_sift_verification_apis.py | 66 ---------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 test_sift_verification_apis.py diff --git a/test_sift_verification_apis.py b/test_sift_verification_apis.py deleted file mode 100644 index 5b2ab9c..0000000 --- a/test_sift_verification_apis.py +++ /dev/null @@ -1,66 +0,0 @@ -from decimal import Decimal -import sift -import sys - -if sys.version_info[0] < 3: - import six.moves.urllib as urllib -else: - import urllib.parse - -def response_with_data_header(): - return { - 'content-type': 'application/json; charset=UTF-8' - } - -sendProperties = { - '$user_id' : 'haneeshv@exalture.com', - '$send_to' : 'haneeshv@exalture.com', - '$verification_type': '$email', - '$brand_name' : 'MyTopBrand', - '$language' : 'en', - "$site_country": "IN", - '$event': { - '$session_id': 'SOME_SESSION_ID', - # '$verified_event': '$login', - '$verified_entity_id': 'SOME_SESSION_ID', - '$reason': '$automated_rule', - '$ip': '192.168.1.1', - '$browser': { - '$user_agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36' - } - } -} - -resendProperties = { - '$user_id' : 'haneeshv@exalture.com', - '$verified_event': '$login', - '$verified_entity_id': 'SOME_SESSION_ID' -} - -checkProperties = { - '$user_id' : 'haneeshv@exalture.com', - '$code' : '636068', - '$verified_event': '$login', - '$verified_entity_id' : "SOME_SESSION_ID" -} - -def test_verification_send(): - client = sift.Client(api_key='valid-api-key', account_id='ACCT') - response = client.verification_send(sendProperties) - print(response) - -def test_verification_resend(): - client = sift.Client(api_key='valid-api-key', account_id='ACCT') - response = client.verification_resend(resendProperties) - print(response) - -def test_verification_check(): - client = sift.Client(api_key='valid-api-key', account_id='ACCT') - response = client.verification_check(checkProperties) - print(response) - -test_verification_send() - -# test_verification_resend() - -# test_verification_check() From 05c4500d3b9606b2e1fe85b3f955457da9ea6637 Mon Sep 17 00:00:00 2001 From: Haneesh Date: Sat, 30 Sep 2023 13:52:03 +0530 Subject: [PATCH 08/11] Review changes updated --- .../decisions_api/__init__.py | 1 - .../decisions_api/test_decisions_api.py | 20 ++--- test_integration_app/events_api/__init__.py | 1 - .../events_api/test_events_api.py | 78 ++++++++++--------- test_integration_app/globals.py | 4 + test_integration_app/main.py | 44 ++++++----- .../psp_merchant_api/__init__.py | 1 - .../psp_merchant_api/test_psp_merchant_api.py | 4 +- test_integration_app/score_api/__init__.py | 1 - .../score_api/test_score_api.py | 6 +- .../verifications_api/__init__.py | 1 - .../test_verification_api.py | 15 ++-- .../workflows_api/__init__.py | 1 - .../workflows_api/test_workflows_api.py | 13 ++-- 14 files changed, 101 insertions(+), 89 deletions(-) create mode 100644 test_integration_app/globals.py diff --git a/test_integration_app/decisions_api/__init__.py b/test_integration_app/decisions_api/__init__.py index 993fb27..e6af361 100644 --- a/test_integration_app/decisions_api/__init__.py +++ b/test_integration_app/decisions_api/__init__.py @@ -1,2 +1 @@ from decisions_api import test_decisions_api - diff --git a/test_integration_app/decisions_api/test_decisions_api.py b/test_integration_app/decisions_api/test_decisions_api.py index 1f604b1..1993f3d 100644 --- a/test_integration_app/decisions_api/test_decisions_api.py +++ b/test_integration_app/decisions_api/test_decisions_api.py @@ -1,12 +1,15 @@ import sift +import globals from os import environ as env class DecisionAPI(): # Get the value of API_KEY from environment variable api_key = env['API_KEY'] - account_id = env['ACCT'] + account_id = env['ACCOUNT_ID'] client = sift.Client(api_key = api_key, account_id = account_id) + globals.initialize() + user_id = globals.user_id def apply_user_decision(self): applyDecisionRequest = { @@ -16,7 +19,7 @@ def apply_user_decision(self): "description" : "User linked to three other payment abusers and ordering high value items" } - return self.client.apply_user_decision("billy_jones_301", applyDecisionRequest) + return self.client.apply_user_decision(self.user_id, applyDecisionRequest) def apply_order_decision(self): applyOrderDecisionRequest = { @@ -25,7 +28,7 @@ def apply_order_decision(self): "description" : "Auto block pending order as score exceeded risk threshold of 90" } - return self.client.apply_order_decision("billy_jones_301", "ORDER-1234567", applyOrderDecisionRequest) + return self.client.apply_order_decision(self.user_id, "ORDER-1234567", applyOrderDecisionRequest) def apply_session_decision(self): applySessionDecisionRequest = { @@ -35,7 +38,7 @@ def apply_session_decision(self): "description" : "compromised account reported to customer service" } - return self.client.apply_session_decision('billy_jones_301', "session_id", applySessionDecisionRequest) + return self.client.apply_session_decision(self.user_id, "session_id", applySessionDecisionRequest) def apply_content_decision(self): applyContentDecisionRequest = { @@ -45,20 +48,19 @@ def apply_content_decision(self): "description" : "fraudulent listing" } - return self.client.apply_content_decision('billy_jones_301', "content_id", applyContentDecisionRequest) + return self.client.apply_content_decision(self.user_id, "content_id", applyContentDecisionRequest) def get_user_decisions(self): - return self.client.get_user_decisions("billy_jones_301") + return self.client.get_user_decisions(self.user_id) def get_order_decisions(self): return self.client.get_order_decisions("ORDER-1234567") def get_content_decisions(self): - return self.client.get_content_decisions("billy_jones_301", "CONTENT_ID") + return self.client.get_content_decisions(self.user_id, "CONTENT_ID") def get_session_decisions(self): - return self.client.get_session_decisions("billy_jones_301", "SESSION_ID") + return self.client.get_session_decisions(self.user_id, "SESSION_ID") def get_decisions(self): return self.client.get_decisions(entity_type='user', limit=10, start_from=5, abuse_types='legacy,payment_abuse') - diff --git a/test_integration_app/events_api/__init__.py b/test_integration_app/events_api/__init__.py index 2a42a7a..3bf15fe 100644 --- a/test_integration_app/events_api/__init__.py +++ b/test_integration_app/events_api/__init__.py @@ -1,2 +1 @@ from events_api import test_events_api - diff --git a/test_integration_app/events_api/test_events_api.py b/test_integration_app/events_api/test_events_api.py index 57aceb7..f123a73 100644 --- a/test_integration_app/events_api/test_events_api.py +++ b/test_integration_app/events_api/test_events_api.py @@ -1,17 +1,20 @@ import sift +import globals from os import environ as env - class EventsAPI(): # Get the value of API_KEY from environment variable api_key = env['API_KEY'] client = sift.Client(api_key = api_key) + globals.initialize() + user_id = globals.user_id + user_email = globals.user_email def add_item_to_cart(self): add_item_to_cart_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported Fields "$session_id" : "gigtleqddo84l8cm15qe4il", "$item" : { @@ -44,7 +47,7 @@ def add_item_to_cart(self): def add_promotion(self): add_promotion_properties = { # Required fields. - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported fields. "$promotions" : [ # Example of a promotion for monetary discounts off good or services @@ -75,7 +78,7 @@ def chargeback(self): "$order_id" : "ORDER-123124124", "$transaction_id" : "719637215", # Recommended Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$chargeback_state" : "$lost", "$chargeback_reason" : "$duplicate" } @@ -85,7 +88,7 @@ def content_status(self): # Sample $content_status event content_status_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$content_id" : "9671500641", "$status" : "$paused", @@ -102,10 +105,10 @@ def create_account(self): # Sample $create_account event create_account_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported Fields "$session_id" : "gigtleqddo84l8cm15qe4il", - "$user_email" : "billjones1@example.com", + "$user_email" : self.user_email, "$verification_phone_number" : "+123456789012", "$name" : "Bill Jones", "$phone" : "1-415-555-6040", @@ -172,7 +175,7 @@ def create_content_comment(self): # Sample $create_content event for comments comment_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "comment-23412", # Recommended fields @@ -207,7 +210,7 @@ def create_content_listing(self): # Sample $create_content event for listings listing_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "listing-23412", # Recommended fields @@ -266,7 +269,7 @@ def create_content_message(self): # Sample $create_content event for messages message_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "message-23412", # Recommended fields @@ -301,7 +304,7 @@ def create_content_post(self): # Sample $create_content event for posts post_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "post-23412", # Recommended fields @@ -353,7 +356,7 @@ def create_content_profile(self): # Sample $create_content event for reviews profile_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "profile-23412", # Recommended fields @@ -399,7 +402,7 @@ def create_content_review(self): # Sample $create_content event for reviews review_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "review-23412", # Recommended fields @@ -444,11 +447,11 @@ def create_order(self): # Sample $create_order event order_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported Fields "$session_id" : "gigtleqddo84l8cm15qe4il", "$order_id" : "ORDER-28168441", - "$user_email" : "billjones1@example.com", + "$user_email" : self.user_email, "$verification_phone_number" : "+123456789012", "$amount" : 115940000, # $115.94 "$currency_code" : "USD", @@ -562,7 +565,7 @@ def flag_content(self): # Sample $flag_content event flag_content_properties = { # Required Fields - "$user_id" : "billy_jones_301", # content creator + "$user_id" : self.user_id, # content creator "$content_id" : "9671500641", # Supported Fields @@ -574,7 +577,7 @@ def link_session_to_user(self): # Sample $link_session_to_user event link_session_to_user_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$session_id" : "gigtleqddo84l8cm15qe4il" } return self.client.track("$link_session_to_user", link_session_to_user_properties) @@ -583,13 +586,13 @@ def login(self): # Sample $login event login_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$login_status" : "$failure", "$session_id" : "gigtleqddo84l8cm15qe4il", "$ip" : "128.148.1.135", # Optional Fields - "$user_email" : "billjones1@example.com", + "$user_email" : self.user_email, "$verification_phone_number" : "+123456789012", "$failure_reason" : "$wrong_password", "$username" : "billjones1@example.com", @@ -612,7 +615,7 @@ def logout(self): # Sample $logout event logout_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Send this information from a BROWSER client. "$browser" : { @@ -627,7 +630,7 @@ def order_status(self): # Sample $order_status event order_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$order_id" : "ORDER-28168441", "$order_status" : "$canceled", @@ -651,7 +654,7 @@ def remove_item_from_cart(self): # Sample $remove_item_from_cart event remove_item_from_cart_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported Fields "$session_id" : "gigtleqddo84l8cm15qe4il", @@ -683,7 +686,7 @@ def security_notification(self): # Sample $security_notification event security_notification_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$session_id" : "gigtleqddo84l8cm15qe4il", "$notification_status" : "$sent", # Optional fields if applicable @@ -703,11 +706,11 @@ def transaction(self): # Sample $transaction event transaction_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$amount" : 506790000, # $506.79 "$currency_code" : "USD", # Supported Fields - "$user_email" : "billjones1@example.com", + "$user_email" : self.user_email, "$verification_phone_number" : "+123456789012", "$transaction_type" : "$sale", "$transaction_status" : "$failure", @@ -788,11 +791,11 @@ def update_account(self): # Sample $update_account event update_account_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported Fields "$changed_password" : True, - "$user_email" : "billjones1@example.com", + "$user_email" : self.user_email, "$verification_phone_number" : "+123456789012", "$name" : "Bill Jones", "$phone" : "1-415-555-6040", @@ -843,7 +846,7 @@ def update_content_comment(self): # Sample $update_content event for comments update_content_comment_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "comment-23412", # Recommended fields @@ -884,7 +887,7 @@ def update_content_listing(self): # Sample $update_content event for listings update_content_listing_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "listing-23412", # Recommended fields @@ -948,7 +951,7 @@ def update_content_message(self): # Sample $update_content event for messages update_content_message_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "message-23412", # Recommended fields @@ -984,7 +987,7 @@ def update_content_post(self): # Sample $update_content event for posts update_content_post_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "post-23412", # Recommended fields @@ -1041,7 +1044,7 @@ def update_content_profile(self): # Sample $update_content event for reviews update_content_profile_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "profile-23412", # Recommended fields @@ -1093,7 +1096,7 @@ def update_content_review(self): # Sample $update_content event for reviews update_content_review_properties = { # Required fields - "$user_id" : "fyw3989sjpqr71", + "$user_id" : self.user_id, "$content_id" : "review-23412", # Recommended fields @@ -1143,11 +1146,11 @@ def update_order(self): # Sample $update_order event update_order_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, # Supported Fields "$session_id" : "gigtleqddo84l8cm15qe4il", "$order_id" : "ORDER-28168441", - "$user_email" : "billjones1@example.com", + "$user_email" : self.user_email, "$verification_phone_number" : "+123456789012", "$amount" : 115940000, # $115.94 "$currency_code" : "USD", @@ -1266,7 +1269,7 @@ def update_password(self): # Sample $update_password event update_password_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$session_id" : "gigtleqddo84l8cm15qe4il", "$status" : "$success", "$reason" : "$forced_reset", @@ -1290,7 +1293,7 @@ def verification(self): # Sample $verification event verification_properties = { # Required Fields - "$user_id" : "billy_jones_301", + "$user_id" : self.user_id, "$session_id" : "gigtleqddo84l8cm15qe4il", "$status" : "$pending", @@ -1301,5 +1304,4 @@ def verification(self): "$verified_value" : "14155551212" } return self.client.track("$verification", verification_properties) - \ No newline at end of file diff --git a/test_integration_app/globals.py b/test_integration_app/globals.py new file mode 100644 index 0000000..5cb65ab --- /dev/null +++ b/test_integration_app/globals.py @@ -0,0 +1,4 @@ +def initialize(): + global user_id, user_email + user_id = 'billy_jones_301' + user_email = 'billjones1@example.com' diff --git a/test_integration_app/main.py b/test_integration_app/main.py index 4ce0a6a..10321f4 100644 --- a/test_integration_app/main.py +++ b/test_integration_app/main.py @@ -11,11 +11,11 @@ def isOK(self, response): return ((response.status == 0) and ((response.http_status_code == 200) or (response.http_status_code == 201))) else: return ((response.http_status_code == 200) or (response.http_status_code == 201)) - + def runAllMethods(): objUtils = Utils() objEvents = test_events_api.EventsAPI() - ObjDecision = test_decisions_api.DecisionAPI() + objDecision = test_decisions_api.DecisionAPI() objScore = test_score_api.ScoreAPI() objWorkflow = test_workflows_api.WorkflowsAPI() objVerification = test_verification_api.VerificationAPI() @@ -53,33 +53,40 @@ def runAllMethods(): assert (objUtils.isOK(objEvents.update_order()) == True) assert (objUtils.isOK(objEvents.update_password()) == True) assert (objUtils.isOK(objEvents.verification()) == True) - + print("Events API Tested") + # Decision APIs - assert (objUtils.isOK(ObjDecision.apply_user_decision()) == False) - assert (objUtils.isOK(ObjDecision.apply_order_decision()) == False) - assert (objUtils.isOK(ObjDecision.apply_session_decision()) == False) - assert (objUtils.isOK(ObjDecision.apply_content_decision()) == False) - assert (objUtils.isOK(ObjDecision.get_user_decisions()) == True) - assert (objUtils.isOK(ObjDecision.get_order_decisions()) == True) - assert (objUtils.isOK(ObjDecision.get_content_decisions()) == True) - assert (objUtils.isOK(ObjDecision.get_session_decisions()) == True) - assert (objUtils.isOK(ObjDecision.get_decisions()) == True) - + assert (objUtils.isOK(objDecision.apply_user_decision()) == False) + assert (objUtils.isOK(objDecision.apply_order_decision()) == False) + assert (objUtils.isOK(objDecision.apply_session_decision()) == False) + assert (objUtils.isOK(objDecision.apply_content_decision()) == False) + assert (objUtils.isOK(objDecision.get_user_decisions()) == True) + assert (objUtils.isOK(objDecision.get_order_decisions()) == True) + assert (objUtils.isOK(objDecision.get_content_decisions()) == True) + assert (objUtils.isOK(objDecision.get_session_decisions()) == True) + assert (objUtils.isOK(objDecision.get_decisions()) == True) + print("Decision API Tested") + # Workflows APIs assert (objUtils.isOK(objWorkflow.synchronous_workflows()) == True) - + print("Workflow API Tested") + # Score APIs assert (objUtils.isOK(objScore.get_user_score()) == False) - + print("Score API Tested") + # Verification APIs assert (objUtils.isOK(objVerification.send()) == True) assert (objUtils.isOK(objVerification.resend()) == True) - assert (objUtils.isOK(objVerification.check()) == True) - + checkResponse = objVerification.check() + assert (objUtils.isOK(checkResponse) == True) + assert (checkResponse.body["status"] == 50) + print("Verification API Tested") + # PSP Merchant APIs assert (objUtils.isOK(objPSPMerchant.create_merchant()) == True) @@ -87,7 +94,6 @@ def runAllMethods(): assert (objUtils.isOK(objPSPMerchant.get_a_merchant_profile()) == True) assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles()) == True) assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles(batch_size=10, batch_token=None)) == True) - + print("PSP Merchant API Tested") runAllMethods() - diff --git a/test_integration_app/psp_merchant_api/__init__.py b/test_integration_app/psp_merchant_api/__init__.py index 5aa1905..46637e6 100644 --- a/test_integration_app/psp_merchant_api/__init__.py +++ b/test_integration_app/psp_merchant_api/__init__.py @@ -1,2 +1 @@ from psp_merchant_api import test_psp_merchant_api - diff --git a/test_integration_app/psp_merchant_api/test_psp_merchant_api.py b/test_integration_app/psp_merchant_api/test_psp_merchant_api.py index 4570cb6..c321f0d 100644 --- a/test_integration_app/psp_merchant_api/test_psp_merchant_api.py +++ b/test_integration_app/psp_merchant_api/test_psp_merchant_api.py @@ -4,11 +4,10 @@ from os import environ as env - class PSPMerchantAPI(): # Get the value of API_KEY and ACCOUNT_ID from environment variable api_key = env['API_KEY'] - account_id = env['ACCT'] + account_id = env['ACCOUNT_ID'] client = sift.Client(api_key = api_key, account_id = account_id) @@ -68,5 +67,4 @@ def get_a_merchant_profile(self): def get_merchant_profiles(self, batch_token = None, batch_size = None): return self.client.get_psp_merchant_profiles(batch_token, batch_size) - \ No newline at end of file diff --git a/test_integration_app/score_api/__init__.py b/test_integration_app/score_api/__init__.py index 4ab0dee..71ccddf 100644 --- a/test_integration_app/score_api/__init__.py +++ b/test_integration_app/score_api/__init__.py @@ -1,2 +1 @@ from score_api import test_score_api - diff --git a/test_integration_app/score_api/test_score_api.py b/test_integration_app/score_api/test_score_api.py index f8b55c6..5c61b22 100644 --- a/test_integration_app/score_api/test_score_api.py +++ b/test_integration_app/score_api/test_score_api.py @@ -1,4 +1,5 @@ import sift +import globals from os import environ as env @@ -6,7 +7,8 @@ class ScoreAPI(): # Get the value of API_KEY from environment variable api_key = env['API_KEY'] client = sift.Client(api_key = api_key) + globals.initialize() + user_id = globals.user_id def get_user_score(self): - return self.client.get_user_score(user_id = "billy_jones_301", abuse_types=["payment_abuse", "promotion_abuse"]) - + return self.client.get_user_score(user_id = self.user_id, abuse_types=["payment_abuse", "promotion_abuse"]) diff --git a/test_integration_app/verifications_api/__init__.py b/test_integration_app/verifications_api/__init__.py index 1985889..710885a 100644 --- a/test_integration_app/verifications_api/__init__.py +++ b/test_integration_app/verifications_api/__init__.py @@ -1,2 +1 @@ from verifications_api import test_verification_api - diff --git a/test_integration_app/verifications_api/test_verification_api.py b/test_integration_app/verifications_api/test_verification_api.py index 0fd0cde..b35478d 100644 --- a/test_integration_app/verifications_api/test_verification_api.py +++ b/test_integration_app/verifications_api/test_verification_api.py @@ -1,4 +1,5 @@ import sift +import globals from os import environ as env @@ -6,11 +7,14 @@ class VerificationAPI(): # Get the value of API_KEY from environment variable api_key = env['API_KEY'] client = sift.Client(api_key = api_key) - + globals.initialize() + user_id = globals.user_id + user_email = globals.user_email + def send(self): sendProperties = { - '$user_id': 'billy_jones_301', - '$send_to': 'billy_jones_301@gmail.com', + '$user_id': self.user_id, + '$send_to': self.user_email, '$verification_type': '$email', '$brand_name': 'MyTopBrand', '$language': 'en', @@ -32,7 +36,7 @@ def send(self): def resend(self): resendProperties = { - '$user_id': 'billy_jones_301', + '$user_id': self.user_id, '$verified_event': '$login', '$verified_entity_id': 'SOME_SESSION_ID' } @@ -40,10 +44,9 @@ def resend(self): def check(self): checkProperties = { - '$user_id': 'billy_jones_301', + '$user_id': self.user_id, '$code': '123456', '$verified_event': '$login', '$verified_entity_id': "SOME_SESSION_ID" } return self.client.verification_check(checkProperties) - diff --git a/test_integration_app/workflows_api/__init__.py b/test_integration_app/workflows_api/__init__.py index 353cd25..0b1a1fe 100644 --- a/test_integration_app/workflows_api/__init__.py +++ b/test_integration_app/workflows_api/__init__.py @@ -1,2 +1 @@ from workflows_api import test_workflows_api - diff --git a/test_integration_app/workflows_api/test_workflows_api.py b/test_integration_app/workflows_api/test_workflows_api.py index 62f9a85..4dd26d6 100644 --- a/test_integration_app/workflows_api/test_workflows_api.py +++ b/test_integration_app/workflows_api/test_workflows_api.py @@ -1,19 +1,20 @@ import sift - +import globals from os import environ as env - class WorkflowsAPI(): # Get the value of API_KEY from environment variable api_key = env['API_KEY'] client = sift.Client(api_key = api_key) + globals.initialize() + user_id = globals.user_id + user_email = globals.user_email def synchronous_workflows(self): properties = { - '$user_id' : 'test_user', - '$user_email' : 'sample_user@gmail.com' + '$user_id' : self.user_id, + '$user_email' : self.user_email } return self.client.track('$create_order', properties, return_workflow_status=True, return_route_info=True, abuse_types=['promo_abuse', 'content_abuse', 'payment_abuse']) - - + \ No newline at end of file From 089e47452a580bf84a1b45465c646377eb18bf8a Mon Sep 17 00:00:00 2001 From: mjouahri-sift <113396109+mjouahri-sift@users.noreply.github.com> Date: Tue, 3 Oct 2023 03:22:29 -0700 Subject: [PATCH 09/11] [API-7343] Enable scores percentiles in the scores api. (#100) Enable scores percentiles in the scores api --- sift/client.py | 19 ++++++++++++++---- tests/test_client.py | 47 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/sift/client.py b/sift/client.py index e3242a2..37c9d6e 100644 --- a/sift/client.py +++ b/sift/client.py @@ -180,8 +180,7 @@ def track( params['force_workflow_run'] = 'true' if include_score_percentiles: - field_types = ['SCORE_PERCENTILES'] - params['fields'] = ','.join(field_types) + params['fields'] = 'SCORE_PERCENTILES' try: response = self.session.post( path, @@ -193,7 +192,7 @@ def track( except requests.exceptions.RequestException as e: raise ApiException(str(e), path) - def score(self, user_id, timeout=None, abuse_types=None, version=None): + def score(self, user_id, timeout=None, abuse_types=None, version=None, include_score_percentiles=False): """Retrieves a user's fraud score from the Sift Science API. This call is blocking. Check out https://siftscience.com/resources/references/score_api.html for more information on our Score response structure. @@ -210,6 +209,9 @@ def score(self, user_id, timeout=None, abuse_types=None, version=None): version(optional): Use a different version of the Sift Science API for this call. + include_score_percentiles(optional) : Whether to add new parameter in the query parameter. + if include_score_percentiles is true then add a new parameter called fields in the query parameter + Returns: A sift.client.Response object if the score call succeeded, or raises an ApiException. @@ -227,6 +229,9 @@ def score(self, user_id, timeout=None, abuse_types=None, version=None): if abuse_types: params['abuse_types'] = ','.join(abuse_types) + if include_score_percentiles: + params['fields'] = 'SCORE_PERCENTILES' + url = self._score_url(user_id, version) try: @@ -239,7 +244,7 @@ def score(self, user_id, timeout=None, abuse_types=None, version=None): except requests.exceptions.RequestException as e: raise ApiException(str(e), url) - def get_user_score(self, user_id, timeout=None, abuse_types=None): + def get_user_score(self, user_id, timeout=None, abuse_types=None, include_score_percentiles=False): """Fetches the latest score(s) computed for the specified user and abuse types from the Sift Science API. As opposed to client.score() and client.rescore_user(), this *does not* compute a new score for the user; it simply fetches the latest score(s) which have computed. These scores may be arbitrarily old. @@ -256,6 +261,9 @@ def get_user_score(self, user_id, timeout=None, abuse_types=None): should be returned (if scores were requested). If not specified, a score will be returned for every abuse_type to which you are subscribed. + include_score_percentiles(optional) : Whether to add new parameter in the query parameter. + if include_score_percentiles is true then add a new parameter called fields in the query parameter + Returns: A sift.client.Response object if the score call succeeded, or raises an ApiException. @@ -271,6 +279,9 @@ def get_user_score(self, user_id, timeout=None, abuse_types=None): if abuse_types: params['abuse_types'] = ','.join(abuse_types) + if include_score_percentiles: + params['fields'] = 'SCORE_PERCENTILES' + try: response = self.session.get( url, diff --git a/tests/test_client.py b/tests/test_client.py index adca48e..b7a6553 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1411,7 +1411,7 @@ def test_update_psp_merchant_profile(self): self.assertIsInstance(response, sift.client.Response) assert ('address' in response.body) - def test_with__include_score_percentiles_ok(self): + def test_with_include_score_percentiles_ok(self): event = '$transaction' mock_response = mock.Mock() mock_response.content = '{"status": 0, "error_message": "OK"}' @@ -1453,6 +1453,51 @@ def test_include_score_percentiles_as_false_ok(self): assert (response.api_status == 0) assert (response.api_error_message == "OK") + def test_score_api_include_score_percentiles_ok(self): + mock_response = mock.Mock() + mock_response.content = score_response_json() + mock_response.json.return_value = json.loads(mock_response.content) + mock_response.status_code = 200 + mock_response.headers = response_with_data_header() + with mock.patch.object(self.sift_client.session, 'get') as mock_get: + mock_get.return_value = mock_response + response = self.sift_client.score(user_id='12345', include_score_percentiles=True) + mock_get.assert_called_with( + 'https://api.siftscience.com/v205/score/12345', + params={'api_key': self.test_key, 'fields': 'SCORE_PERCENTILES'}, + headers=mock.ANY, + timeout=mock.ANY) + self.assertIsInstance(response, sift.client.Response) + assert (response.is_ok()) + assert (response.api_error_message == "OK") + assert (response.body['score'] == 0.85) + assert (response.body['scores']['content_abuse']['score'] == 0.14) + assert (response.body['scores']['payment_abuse']['score'] == 0.97) + + def test_get_user_score_include_score_percentiles_ok(self): + """Test the GET /{version}/users/{userId}/score API, i.e. client.get_user_score() + """ + test_timeout = 5 + mock_response = mock.Mock() + mock_response.content = USER_SCORE_RESPONSE_JSON + mock_response.json.return_value = json.loads(mock_response.content) + mock_response.status_code = 200 + mock_response.headers = response_with_data_header() + with mock.patch.object(self.sift_client.session, 'get') as mock_get: + mock_get.return_value = mock_response + response = self.sift_client.get_user_score(user_id='12345', timeout=test_timeout, include_score_percentiles=True) + mock_get.assert_called_with( + 'https://api.siftscience.com/v205/users/12345/score', + params={'api_key': self.test_key, 'fields': 'SCORE_PERCENTILES'}, + headers=mock.ANY, + timeout=test_timeout) + self.assertIsInstance(response, sift.client.Response) + assert (response.is_ok()) + assert (response.api_error_message == "OK") + assert (response.body['entity_id'] == '12345') + assert (response.body['scores']['content_abuse']['score'] == 0.14) + assert (response.body['scores']['payment_abuse']['score'] == 0.97) + assert ('latest_decisions' in response.body) def main(): unittest.main() From adbd15f806a0692624659cfc648fe97ba1b85bf8 Mon Sep 17 00:00:00 2001 From: Vitalii Iaskal <112494848+viaskal-sift@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:29:56 +0300 Subject: [PATCH 10/11] Release 5.5.0 (#101) Release 5.5.0 --- CHANGES.md | 3 +++ sift/version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 62622ec..ba98b37 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +5.5.0 2023-10-03 +- Score percentiles for Score API + 5.4.0 2023-07-26 - Support for Verification API diff --git a/sift/version.py b/sift/version.py index db10107..e3f5976 100644 --- a/sift/version.py +++ b/sift/version.py @@ -1,2 +1,2 @@ -VERSION = '5.4.0' +VERSION = '5.5.0' API_VERSION = '205' From 83af6fa399708cd51f3f7220b1678e5a0aed05cc Mon Sep 17 00:00:00 2001 From: Haneesh Date: Fri, 13 Oct 2023 18:50:51 +0530 Subject: [PATCH 11/11] message added --- test_integration_app/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_integration_app/main.py b/test_integration_app/main.py index 10321f4..348de2d 100644 --- a/test_integration_app/main.py +++ b/test_integration_app/main.py @@ -95,5 +95,7 @@ def runAllMethods(): assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles()) == True) assert (objUtils.isOK(objPSPMerchant.get_merchant_profiles(batch_size=10, batch_token=None)) == True) print("PSP Merchant API Tested") + + print("Execution completed") runAllMethods()