View Source AtEx.Gateway.Sms.PremiumSubscriptions (AtEx v0.20.23)

This module holds the implementation for the HTTP Gateway that runs calls against the Africas Talking API Premium SMS endpoint, complete a premium sms create subscription request, incrementally fetch your premium sms subscriptions, delete a premium sms subscription

Summary

Functions

This function makes a post request to subscribe to premium sms content via the Africa's talking subscription endpoint, this function accepts an map of parameters. sent

This function makes a POST request to delete sms subscriptions via the Africa's talking subscription endpoint, this function accepts an map of parameters

This function makes a GET request to fetch premium sms subscriptions via the Africa's talking subscription endpoint, this function accepts an map of parameters. sent

This function fetches the checkout token from the checkout token endpoint THIS IS DIFFERENT THAN THE SMS ENDPOINT!!

Process results from calling the gateway

Functions

Link to this function

create_subscription(attrs)

View Source
@spec create_subscription(map()) :: {:error, any()} | {:ok, any()}

This function makes a post request to subscribe to premium sms content via the Africa's talking subscription endpoint, this function accepts an map of parameters. sent

Config

Add shortcode, and keyword to the AtEx configs

Parameters

attrs: - a map containing:

Example

iex> AtEx.Gateway.Sms.PremiumSubscriptions.create_subscription(%{phoneNumber: "+25471231111"})
{:ok, 
  %{
  "SMSMessageData" => %{"Message" => "Sent to 1/1 Total Cost: ZAR 0.1124", "Recipients" => [%{"cost" => "KES 0.8000", "messageId" => "ATXid_a584c3fd712a00b7bce3c4b7b552ac56", "number" => "+254728833181", "status" => "Success", "statusCode" => 101}]}
  }}
Link to this function

delete_subscription(attrs)

View Source
@spec delete_subscription(map()) :: {:error, any()} | {:ok, any()}

This function makes a POST request to delete sms subscriptions via the Africa's talking subscription endpoint, this function accepts an map of parameters:

Parameters

attrs: - a map containing:

  • shortCode - premium short code mapped to your account
  • keyword - premium keyword under the above short code mapped to your account
  • phoneNumber - phone number to be unsubscribed

Example

iex> AtEx.Gateway.Sms.PremiumSubscriptions.delete_subscription(%{ phoneNumber: "+25471231111"})
{:ok,  %{"description" => "Succeeded", "status" => "Success"}}
@spec fetch_subscriptions() :: {:error, any()} | {:ok, any()}

This function makes a GET request to fetch premium sms subscriptions via the Africa's talking subscription endpoint, this function accepts an map of parameters. sent

Parameters

attrs: - a map containing:

  • shortCode - premium short code mapped to your account
  • keyword - premium keyword under the above short code mapped to your account
  • lastReceivedId - (optional) ID of the subscription you believe to be your last. Set it to 0 to for the first time. For more info, look at the docs here https://build.at-labs.io/docs/sms%2Fpremium_subscriptions%2Ffetch

Example

iex> AtEx.Gateway.Sms.PremiumSubscriptions.fetch_subscriptions()
{:ok, 
  %{
        "SMSMessageData" => %{
          "Messages" => [
            %{
              "linkId" => "SampleLinkId123",
              "text" => "Hello",
              "to" => "28901",
              "id" => 15071,
              "date" => "2018-03-19T08:34:18.445Z",
              "from" => "+254711XXXYYY"
            }
          ]
        }
      }}
Link to this function

generate_checkout_token(phone_number)

View Source
@spec generate_checkout_token(String.t()) :: {:error, any()} | {:ok, any()}

This function fetches the checkout token from the checkout token endpoint THIS IS DIFFERENT THAN THE SMS ENDPOINT!!

phone_number: - a string representing a valid phone number in EL64 (+<country code><phone number> with all non digit characters removed) [NOTE: function does not verify the phone number is in any way correct before sending to the endpoint.]

Returns a success tuple: {:ok, <client_token>}} or {:error, <reason>}

Process results from calling the gateway