1

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);
}
Vidya
  • 11
  • 1
  • 3

2 Answers2

1

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.

Andrea Motto
  • 1,540
  • 21
  • 38
  • im having a same problem can you help me out here is my question https://stackoverflow.com/questions/67874965/unexpected-response-code-403-but-work-fine-in-browser?noredirect=1#comment119974386_67874965 – Tehleel Mir Jun 08 '21 at 01:54
0

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!