Skip to content

Instantly share code, notes, and snippets.

@fida1989
Created May 23, 2018 06:44
Show Gist options
  • Save fida1989/b72eb236b8fd75485b8b16d08597c542 to your computer and use it in GitHub Desktop.
Save fida1989/b72eb236b8fd75485b8b16d08597c542 to your computer and use it in GitHub Desktop.
SSLCommerz Android Code
private void doPay() {
int rand = new Random().nextInt();
/*Mandatory Field*/
MandatoryFieldModel mandatoryFieldModel = new MandatoryFieldModel("", "", "200",
"trans_" + rand, CurrencyType.BDT, SdkType.TESTBOX, SdkCategory.BANK_LIST);
/*Call for the payment*/
PayUsingSSLCommerz.getInstance().setData(this, mandatoryFieldModel, new OnPaymentResultListener() {
@Override
public void transactionSuccess(TransactionInfo transactionInfo) {
// If payment is success and risk label is 0.
if (transactionInfo.getRiskLevel().equals("0")) {
Log.d(TAG, "Transaction Successfully completed");
Log.d(TAG, transactionInfo.getTranId());
Log.d(TAG, transactionInfo.getBankTranId());
Log.d(TAG, transactionInfo.getAmount());
Log.d(TAG, transactionInfo.getStoreAmount());
Log.d(TAG, transactionInfo.getTranDate());
Log.d(TAG, transactionInfo.getStatus());
}
// Payment is success but payment is not complete yet. Card on hold now.
else {
Log.d(TAG, "Transaction in risk. Risk Title : " + transactionInfo.getRiskTitle().toString());
}
}
@Override
public void transactionFail(TransactionInfo transactionInfo) {
// Transaction failed
Log.e(TAG, "Transaction Fail");
}
@Override
public void error(int errorCode) {
switch (errorCode) {
// Your provides information is not valid.
case ErrorKeys.USER_INPUT_ERROR:
Log.e(TAG, "User Input Error");
break;
// Internet is not connected.
case ErrorKeys.INTERNET_CONNECTION_ERROR:
Log.e(TAG, "Internet Connection Error");
break;
// Server is not giving valid data.
case ErrorKeys.DATA_PARSING_ERROR:
Log.e(TAG, "Data Parsing Error");
break;
// User press back button or canceled the transaction.
case ErrorKeys.CANCEL_TRANSACTION_ERROR:
Log.e(TAG, "User Cancel The Transaction");
break;
// Server is not responding.
case ErrorKeys.SERVER_ERROR:
Log.e(TAG, "Server Error");
break;
// For some reason network is not responding
case ErrorKeys.NETWORK_ERROR:
Log.e(TAG, "Network Error");
break;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment