How to use the africastalking.Payment 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_payment.py View on Github external
mobileB2C(productName: String, consumers: List): Send mobile money to consumers.

mobileB2B(productName: String, recipient: Business): Send mobile money to a business.

walletTransfer(productName: String, targetProductCode: Integer, amount: String, metadata: Map)

topupStash(productName: String, amount: String, metadata: Map)
"""
import africastalking
import unittest
import random
import time
from test import USERNAME, API_KEY

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


class TestPaymentService(unittest.TestCase):

    def test_mobile_checkout(self):
        res = service.mobile_checkout(product_name='TestProduct', phone_number='+254718769882', currency_code="USD", amount=10)
        assert res['status'] == 'PendingConfirmation'

    def test_mobile_b2c(self):
        consumer = {
            'name': 'Salama',
            'phoneNumber': '+254718769882',
            'currencyCode': 'KES',
            'amount': 892,
            # Optionals
            'reason': service.REASON['SalaryPayment'],
github AfricasTalkingLtd / africastalking-python / example / webApp.py View on Github external
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):
      return {'hello': 'world'}