web-dev-qa-db-ja.com

Paytm PGSDK_V2.0を統合するAndroid

AndroidアプリでPaytm PGSDK_V2.0を統合しています。 Github に関するすべてのドキュメントを読みました。すべてを理解しましたが、問題は以前のSDKにありますここで、Paytm Merchantオブジェクトを使用してチェックサムを簡単に生成できます。

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

これをこのようにServiceに入れます

 Service.initialize(Order,merchant,null);

しかし、新しいSDKでは次のように変わります

 Service.initialize(Order,null);

新しいSDKでチェックサムを生成する方法を教えてください

12
Mayank Garg

Paytmには、セキュリティを強化するための変更プロセスがあります。 PGSDK_V2.0では、まずサーバー側でapi Checksum Generationを呼び出して生成する必要があります。

 @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;
        }

CHECKSUMonPostExecute文字列を取得した後、paytm Serviceオブジェクトを初期化し、次のような処理を行います。

  @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クラス

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;
    }
}

とパラメータ値は両方とも同じでなければなりません。

12

チェックサムの生成は非常に簡単です。

  • GithubからPaytmアプリチェックサムキットを入手してください。
  • ダウンロードしたキットを抽出してサーバーに配置します。 xamppを使用するローカルサーバーを使用している場合、パスはc:/ xampp/htdocs/paytmになります。フォルダー名をpaytmまたは小さな名前に変更することをお勧めします。
  • キット内にはlibという名前のフォルダーがあります。このフォルダ内にconfig_paytm.phpという名前のファイルがあります。このファイルを開き、Paytmマーチャントキーをここに配置します。
  • これで、ファイルgenerateChecksum.phpを使用してチェックサムを生成できます。
  • トランザクションで渡すすべてのパラメーターを渡す必要があることに注意してください。
  • 以下は、POSTリクエストをgenerateChecksum.phpに送信するための改良APIコードサンプルです。

    //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は常に一意である必要があります。

出典:Paytm Integration in Android Example

4
Belal Khan

SDK 2.0以降からのチェックサム生成では、8つのパラメーターのみを渡す必要があります。以前のバージョンでは、メールと携帯電話番号も渡す必要があります。現在、これらのパラメーターは使用されていません。最初に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" , "[email protected]");   // 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  );
0
Kamal Bunkar