12

我正在集成Paytm PGSDK_V2.0到我的 android 应用程序中。我已阅读Github上的所有文档。我已经了解一切。但问题出在其早期的 SDK 中,我们可以简单地使用Paytm Merchant对象生成校验和,例如:

PaytmMerchant merchant=new PaytmMerchant("Checksum generation url","Checksum verification url");  

并将其放入服务中

 Service.initialize(Order,merchant,null);

但在新的 SDK 中它变为

 Service.initialize(Order,null);

所以请帮助我如何在新的 SDK 中生成校验和

4

4 回答 4

12

Paytm has change process to increase the security. now in PGSDK_V2.0 first you have to generate through calling the api Checksum Generation on your server side Like this:

 @Override
        protected String doInBackground(String... params) {
            url ="http://xxx.co.in/generateChecksum.php";
            JSONParser jsonParser = new JSONParser(MainActivity.this);

                param="ORDER_ID=" + orderId+
                        "&MID="+YourMID+
                        "&CUST_ID="+custId+
                        "&CHANNEL_ID=WAP&INDUSTRY_TYPE_ID=Retail110&WEBSITE=xxxwap&TXN_AMOUNT="+billAmt+"&CALLBACK_URL=http://xxx.co.in/verifyChecksum.php";

            JSONObject jsonObject = jsonParser.makeHttpRequest(url,"POST",param);
            Log.e("CheckSum result >>",jsonObject.toString());
            if(jsonObject != null){
                Log.d("CheckSum result >>",jsonObject.toString());
                try {

                    CHECKSUMHASH=jsonObject.has("CHECKSUMHASH")?jsonObject.getString("CHECKSUMHASH"):"";
                    Log.e("CheckSum result >>",CHECKSUMHASH);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

now after getting CHECKSUM string in your onPostExecute initialize paytm Service object and do further process Like This:

  @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            progressDialog.hide();
            Service = PaytmPGService.getProductionService();

    /*PaytmMerchant constructor takes two parameters
    1) Checksum generation url
    2) Checksum verification url
    Merchant should replace the below values with his values*/




            //below parameter map is required to construct PaytmOrder object, Merchant should replace below map values with his own values

            Map<String, String> paramMap = new HashMap<String, String>();

            //these are mandatory parameters


            paramMap.put("ORDER_ID", orderId);
            //MID provided by paytm

            paramMap.put("MID", yourMID);
            paramMap.put("CUST_ID", custId);
            paramMap.put("CHANNEL_ID", "WAP");
            paramMap.put("INDUSTRY_TYPE_ID", "Retail");
            paramMap.put("WEBSITE", "xxxwap");
            paramMap.put("TXN_AMOUNT",billAmt);
            // 
            paramMap.put("CALLBACK_URL" ,"http://xxx.co.in/verifyChecksum.php");
            paramMap.put("CHECKSUMHASH" ,CHECKSUMHASH);
            PaytmOrder Order = new PaytmOrder(paramMap);



            Service.initialize(Order,null);
            Service.startPaymentTransaction(ReviewBooking.this, true, true, new PaytmPaymentTransactionCallback() {
                @Override
                public void someUIErrorOccurred(String inErrorMessage) {
                    // Some UI Error Occurred in Payment Gateway Activity.
                    // // This may be due to initialization of views in
                    // Payment Gateway Activity or may be due to //
                    // initialization of webview. // Error Message details
                    // the error occurred.
                }

                @Override
                public void onTransactionResponse(Bundle inResponse) {
                    Log.d("LOG", "Payment Transaction : " + inResponse);
                    String response=inResponse.getString("RESPMSG");
                    if (response.equals("Txn Successful."))
                    {
                        new ConfirmMerchent().execute();
                    }else
                    {
                        Toast.makeText(getApplicationContext(),response,Toast.LENGTH_SHORT).show();
                    }
                    Toast.makeText(getApplicationContext(), "Payment Transaction response "+inResponse.toString(), Toast.LENGTH_LONG).show();
                }


                @Override
                public void networkNotAvailable() {
                    // If network is not
                    // available, then this
                    // method gets called.
                }

                @Override
                public void clientAuthenticationFailed(String inErrorMessage) {
                    // This method gets called if client authentication
                    // failed. // Failure may be due to following reasons //
                    // 1. Server error or downtime. // 2. Server unable to
                    // generate checksum or checksum response is not in
                    // proper format. // 3. Server failed to authenticate
                    // that client. That is value of payt_STATUS is 2. //
                    // Error Message describes the reason for failure.
                }

                @Override
                public void onErrorLoadingWebPage(int iniErrorCode,
                                                  String inErrorMessage, String inFailingUrl) {

                }

                // had to be added: NOTE
                @Override
                public void onBackPressedCancelTransaction() {
                    // TODO Auto-generated method stub
                }

                @Override
                public void onTransactionCancel(String inErrorMessage, Bundle inResponse) {
                    Log.d("LOG", "Payment Transaction Failed " + inErrorMessage);
                    Toast.makeText(getBaseContext(), "Payment Transaction Failed ", Toast.LENGTH_LONG).show();
                }
            });
        }

JsonParser Class

public class JSONParser {
    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    HttpURLConnection urlConnection = null;
    // variable to hold context
    private Context context;
    // constructor
    public JSONParser(Context context){
        this.context=context;
    }


    public JSONObject makeHttpRequest(String url,String method,String params) {

       // boolean isReachable =Config.isURLReachable(context);
        // Making HTTP request
        try {
            String retSrc="";
            char current = '0';

                URL url1 = new URL(url);
                // check for request method
                HttpURLConnection urlConnection = (HttpURLConnection) url1.openConnection();
            if (method == "POST") {
                // request method is POST
               urlConnection.setDoOutput(true);
                urlConnection.setRequestMethod("POST");
                urlConnection.setFixedLengthStreamingMode(params.getBytes().length);
                urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
                out.print(params);
                out.close();
            }
                InputStream in = urlConnection.getInputStream();

                InputStreamReader isw = new InputStreamReader(in);

                byte[] bytes = new byte[10000];
                StringBuilder x = new StringBuilder();
                int numRead = 0;
                while ((numRead = in.read(bytes)) >= 0) {
                    x.append(new String(bytes, 0, numRead));
                }
                retSrc=x.toString();



            jObj = new JSONObject(retSrc);
            } catch (Exception e) {
            e.printStackTrace();
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(context, "Connectivity issue. Please try again later.", Toast.LENGTH_LONG).show();
                }
            });
            return null;
        }finally {
                if (urlConnection != null) {
                    urlConnection.disconnect();
                }
            }
        return jObj;
    }
}

