Android - ESewa SDK Documentation
Android - ESewa SDK Documentation
Android - ESewa SDK Documentation
For Android
Table Of
Contents
Chapter 1 Introduction 2-4
General Description 2
Transaction Flow 3
System Interaction 3
Call back url 4
Transaction Verification 4
Chapter 2 Implementation 5-9
Overview 5
Prerequisite 6
Call back url Pattern 6
Transaction Verification API 7-8
Error Cases and Handling 8
During Final Verification 9
Chapter 3 Appendix 10-12
Appendix A 10
Appendix B 11
Appendix C 12
Chapter 4 FAQ 13-15
For Merchants 13
For Users 15
1
Chapter 1 Introduction
Introduction
This document is intended to be used as a reference in the planning and building of applications wishing to
integrate eSewa SDK. This information should help accelerate the integration efforts of eSewa System with
merchant application.
The focus of this document is to detail how partner applications establish connectivity to eSewa and outline
the transaction process with verification process. A full and detailed description of the transactions and
associated data elements is included.
This document is intended for partner merchant/clients seeking to integrate and transact with the eSewa.
It should be used as a reference during the planning, building, and testing of such applications. eSewa
enables partner merchant/clients to perform transaction initiated by customers having eSewa account in
secure environment. The transaction amount is deposited into their eSewa merchant wallet or bank account.
Overview
General Description
The eSewa Mobile SDK enable native android to easily accept eSewa payments.
The SDK supports only one use case for making payment – Single Payment (i.e. One payment per one user log in).
Transaction Flow
1. Client Mobile Application initiates eSewa Payment procedure by sending their client_id and client_secret
along with product/service name, product/service price, product_ id and callback-url to sdk.
*client_id and client_secret values are provided by eSewa to its merchant/client.
2. SDK verifies merchant/client credentials with eSewa server, proceeds to next step if verification succeeds else
freezes with appropriate error message.
3. User login in eSewa.
4. User makes payment if sufficient balance is available .
5. If successful payment is made, SDK receives (from eSewa server) and forwards proof of payment to client mobile
application (in the form of transaction details shown in Appendix C) and at the same time, eSewa server also
sends the same copy to merchant/client application server in the callback-url. (* This proof of payment is
significant for payment verification).
6. Client/merchant verifies the transaction with eSewa through a verification api. This final verification procedure
is strongly recommended before product/service delivery.
7. Deliver Product/Service to user.
[Note:
2
After the completion of login, if the device stays ideal for more than 1 minute before confirming the payment, the particular session will
be time out and user have to re-login to confirm the payment.]
1. Client/Merchant app triggers sdk with required params as mentioned in step one of transaction flow.
2. Sdk ( in communication with eSewa server) verifies merchant, proceeds to login eventually landing at
payment confirmation.
3. User confirms payment. With payment being successful, eSewa server sends a proof of payment to
Client/Merchant Server in their provided callback-url.
4. At the same time, the same copy is also sent to eSewa SDK.
5. eSewa SDK forwards the payment response to client/merchant mobile app.
6. Transaction verification is strongly recommended before the delivery of any product/service.
3
Call Back Url
Callback-url is an API exposed at merchant/client`server at which eSewa sends a copy of proof of payment after
successful payment; the client/merchant must send a callback-url while initiating the payment through eSewa. The
sent callback-url is later used by eSewa to send a copy of proof of payment after a payment is received. The
callback-url must be an API with Request Method POST. The pattern in which eSewa sends the proof of payment is
described in Chapter 2 (Implementation).
Transaction Verification
Clients using eSewa SDK are requested to go through final verification by comparing all the parameters proof
of payment obtained by application through SDK and that obtained by client application server through
eSewa. Clients/merchants are strongly recommended to send verification request for each successful
payment with required parameters to eSewa Server before product/service delivery. This can be done
through verification api which is shown in Chapter 2 (Implementation).
The partner merchant will receive transaction details on success or error message on failure response.
4
Chapter 2 Implementation
Implementation
Overview
eSewa integration on partner merchant’s application is the process of implementing eSewa as
payment option. The integration process itself is performed in two phases, namely:
This phase is intended to test process flow, transactions and other integration results. A test merchant id
& secret key along with a test eSewa Id & password will be provided to the partner merchant to test the
payments through eSewa.
After successful testing phase, the partner merchant will be provided with production environment
merchant id & secret key.
Partner merchants have to modify the eSewa Environment from test to production to use live
environment merchant credentials. Then, partner merchant will be able to start accepting payments using
eSewa SDK.
5
Integration
Prerequisite for Android Applications
It is required for clients to provide eSewa with two email ids. Those emails will be used for creating merchant and
end user in test environment. During this phase, client will use test user credentials to login in eSewa and process
the transaction. Adequate balance will be updated to test user account. SDK will support minimum android version
of 2.3.
Headers: {
Content-Type: application/json
merchantId: {merchant_id}
merchantSecret: {merchant_secret_key}
Request Body:
{
"productId":"productId",
"productName":"productName",
"totalAmount":"10.0",
"environment":"live",
"Code":"00",
"merchantName":"merchantName",
"message": {
"successMessage":"Your transaction has been completed.",
"technicalSuccessMessage":"Your transaction has been completed."
},
6
"transactionDetails": {
"status":"COMPLETE",
"referenceId":"00X3XHG",
"date":"2016-11-17 12:38:18.0"
}
}
Request URI:
Live environment: https://esewa.com.np/mobile/transaction?txnRefId={txnReferenceId}
Test environment: https://ir-user.esewa.com.np/mobile/transaction?txnRefId={txnReferenceId}
Request Method : GET
Headers : {
Content-Type: application/json
merchantId: {merchant_id}
merchantSecret: {merchant_secret_key}
}
In success, the response is the transaction detail for queried reference Id as in appendix C
2. API for transaction verification with product Id & amount:
}
In success, the response is the transaction detail for queried reference Id as in appendix C.
7
In failure, response is as:
"code": 1,
"message": "Transaction not found."
Test merchant ID and merchant secret key and a test eSewa Id with password will be provided to the
partner merchant to complete the transaction.
8
3. Canceled by user
If end user presses Back Button or Cancel button then user is returned to previous mobile application’s
activity and result code RESULT_CANCELED is returned to mobile application.
And if user has sufficient balance initially but balance is expended via other parties before confirming the
payment, message “Transaction could not be completed” is shown to user and message “Insufficient user
balance” which is returned to mobile application as result with result code
EsewaPayment.RESULT_EXTRAS_INVALID.
9
Chapter 3 Appendix
I. Appendix
Appendix A
Code in build.gradle to add SDK
repositories
{ flatDir {
dirs "libs"
}
}
dependencies {
Appendix B
Start with test environment. When application is ready, you can switch it to
live (ENVIRONMENT_PRODUCTION)
10
Create the payment and launch the payment intent on some action done (for example when button
is pressed)
}
});
Where,
Product Price : Price of Product or Service
Product Name : Name of Product or Service
ProductId : Set a unique Id for your particular product or services
Callback-url : API exposed at merchant/client`server where eSewa sends a copy of proof of payment after
successful payment
Implement onActivityResult()
Returns proof of payment in case of successful transaction and reason for failure in case of transaction failure
( In case of ( result == RESULT_CANCEL ) no additional in-formation will be sent on intent and in case of
successful and unsuccessful payment proof of payment and reason of failure are sent respectively to string
value Esewa-Payment.EXTRA_RESULT_MESSAGE).
Sample Code:
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) { super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == RESULT_OK) {
String s = data.getStringExtra(ESewaPayment.EXTRA_RESULT_MESSAGE);
Log.i("Proof of Payment", s);
11
else if (resultCode == RESULT_CANCELED) {
Appendix C
Proof of Payment Sample:
{
"code":"00",
"merchantName":"SDKTESTING ",
"productName":"SomeProductName",
"productId":" SomeProductId",
"totalAmount":"500.0",
"message":{
"successMessage":"Your transaction has been completed.",
"technicalSuccessMessage":" Your transaction has been completed."
},
"transactionDetails":{
"status":"COMPLETE",
"referenceId":"00CPPAT",
"date":"2016-11-23 16:34:44.0"
}
}
12
Chapter 4 FAQ
For Merchants
i. What is eSewa Mobile Payment SDK?
eSewa Mobile payment SDK is the payment gateway for the native android applications. It enables native
android application to easily accept eSewa payments.
ii. What are the items I will get for implementing eSewa mobile payment SDK?
You will be provided with .aar file of eSewa SDK, documentation for integration, test merchant ID and
merchant key and test user ID with password for test transaction.
iii. Can I use same SDK in multiple mobile applications?
No, one merchant Id and key is valid only for one android application. However merchant can get other id
and key from eSewa for integrating in multiple applications.
v. When Merchant servers must do validation with eSewa Server and Why?
In case, eSewa is unable to send proof of payment to client application server or client application server
is unable to receive proof of payment from eSewa then merchant server must validate the payment to
avoid fraud transactions and to ensure your account has actually received the expected payment. If you
don’t verify payments, you open yourself to fraud. Validation request can be sent to eSewa anytime.
vi. What is the settlement mechanism from eSewa to Merchant Bank Account?
On successful transaction the balance from eSewa user is transferred to merchant account and merchant
can withdraw balance to respective bank account in free of cost i.e. without any withdrawal charges.
vii. How eSewa provides support up on receiving any trouble because of eSewa mobile payment SDK?
eSewa provides 24 hours of customer support service . You can contact us in case of any inconvenience.
viii. How merchant can start testing eSewa mobile payment SDK?
Test merchant ID and merchant secret key and a test eSewa Id with password will be provided to the
partner merchant to complete the transaction. Test transaction can be made by setting
EsewaEnvironment to ESewaConfiguration.TEST during setting configuration.
13
ix. What if Merchant server received payment confirmation only from Mobile application?
There may be the possibility of two cases:
a. eSewa Server not being able to send the proof of payment in callback-url or merchant server not
being
b. able to receive the proof of payment.
c. Fraud case
So, the first case must be cross checked for which the merchant server should call eSewa server with the given
product Id and product amount to know if the transaction for the sent id and amount of product/service has been
processed or not (as explained in Chapter 2). If yes, the response is a proof of payment (i.e. transaction detail as
show in appendix C) and if no, “no transaction found” error message is returned which may be the case b so
delivery of product/service must be stopped and one should contact as soon as possible.
x. What are you supposed to do if the payment amount confirmed by eSewa and transaction amount
requested by Mobile application are not equal?
This may be the case of fraud transaction so in this case service/product delivery must be stopped and
one should contact as soon as possible.
xi. Is eSewa SDK mobile platform dependent? Can we implement this on Android and iOS or do we have to take
different SDK for different platform?
eSewa SDK is now available for both native android and iOS applications. If you want to integrate eSewa sdk in
your IOS application as well; then you can consult our merchant team.
xii. What is the time per session to make successful payment?
User must complete login and payment process within 5 minutes or else will have to re-initiation the payment
process from the beginning.
14
For Users
i. Should I have eSewaID and its credential to make payment by eSewa in Mobile application?
Yes users should be registered in eSewa and must have user ID (i.e. eSewa Id) and password for the
completing the transaction.
ii. How can I initiate payment by eSewa in Mobile application if I don’t have eSewaID?
User must register to eSewa using www.esewa.com.np or bye typing REG and send it to 32121 via SMS.
iii. How can I load balance in eSewa for the payments?
User can load balance by transferring balance from our partner banks or by counter deposit directly from
some banks or deposit balance through eSewa Zone/ Point.
iv. Can I ensure that my eSewaID and credential is safe to payment by eSewa in third party Mobile
application?
Your eSewaID and password are safe and secure as it travels in encrypted form and over HTTPS channel.
15
16