javapayment-gatewaypaymentpayment-processingneteller

Attempt to get OAuth access token from Neteller produces error: "Server returned HTTP response code: 401 for URL"


I want to set a successful request to Neteller, I am trying to get an access token using the code from the Neteller documentation. However, it consistently fails with with the following exception:

java.io.IOException: Server returned HTTP response code: 401 for URL: https://test.api.neteller.com/v1/oauth2/token?grant_type=client_credentials

Here's the code (again, from the Neteller documentation):

    String testUrl = " https://test.api.neteller.com";
    String secureUrl = "https://api.neteller.com";
    String url = testUrl;
    if("live".equals(configBean.get("environment"))){
        url = secureUrl;
    }
    url += "/v1/oauth2/token?grant_type=client_credentials";
    String xml = "grant_type=client_credentials?grant_type=client_credentials";
    xml = "";
    String test = Base64.encodeBytes((accountID + ":" + secureID).getBytes());
    try { 
        URL urls = new URL ("https://test.api.neteller.com/v1/oauth2/token?grant_type=client_credentials");
        HttpURLConnection connection = (HttpURLConnection) urls.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty  ("Authorization", "Bearer " + test);
        connection.setRequestProperty  ("Content-Type", "application/json");
        connection.setRequestProperty  ("Cache-Control", "no-cache");
        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.flush();
        wr.close();
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        String accessToken = "";
    } catch(Exception e) {
        e.printStackTrace();
    }

Why is my implementation failing here?


Solution

  • There is nothing wrong with your code. The problem is that you are trying use a regular member account for the API integration, where you need to be using a merchant account for that. Below are the steps you will need to complete in order to get it to work:

    1. You need to get a test merchant account (http://www.neteller.com/business/contact-sales/). Registering on www.neteller.com creates a regular member account, which cannot receive payments via the API.
    2. Once you have a test merchant account, you will need to white-list the IP address from which you will be making requests to the API. (pg. 31 of the manual).
    3. Then, you will need to add an application to it (pg. 32 of the manual).
    4. Once you have added the application, use the "client ID" and "client secret" in the Authorization header - just like you do now, base64 encoded values, separated with colon (:).