Siftsciex v0.3.1 Siftsciex.Event.Account View Source

Functions for managing Account related events in Sift Science

This module provides functions for registering Account related events with Sift Science there are two reserved events relating to accounts for Sift Science. This module supports both those events:

  • create_account
  • update_account

They are fairly self-explanatory, this module provides functions that abstract away the full round trip. To use the functions in this module you will need to map your internal account representation to match the Siftsciex.Event.Account.data/0 structure, the only required key is user_id although the more data you can provide the better your results will be.

Link to this section Summary

Functions

Creates a new Account Event for Sift Science, this is not a complete event but will generate all the data specific to the account

Creates a new $update_account Event for Sift Science, this handles everything for the payload except the $api_key

Link to this section Types

Link to this type data() View Source
data() :: %{
  :user_id => String.t(),
  optional(string_attr()) => String.t(),
  optional(:payment_methods) => [Siftsciex.Event.Payload.PaymentMethod.data()],
  optional(:billing_address) => Siftsciex.Event.Payload.Address.data(),
  optional(:shipping_address) => Siftsciex.Event.Payload.Address.data(),
  optional(:promotions) => [Siftsciex.Event.Payload.Promotion.data()]
}
Link to this type string_attr() View Source
string_attr() ::
  :user_email | :name | :phone | :referrer_user_id | :social_sign_on_type
Link to this type t() View Source
t() :: %Siftsciex.Event.Account{
  "$api_key": String.t(),
  "$billing_address": :empty | Siftsciex.Event.Payload.Address.t(),
  "$name": Siftsciex.Event.Payload.payload_string(),
  "$payment_methods": :empty | [Siftsciex.Event.Payload.PaymentMethod.t()],
  "$phone": Siftsciex.Event.Payload.payload_string(),
  "$promotions": :empty | [Siftsciex.Event.Payload.Promotion.t()],
  "$referrer_user_id": Siftsciex.Event.Payload.payload_string(),
  "$shipping_address": :empty | Siftsciex.Event.Payload.Address.t(),
  "$social_sign_on_type": Siftsciex.Event.Payload.payload_string(),
  "$type": Siftsciex.Event.Payload.payload_string(),
  "$user_email": Siftsciex.Event.Payload.payload_string(),
  "$user_id": Siftsciex.Event.Payload.payload_string()
}

Link to this section Functions

Link to this function create_account(account_data) View Source
create_account(data()) :: Siftsciex.Event.Account.t()

Creates a new Account Event for Sift Science, this is not a complete event but will generate all the data specific to the account.

Parameters

  • account_data: The data pertinent to the account that has been created, there are several fields available.

    • :user_email - The email address for the account
    • :name - The name of the user
    • :phone - The phone number given with the account (if any)
    • :referrer_user_id - The internal user_id of any referrer for this signup
    • :social_sign_on_type - If the account is tied to a social account this should be the provider ("facebook", "twitter", "google", "linkedin", "yahoo", "other")
    • :payment_methods - A list of any payment methods used/given during signup (Siftsciex.Event.Payload.PaymentMethod.data)
    • :billing_address - The billing address for the account, if given (Siftsciex.Event.Payload.Address.data)
    • :shipping_address - The shipping address provided for the account, if given (Siftsciex.Event.Payload.Address.data)
    • :promotions - A list of any pormotions (Siftsciex.Event.Payload.Promotion.data) used in conjunction with the signup

Examples

iex> Account.create_account(%{user_id: "bob", user_email: "bob@example.com"})
%Account{"$user_email": "bob@example.com", "$user_id": "bob", "$api_key": api_key, "$type": "$create_account"}

iex> Account.create_account(%{user_email: "bob@example.com", user_id: "bob", payment_methods: [%{payment_type: :cash}]})
%Account{"$user_email": "bob@example.com", "$user_id": "bob", "$api_key": api_key, "$payment_methods": [%PaymentMethod{"$payment_type": "$cash"}], "$type": "$create_account"}

iex> Account.create_account(%{user_email: "bob@example.com", user_id: "bob", billing_address: %{name: "Bob", zipcode: "87102"}})
%Account{"$user_email": "bob@example.com", "$user_id": "bob", "$type": "$create_account", "$api_key": api_key, "$billing_address": %Address{"$name": "Bob", "$zipcode": "87102"}}

iex> Account.create_account(%{user_email: "bob@example.com", user_id: "bob", promotions: [%{promotion_id: "promo"}]})
%Account{"$user_email": "bob@example.com", "$user_id": "bob", "$type": "$create_account", "$api_key": api_key, "$promotions": [%Promotion{"$promotion_id": "promo"}]}
Link to this function update_account(account_data) View Source
update_account(data()) :: Siftsciex.Event.Account.t()

Creates a new $update_account Event for Sift Science, this handles everything for the payload except the $api_key

Parameters

Examples

iex> Account.update_account(%{user_id: "bob", user_email: "bob@example.com"})
%Account{"$user_email": "bob@example.com", "$user_id": "bob", "$type": "$update_account"}

iex> Account.update_account(%{user_id: "bob", payment_methods: [%{payment_type: :cash}]})
%Account{"$user_id": "bob", "$type": "$update_account", "$payment_methods": [%PaymentMethod{"$payment_type": "$cash"}]}