For this first sample, the Use Case is a Customer purchasing an MTN Data Bundle from the Hubtel App (Android/iOS). The interaction below describes what happens between the MTN Data Bundle Service App, Hubtel's Programmable Service API and the Customer. For this purpose, we have the following URLs for the MTN Data Bundle Service:Service Interaction URL: https://www.mtnghana.com/api/service-flowService Fulfillment URL: https://www.mtnghana.com/api/fulfillmentWe also have the following sample URL for the Programmable service API which is used for the Service Fulfillment Callback: https://gs-callback.hubtel.com:9055/callback

STEP 1: The User sees MTN Data on the Hubtel App (Android/iOS) and selects the service.

688

The Programmable Services API sends the following request to the MTN Data Service Application. This is sent to the Service Interaction URL.

POST /api/service-flow HTTP/1.1
Host: https://www.mtnghana.com
Content-Type: application/json
Accept: application/json
{
   "Sequence":"1",
   "Type":"initiation",
   "Message":"",
   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
   "Operator":"Hubtel-Android",
   "ClientState":"",
   "Mobile":"233246912184",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
}
curl --location --request POST 'https://www.mtnghana.com/api/service-flow' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw '{
   "Sequence":"1",
   "Type":"initiation",
   "Message":"",
   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
   "Operator":"Hubtel-Android",
   "ClientState":"",
   "Mobile":"233246912184",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.mtnghana.com/api/service-flow');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
));
$request->setBody('{
\n   "Sequence":"1",
\n   "Type":"initiation",
\n   "Message":"",
\n   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
\n   "Operator":"Hubtel-Android",
\n   "ClientState":"",
\n   "Mobile":"233246912184",
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "https://www.mtnghana.com/api/service-flow"

payload = "{\r\n   \"Sequence\":\"1\",\r\n   \"Type\":\"initiation\",\r\n   \"Message\":\"\",\r\n   \"ServiceCode\":\"b230733cd56b4a0fad820e39f66bc27c\",\r\n   \"Operator\":\"Hubtel-Android\",\r\n   \"ClientState\":\"\",\r\n   \"Mobile\":\"233246912184\",\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\"\r\n}"
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

The MTN Data Service Application sends the following response to the Programmable Services API:

{
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "Type":"Response",
   "Message":"Enter recipient's number:\n",
   "Mask":null,
   "MaskNextRoute":null,
   "Item":null,
   "ServiceCode":null,
   "Label":"Enter recipient's number",
   "DataType":"input",
   "FieldType":"phone",
   "FieldName":"mobileNumber",
   "ClientState":null,
   "Data":null
}
curl --location --request POST 'https://www.hubtel.com' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data-raw ' {
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "Type":"Response",
   "Message":"Enter recipient'\''s number:\n",
   "Mask":null,
   "MaskNextRoute":null,
   "Item":null,
   "ServiceCode":null,
   "Label":"Enter recipient'\''s number",
   "DataType":"input",
   "FieldType":"phone",
   "FieldName":"mobileNumber",
   "ClientState":null,
   "Data":null
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.hubtel.com');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
));
$request->setBody(' {
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
\n   "Type":"Response",
\n   "Message":"Enter recipient\'s number:\\n",
\n   "Mask":null,
\n   "MaskNextRoute":null,
\n   "Item":null,
\n   "ServiceCode":null,
\n   "Label":"Enter recipient\'s number",
\n   "DataType":"input",
\n   "FieldType":"phone",
\n   "FieldName":"mobileNumber",
\n   "ClientState":null,
\n   "Data":null
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "www.hubtel.com"

payload = " {\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\",\r\n   \"Type\":\"Response\",\r\n   \"Message\":\"Enter recipient's number:\\n\",\r\n   \"Mask\":null,\r\n   \"MaskNextRoute\":null,\r\n   \"Item\":null,\r\n   \"ServiceCode\":null,\r\n   \"Label\":\"Enter recipient's number\",\r\n   \"DataType\":\"input\",\r\n   \"FieldType\":\"phone\",\r\n   \"FieldName\":\"mobileNumber\",\r\n   \"ClientState\":null,\r\n   \"Data\":null\r\n}"
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

STEP 2: The User sees the below screen and inputs the phone number as requested.

688

The Programmable Services API sends the following request which contains the user's input to the MTN Data Service application. This is sent to the Service Interaction URL.

POST /api/service-flow HTTP/1.1
Host: https://www.mtnghana.com
Content-Type: application/json
Accept: application/json
{
   "Type":"Response",
   "Message":"0246912184",
   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
   "Operator":"Hubtel-Android",
   "ClientState":"",
   "Mobile":"233246912184",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
}
curl --location --request POST 'https://www.mtnghana.com/api/service-flow' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
   "Type":"Response",
   "Message":"0246912184",
   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
   "Operator":"Hubtel-Android",
   "ClientState":"",
   "Mobile":"233246912184",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.mtnghana.com/api/service-flow');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n   "Type":"Response",
\n   "Message":"0246912184",
\n   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
\n   "Operator":"Hubtel-Android",
\n   "ClientState":"",
\n   "Mobile":"233246912184",
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "https://www.mtnghana.com/api/service-flow"

payload = "{\r\n   \"Type\":\"Response\",\r\n   \"Message\":\"0246912184\",\r\n   \"ServiceCode\":\"b230733cd56b4a0fad820e39f66bc27c\",\r\n   \"Operator\":\"Hubtel-Android\",\r\n   \"ClientState\":\"\",\r\n   \"Mobile\":\"233246912184\",\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\"\r\n}"
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

The MTN Data Service Application sends the following response to the Programmable Services API for the User to select a bundle:

{
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "Type":"Response",
   "Message":"Select Bundle\nEnter Select Bundle:\n",
   "Mask":null,
   "MaskNextRoute":null,
   "Item":null,
   "ServiceCode":null,
   "Label":"Select Bundle",
   "DataType":"select",
   "FieldType":"text",
   "FieldName":"",
   "ClientState":null,
   "Data":[
      {
         "Display":"Daily 20MB (GHs 0.5)",
         "Value":"DAILY_20MB",
         "Amount":0.5
      },
      {
         "Display":"Daily 50MB (GHs 1)",
         "Value":"DAILY_50MB",
         "Amount":1.0
      },
      {
         "Display":"Daily 120MB (GHs 2)",
         "Value":"DAILY_120MB",
         "Amount":2.0
      },
      {
         "Display":"Weekly 60MB (GHs 2)",
         "Value":"WEEKLY_60MB",
         "Amount":2.0
      },
      {
         "Display":"Weekly 180MB (GHs 3)",
         "Value":"WEEKLY_180MB",
         "Amount":3.0
      },
      {
         "Display":"Weekly 300MB (GHs 5)",
         "Value":"WEEKLY_300MB",
         "Amount":5.0
      },
      {
         "Display":"Monthly 400MB (GHs 10)",
         "Value":"MONTHLY_400MB",
         "Amount":10.0
      },
      {
         "Display":"Monthly 1GB (GHs 20)",
         "Value":"MONTHLY_1GB",
         "Amount":20.0
      }
   ]
}
curl --location --request POST 'https://www.hubtel.com' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "Type":"Response",
   "Message":"Select Bundle\nEnter Select Bundle:\n",
   "Mask":null,
   "MaskNextRoute":null,
   "Item":null,
   "ServiceCode":null,
   "Label":"Select Bundle",
   "DataType":"select",
   "FieldType":"text",
   "FieldName":"",
   "ClientState":null,
   "Data":[
      {
         "Display":"Daily 20MB (GHs 0.5)",
         "Value":"DAILY_20MB",
         "Amount":0.5
      },
      {
         "Display":"Daily 50MB (GHs 1)",
         "Value":"DAILY_50MB",
         "Amount":1.0
      },
      {
         "Display":"Daily 120MB (GHs 2)",
         "Value":"DAILY_120MB",
         "Amount":2.0
      },
      {
         "Display":"Weekly 60MB (GHs 2)",
         "Value":"WEEKLY_60MB",
         "Amount":2.0
      },
      {
         "Display":"Weekly 180MB (GHs 3)",
         "Value":"WEEKLY_180MB",
         "Amount":3.0
      },
      {
         "Display":"Weekly 300MB (GHs 5)",
         "Value":"WEEKLY_300MB",
         "Amount":5.0
      },
      {
         "Display":"Monthly 400MB (GHs 10)",
         "Value":"MONTHLY_400MB",
         "Amount":10.0
      },
      {
         "Display":"Monthly 1GB (GHs 20)",
         "Value":"MONTHLY_1GB",
         "Amount":20.0
      },
      {
         "Display":"Monthly 2.5GB (GHs 40)",
         "Value":"MONTHLY_2.5GB",
         "Amount":40.0
      },
      {
         "Display":"Monthly 4GB (GHs 60)",
         "Value":"MONTHLY_4GB",
         "Amount":60.0
      },
      {
         "Display":"Monthly 6GB (GHs 80)",
         "Value":"MONTHLY_6GB",
         "Amount":80.0
      },
      {
         "Display":"Monthly 10GB (GHs 120)",
         "Value":"MONTHLY_10GB",
         "Amount":120.0
      },
      {
         "Display":"Monthly 15GB (GHs 150)",
         "Value":"MONTHLY_15GB",
         "Amount":150.0
      },
      {
         "Display":"Monthly 200GB (GHs 399)",
         "Value":"MONTHLY_200GB",
         "Amount":399.0
      },
      {
         "Display":"Midnight 3GB (GHs 1)",
         "Value":"MIDNIGHT_3G",
         "Amount":1.0
      },
      {
         "Display":"Midnight (GHs 2)",
         "Value":"MIDNIGHT",
         "Amount":2.0
      },
      {
         "Display":"Youtube 50MB (GHs 0.5)",
         "Value":"YOUTUBE_50MB",
         "Amount":0.5
      },
      {
         "Display":"Youtube 300MB (GHs 3)",
         "Value":"YOUTUBE_300MB",
         "Amount":3.0
      },
      {
         "Display":"Lifestyle 400MB (GHs 5)",
         "Value":"LIFESTYLE",
         "Amount":5.0
      }
   ]
}
'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.hubtel.com');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
\n   "Type":"Response",
\n   "Message":"Select Bundle\\nEnter Select Bundle:\\n",
\n   "Mask":null,
\n   "MaskNextRoute":null,
\n   "Item":null,
\n   "ServiceCode":null,
\n   "Label":"Select Bundle",
\n   "DataType":"select",
\n   "FieldType":"text",
\n   "FieldName":"",
\n   "ClientState":null,
\n   "Data":[
\n      {
\n         "Display":"Daily 20MB (GHs 0.5)",
\n         "Value":"DAILY_20MB",
\n         "Amount":0.5
\n      },
\n      {
\n         "Display":"Daily 50MB (GHs 1)",
\n         "Value":"DAILY_50MB",
\n         "Amount":1.0
\n      },
\n      {
\n         "Display":"Daily 120MB (GHs 2)",
\n         "Value":"DAILY_120MB",
\n         "Amount":2.0
\n      },
\n      {
\n         "Display":"Weekly 60MB (GHs 2)",
\n         "Value":"WEEKLY_60MB",
\n         "Amount":2.0
\n      },
\n      {
\n         "Display":"Weekly 180MB (GHs 3)",
\n         "Value":"WEEKLY_180MB",
\n         "Amount":3.0
\n      },
\n      {
\n         "Display":"Weekly 300MB (GHs 5)",
\n         "Value":"WEEKLY_300MB",
\n         "Amount":5.0
\n      },
\n      {
\n         "Display":"Monthly 400MB (GHs 10)",
\n         "Value":"MONTHLY_400MB",
\n         "Amount":10.0
\n      },
\n      {
\n         "Display":"Monthly 1GB (GHs 20)",
\n         "Value":"MONTHLY_1GB",
\n         "Amount":20.0
\n      },
\n      {
\n         "Display":"Monthly 2.5GB (GHs 40)",
\n         "Value":"MONTHLY_2.5GB",
\n         "Amount":40.0
\n      },
\n      {
\n         "Display":"Monthly 4GB (GHs 60)",
\n         "Value":"MONTHLY_4GB",
\n         "Amount":60.0
\n      },
\n      {
\n         "Display":"Monthly 6GB (GHs 80)",
\n         "Value":"MONTHLY_6GB",
\n         "Amount":80.0
\n      },
\n      {
\n         "Display":"Monthly 10GB (GHs 120)",
\n         "Value":"MONTHLY_10GB",
\n         "Amount":120.0
\n      },
\n      {
\n         "Display":"Monthly 15GB (GHs 150)",
\n         "Value":"MONTHLY_15GB",
\n         "Amount":150.0
\n      },
\n      {
\n         "Display":"Monthly 200GB (GHs 399)",
\n         "Value":"MONTHLY_200GB",
\n         "Amount":399.0
\n      },
\n      {
\n         "Display":"Midnight 3GB (GHs 1)",
\n         "Value":"MIDNIGHT_3G",
\n         "Amount":1.0
\n      },
\n      {
\n         "Display":"Midnight (GHs 2)",
\n         "Value":"MIDNIGHT",
\n         "Amount":2.0
\n      },
\n      {
\n         "Display":"Youtube 50MB (GHs 0.5)",
\n         "Value":"YOUTUBE_50MB",
\n         "Amount":0.5
\n      },
\n      {
\n         "Display":"Youtube 300MB (GHs 3)",
\n         "Value":"YOUTUBE_300MB",
\n         "Amount":3.0
\n      },
\n      {
\n         "Display":"Lifestyle 400MB (GHs 5)",
\n         "Value":"LIFESTYLE",
\n         "Amount":5.0
\n      }
\n   ]
\n}
\n');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "https://www.hubtel.com"

