Fawry

Cowpay service to charge customers offline via fawry outlets

The old v0 fawry API still functional and working but we recommend to migrate to the current version as it more secure.

How it works

Initiate a POST charge request to the following URL

https://cowpay.me/api/v1/charge/fawry
https://staging.cowpay.me/api/v1/charge/fawry

Make sure to send all the listed below headers and keys with the proper values

Headers

FieldTypeDescription
AuthorizationstringBearer Token
Content-Typestringapplication/json
Acceptstringapplication/json

Keys

FieldRequiredTypeDescription
merchant_reference_idyesstringUnique alphanumeric value required as identifier for the charge request
customer_merchant_profile_idyesstringID of the customer being charged on your system
amountyesstringtwo decimal value like: "15.60"
customer_namepartialstringcustomer name required in case of the customer being charged for the first time
customer_mobilepartialstringinternationally formatted customer mobile required in case of the customer being charged for the first time
customer_emailpartialstringcustomer email required in case of the customer being charged for the first time
descriptionyesstringcharge request description that represents the payment name
signatureyesstringsha-256 hash for the following concatenated params: merchant_code + merchant_reference_id + customer_merchant_profile_id + amount + hash_key
Both merchant_code and hash_key are being found in your API settings page in your cowpay dashboard
You can generate signatures while testing here

Request Payload Example

{
    "merchant_reference_id": "12545",
    "customer_merchant_profile_id": "253",
    "customer_name": "John Doe",
    "customer_email": "example@gmail.com",
    "customer_mobile": "+201xxxxxxxxxx",
    "amount": "10.00",
    "signature": "ca2f64dc29dc89aa24aecc664a5791ad35b244c4fe47ddb93520fa96f9593ec8",
    "description": "Charge request description"
}

Response

{
    "success": true,
    "status_code": 200,
    "status_description": "Operation done successfully",
    "type": "Pay at Fawry Charge Request",
    "payment_gateway_reference_id": "971453632",
    "merchant_reference_id": "12545",
    "cowpay_reference_id": 1000251
}

Code Examples

POST /api/v1/charge/fawry HTTP/1.1
Host: cowpay.me
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjA4YzExYWRkOTgxYmEyMTAxMjBiNDU4NjU0YzJhNmFkYjdhYjRkNTg0M2UxYTFkMzVlMDM2MDdlNmY2ODMyN2QwZTA1ZmVhY2ExOWExYWIxIn0.eyJhdWQiOiIzIiwianRpIjoiMDhjMTFhZGQ5ODFiYTIxMDEyMGI0NTg2NTRjMmE2YWRiN2FiNGQ1ODQzZTFhMWQzNWUwMzYwN2U2ZjY4MzI3ZDBlMDVmZWFjYTE5YTFhYjEiLCJpYXQiOjE2MDAwODMwNjgsIm5iZiI6MTYwMDA4MzA2OCwiZXhwIjoxNjMxNjE5MDY4LCJzdWIiOiIxNyIsInNjb3BlcyI6W119.f--W72hdY9ABlepGkzFubQx4PNNbxiYJZj8hPfXC2EwsUhPwWYGOL3rTSFnhYTuubJcEXLKnncoXInhBf9Ho2g
Content-Type: application/json

{
    "merchant_reference_id": "12545",
    "customer_merchant_profile_id": "253",
    "customer_name": "Testing",
    "customer_email": "example@gmail.com",
    "customer_mobile": "+201xxxxxxxxxx",
    "amount": "10.00",
    "signature": "ca2f64dc29dc89aa24aecc664a5791ad35b244c4fe47ddb93520fa96f9593ec8",
    "description": "Charge request description"
}
let axios = require('axios');

let data = {
   "merchant_reference_id": "12545",
   "customer_merchant_profile_id": "253",
   "customer_name": "Testing",
   "customer_email": "example@gmail.com",
   "customer_mobile": "+201xxxxxxxxxx",
   "amount": "10.00",
   "signature": "ca2f64dc29dc89aa24aecc664a5791ad35b244c4fe47ddb93520fa96f9593ec8",
   "description": "Charge request description"
}


