cancel
Showing results for 
Search instead for 
Did you mean: 

Trasaction not being Processed.

I am getting an issue as  

You are not authorized to view this page. The transaction has not been processed.

If the problem persists please report your problem and quote the following Error Reference Number:

E-43CB2AAA59404F2C9D5212E736B92C84

Here is my code 

package nimbRestWebService;

 

import java.nio.charset.StandardCharsets;

import java.text.SimpleDateFormat;

import java.util.*;

import javax.crypto.Mac;

import javax.crypto.spec.SecretKeySpec;

import java.nio.file.Files;

import java.nio.file.Paths;

import java.util.Base64;

 

public class CyberSourcePayment {

 

private static final String CYBERSOURCE_URL = "https://testsecureacceptance.cybersource.com/pay";

private static final String ACCESS_KEY = "714a6c495ec13d40a6245a01e9621ae9";

private static final String PROFILE_ID = "DF5DB6E1-9725-493D-ABBC-FC34F027391C";

private static final String SECRET_KEY = "7f0657d984b94508b5bf8bf2ece7211632aa317fdfef4148a87369ea565045b06019800d081b430bb5cb1e27638ff898afc311d42fcf4fd08cb12a67aabb35707c951ede0fe146a7accda64a726a11351770fd0478b84264ba585b0d2656366ec0bac67ca517419ea8dcf9f351ae7e06ad268b29f4e84527be5186d1d6f560f3";

 

public static String generatePaymentForm() throws Exception {

Map<String, String> params = new TreeMap<>();

 

params.put("access_key", ACCESS_KEY);

params.put("profile_id", PROFILE_ID);

params.put("transaction_uuid", UUID.randomUUID().toString());

params.put("signed_date_time", getUTCDateTime());

params.put("transaction_type", "sale");

params.put("amount", "100.95");

params.put("currency", "USD");

params.put("reference_number", "1730560013735542024294683");

params.put("locale", "en");

// params.put("payment_method", "card");

params.put("unsigned_field_names", "");

 

/*

* params.put("bill_to_forename", "John"); params.put("bill_to_surname", "Doe");

* params.put("bill_to_address_line1", "123 Main St");

* params.put("bill_to_address_city", "New York");

* params.put("bill_to_address_country", "US"); params.put("bill_to_email",

* "john.doe@example.com"); params.put("bill_to_phone", "1234567890");

* params.put("bill_to_address_postal_code", "10001");

* params.put("bill_to_address_state", "NY");

*/

 

String signedFieldNames = String.join(",", params.keySet());

params.put("signed_field_names", signedFieldNames);

 

String signature = generateSignature(params, SECRET_KEY);

params.put("signature", signature);

 

StringBuilder form = new StringBuilder();

form.append("<html><body onload='document.forms[\"paymentForm\"].submit();'>")

.append("<form name='paymentForm' method='POST' action='").append(CYBERSOURCE_URL).append("'>");

 

for (Map.Entry<String, String> entry : params.entrySet()) {

form.append("<input type='hidden' name='").append(entry.getKey())

.append("' value='").append(entry.getValue()).append("'/>");

}

 

form.append("<noscript><input type='submit' value='Click here to proceed to payment'/></noscript>")

.append("</form></body></html>");

 

return form.toString();

}

 

private static String getUTCDateTime() {

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

return simpleDateFormat.format(new Date());

}

 

private static String generateSignature(Map<String, String> params, String secretKey) throws Exception {

StringBuilder data = new StringBuilder();

 

for (String field : params.get("signed_field_names").split(",")) {

data.append(field).append("=").append(params.get(field)).append(",");

}

 

if (data.length() > 0) {

data.setLength(data.length() - 1);

}

 

byte[] decodedKey = hexStringToByteArray(secretKey);

SecretKeySpec secretKeySpec = new SecretKeySpec(decodedKey, "HmacSHA256");

 

Mac mac = Mac.getInstance("HmacSHA256");

mac.init(secretKeySpec);

byte[] rawHmac = mac.doFinal(data.toString().getBytes(StandardCharsets.UTF_8));

 

return Base64.getEncoder().encodeToString(rawHmac);

}

 

private static byte[] hexStringToByteArray(String hex) {

int length = hex.length();

byte[] data = new byte[length / 2];

for (int i = 0; i < length; i += 2) {

data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)

+ Character.digit(hex.charAt(i + 1), 16));

}

return data;

}

 

public static void main(String[] args) {

try {

 

String paymentForm = generatePaymentForm();

 

Files.write(Paths.get("payment.html"), paymentForm.getBytes());

System.out.println("Payment form saved as payment.html. Opening in browser...");

 

java.awt.Desktop.getDesktop().browse(Paths.get("payment.html").toUri());

} catch (Exception e) {

e.printStackTrace();

}

}

}

Can anyone help me out to solved this problem immediately ?

BIBHAV12
New Member
0 REPLIES 0