payload = "{\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\",\r\n   \"Type\":\"Response\",\r\n   \"Message\":\"Select Bundle\\nEnter Select Bundle:\\n\",\r\n   \"Mask\":null,\r\n   \"MaskNextRoute\":null,\r\n   \"Item\":null,\r\n   \"ServiceCode\":null,\r\n   \"Label\":\"Select Bundle\",\r\n   \"DataType\":\"select\",\r\n   \"FieldType\":\"text\",\r\n   \"FieldName\":\"\",\r\n   \"ClientState\":null,\r\n   \"Data\":[\r\n      {\r\n         \"Display\":\"Daily 20MB (GHs 0.5)\",\r\n         \"Value\":\"DAILY_20MB\",\r\n         \"Amount\":0.5\r\n      },\r\n      {\r\n         \"Display\":\"Daily 50MB (GHs 1)\",\r\n         \"Value\":\"DAILY_50MB\",\r\n         \"Amount\":1.0\r\n      },\r\n      {\r\n         \"Display\":\"Daily 120MB (GHs 2)\",\r\n         \"Value\":\"DAILY_120MB\",\r\n         \"Amount\":2.0\r\n      },\r\n      {\r\n         \"Display\":\"Weekly 60MB (GHs 2)\",\r\n         \"Value\":\"WEEKLY_60MB\",\r\n         \"Amount\":2.0\r\n      },\r\n      {\r\n         \"Display\":\"Weekly 180MB (GHs 3)\",\r\n         \"Value\":\"WEEKLY_180MB\",\r\n         \"Amount\":3.0\r\n      },\r\n      {\r\n         \"Display\":\"Weekly 300MB (GHs 5)\",\r\n         \"Value\":\"WEEKLY_300MB\",\r\n         \"Amount\":5.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 400MB (GHs 10)\",\r\n         \"Value\":\"MONTHLY_400MB\",\r\n         \"Amount\":10.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 1GB (GHs 20)\",\r\n         \"Value\":\"MONTHLY_1GB\",\r\n         \"Amount\":20.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 2.5GB (GHs 40)\",\r\n         \"Value\":\"MONTHLY_2.5GB\",\r\n         \"Amount\":40.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 4GB (GHs 60)\",\r\n         \"Value\":\"MONTHLY_4GB\",\r\n         \"Amount\":60.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 6GB (GHs 80)\",\r\n         \"Value\":\"MONTHLY_6GB\",\r\n         \"Amount\":80.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 10GB (GHs 120)\",\r\n         \"Value\":\"MONTHLY_10GB\",\r\n         \"Amount\":120.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 15GB (GHs 150)\",\r\n         \"Value\":\"MONTHLY_15GB\",\r\n         \"Amount\":150.0\r\n      },\r\n      {\r\n         \"Display\":\"Monthly 200GB (GHs 399)\",\r\n         \"Value\":\"MONTHLY_200GB\",\r\n         \"Amount\":399.0\r\n      },\r\n      {\r\n         \"Display\":\"Midnight 3GB (GHs 1)\",\r\n         \"Value\":\"MIDNIGHT_3G\",\r\n         \"Amount\":1.0\r\n      },\r\n      {\r\n         \"Display\":\"Midnight (GHs 2)\",\r\n         \"Value\":\"MIDNIGHT\",\r\n         \"Amount\":2.0\r\n      },\r\n      {\r\n         \"Display\":\"Youtube 50MB (GHs 0.5)\",\r\n         \"Value\":\"YOUTUBE_50MB\",\r\n         \"Amount\":0.5\r\n      },\r\n      {\r\n         \"Display\":\"Youtube 300MB (GHs 3)\",\r\n         \"Value\":\"YOUTUBE_300MB\",\r\n         \"Amount\":3.0\r\n      },\r\n      {\r\n         \"Display\":\"Lifestyle 400MB (GHs 5)\",\r\n         \"Value\":\"LIFESTYLE\",\r\n         \"Amount\":5.0\r\n      }\r\n   ]\r\n}\r\n"
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

