HMAC Transaction Callback
Outcome - Understand how to calculate the hmac value for the transaction callbacks (Processed and Response)
Step 1: Sort the Data Lexicographically by Key
Sort the parameters received in the callback in lexicographical order based on their keys. The keys/parameters should be in the same order as shown in the list below.
Shape of data received:
- POST callbacks: data is received as a JSON object
- GET callbacks: data is received as query parameters
You can check the callbacks guide to know more about each type of callback.
HMAC String Keys:
amount_cents
created_at
currency
error_occured
has_parent_transaction
obj.id // for Processed (POST) | id for Response (GET)
integration_id
is_3d_secure
is_auth
is_capture
is_refunded
is_standalone_payment
is_voided
order.id // for Processed (POST) | order_id for Response (GET)
owner
pending
source_data.pan
source_data.sub_type
source_data.type
successStep 2: Concatenate the Values
Concatenate the values of the keys/parameters into a single string in the same order as they are listed. This string will be used to calculate the HMAC in the next step. For example, if we consider the sample transaction processed callback, the resultant string would look like this:
HMAC Concatenated String:
1000002024-06-13T11:33:44.592345EGPfalsefalse1920364654097558truefalsefalsefalsetruefalse217503754302852false2346MasterCardcardtrueStep 3: Calculate the HMAC
Use your HMAC secret and the SHA-512 hashing algorithm to generate an HMAC from the concatenated string.
To know how to get your hmac secret, please check the Getting Integration Credentials page.
HMAC Calculated Sample:
fa8ac0b7f3852e60c50e7fdd4ea5ef0bda96030c19dea1d55df8c76d6c08ab1877774662cbb049
81dc84839ad4da560bcc8cb53b8973548657f7e8f8d2e79930Step 4: Compare the Calculated HMAC
Compare the HMAC value you calculated with the hmac value received in the callback’s query parameters (e.g., ...?hmac=generated_hash) to verify the integrity and authenticity of the data.
Transaction
Show child attributes
What made this section helpful for you?
What made this section unhelpful for you?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
"type": "TRANSACTION",
"obj": {
"id": 192036465,
"pending": false,
"amount_cents": 100000,
"success": true,
"is_auth": false,
"is_capture": false,
"is_standalone_payment": true,
"is_voided": false,
"is_refunded": false,
"is_3d_secure": true,
"integration_id": 4097558,
"profile_id": 164295,
"has_parent_transaction": false,
"order": {
"id": 217503754,
"created_at": "2024-06-13T11:32:09.628623",
"delivery_needed": false,
"merchant": {
"id": 164295,
"created_at": "2022-03-24T21:13:47.852384",
"phones": [
"+201024710769"
],
"company_emails": [
"mohamedabdelsttar97@gmail.com"
],
"company_name": "Parmagly",
"state": "",
"country": "EGY",
"city": "Cairo",
"postal_code": "",
"street": ""
},
"collector": null,
"amount_cents": 100000,
"shipping_data": {
"id": 108010028,
"first_name": "dumy",
"last_name": "dumy",
"street": "dumy",
"building": "dumy",
"floor": "dumy",
"apartment": "sympl",
"city": "dumy",
"state": "dumy",
"country": "EG",
"email": "dumy@dumy.com",
"phone_number": "+201125773493",
"postal_code": "NA",
"extra_description": "",
"shipping_method": "UNK",
"order_id": 217503754,
"order": 217503754
},
"currency": "EGP",
"is_payment_locked": false,
"is_return": false,
"is_cancel": false,
"is_returned": false,
"is_canceled": false,
"merchant_order_id": null,
"wallet_notification": null,
"paid_amount_cents": 100000,
"notify_user_with_email": false,
"items": [],
"order_url": "NA",
"commission_fees": null,
"delivery_fees_cents": null,
"delivery_vat_cents": null,
"payment_method": "tbc",
"merchant_staff_tag": null,
"api_source": "OTHER",
"data": {}
},
"created_at": "2024-06-13T11:33:44.592345",
"transaction_processed_callback_responses": [],
"currency": "EGP",
"source_data": {
"pan": "2346",
"type": "card",
"tenure": null,
"sub_type": "MasterCard"
},
"api_source": "IFRAME",
"terminal_id": null,
"merchant_commission": null,
"installment": null,
"discount_details": [],
"is_void": false,
"is_refund": false,
"data": {
"gateway_integration_pk": 4097558,
"klass": "MigsPayment",
"created_at": "2024-06-13T08:34:07.076347",
"amount": 100000,
"currency": "EGP",
"migs_order": {
"acceptPartialAmount": false,
"amount": 1000,
"authenticationStatus": "AUTHENTICATION_SUCCESSFUL",
"chargeback": {
"amount": null,
"currency": "EGP"
},
"creationTime": "2024-06-13T08:34:00.850Z",
"currency": "EGP",
"description": "PAYMOB Parmagly",
"id": "217503754",
"lastUpdatedTime": "2024-06-13T08:34:06.883Z",
"merchantAmount": 1000,
"merchantCategoryCode": "7299",
"merchantCurrency": "EGP",
"status": "CAPTURED",
"totalAuthorizedAmount": 1000,
"totalCapturedAmount": 1000,
"totalRefundedAmount": null
},
"merchant": "TESTMERCH_C_25P",
"migs_result": "SUCCESS",
"migs_transaction": {
"acquirer": {
"batch": 20240613,
"date": "0613",
"id": "BMNF_S2I",
"merchantId": "MERCH_C_25P",
"settlementDate": "2024-06-13",
"timeZone": "+0200",
"transactionId": "123456789"
},
"amount": 1000,
"authenticationStatus": "AUTHENTICATION_SUCCESSFUL",
"authorizationCode": "326441",
"currency": "EGP",
"id": "192036465",
"receipt": "416508326441",
"source": "INTERNET",
"stan": "326441",
"terminal": "BMNF0506",
"type": "PAYMENT"
},
"txn_response_code": "APPROVED",
"acq_response_code": "00",
"message": "Approved",
"merchant_txn_ref": "192036465",
"order_info": "217503754",
"receipt_no": "416508326441",
"transaction_no": "123456789",
"batch_no": 20240613,
"authorize_id": "326441",
"card_type": "MASTERCARD",
"card_num": "512345xxxxxx2346",
"secure_hash": "",
"avs_result_code": "",
"avs_acq_response_code": "00",
"captured_amount": 1000,
"authorised_amount": 1000,
"refunded_amount": null,
"acs_eci": "02"
},
"is_hidden": false,
"payment_key_claims": {
"extra": {},
"user_id": 302852,
"currency": "EGP",
"order_id": 217503754,
"amount_cents": 100000,
"billing_data": {
"city": "dumy",
"email": "dumy@dumy.com",
"floor": "dumy",
"state": "dumy",
"street": "dumy",
"country": "EG",
"building": "dumy",
"apartment": "sympl",
"last_name": "dumy",
"first_name": "dumy",
"postal_code": "NA",
"phone_number": "+201125773493",
"extra_description": "NA"
},
"redirect_url": "https://accept.paymob.com/unifiedcheckout/payment-status?payment_token=ZXlKaGJHY2lPaUpJVXpVeE1pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjFjMlZ5WDJsa0lqb3pNREk0TlRJc0ltRnRiM1Z1ZEY5alpXNTBjeUk2TVRBd01EQXdMQ0pqZFhKeVpXNWplU0k2SWtWSFVDSXNJbWx1ZEdWbmNtRjBhVzl1WDJsa0lqbzBNRGszTlRVNExDSnZjbVJsY2w5cFpDSTZNakUzTlRBek56VTBMQ0ppYVd4c2FXNW5YMlJoZEdFaU9uc2labWx5YzNSZmJtRnRaU0k2SW1SMWJYa2lMQ0pzWVhOMFgyNWhiV1VpT2lKa2RXMTVJaXdpYzNSeVpXVjBJam9pWkhWdGVTSXNJbUoxYVd4a2FXNW5Jam9pWkhWdGVTSXNJbVpzYjI5eUlqb2laSFZ0ZVNJc0ltRndZWEowYldWdWRDSTZJbk41YlhCc0lpd2lZMmwwZVNJNkltUjFiWGtpTENKemRHRjBaU0k2SW1SMWJYa2lMQ0pqYjNWdWRISjVJam9pUlVjaUxDSmxiV0ZwYkNJNkltUjFiWGxBWkhWdGVTNWpiMjBpTENKd2FHOXVaVjl1ZFcxaVpYSWlPaUlyTWpBeE1USTFOemN6TkRreklpd2ljRzl6ZEdGc1gyTnZaR1VpT2lKT1FTSXNJbVY0ZEhKaFgyUmxjMk55YVhCMGFXOXVJam9pVGtFaWZTd2liRzlqYTE5dmNtUmxjbDkzYUdWdVgzQmhhV1FpT21aaGJITmxMQ0psZUhSeVlTSTZlMzBzSW5OcGJtZHNaVjl3WVhsdFpXNTBYMkYwZEdWdGNIUWlPbVpoYkhObExDSnVaWGgwWDNCaGVXMWxiblJmYVc1MFpXNTBhVzl1SWpvaWNHbGZkR1Z6ZEY5a01EUmtNV0U0TkRrMk1tSTBOemt5T1dJeVpHTXhOalJoTURReU5qaGlZeUo5LkFPc3l2S1A4a3Fob0E5aVFOSEZfQWFaZl9HQi1NcU5kcXhrQmhlZm1feVpIZHJ3ci1xbkUxWklKT2FxekRFMkp5cXhCWXVEdnZ1VVZweGV3bFVGTTlB&trx_id=192036465",
"integration_id": 4097558,
"lock_order_when_paid": false,
"next_payment_intention": "pi_test_d04d1a84962b47929b2dc164a04268bc",
"single_payment_attempt": false
},
"error_occured": false,
"is_live": false,
"other_endpoint_reference": null,
"refunded_amount_cents": null,
"source_id": -1,
"is_captured": false,
"captured_amount": null,
"merchant_staff_tag": null,
"updated_at": "2024-06-13T11:34:07.272638",
"is_settled": false,
"bill_balanced": false,
"is_bill": false,
"owner": 302852,
"parent_transaction": null
},
"issuer_bank": null,
"transaction_processed_callback_responses": ""
}