Vidya
Vidya

Reputation: 11

Android - com.android.volley.AuthFailureError

I'm developing an Android app where I am trying to use Paygenious api to implement payment gateway. You can refer the link for doc : https://developer.paygenius.co.za/docs/developer.html#code-samples I am using Volley to send HTTP request . I am getting error as “com.android.volley.AuthFailureError” inside onErrorResponse. cannot find a way to resolve this error

Here is trying to use JSONRequest:

    String paymentUrl = "https://developer.paygenius.co.za/pg/api/v2/util/validate";
  try {
      JSONObject paymentObj = new JSONObject();
      paymentObj.put("creditCard",creditCard );
      paymentObj.put("transaction", transactionObj);
      paymentObj.put( "threeDSecure",false);

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

RequestQueue mQueue = Volley.newRequestQueue(context);
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,paymentUrl, paymentObj,
            new Response.Listener<JSONObject>(){
                @Override
                public void onResponse(JSONObject response) {
                    Log.i("VOLLEY", response.toString());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error instanceof AuthFailureError) {
                        Toast.makeText(context, "Auth ERROR: " + error, Toast.LENGTH_SHORT ).show();
                    }
                    else {
                        Toast.makeText(context, "ERROR: " + error, Toast.LENGTH_SHORT ).show();
                        Log.e("TAG", error.getMessage(), error);
                    }
                }
                })

    {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json");
            headers.put("Accept", "application/json");
            headers.put("X-Token", " b3394743-4c5b-496f-a0e6-06580ba12b1e");
            headers.put("X-Signature",” 8e2b0b84da61d92814eabd9e5e06d0178c27fa169c5f58d6478b22f89bf032e5”);
            return headers;
        }

    };
    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(1000, 2, 1));
    mQueue.add(jsonObjectRequest);
}

Upvotes: 1

Views: 12207

Answers (2)

talent makhanya
talent makhanya

Reputation: 29

In my case it was a network error, the url I was trying to reach was not accessible on the network that I was on, when I switched to a different network/connection, it worked!

Upvotes: 0

R3V0LUT10N 909
R3V0LUT10N 909

Reputation: 1560

Try to remove this from headers:

headers.put("Content-Type", "application/json");

Because you're using JsonObjectRequest and Content-Type is already set in JsonRequest.

Upvotes: 1

Related Questions