STEP 3: The User sees the below screen with the various bundle options and selects the desired option. In this case, he chooses the Daily 20MB (GHs 0.5) Bundle.

688

The Programmable Services API sends the following request which contains the user's selection to the MTN Data Service application. This is sent to the Service Interaction URL.

POST /api/service-flow HTTP/1.1
Host: https://www.mtnghana.com
Content-Type: application/json
{
   "Type":"Response",
   "Message":"DAILY_20MB",
   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
   "Operator":"Hubtel-Android",
   "ClientState":"",
   "Mobile":"233246912184",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
}
curl --location --request POST 'https://www.mtnghana.com/api/service-flow' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
   "Type":"Response",
   "Message":"DAILY_20MB",
   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
   "Operator":"Hubtel-Android",
   "ClientState":"",
   "Mobile":"233246912184",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.mtnghana.com/api/service-flow');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n   "Type":"Response",
\n   "Message":"DAILY_20MB",
\n   "ServiceCode":"b230733cd56b4a0fad820e39f66bc27c",
\n   "Operator":"Hubtel-Android",
\n   "ClientState":"",
\n   "Mobile":"233246912184",
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8"
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "https://www.mtnghana.com/api/service-flow"

payload = "{\r\n   \"Type\":\"Response\",\r\n   \"Message\":\"DAILY_20MB\",\r\n   \"ServiceCode\":\"b230733cd56b4a0fad820e39f66bc27c\",\r\n   \"Operator\":\"Hubtel-Android\",\r\n   \"ClientState\":\"\",\r\n   \"Mobile\":\"233246912184\",\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\"\r\n}"
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

