Transaction Status¶
Khalti provides API for transaction status/lookup to check the state of the user's transaction made to the merchant. A merchant should use secret test and live keys to check test and live transaction status respectively.
API¶
The request signature for transaction lookup is as follows:
URL
:https://khalti.com/api/v2/payment/status/
Method
:GET
- Headers:
Authorization
: test or live secret key in the formKey <secret key>
- Params:
token
: Token or idx given by Khalti after payment confirmation.amount
: Amount (in paisa) with which payment was initiated.
Responses¶
Once you've made a request as specified above, Khalti server will return you a response of Transaction States in the following format.
Success Response¶
Success response consists of the Complete
state.
Completed State¶
Error Response¶
1. Transaction Not Found¶
An error occurs, if wrong token/idx or wrong amount is passed in the parameter. It consist of the detail of error.
2. Failed State¶
A transaction could be failed due to the possibility of 'confirmation_code' exploitation.
Other Responses¶
1. Initiated State¶
Transactions are initiated after mobile number and khalti pin along with other transaction details are provided.
2. Confirmed State¶
A transaction is confirmed after transaction details (transaction token, confirmation_code and 3rd party transaction_pin) are provided by the consumer.
3. Refunded State¶
4. Partially Refunded State¶
Example Requests¶
Assuming the token/idx that we received is XPPrDcwtHUg4UQbWEnxRzA
.
const axios = require('axios');
let data = {
"token": "XPPrDcwtHUg4UQbWEnxRzA",
"amount": 1000
};
let config = {
headers: {'Authorization': 'Key test_secret_key_f59e8b7d18b4499ca40f68195a846e9b'}
};
axios.get("https://khalti.com/api/v2/payment/status/", data, config)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});