### Encrypted Payload Example Source: https://developer.chapa.co/charge/authorize-payments This JSON structure represents a successfully encrypted payload, typically used when handling sensitive security information like OTPs with Chapa's Direct Charges API. The 'client' field contains the encrypted data, which needs to be generated using your encryption key from the Chapa dashboard and the 3DES algorithm. ```json { "client": "0jhd12Dfee+2h/FzHA/X1zPlDmRmH5v+F4sdsfFFSEgg44FAFDSFS000+YwUHegTSogQdnXp7OGdUxPngiv6592YoL0YXa4eHcH1fRGjAimdqucGJPurFVu4sE5gJIEmBCXdESVqNPG72PwdRPfAINT9x1bXemI1M3bBdydtWvAx58ZE4fcOtWkD/IDi+o8K7qpmzgUR8YUbgZ71yi0pg5UmrT4YpcY2eq5i46Gg3L+rtjhjkgjkjg83hfkjajhf3" } ``` -------------------------------- ### Verify Transaction using Python Source: https://developer.chapa.co/charge/authorize-payments This Python code snippet demonstrates how to verify a transaction using Chapa's API. It constructs a multipart/form-data POST request to the validation endpoint, including the transaction reference and an encrypted client payload. The Authorization header must contain your secret key as a bearer token. The response from the API call is then printed. ```python import requests url = "https://api.chapa.co/v1/validate?type=amole" dataList = [] boundary = 'wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T' dataList.append('--' + boundary) dataList.append('Content-Disposition: form-data; name="reference"') dataList.append('') dataList.append('CHcuKjgnN0Dk0') dataList.append('--' + boundary) dataList.append('Content-Disposition: form-data; name="client"') dataList.append('') dataList.append('0jhd12Dfee+2h/FzHA/X1zPlDmRmH5v+F4sdsfFFSEgg44FAFDSFS000+YwUHegTSogQdnXp7OGdUxPngiv6592YoL0YXa4eHcH1fRGjAimdqucGJPurFVu4sE5gJIEmBCXdESVqNPG72PwdRPfAINT9x1bXemI1M3bBdydtWvAx58ZE4fcOtWkD/IDi+o8K7qpmzgUR8YUbgZ71yi0pg5UmrT4YpcY2eq5i46Gg3L+rtjhjkgjkjg83hfkjajhf3') dataList.append('--' + boundary + '--') dataList.append('') body = ' '.join(dataList) payload = body.encode('utf-8') headers = { 'Authorization': 'Bearer CHASECK-xxxxxxxxxxxxxxxx', 'Content-type': 'multipart/form-data; boundary={}'.format(boundary) } response = requests.post(url, data=payload, headers=headers) data = response.text print(data) ``` -------------------------------- ### Webhook Source: https://developer.chapa.co/charge/authorize-payments Information about Chapa's webhook service, which sends notifications upon successful payment authorization. ```APIDOC ## Webhook ### Description Chapa provides a webhook service that sends automated messages to your specified endpoint whenever a payment is successfully authorized. This allows for real-time updates on your server. ### Usage Ensure you have enabled webhook notifications in your Chapa dashboard settings. Configure your endpoint URL to receive these notifications. ### Event - **payment.authorized**: Triggered upon successful payment authorization. ### Payload Structure (Specific payload structure not detailed, but typically includes transaction details and status.) ### Security It is recommended to verify the authenticity of incoming webhooks to prevent security risks. ``` -------------------------------- ### Authorize Transaction Source: https://developer.chapa.co/charge/authorize-payments This endpoint is used to authorize transactions after a direct charge payment has been initiated. The request requires a transaction reference and varies based on the payment method. ```APIDOC ## POST /v1/validate ### Description Initiates the authorization process for a transaction after a direct charge payment. ### Method POST ### Endpoint `https://api.chapa.co/v1/validate` ### Query Parameters - **type** (string) - Required - The type of direct charge (e.g., 'amole', 'telebirr'). ### Headers - **Authorization** (string) - Required - Your secret key as a bearer token (e.g., 'Bearer CHASECK-xxxxxxxxxxxxxxxx'). - **Content-type** (string) - Required - 'multipart/form-data; boundary={boundary_string}' ### Request Body This endpoint uses multipart/form-data. The `client` field should contain the encrypted payload. - **reference** (string) - Required - The transaction reference. - **client** (string) - Required - The encrypted sensitive information, typically OTPs, using the 3DES algorithm. ### Request Example ``` --wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T Content-Disposition: form-data; name="reference" CHcuKjgnN0Dk0 --wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T Content-Disposition: form-data; name="client" 0jhd12Dfee+2h/FzHA/X1zPlDmRmH5v+F4sdsfFFSEgg44FAFDSFS000+YwUHegTSogQdnXp7OGdUxPngiv6592YoL0YXa4eHcH1fRGjAimdqucGJPurFVu4sE5gJIEmBCXdESVqNPG72PwdRPfAINT9x1bXemI1M3bBdydtWvAx58ZE4fcOtWkD/IDi+o8K7qpmzgUR8YUbgZ71yi0pg5UmrT4YpcY2eq5i46Gg3L+rtjhjkgjkjg83hfkjajhf3 --wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T-- ``` ### Response #### Success Response (200) Details of the successful authorization response are not explicitly provided in the documentation, but typically include transaction status. #### Failed Response Refer to the Error Codes page for detailed error responses. ``` -------------------------------- ### Direct Charge API Encryption Source: https://developer.chapa.co/charge/encryption Explains the process of encrypting sensitive data for the Direct Charge API using the 3DES algorithm. ```APIDOC ## Encryption When using the `Direct Charge API` to charge a card directly or send OTP, you need to encrypt the payload containing sensitive information before making the request. ### How to Encrypt Payload To encrypt the payload manually, you will need your encryption key (obtainable from the Settings > API section of your dashboard). The 3DES algorithm is used for this encryption. ### What to Encrypt When sending sensitive information such as card details or OTP, you must encrypt the following body parameters. If OTP is required, ensure you include the request token previously returned when initiating the transaction. ```json { "requestID": "13434jjfhd8ududfy82e324234234jkhjsfhdfhskdjfh89fjhduohdfjhsgkdfksjdfskldhfkjs", "otp": 1234 } ``` ### Encryption Function Example (Python) This example demonstrates an encryption function that takes a payload, converts it to JSON, encrypts it using 3DES, and then encodes it in base64. ```python import json import base64 from Crypto.Cipher import DES3 import hashlib def encryptData(key, plainText): blockSize = 8 padDiff = blockSize - (len(plainText) % blockSize) cipher = DES3.new(key, DES3.MODE_ECB) plainText = "{}{}".format(plainText, "\x00" * padDiff) encrypted = base64.b64encode(cipher.encrypt(plainText)) return encrypted.decode('utf-8') ``` ``` -------------------------------- ### Verify Transaction Source: https://developer.chapa.co/charge/authorize-payments This section describes the importance and method of verifying the final status of a transaction after payment authorization. ```APIDOC ## Verify Transaction ### Description It is crucial to verify the transaction and confirm its final status after authorization. This process ensures the integrity of the payment. ### Method Details on the specific HTTP method and endpoint for verification are not provided in this section, but it is implied that a request to Chapa's API is necessary. ### Parameters - **transaction_reference** (string) - Required - The unique identifier for the transaction to be verified. - **secret_key** (string) - Required - Your Chapa secret key for authentication. ### Request Example (Specific request example not provided, refer to general API usage for authentication and request structure.) ### Response #### Success Response - **status** (string) - The final status of the transaction (e.g., 'success', 'failed'). - **transaction_id** (string) - The unique ID of the transaction. #### Failed Response Refer to the Error Codes page for detailed error responses. ``` -------------------------------- ### Encrypt Payload for Direct Charge API (Python) Source: https://developer.chapa.co/charge/encryption Encrypts a given plaintext string using 3DES ECB mode and base64 encodes the result. This function is used to secure sensitive data before sending it to the Direct Charge API. It requires the 'pycryptodome' library. ```python import json, requests import base64 from Crypto.Cipher import DES3 import hashlib def encryptData(self, key, plainText): blockSize = 8 padDiff = blockSize - (len(plainText) % blockSize) cipher = DES3.new(key, DES3.MODE_ECB) plainText = "{}{}".format(plainText, "".join(chr(padDiff) * padDiff)) encrypted = base64.b64encode(cipher.encrypt(plainText)) return encrypted ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.