The MTN Data Service Application sends the following response to the Programmable Services API for the payment process to begin:

{
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "Type":"AddToCart",
   "Message":"Add to Cart",
   "Mask":null,
   "MaskNextRoute":null,
   "Item":{
      "ItemName":"MTN Data Bundle (Daily 20MB) for 233246912184",
      "Qty":1,
      "Price":0.5
   },
   "ServiceCode":null,
   "Label":null,
   "DataType":"display",
   "FieldType":"text",
   "FieldName":null,
   "ClientState":null,
   "Data":[   ]
}
curl --location --request POST 'https://www.hubtel.com' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "Type":"AddToCart",
   "Message":"Add to Cart",
   "Mask":null,
   "MaskNextRoute":null,
   "Item":{
      "ItemName":"MTN Data Bundle (Daily 20MB) for 233246912184",
      "Qty":1,
      "Price":0.5,
      "ServiceData":{
         "destination":"233246912184",
         "amount":"0.5",
         "bundle":"DAILY_20MB"
      }
   },
   "ServiceCode":null,
   "Label":null,
   "DataType":"display",
   "FieldType":"text",
   "FieldName":null,
   "ClientState":null,
   "Data":[   ]
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.hubtel.com');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
\n   "Type":"AddToCart",
\n   "Message":"Add to Cart",
\n   "Mask":null,
\n   "MaskNextRoute":null,
\n   "Item":{
\n      "ItemName":"MTN Data Bundle (Daily 20MB) for 233246912184",
\n      "Qty":1,
\n      "Price":0.5,
\n      "ServiceData":{
\n         "destination":"233246912184",
\n         "amount":"0.5",
\n         "bundle":"DAILY_20MB"
\n      }
\n   },
\n   "ServiceCode":null,
\n   "Label":null,
\n   "DataType":"display",
\n   "FieldType":"text",
\n   "FieldName":null,
\n   "ClientState":null,
\n   "Data":[   ]
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "https://www.hubtel.com"

