This is the website I’m sending the order to API
How to Purchase Data via VTU.ng HTTP API
Data Endpoint URL: https://vtu.ng/wp-json/api/v1/data
Request Method: GET
Parameters
Field Name Example Value Description
username Frank The login username/email for your VTU.ng account
password 123456 The login password for your VTU.ng account
phone 07045461790 The phone number that will receive the data
network_id mtn The network_id is used to make each network unique. They include mtn, glo, airtel and etisalat. Notice that they are all in small letters.
variation_id M1024 The variation ID of the data plan you want to purchase. They are as follows:
M1024 = MTN Data 1GB (SME) – 30 Days
M2024 = MTN Data 2GB (SME) – 30 Days
GIFT500 = MTN Data 2.5GB (Direct) – 30 Days
5000 = MTN Data 5GB (SME) – 30 Days
GIFT8000 = MTN Data 8GB (Direct) – 30 Days
GIFT5000 = MTN Data 15GB (Direct) – 30 Days
G500 = Glo Data 1GB – 14 Days
G2000 = Glo Data 5.8GB – 30 Days
G1000 = Glo Data 2GB/2.5GB – 30 Days
G2500 = Glo Data 7.7GB – 30 Days
G3000 = Glo Data 10GB – 30 Days
G4000 = Glo Data 13.25GB – 30 Days
G5000 = Glo Data 18.25GB – 30 Days
G8000 = Glo Data 20GB/25GB – 30 Days
AIR1000 = Airtel Data 1.5GB – 30 Days
Air1200 = Airtel Data 2GB – 30 Days
Air1500 = Airtel Data 3GB – 30 Days
AIR2000 = Airtel Data 4.5GB – 30 Days
AIR2500 = Airtel Data 6GB – 30 Days
Air3000 = Airtel Data 8GB – 30 Days
Air5000 = Airtel Data 15GB – 30 Days
Air100000 = Airtel Data 40GB – 30 Days
9MOB1000 = 9mobile Data 1.5GB – 30 Days
9MOB2000 = 9mobile Data 2GB – 30 Days
9MOB3000 = 9mobile Data 3GB – 30 Days
9MOB34500 = 9mobile Data 4.5GB – 30 Days
9MOB4000 = 9mobile Data 11GB – 30 Days
9MOB5000 = 9mobile Data 15GB – 30 Days
9MOB40000 = 9mobile Data 40GB – 30 Days
Example [Purchasing Data]
https://vtu.ng/wp-json/api/v1/data?username=Frank&password=123456&phone=07045461790&network_id=mtn&variation_id=M1024
Sample Response on Success
{"code":"success","message":"Data successfully delivered","data":{"network":"MTN","data_plan":"MTN Data 1GB (SME) – 30 Days","phone":"07045461790","amount":"NGN319","request_id":"fb69ed8a39ac5684"}}
Sample Response on Failure
{"code":"failure","message":"Invalid data variation_id. Please, crosscheck and enter the correct variation_id."}

This is the name of the products on my website
MTN 1GB
MTN 2GB
MTN 5GB

GLO 2GB
GLO 5.8GB
GLO 7.7GB

AIRTEL 1.5GB
AIRTEL 3GB
AIRTEL 6GB

9MOBILE 1.5GB
9MOBILE 3GB
9MOBILE 4.5GB

Below is the code I’m trying to use..

( // Call API to deliver data Add_action(‘woocommerce_order_status_changed’, ‘sme_data_hub_call_data_api’, 10, 3 );Function sme_data_hub_call_data_api( $order_id, $old_status, $new_status ){ If( $new_status == “processing”){//Set Your VTU.ng Login Details $vtu_ng_username=’Your_VTU_NG_Username’; //Change this to your VTU.ng Username $vtu_ng_password=’Your_VTU_NG_Password’; //Change this to your VTU.ng Password // Get an instance of the WC_Order object $order = wc_get_order( $order_id ); $phone = trim($order->get_billing_phone()); $items = $order->get_items(); Foreach ( $items as $item ) { $product_id = $item->get_product_id(); $product_name = strtolower($item->get_name()); } //Assign Network IDs If (strpos($product_name, “mtn”) !== false){$network_id=”mtn”;} If (strpos($product_name, “glo”) !== false){$network_id=”glo”;} If (strpos($product_name, “airtel”) !== false){$network_id=”airtel”;} If (strpos($product_name, “9mobile”) !== false){$network_id=”etisalat”;} //Assign variation_ids If (strpos($product_name, “mtn 1gb”) !== false){$variation_id=”M1024”;} If (strpos($product_name, “mtn 2gb”) !== false){$variation_id=”M2024”;} If (strpos($product_name, “mtn 5gb”) !== false){$variation_id=”5000”;} If (strpos($product_name, “glo 2gb”) !== false){$variation_id=”G1000”;} If (strpos($product_name, “glo 5.8gb”) !== false){$variation_id=”G2000”;} If (strpos($product_name, “glo 7.7gb”) !== false){$variation_id=”G2500”;} If (strpos($product_name, “airtel 1.5gb”) !== false){$variation_id=”AIR1000”;} If (strpos($product_name, “airtel 1.5gb”) !== false){$variation_id=”Air1500”;} If (strpos($product_name, “airtel 1.5gb”) !== false){$variation_id=”AIR2500”;} If (strpos($product_name, “9mobile 1.5gb”) !== false){$variation_id=”9MOB1000”;} If (strpos($product_name, “9mobile 3gb”) !== false){$variation_id=”9MOB3000”;} If (strpos($product_name, “9mobile 4.5gb”) !== false){$variation_id=”9MOB34500”;} //Check to confirm the product is for Data Purchase If(strpos($product_name, “gb”) !== false){ $url = https://vtu.ng/wp-json/api/v1/data?username=$vtu_ng_username&password=$vtu_ng_password&phone=$phone&network_id=$network_id&variation_id=$variation_id; $response = file_get_contents( $url ); $resp_object = json_decode($response); $code=$resp_object->code; $reference=$resp_object->data->request_id; $message=$resp_object->message; If($code==”success”){ $order = new WC_Order($order_id); $order->update_status(‘completed’,$product_name. ‘ Data Successfully Delivered to ‘.$phone.’. Reference: ‘.$reference); $order->add_order_note( $product_name. ‘ Data Successfully Delivered to ‘.$phone, true ); }else{ $order = new WC_Order($order_id); $order->add_order_note( “Error Processing Order! Error Message: “.$message,true ); } } }

}

Please the code doesn’t work please help, check what I’m doing wrong..

I use terrawallet, checkout field options, to edit my woocommerce to my suit..