Version: 2.1.3

Transaction Flow

Initiate a BharatX Transaction#

If the user confirms that they want to use BharatX to pay, your server must make a call to our server to initiate transaction:

Your Server - Request
POST sdk.bharatx.tech/merchant/credit/initiateTransaction
Headers:
X-Signature: base64-encoded sha256(requestBody + privateApiKey)
X-Partnerid: partnerId
Body:
{
"merchantTransactionId": string, // unique
"userPhoneNumber": string,
"userId": string, // user identifier in perspective of you
"amount": number // in paise
}
BharatX Server - Response
Headers:
-
Body:
{
"message": string
}
Status = 201; message = "TRANSACTION_INITIATED"
Status = 400; message = "DUPLICATE_TRANSACTION_ID"
Status = 401; message = "AUTHORIZATION_FAILED"
Status = 400; message = "BAD_REQUEST"
Status = 500; message = "INTERNAL_SERVER_ERROR"

After that, you must also send the transaction ID to our SDK through your app:

Your Android App
// optional - now would be a good time to show the progress dialog
BharatXCommonUtilManager.showBharatXProgressDialog(this);
String transactionId = // from your server
CreditAccessManager.registerTransactionId(activity, transactionId,
new CreditAccessManager.RegisterTransactionListener {
void onRegistered() {
// transaction ID registered successfully
BharatXCommonUtilManager.closeBharatXProgressDialog();
}
void onFailure() {
// registering this transaction failed
BharatXCommonUtilManager.closeBharatXProgressDialog();
}
}
);

Check Status of a BharatX Transaction#

warning

Unless you call the CreditAccessManager.registerTransactionId method from your app, the transaction will never succeed.

If the transaction has not succeeded by 60 seconds, it will fail automatically.

After initiating the transaction, you can check for its status:

Your Server - Request
POST sdk.bharatx.tech/merchant/credit/checkTransactionStatus
Headers:
X-Signature: base64-encoded sha256(requestBody + privateApiKey)
X-Partnerid: partnerId
Body:
{
"merchantTransactionId": string // unique
}
BharatX Server - Response
Headers:
-
Body:
{
"message": string
}
Status = 200; message can be one of ["PENDING", "SUCCESS", "FAILURE"]
Status = 401; message = "AUTHORIZATION_FAILED"
Status = 400; message = "BAD_REQUEST"
Status = 500; message = "INTERNAL_SERVER_ERROR"

Webhook for Status of a BharatX Transaction#

BharatX Server - Request
POST <Your Server Webhook URL>
Headers:
X-Signature: base64-encoded sha256(requestBody + privateApiKey)
Content-Type: application/json
Body:
{
"merchantTransactionId": string,
"status": string // can be one of ["PENDING", "SUCCESS", "FAILURE"]
}
Your Server - Response
Headers:
-
Body:
-
Status = 200: Webhook accepted.
Any other Status: Our servers will try to send the webhook
again and again with increasing time interval.

Refunds#

warning

If amount is not passed, or if amount is passed as 0, the whole order amount would be refunded.

Your Server - Request
POST sdk.bharatx.tech/merchant/credit/refundTransaction
Headers:
X-Signature: base64-encoded sha256(requestBody + privateApiKey)
X-Partnerid: partnerId
Body:
{
"merchantTransactionId": string,
"amount": number // in paise
}
BharatX Server - Response
Headers:
-
Body:
{
"message": string
}
Status = 200; message = "ok"
Status = 400; message = "NO_SUCH_TRANSACTION"
Status = 400; message = "REFUND_AMOUNT_TOO_LARGE"
Status = 400; message = "ALREADY_REFUNDED"
Status = 401; message = "AUTHORIZATION_FAILED"
Status = 500; message = "INTERNAL_SERVER_ERROR"

Discounts#

For the functionality of discounts (one or multiple ones), the following SDK methods need to be integrated:

Your Android App
CreditAccessManager.getDiscountsApplicable(this, amountInPaise,
new CreditAccessManager.OnCompleteListener<ArrayList<Discount>>() {
@Override
void onComplete(ArrayList<Discount> result) {
// ...
}
}
);

Each Discount object has the following structure:

{
"discountId": "",
"amount": 0,
"display": {
"prefixHexTint": "#FFFFFF", // color hex - you won't need this mostly
"prefix": "",
"message": ""
// prefix + message gives the complete message
// prefix is a phrase to capture the user's attention, like FLAT 30 RS OFF
}
}