How to use the africastalking.Airtime function in africastalking

To help you get started, we’ve selected a few africastalking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AfricasTalkingLtd / africastalking-python / test / test_airtime.py View on Github external
"""
Airtime

send(phoneNumber: String, amount: String): Send airtime to a phone number.

send(recipients: Map): Send airtime to a bunch of phone numbers. The keys in the recipients map are phone
    numbers while the values are airtime amounts.
"""
import africastalking
import unittest
import random
from test import USERNAME, API_KEY

africastalking.initialize(USERNAME, API_KEY)
service = africastalking.Airtime


class TestAirtimeService(unittest.TestCase):

    def test_send_single(self):
        currency_code = "KES"
        amount = str(random.randint(10, 1000))
        phone = '+254718763456'
        idempotency_key = 'req-1234'
        res = service.send(phone_number=phone, amount=amount, currency_code=currency_code, idempotency_key=idempotency_key)
        assert res['numSent'] == 1

    def test_send_multiple(self):
        res = service.send(recipients=[
            {'phoneNumber': '+2348160663047', 'amount': str(random.randint(1, 10)), 'currency_code': 'USD'},
            {'phoneNumber': '+254718769881', 'amount':str(random.randint(138, 13223)), 'currency_code':  'KES'},
github AfricasTalkingLtd / africastalking-python / example / webApp.py View on Github external
import os
from flask import Flask, request, render_template
from flask_restful import Resource, Api

import africastalking

app = Flask(__name__)
api = Api(app)

username = os.getenv('user_name', 'sandbox')
api_key = os.getenv('api_key', 'fake')


africastalking.initialize(username, api_key)
sms = africastalking.SMS
airtime  = africastalking.Airtime
payment = africastalking.Payment

@app.route('/')
def index():
    return render_template('index.html')

class send_sms(Resource):
    def get(self):
      return {'hello': 'world'}
    def post(self):
      number = str(request.form['number'])
      return sms.send("Test message", [number])
api.add_resource(send_sms, '/sms')

class send_airtime(Resource):
    def get(self):