Skip to content

Commit

Permalink
Merge pull request #2 from adilmohak/main
Browse files Browse the repository at this point in the history
  • Loading branch information
isrugeek committed Aug 30, 2022
2 parents 0fc8801 + e7bdd29 commit bcaaaff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/checkout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from chapa import Chapa


def checkout():
data = {
# Required fields
'email': 'user@example.com', # customer/client email address
'amount': 1311.00, # total payment
'first_name': 'Abebe', # customer/client first name
'last_name': 'Bikila', # customer/client last name
'tx_ref': '[transaction_id] or [order_id]',

# Optional fields
'callback_url': 'your_callback_url', # after successful payment chapa will redirect your customer/client to this url
'customization': {
'title': 'Example.com',
'description': 'Payment for your services',
}
}

chapa = Chapa('[YOUR_CHAPA_SECRET_KEY]')
response = chapa.initialize(**data)

# After successfull initialization redirect to the `checkout_url`
if response['status'] == 'success':
# do some action
""" Redirect to the checkout page using `response['data']['checkout_url']` """
else:
# If initialization fails display the error message
print(response['message'])
24 changes: 24 additions & 0 deletions examples/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from chapa import Chapa


def verify(transaction_id):
""" Accept the transaction id and verify it """
chapa = Chapa('[YOUR_CHAPA_SECRET_KEY]')
response = chapa.verify(transaction_id)

if response['status'] == 'success':
# do some actions, probably redirect to success page
pass
else:
# do some actions, probably redirect to failed page
pass

"""
If verification response has succeed it looks like
{'message': 'Payment details', 'status': 'success', 'data': {
'first_name': 'Abebe', 'last_name': 'Bikila', 'email': 'user@example.com', 'currency': 'ETB',
'amount': '1,311.00', 'charge': '45.89', 'mode': 'test', 'method': 'test', 'type': 'API',
'status': 'success', 'reference': '[reference]', 'tx_ref': '[tx_ref]',
'customization': {'title': 'Example.com', 'description': 'Payment for your services', 'logo': None},
'meta': None, 'created_at': '2022-08-24T12:29:52.000000Z', 'updated_at': '2022-08-24T12:29:52.000000Z'}}
"""

0 comments on commit bcaaaff

Please sign in to comment.