and parameter values should be same both time.

于 2017-04-17T05:49:43.953 回答
4

生成校验和非常容易。

  • 只需从 Github 获取 Paytm App Checksum Kit。
  • 提取下载的套件并将其放入您的服务器。如果您使用的是使用 xampp 的本地服务器,那么路径将是 c:/xampp/htdocs/paytm。我建议将文件夹名称重命名为 paytm 或小名称。
  • 在套件中有一个名为 lib 的文件夹。在此文件夹中,您将找到一个名为config_paytm.php的文件,打开此文件并将您的 Paytm 商家密钥放在这里。
  • 现在您可以使用文件 generateChecksum.php 来生成校验和。
  • 请记住,您需要传递将与事务一起传递的每个参数。
  • 下面你可以看到一个改造 api 代码示例,用于将 POST 请求发送到generateChecksum.php

    //this is the URL of the paytm folder that we added in the server
    //make sure you are using your ip else it will not work 
    String BASE_URL = "http://192.168.101.1/paytm/";
    
    @FormUrlEncoded
    @POST("generateChecksum.php")
    Call<Checksum> getChecksum(
            @Field("MID") String mId,
            @Field("ORDER_ID") String orderId,
            @Field("CUST_ID") String custId,
            @Field("CHANNEL_ID") String channelId,
            @Field("TXN_AMOUNT") String txnAmount,
            @Field("WEBSITE") String website,
            @Field("CALLBACK_URL") String callbackUrl,
            @Field("INDUSTRY_TYPE_ID") String industryTypeId
    );
    

这部分非常重要,您必须发送所有参数。并且 order_id 每次都应该是唯一的。

来源:Android 示例中的 Paytm 集成

于 2018-01-11T11:35:44.313 回答
0

您只需传递 8 个参数即可从 SDK 2.0 及更高版本生成校验和。在早期版本中,您还需要传递电子邮件和手机号码。现在没有使用这些参数。首先在您的服务器上上传 PHP 文件并更改 lib 文件夹内 config.php 文件中的商家密钥。现在从 android 使用可以使用改造或凌空或 httpconnection 请求从您的服务器获取校验和。这里我使用 Httpconnection(在这段代码中 JSONParse 是一个单独的 java 类来调用 httpconnection)。您可以在此链接上获得参考 - http://www.blueappsoftware.in/android/blog/paytm-integration-sdk-2-1-android/