payload = "{\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\",\r\n   \"Type\":\"AddToCart\",\r\n   \"Message\":\"Add to Cart\",\r\n   \"Mask\":null,\r\n   \"MaskNextRoute\":null,\r\n   \"Item\":{\r\n      \"ItemName\":\"MTN Data Bundle (Daily 20MB) for 233246912184\",\r\n      \"Qty\":1,\r\n      \"Price\":0.5,\r\n      \"ServiceData\":{\r\n         \"destination\":\"233246912184\",\r\n         \"amount\":\"0.5\",\r\n         \"bundle\":\"DAILY_20MB\"\r\n      }\r\n   },\r\n   \"ServiceCode\":null,\r\n   \"Label\":null,\r\n   \"DataType\":\"display\",\r\n   \"FieldType\":\"text\",\r\n   \"FieldName\":null,\r\n   \"ClientState\":null,\r\n   \"Data\":[   ]\r\n}"
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

STEP 4: The User goes through the payment process on the Hubtel App (Android/iOS) and pays Successfully.

688

After the payment is successful, the Programmable Services API sends the below request to the MTN Data Service Application so the data bundle top-up can be done. This is sent to the Service Fulfillment URL:

POST /api/fulfillment HTTP/1.1
Host: https://www.mtnghana.com
Content-Type: application/json
{
   "OrderId":"97473921905444d2ae166ec4c38787d5",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "ExtraData":{
   },
   "OrderInfo":null
}
curl --location --request POST 'https://www.mtnghana.com/api/service-flow' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
   "OrderId":"97473921905444d2ae166ec4c38787d5",
   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
   "ExtraData":{
   },
   "OrderInfo":null
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://www.mtnghana.com/api/service-flow');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n   "OrderId":"97473921905444d2ae166ec4c38787d5",
\n   "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
\n   "ExtraData":{
\n   },
\n   "OrderInfo":null
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "https://www.mtnghana.com/api/service-flow"

