Implementing authorize.net in android

戏子无情 提交于 2019-12-06 01:36:50

Thanks for your code :) I got new idea form your code to implement authorize.net in android I have no idea what you faced error but when I tried to use post url for integration I faced one error and I have added "x_market_type" in my code and I got the result

 post_values.put ("x_market_type", "2");
I have also integrated Sample code which authorize.net provide, but for my custom requirement your code helps me lot.

If you need any help than post comment. :)

dparnas

Recommend you use the HTTPClient instead as shown in this example How do I make an http request using cookies on Android?

From what I can see in your code:

  1. This section will given an extra & at the end
    while( keys.hasMoreElements() ) {
    String key = URLEncoder.encode(keys.nextElement().toString(),"UTF-8");
    String value = URLEncoder.encode(post_values.get(key).toString(),"UTF-8");
    post_string.append(key + "=" + value + "&");
    

    }

  2. You read only a single line of what has been returned by the server. Even though the content might be placed in one line, the HTTP headers will span several lines
String responseData = rawResponse.readLine();
  1. You use the default user-agent request header which may not be accepted by the server

If you want to try fixing your current code, I recommend you debug it or throw in some log statements (which you can view with for example the aLogCat application)

//Authorize.net android implementation using volley post. this might help you and rashmi thanks for the code and bhavin for the error help

final String txtAmount=totalprice.getText().toString();
        final String txtFName = first_name;
        final String txtLName=last_name;
        final String txtAddress=address_1;
        final String txtCity=city;
        final String txtState=state;
        final String txtzipcode=postcode;
        final String txtEmail=email;
        final String txtCreditCard=CardNumber;
        String txtCVV2=Cvv;

        String drpMonth=Month;
        String drpYear=Year;
        final String date= drpMonth.concat(drpYear);



        String url = Uri.parse("https://test.authorize.net/gateway/transact.dll").buildUpon()
                .build().toString();

        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.e("====", response);
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                        }

                        try {
                            JSONObject jsonObject = new JSONObject(response);



                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("====", error.toString());
                        if (dialog != null && dialog.isShowing()) {
                            dialog.dismiss();
                        }
                    }
                }) {

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> post_values = new HashMap<String, String>();
                post_values.put ("x_login", "8RtP63yV");
                post_values.put ("x_tran_key", "9A4a59AThQh4c6wG");

                post_values.put ("x_version", "3.1");
                post_values.put ("x_delim_data", "TRUE");
                post_values.put ("x_delim_char", "|");
                post_values.put ("x_relay_response", "FALSE");
                post_values.put ("x_market_type", "2");

                post_values.put ("x_type", "AUTH_CAPTURE");
                post_values.put ("x_method", "CC");
                post_values.put ("x_card_num", txtCreditCard);
                post_values.put ("x_exp_date", date);

                post_values.put ("x_amount", txtAmount);
                post_values.put ("x_description", "Sample Transaction");

                post_values.put ("x_first_name",txtFName);
                post_values.put ("x_last_name",txtLName);
                post_values.put ("x_address", txtAddress);
                post_values.put ("x_city", txtCity);
                post_values.put ("x_state",txtState);
                post_values.put ("x_zip", txtzipcode);
                post_values.put ("x_email", txtEmail);
                return post_values;
            }
        };

        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!