public class sendUserDetailTOServerdd extends AsyncTask<ArrayList<String>, Void, String> {

    private ProgressDialog dialog = new ProgressDialog(checksum.this);

    private String orderId , mid, custid, amt;
    String url ="http://www.blueappsoftware.com/payment/payment_paytm/generateChecksum.php";
    String varifyurl = // "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=<ORDER_ID>"; //
                         "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp";//
    String CHECKSUMHASH ="";

            @Override
    protected void onPreExecute() {
        this.dialog.setMessage("Please wait");
        this.dialog.show();

       // initOrderId();
        orderId ="KK100343";  // NOTE :  order id must be unique
        mid = "blueap01867059473586";  // CREATI42545355156573
        custid = "KKCUST0342";

    }

    protected String doInBackground(ArrayList<String>... alldata) {

        // String  url ="http://xxx.co.in/generateChecksum.php";

        JSONParser jsonParser = new JSONParser(checksum.this);
        String  param=
                "MID="+mid+
                "&ORDER_ID=" + orderId+
                "&CUST_ID="+custid+
                "&CHANNEL_ID=WEB&TXN_AMOUNT=100&WEBSITE=www.blueappsoftware.in"+"&CALLBACK_URL="+ varifyurl+"&INDUSTRY_TYPE_ID=Retail";

        Log.e("checksum"," param string "+param );



        JSONObject jsonObject = jsonParser.makeHttpRequest(url,"POST",param);
        // yaha per checksum ke saht order id or status receive hoga..
        Log.e("CheckSum result >>",jsonObject.toString());
        if(jsonObject != null){
            Log.e("CheckSum result >>",jsonObject.toString());
            try {

                CHECKSUMHASH=jsonObject.has("CHECKSUMHASH")?jsonObject.getString("CHECKSUMHASH"):"";
                Log.e("CheckSum result >>",CHECKSUMHASH);

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return CHECKSUMHASH;
    }

    @Override
    protected void onPostExecute(String result) {
        // jab run kroge to yaha checksum dekhega
        ///ab service ko call krna hai
        Log.e(" setup acc ","  signup result  " + result);
        if (dialog.isShowing()) {
            dialog.dismiss();
        }}

第 2 步)现在 onPostExceute 方法你有校验和作为结果。是时候调用 paytm 暂存服务并调用开始交易了。下面是调用paytm服务的代码

 PaytmPGService Service =PaytmPGService.getStagingService();
       // when app is ready to publish use production service
        // PaytmPGService  Service = PaytmPGService.getProductionService();

        // now call paytm service here
        //below parameter map is required to construct PaytmOrder object, Merchant should replace below map values with his own values
        Map<String, String> paramMap = new HashMap<String, String>();
        //these are mandatory parameters
        // ye sari valeu same hon achaiye

        //MID provided by paytm
        paramMap.put("MID", mid);
        paramMap.put("ORDER_ID", orderId);
        paramMap.put("CUST_ID", custid);
        paramMap.put("CHANNEL_ID", "WEB");
        paramMap.put("TXN_AMOUNT", "100");
        paramMap.put("WEBSITE", "www.blueappsoftware.in");
        paramMap.put("CALLBACK_URL" ,varifyurl);
        //paramMap.put( "EMAIL" , "abc@gmail.com");   // no need
       // paramMap.put( "MOBILE_NO" , "9144040888");  // no need
        paramMap.put("CHECKSUMHASH" ,CHECKSUMHASH);
        //paramMap.put("PAYMENT_TYPE_ID" ,"CC");    // no need
        paramMap.put("INDUSTRY_TYPE_ID", "Retail");

        PaytmOrder Order = new PaytmOrder(paramMap);

        Log.e("checksum ", paramMap.toString());


        Service.initialize(Order,null);
        // start payment service call here
        Service.startPaymentTransaction(checksum.this, true, true, checksum.this  );
于 2018-02-09T08:42:00.570 回答
-1

什么是新的 ConfirmMerchent().execute(); 并在商家验证后的文档中再次检查此 uri 以进行付款确认 https://secure.paytm.in/oltp/HANDLER_INTERNAL/TXNSTATUS

于 2017-04-24T14:43:16.790 回答