-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from adilmohak/main
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}} | ||
""" |