Skip to main content

A python package for connecting to payments platforms like MPESA,PayPal,RazorPay

Project description

koros_python_payments

A python package for connecting to payments platforms like MPESA,PayPal,RazorPay

Installation

pip install koros-python-payments

Configuration

Create an env file and add the following: Update the configuration according to your needs

MPESA_ENV=0 #0 means the sandbox credentails will be used while 1 means live credentations will be used

#Test
MPESA_TEST_CONSUMER_KEY=""
MPESA_TEST_CONSUMER_SECRET=""
MPESA_TEST_TOKEN_URL="https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials"
MPESA_TEST_INITIATOR="testapi"
MPESA_TEST_PASSWORD="Safaricom999!*!"
MPESA_TEST_B2C_PARTY_A=600997
MPESA_TEST_B2C_RESULT_URL=""
MPESA_TEST_B2C_QUEUE_TIMEOUT_URL=""
MPESA_TEST_B2C_URL="https://sandbox.safaricom.co.ke/mpesa/b2c/v1/paymentrequest"
MPESA_TEST_B2C_COMMAND_ID = "BusinessPayment"
MPESA_TEST_BUSINESS_SHORTCODE = 174379
MPESA_TEST_PASSKEY = ""
MPESA_TEST_CUSTOMER_TO_BUSINESS_URL = "https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
MPESA_TEST_CALLBACK_URL = "http://localhost:8000"
MPESA_TEST_TRANSACTION_QUERY_URL = "https://sandbox.safaricom.co.ke/mpesa/transactionstatus/v1/query"
MPESA_TEST_TRANSACTION_QUERY_RESULT_URL="http://localhost:8000/callback/transaction-query/"
MPESA_TEST_TRANSACTION_QUERY_QUEUE_TIMEOUT_URL="https://localhost/callback/transaction-query"
MPESA_TEST_TRANSACTION_QUERY_IDENTIFIER_TYPE='4'
MPESA_TEST_TRANSACTION_QUERY_COMMAND_ID = "TransactionStatusQuery"
MPESA_TEST_TRANSACTION_QUERY_TRANSACTION_CODE = "OEI2AK4Q16"
MPESA_TEST_TRANSACTION_QUERY_PARTY_A= 600987
MPESA_TEST_TRANSACTION_ORIGINATOR_CONVERSATION_ID = ""
MPESA_TEST_CERT_PATH='./certs/SandboxCertificate.cer' #certificate is already uploaded in the package


#Live
MPESA_LIVE_CONSUMER_KEY=""
MPESA_LIVE_CONSUMER_SECRET=""
MPESA_LIVE_TOKEN_URL="https://api.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials"
MPESA_LIVE_INITIATOR=""
MPESA_LIVE_PASSWORD=""
MPESA_LIVE_B2C_PARTY_A=""
MPESA_LIVE_B2C_RESULT_URL=""
MPESA_LIVE_B2C_QUEUE_TIMEOUT_URL=""
MPESA_LIVE_B2C_URL="https://api.safaricom.co.ke/mpesa/b2c/v1/paymentrequest"
MPESA_LIVE_B2C_COMMAND_ID = "BusinessPayment"
MPESA_LIVE_BUSINESS_SHORTCODE =""
MPESA_LIVE_PASSKEY = ""
MPESA_LIVE_CUSTOMER_TO_BUSINESS_URL = "https://api.safaricom.co.ke/mpesa/stkpush/v1/processrequest"
MPESA_LIVE_CALLBACK_URL = ""
MPESA_LIVE_TRANSACTION_QUERY_URL = "https://api.safaricom.co.ke/mpesa/transactionstatus/v1/query"
MPESA_LIVE_TRANSACTION_QUERY_RESULT_URL=""
MPESA_LIVE_TRANSACTION_QUERY_QUEUE_TIMEOUT_URL=""
MPESA_LIVE_TRANSACTION_QUERY_IDENTIFIER_TYPE='4'
MPESA_LIVE_TRANSACTION_QUERY_COMMAND_ID = "TransactionStatusQuery"
MPESA_LIVE_TRANSACTION_QUERY_TRANSACTION_CODE = "OEI2AK4Q16"
MPESA_LIVE_TRANSACTION_QUERY_PARTY_A=
MPESA_LIVE_TRANSACTION_ORIGINATOR_CONVERSATION_ID = ""

Make STK Push/ Request payment from user

from mpesa.customer_to_business import CustomerToBusiness

def make_skt_push():
    amount = 1
    phone = "254712345678"
    bill_reference = "12345"
    customer_to_business=CustomerToBusiness()
    repsonse=customer_to_business.stk_push(amount,phone,bill_reference)
    response_code = repsonse.get("ResponseCode","")
    if response_code == "0":
        #Request was  successful, stk sent to customer
        customerMessage = response.get("CustomerMessage","")
        print(customerMessage)
    else:
        #Request was not successful, stk sent to customer
        errorMessage = response.get("errorMessage","")
        print(errorMessage)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

koros_python_payments-1.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

koros_python_payments-1.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file koros_python_payments-1.0.2.tar.gz.

File metadata

  • Download URL: koros_python_payments-1.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for koros_python_payments-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ec6ccf9ddbbb65ce90b370072eef1207551562f796239686bad9994edc2daaca
MD5 a1b732fae716c6a1a1c6e230d5638086
BLAKE2b-256 65e1714b763cf08a1257e67a2427973c3b1b06a990db0b6eec0c3bada30146ca

See more details on using hashes here.

File details

Details for the file koros_python_payments-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for koros_python_payments-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eabc30183b0701fe69837f883d73dbb08d3a66441b52733733c2db0605122dfb
MD5 92c576af3ddf7d177a16cf234447627d
BLAKE2b-256 9e7c05c6ccd9fb0e1a98479b63b97b839e1d6b86de5f1a16b4f89b8ad44ebe57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page