payload = "{\r\n   \"OrderId\":\"97473921905444d2ae166ec4c38787d5\",\r\n   \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\",\r\n   \"ExtraData\":{\r\n   },\r\n   \"OrderInfo\":null\r\n}"
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

Finally, when MTN does the data bundle top-up, the MTN Data Service Application sends the below request as a callback to the Fulfillment Callback URL of Programmable Services.

POST /callback HTTP/1.1
Host: http://62.60.117.64:9055/
Content-Type: application/json
{
  "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
  "OrderId": "97473921905444d2ae166ec4c38787d5",
  "ServiceStatus":"success",
  "MetaData":null
}
curl --location --request POST 'http://62.60.117.64:9055/callback' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
  "OrderId": "97473921905444d2ae166ec4c38787d5",
  "ServiceStatus":"success",
  "MetaData":null
}'
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('http://62.60.117.64:9055/callback');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Accept' => 'application/json',
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n  "SessionId":"8d440a43a98b4614b9df22b79c8190b8",
\n  "OrderId": "97473921905444d2ae166ec4c38787d5",
\n  "ServiceStatus":"success",
\n  "MetaData":null
\n}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
import requests

url = "http://62.60.117.64:9055/callback"

payload = "{\r\n  \"SessionId\":\"8d440a43a98b4614b9df22b79c8190b8\",\r\n  \"OrderId\": \"97473921905444d2ae166ec4c38787d5\",\r\n  \"ServiceStatus\":\"success\",\r\n  \"MetaData\":null\r\n}"
headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

Because Hubtel App (Android/iOS) gives the User details of the service purchase, the User can now see that his purchase was successful, and the service (Data bundle) was received appropriately.

688