Skip to content

Error 500 using Java #2

@Chokrii

Description

@Chokrii

Hello Team,
please i'm using this doc http://docs.icepay.com for getpaymentmethods it work well but the other function i'm always getting error 500 (by the way i'm using java not C# as i can;t find any topic related to java this is why i'm posting here)

this is my function curl for vaultcheckout example

`
public String Curl(String uurl,String merchantid) throws Exception
{
URL url;
HttpURLConnection connection = null;
//Create connection
url = new URL(uurl);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept",
"application/json");
connection.setRequestProperty("MerchantID", merchantid);

      connection.setUseCaches (false);
      connection.setDoInput(true);
      connection.setDoOutput(true);

      JSONObject j = new JSONObject();
		j.put("Timestamp", Constant.TimeStp());
		j.put("Amount ", "100");
		j.put("Country ", "GB");
		j.put("Currency", "GBP");
		j.put("URLPostback", "http://bixipay.co.uk");
		j.put("Description", "Bill #12222");
		j.put("Issuer", "VISA");
		j.put("Language", "EN");
		j.put("OrderID ", "9541");
		j.put("PaymentMethod", "creditcard");
		j.put("Reference", "12222");
		j.put("URLCompleted", "http://bixipay.co.uk");
		j.put("URLError", "http://bixipay.co.uk");
		j.put("EndUserIP ", "84.241.211.47");
		j.put("ConsumerID", "1524");
      String base = uurl+"/POST"+merchantid+apikey+j.toString();
      System.out.println(base);
      String hex = Constant.sha256(base);
      
      connection.setRequestProperty("Checksum", hex);
      //Send request
      DataOutputStream wr = new DataOutputStream (
                  connection.getOutputStream ());
      
      wr.writeBytes (j.toString());
      wr.flush ();
      wr.close ();

      //Get Response	
      InputStream is = connection.getInputStream();
      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
      String line;
      StringBuffer response = new StringBuffer(); 
      while((line = rd.readLine()) != null) {
        response.append(line);
        response.append('\r');
      }
      rd.close();
      JSONObject resp = new JSONObject(response.toString());
      System.out.println(connection.getResponseCode() +response.toString());
      return response.toString();
	
}

`

and this is to calculate sha-256 and timestamp
`
public class Constant {

public static String TimeStp()
{
	Date now = new Date();
	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss");
	System.out.println(formatter.format(now));
	return formatter.format(now) ;
}

public static String sha256(String base) 
{
    try{
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hash = digest.digest(base.getBytes("UTF-8"));
        StringBuffer hexString = new StringBuffer();

        for (int i = 0; i < hash.length; i++) {
            String hex = Integer.toHexString(0xff & hash[i]);
            if(hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    } catch(Exception ex){
       throw new RuntimeException(ex);
    }
}

}
`

any help please

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions