New code to load mtn recharge card

Here is an example of new code to load Mtn recharge card in Python:

Note: This code uses the requests library to send HTTP requests to the MTN recharge API. You will need to install this library if you haven't already. You can do this by running pip install requests in your terminal.

Code:

import requests
import json

# Set your MTN recharge API credentials
api_username = "your_api_username"
api_password = "your_api_password"
api_url = "https://api.mtn.com.ng/recharge"

# Set the recharge card details
recharge_card_number = "your_recharge_card_number"
recharge_card_pin = "your_recharge_card_pin"
amount = "100"  # Amount to recharge (in Naira)

# Set the headers for the API request
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Basic {api_username}:{api_password}"
}

# Set the request body
body = {
    "rechargeCardNumber": recharge_card_number,
    "rechargeCardPin": recharge_card_pin,
    "amount": amount
}

# Send the request to the API
response = requests.post(api_url, headers=headers, json=body)

# Check if the request was successful
if response.status_code == 200:
    print("Recharge successful!")
    print("Your new balance is:", response.json()["newBalance"])
else:
    print("Error:", response.text)

How to use:

  1. Replace your_api_username and your_api_password with your actual MTN recharge API credentials.
  2. Replace your_recharge_card_number and your_recharge_card_pin with your actual recharge card details.
  3. Set the amount variable to the amount you want to recharge (in Naira).
  4. Run the code by saving it to a file (e.g. mtn_recharge.py) and running it with Python (e.g. python mtn_recharge.py).

Note: This code is just an example and may not work for you. You will need to check the MTN recharge API documentation to ensure that the API endpoint, headers, and request body are correct. Additionally, you may need to modify the code to handle errors and exceptions.