let axiosConfig = {
    method: 'post',
    baseURL: 'https://cowpay.me/api/v1/', // or https://staging.cowpay.me/api/v1/,
    url: 'charge/fawry',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjA4YzExYWRkOTgxYmEyMTAxMjBiNDU4NjU0YzJhNmFkYjdhYjRkNTg0M2UxYTFkMzVlMDM2MDdlNmY2ODMyN2QwZTA1ZmVhY2ExOWExYWIxIn0.eyJhdWQiOiIzIiwianRpIjoiMDhjMTFhZGQ5ODFiYTIxMDEyMGI0NTg2NTRjMmE2YWRiN2FiNGQ1ODQzZTFhMWQzNWUwMzYwN2U2ZjY4MzI3ZDBlMDVmZWFjYTE5YTFhYjEiLCJpYXQiOjE2MDAwODMwNjgsIm5iZiI6MTYwMDA4MzA2OCwiZXhwIjoxNjMxNjE5MDY4LCJzdWIiOiIxNyIsInNjb3BlcyI6W119.f--W72hdY9ABlepGkzFubQx4PNNbxiYJZj8hPfXC2EwsUhPwWYGOL3rTSFnhYTuubJcEXLKnncoXInhBf9Ho2g'
    },
    data: data
}

axios(axiosConfig)
    .then(response => {
        let paymentReferenceId = response.data.payment_gateway_reference_id // used for outlet payments
    })
    .catch(error => {
        console.log(error.response.data)
    })
$client = new \GuzzleHttp\Client([
    'base_uri' => 'https://cowpay.me/api/v1/', // or https://staging.cowpay.me/api/v1
    'headers' => [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'Authorization' => 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjA4YzExYWRkOTgxYmEyMTAxMjBiNDU4NjU0YzJhNmFkYjdhYjRkNTg0M2UxYTFkMzVlMDM2MDdlNmY2ODMyN2QwZTA1ZmVhY2ExOWExYWIxIn0.eyJhdWQiOiIzIiwianRpIjoiMDhjMTFhZGQ5ODFiYTIxMDEyMGI0NTg2NTRjMmE2YWRiN2FiNGQ1ODQzZTFhMWQzNWUwMzYwN2U2ZjY4MzI3ZDBlMDVmZWFjYTE5YTFhYjEiLCJpYXQiOjE2MDAwODMwNjgsIm5iZiI6MTYwMDA4MzA2OCwiZXhwIjoxNjMxNjE5MDY4LCJzdWIiOiIxNyIsInNjb3BlcyI6W119.f--W72hdY9ABlepGkzFubQx4PNNbxiYJZj8hPfXC2EwsUhPwWYGOL3rTSFnhYTuubJcEXLKnncoXInhBf9Ho2g'
    ]
]);

try {
    $response = $client->request('POST', 'charge/fawry', [
        'json' => [
            'merchant_reference_id' => 'mc-125410',
            'customer_merchant_profile_id' => '253',
            'customer_name' => 'Testing',
            'customer_email' => 'dev@cowpay.me',
            'customer_mobile' => '+201096545211',
            'amount' => '10.00',
            'signature' => '23fa42cfea412eb370dc6b43b64461cff84d9da80906d6a53d25e167a53edf3f',
            'description' => 'Charge request description'
        ]
    ]);

    $result = json_decode($response->getBody()->getContents(), true);

    $paymentReferenceId = $result['payment_gateway_reference_id']; // used in outlet payment

} catch (\GuzzleHttp\Exception\RequestException $exception) {

    $response = json_decode($exception->getResponse()->getBody()->getContents(), true);

    if ($response['status_code'] == 422) {

        $errors = $response['errors']; // check invalid date messages

    }
}