Example #1
0
def lipa_na_mpesa():

    formatted_time = get_timestamp()
    decoded_password = generate_password(formatted_time)
    access_token = generate_access_token()

    api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"

    headers = {"Authorization": "Bearer %s" % access_token}
    request = {
        "BusinessShortCode": keys.business_shortCode,
        "Password": decoded_password,
        "Timestamp": formatted_time,
        "TransactionType": "CustomerPayBillOnline",
        "Amount": "5",
        "PartyA": keys.phone_number,
        "PartyB": keys.business_shortCode,
        "PhoneNumber": keys.phone_number,
        "CallBackURL": "https://fullstackdjango.com/lipanampesa/",
        "AccountReference": "12345678",
        "TransactionDesc": "Pay School Fees"
    }

    response = requests.post(api_url, json=request, headers=headers)

    print(response.text)
Example #2
0
def lipa_na_mpesa():

    timestamp = get_timestamp()
    password = generate_password(timestamp)
    access_token = generate_access_token()

    api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
    headers = {"Authorization": "Bearer %s" % access_token}
    request = {
        "BusinessShortCode": keys.business_short_code,
        "Password": password,
        "Timestamp": timestamp,
        "TransactionType": "CustomerPayBillOnline",
        "Amount": "1",
        "PartyA": keys.phone_number,
        "PartyB": keys.business_short_code,
        "PhoneNumber": keys.phone_number,
        "CallBackURL": "https://edwinthedjangodev.com/lnm/",
        "AccountReference": "11568",
        "TransactionDesc": "pay school fees"
    }

    response = requests.post(api_url, json=request, headers=headers)

    print(response.text)
Example #3
0
def lipa_na_mpesa(amount, account_reference, phone_number):
    formatted_time = get_timestamp()
    decoded_password = generate_password(formatted_time)
    access_token = generate_access_token()
    api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
    headers = {"Authorization": "Bearer %s" % access_token}
    request = {
        "BusinessShortCode": mpesa_keys.businessShortCode,
        "Password": decoded_password,
        "Timestamp": formatted_time,
        "TransactionType": "CustomerPayBillOnline",
        "Amount": amount,
        "PartyA": mpesa_keys.phone_no,
        "PartyB": mpesa_keys.businessShortCode,
        "PhoneNumber": str(phone_number),
        "CallBackURL": mpesa_keys.lipa_na_mpesa_online_callback_url,
        "AccountReference": account_reference,
        "TransactionDesc": mpesa_keys.lipa_na_mpesa_online_transaction_description
    }

    response = requests.post(api_url, json=request, headers=headers)

    print(response.text)
Example #4
0
def lipa_na_mpesa():

    formatted_time = get_timestamp()
    decoded_pass = generate_password(formatted_time)
    access_token = generate_token()
    api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
    headers = {"Authorization": "Bearer %s" % access_token}
    request = {
        "BusinessShortCode": keys.LNM_Short_code,
        "Password": decoded_pass,
        "Timestamp": formatted_time,
        "TransactionType": "CustomerPayBillOnline",
        "Amount": "1",
        "PartyA": keys.PhoneNumber,
        "PartyB": keys.LNM_Short_code,
        "PhoneNumber": keys.PhoneNumber,
        "CallBackURL": "https://692e842ae4a1.ngrok.io/api/payments/lnm/",
        "AccountReference": "1234567",
        "TransactionDesc": "test Mpesa"
    }

    response = requests.post(api_url, json=request, headers=headers)

    print(response.text)
Example #5
0
import requests

from datetime import datetime
from access_token import generate_access_token
from encode import generate_password
import keys

formatted_time = datetime.now().strftime('%Y%m%d%H%M%S')
# print(formatted_time)

decode_password = generate_password(formatted_time)

my_access_token = generate_access_token()


def lipa_na_mpesa():

    access_token = my_access_token
    api_url = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
    headers = {"Authorization": "Bearer %s" % access_token}
    request = {
        "BusinessShortCode": keys.business_shortcode,
        "Password": decode_password,
        "Timestamp": formatted_time,
        "TransactionType": "CustomerPayBillOnline",
        "Amount": "1",
        "PartyA": keys.phone_number,
        "PartyB": keys.business_shortcode,
        "PhoneNumber": keys.phone_number,
        "CallBackURL": "https://fullstackdjango.com/lipanampesa/",
        "AccountReference": " 123456 ",