Solution 1 :
this is happening due to your server maybe you forget to return the response there is no problem from Paytm SDK it fires callback during transaction happened …
use callback URL Post Request “https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=”
create own callback URL from server request this url
within your server
try to check it from you server side it will fix
Solution 2 :
You should integrate the new SDK offering All-in-One SDK given on their developer page. Refer to the integration for the same.
Solution 3 :
Add Paytm All in One SDK dependency in Project-level Gradle file: -
allprojects {
repositories {
google()
jcenter()
maven {
url "https://artifactory.paytm.in/libs-release-local"
}
}
}
Now add another dependency in the module level Gradle file.
implementation ‘com.paytm.appinvokesdk:appinvokesdk:1.2’
MainActivity :
public class MainActivity extends AppCompatActivity {
private String TAG ="MainActivity";
private ProgressBar progressBar;
private EditText txnAmount;
private String midString ="Your Production mode MID here", txnAmountString="", orderIdString="", txnTokenString="";
private Button btnPayNow;
private Integer ActivityRequestCode = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
btnPayNow = (Button) findViewById(R.id.txnProcessBtn);
txnAmount = (EditText) findViewById(R.id.txnAmountId);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("ddMMyyyy");
String date = df.format(c.getTime());
Random rand = new Random();
int min =1000, max= 9999;
// nextInt as provided by Random is exclusive of the top value so you need to add 1
int randomNum = rand.nextInt((max - min) + 1) + min;
orderIdString = date+String.valueOf(randomNum);
btnPayNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txnAmountString = txnAmount.getText().toString();
String errors = "";
if(orderIdString.equalsIgnoreCase("")){
errors ="Enter valid Order ID heren";
Toast.makeText(MainActivity.this, errors, Toast.LENGTH_SHORT).show();
}else
if(txnAmountString.equalsIgnoreCase("")){
errors ="Enter valid Amount heren";
Toast.makeText(MainActivity.this, errors, Toast.LENGTH_SHORT).show();
}else{
getToken();
}
}
});
}
private void getToken(){
Log.e(TAG, " get token start");
progressBar.setVisibility(View.VISIBLE);
ServiceWrapper serviceWrapper = new ServiceWrapper(null);
Call<Token_Res> call = serviceWrapper.getTokenCall("12345", midString, orderIdString, txnAmountString);
call.enqueue(new Callback<Token_Res>() {
@Override
public void onResponse(Call<Token_Res> call, Response<Token_Res> response) {
Log.e(TAG, " respo "+ response.isSuccessful() );
progressBar.setVisibility(View.GONE);
try {
if (response.isSuccessful() && response.body()!=null){
if (response.body().getBody().getTxnToken()!="") {
Log.e(TAG, " transaction token : "+response.body().getBody().getTxnToken());
startPaytmPayment(response.body().getBody().getTxnToken());
}else {
Log.e(TAG, " Token status false");
}
}
}catch (Exception e){
Log.e(TAG, " error in Token Res "+e.toString());
}
}
@Override
public void onFailure(Call<Token_Res> call, Throwable t) {
progressBar.setVisibility(View.GONE);
Log.e(TAG, " response error "+t.toString());
}
});
}
public void startPaytmPayment (String token){
txnTokenString = token;
// for test mode use it
// String host = "https://securegw-stage.paytm.in/";
// for production mode use it
String host = "https://securegw.paytm.in/";
String orderDetails = "MID: " + midString + ", OrderId: " + orderIdString + ", TxnToken: " + txnTokenString
+ ", Amount: " + txnAmountString;
//Log.e(TAG, "order details "+ orderDetails);
String callBackUrl = host + "theia/paytmCallback?ORDER_ID="+orderIdString;
Log.e(TAG, " callback URL "+callBackUrl);
PaytmOrder paytmOrder = new PaytmOrder(orderIdString, midString, txnTokenString, txnAmountString, callBackUrl);
TransactionManager transactionManager = new TransactionManager(paytmOrder, new PaytmPaymentTransactionCallback(){
@Override
public void onTransactionResponse(Bundle bundle) {
Log.e(TAG, "Response (onTransactionResponse) : "+bundle.toString());
}
@Override
public void networkNotAvailable() {
Log.e(TAG, "network not available ");
}
@Override
public void onErrorProceed(String s) {
Log.e(TAG, " onErrorProcess "+s.toString());
}
@Override
public void clientAuthenticationFailed(String s) {
Log.e(TAG, "Clientauth "+s);
}
@Override
public void someUIErrorOccurred(String s) {
Log.e(TAG, " UI error "+s);
}
@Override
public void onErrorLoadingWebPage(int i, String s, String s1) {
Log.e(TAG, " error loading web "+s+"--"+s1);
}
@Override
public void onBackPressedCancelTransaction() {
Log.e(TAG, "backPress ");
}
@Override
public void onTransactionCancel(String s, Bundle bundle) {
Log.e(TAG, " transaction cancel "+s);
}
});
transactionManager.setShowPaymentUrl(host + "theia/api/v1/showPaymentPage");
transactionManager.startTransaction(this, ActivityRequestCode);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(TAG ," result code "+resultCode);
// -1 means successful // 0 means failed
// one error is - nativeSdkForMerchantMessage : networkError
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ActivityRequestCode && data != null) {
Bundle bundle = data.getExtras();
if (bundle != null) {
for (String key : bundle.keySet()) {
Log.e(TAG, key + " : " + (bundle.get(key) != null ? bundle.get(key) :"NULL"));
}
}
Log.e(TAG, " data "+ data.getStringExtra("nativeSdkForMerchantMessage"));
Log.e(TAG, " data response - "+data.getStringExtra("response"));
/*
data response - {"BANKNAME":"WALLET","BANKTXNID":"1394221115",
"CHECKSUMHASH":"7jRCFIk6eRmrep+IhnmQrlrL43KSCSXrmM+VHP5pH0ekXaaxjt3MEgd1N9mLtWyu4VwpWexHOILCTAhybOo5EVDmAEV33rg2VAS/p0PXdku003d",
"CURRENCY":"INR","GATEWAYNAME":"WALLET","MID":"EAcP3138556","ORDERID":"100620202152",
"PAYMENTMODE":"PPI","RESPCODE":"01","RESPMSG":"Txn Success","STATUS":"TXN_SUCCESS",
"TXNAMOUNT":"2.00","TXNDATE":"2020-06-10 16:57:45.0","TXNID":"2020061011121280011018328631290118"}
*/
Toast.makeText(this, data.getStringExtra("nativeSdkForMerchantMessage")
+ data.getStringExtra("response"), Toast.LENGTH_SHORT).show();
}else{
Log.e(TAG, " payment failed");
}
}
}
Problem :
I am trying to implement Paytm gateway according to this link “https://developer.paytm.com/docs/v1/android-sdk/” but in app webview opens and I am getting stuck at Paytms Processing page. below is the demo code I am using to try it. please help because Paytm is not helping. I am not missing any parameter because if I remove/change any parameter it shows an error at particular parameter.
first, I am creating an order id on the server then checksum then call Paytm service.
the same thing using the same checksum is working on PC browser but not on android.
public class MainActivity extends AppCompatActivity {
APIinterface apiInterface;
String order_id,paytmschecksum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_SMS, Manifest.permission.RECEIVE_SMS}, 101);
}
get_orderid();
}
public void get_orderid(){
apiInterface = APIClient.getClient().create(APIinterface.class);
Call<List<OrderID_response>> call = apiInterface.get_orderid("1","rxazcv89315285244163");
call.enqueue(new Callback<List<OrderID_response>>() {
@Override
public void onResponse(Call<List<OrderID_response>> call, Response<List<OrderID_response>> response) {
// Toast.makeText(LocationUpdateService.this, response.toString(), Toast.LENGTH_SHORT).show();
List<OrderID_response> details = response.body();
if(details!=null){
if(details.get(0).getResponse().equalsIgnoreCase("success")){
order_id = details.get(0).getUnique_id();
Log.d("Order Id :", order_id );
get_paytmchecksum();
}
}
}
@Override
public void onFailure(Call<List<OrderID_response>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failure:" +t, Toast.LENGTH_SHORT).show();
Log.d(TAG, "onFailure: "+t.toString());
}
});
}
// Checksum for paytm
public void get_paytmchecksum(){
apiInterface = APIClient.getClient().create(APIinterface.class);
Call<List<paytm_checksum_model>> call = apiInterface.get_paytmchecksum_temp("[email protected]","7777777777","1",order_id,"100.00"); //100 is recharge amount change it after testing
call.enqueue(new Callback<List<paytm_checksum_model>>() {
@Override
public void onResponse(Call<List<paytm_checksum_model>> call, Response<List<paytm_checksum_model>> response) {
// Toast.makeText(LocationUpdateService.this, response.toString(), Toast.LENGTH_SHORT).show();
List<paytm_checksum_model> details = response.body();
if(details!=null){
paytmschecksum = details.get(0).getCheckSum();
Log.d("Checksum : ", paytmschecksum );
paytm();
}
}
@Override
public void onFailure(Call<List<paytm_checksum_model>> call, Throwable t) {
Toast.makeText(MainActivity.this, "Failure:" +t, Toast.LENGTH_SHORT).show();
Log.d(TAG, "onFailure: "+t.toString());
}
});
}
public void paytm(){
PaytmPGService Service = PaytmPGService.getStagingService("https://securegw-stage.paytm.in/order/process");
HashMap paramMap = new HashMap<>();
paramMap.put( "MID" , "rxazcv89315285244163"); //My mid will be here.
// Key in your staging and production MID available in your dashboard
paramMap.put( "ORDER_ID" , order_id);
paramMap.put( "CUST_ID" , "1");
// paramMap.put( "MOBILE_NO" , "7777777777");
// paramMap.put( "EMAIL" , "[email protected]");
paramMap.put( "CHANNEL_ID" , "WEB");
paramMap.put( "TXN_AMOUNT" , "100.00");
paramMap.put( "WEBSITE" , "WEBSTAGING");
// This is the staging value. Production value is available in your dashboard
paramMap.put( "INDUSTRY_TYPE_ID" , "Retail");
// This is the staging value. Production value is available in your dashboard
paramMap.put( "CALLBACK_URL", "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp");
paramMap.put( "CHECKSUMHASH" , paytmschecksum);
PaytmOrder Order = new PaytmOrder(paramMap);
Service.initialize(Order, null);
Service.startPaymentTransaction(MainActivity.this, true, true, new PaytmPaymentTransactionCallback() {
public void someUIErrorOccurred(String inErrorMessage) {}
public void networkNotAvailable() {
Toast.makeText(MainActivity.this, "Network connection error: Check your internet connectivity", Toast.LENGTH_LONG).show();
}
public void clientAuthenticationFailed(String inErrorMessage) {
Toast.makeText(MainActivity.this, "Authentication failed: Server error" + inErrorMessage.toString(), Toast.LENGTH_LONG).show();
}
public void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingUrl) {
Toast.makeText(MainActivity.this, "Unable to load webpage " + inErrorMessage.toString(), Toast.LENGTH_LONG).show();
}
public void onBackPressedCancelTransaction() {}
public void onTransactionCancel(String inErrorMessage, Bundle inResponse) {}
public void onTransactionResponse(Bundle inResponse) {
Toast.makeText(MainActivity.this, "Payment Transaction response " + inResponse.toString(), Toast.LENGTH_LONG).show();
}
});
}
}