Skip to content Skip to sidebar Skip to footer

Android Paytm Payment Gateway Response

I have implemented Paytm payment system and everything is working fine with a web intent on top of my intent, money is deducted from customer's acc and its getting added on my acco

Solution 1:

Hope you have added 'CALLBACK_URL' which is requied to verify the checksum. As mentioned in paytm documentation

CALLBACK_URL - Security parameter to avoid tampering. Generated using server side checksum utility provided by Paytm. Merchant has to ensure that this always gets generated on server. Utilities to generate checksumhash is available here .

Hope this should do the magic.

Solution 2:

I hope you have added this variable to your code -

PaytmPGService service;

If you are using it than you can get all the payment related methods like this :

service.startPaymentTransaction(this, true,
            true, new PaytmPaymentTransactionCallback() {

                @Override
                public void onTransactionResponse(Bundle inResponse) {
                    System.out.println("===== onTransactionResponse " + inResponse.toString());
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        if (Objects.equals(inResponse.getString("STATUS"), "TXN_SUCCESS")) {
                            //    Payment Success
                        } else if (!inResponse.getBoolean("STATUS")) {
                            //    Payment Failed
                        }
                    }
                }

                @Override
                public void networkNotAvailable() {
                    // network error
                }

                @Override
                public void clientAuthenticationFailed(String inErrorMessage) {
                    // AuthenticationFailed
                }

                @Override
                public void someUIErrorOccurred(String inErrorMessage) {
                    // UI Error
                }

                @Override
                public void onErrorLoadingWebPage(int iniErrorCode, String inErrorMessage, String inFailingUrl) {
                    //  Web page loading error
                }

                @Override
                public void onBackPressedCancelTransaction() {
                    // on cancelling transaction
                }

                @Override
                public void onTransactionCancel(String inErrorMessage, Bundle inResponse) {
                    // maybe same as onBackPressedCancelTransaction()
                }
            });

I hope this will help you.

Solution 3:

Change default callbackurl to suppose, 'http://yourdomain (ip address if checking on localhost)/pgResponse.php';. Add following code to pgResponse.php

<?php
        session_start(); 
        header("Pragma: no-cache");
        header("Cache-Control: no-cache");
        header("Expires: 0");



        // following files need to be includedrequire_once("./lib/config_paytm.php");
        require_once("./lib/encdec_paytm.php");

        $paytmChecksum = "";
        $paramList = array();
        $isValidChecksum = "FALSE";

        $paramList = $_POST;
        $return_array= $_POST;
        $checkSum = getChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);//generate new checksum$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : ""; //Sent by Paytm pg//Verify all parameters received from Paytm pg to your application. Like MID received from paytm pg is same as your applicationís MID, TXN_AMOUNT and ORDER_ID are same as what was sent by you to Paytm PG for initiating transaction etc.$isValidChecksum = verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum); //will return TRUE or FALSE string.$return_array["IS_CHECKSUM_VALID"] = $isValidChecksum ? "Y" : "N";
        unset($return_array["CHECKSUMHASH"]);
        $mid = $_POST['MID'];
      $orderid = $_POST['ORDERID']; 


        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'https://securegw-stage.paytm.in/order/status?JsonData={"MID":"'.$mid.'","ORDERID":"'.$orderid.'","CHECKSUMHASH":"'.$checkSum.'"}',
            CURLOPT_USERAGENT => 'Make Request'
        ));

        $resp = curl_exec($curl);
        $status= json_decode($resp)->STATUS;

//do something in your database$encoded_json = htmlentities(json_encode($return_array));



        ?><html><head><metahttp-equiv="Content-Type"content="text/html;charset=ISO-8859-I"><title>Paytm</title><scripttype="text/javascript">functionresponse(){
                            returndocument.getElementById('response').value;
                    }
             </script></head><body>
          Redirecting back to the app.....</br><formname="frm"method="post"><inputtype="hidden"id="response"name="responseField"value='<?phpecho$encoded_json?>'></form></body></html>

In android studio:

publicvoidonTransactionResponse(Bundle inResponse) {
                            Log.d("Create Response", inResponse.toString());

                            String response = inResponse.getString("RESPMSG");
                            if (response.equals("Txn Successful.")) {
                                Toast.makeText(Bag.this,"Payment done",Toast.LENGTH_LONG).show();

                            }
                            else{
                                Toast.makeText(Bag.this,response,Toast.LENGTH_LONG).show();
                            }
                        }

Post a Comment for "Android Paytm Payment Gateway Response"