Hi,
I am new to AIM integration with Java & Jsp page. I have following code used to get the form token for AIM Accept Host Payment transaction. I am getting the null response only. Can you please suggest me on it. How to get the form token from Java classs.
Java File
private ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
SettingType setting1 = new SettingType();
setting1.setSettingName("hostedPaymentButtonOptions");
setting1.setSettingValue("{\"text\": \"Pay\"}");
SettingType setting2 = new SettingType();
setting2.setSettingName("hostedPaymentOrderOptions");
setting2.setSettingValue("{\"show\": false}");
SettingType setting3 = new SettingType();
setting3.setSettingName("hostedPaymentReturnOptions");
setting3.setSettingValue("{\"showReceipt\" : false, \"url\":\"http://localhost:8080/xxx/thankyou.jsp\", \"urlText\": \"Continue\", \"cancelUrl\": \"http://localhost:8080/xxx/order_now.jsp\", \"cancelUrlText\": \"Cancel\"}");
ArrayOfSetting alist = new ArrayOfSetting();
alist.getSetting().add(setting1);
alist.getSetting().add(setting2);
alist.getSetting().add(setting3);
GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
apiRequest.setTransactionRequest(txnRequest);
apiRequest.setHostedPaymentSettings(alist);
GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
controller.execute();
GetHostedPaymentPageResponse response = new GetHostedPaymentPageResponse();
response = controller.getApiResponse();
if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
System.out.println(response.getToken());
}
else
{
System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
}
}
return response;
}
JSP -
<form method="POST" action="https://test.authorize.net/payment/payment" id="DemoCheckoutForm" name="DemoCheckoutForm">
<input type="hidden" name="token" value="<%=token%>" >
<input type="submit" name="submit_b" value="Buy now" >
</form>
But i got form token when i call the following code from Authorize.net site.
<authenticateTestRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>API_LOGIN_ID</name>
<transactionKey>API_TRANSACTION_KEY</transactionKey>
</merchantAuthentication>
</authenticateTestRequest>
Thanks
Sundar
07-21-2017 10:19 AM
Hello @sundar2508
First, welcome to Authorize.Net. Second, I should clarify that AIM is our legacy Name Value Pair (NVP) and you are using our more feature rich Authorize.Net API.
From your example below, the request below can only lbe used to confirm that you're able to connect to the payment gateway and that your credentials are valid, it does not return a token.
<authenticateTestRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>API_LOGIN_ID</name> <transactionKey>API_TRANSACTION_KEY</transactionKey> </merchantAuthentication> </authenticateTestRequest>
When you send that request from your code, do you get a response from the gateway or are you sending from the API Reference?
Richard
07-21-2017 11:18 AM
Thanks Richard for quick response.
Sorry for pasting the wrong code previous thread.I was used below XML schema to verify my authentication only.
<authenticateTestRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>API_LOGIN_ID</name> <transactionKey>API_TRANSACTION_KEY</transactionKey> </merchantAuthentication> </authenticateTestRequest>
But I got the form token based on below codes in authorize.net. when i tried with JAVA code, am getting the null response only.
<getHostedPaymentPageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>API_LOGIN_ID</name>
<transactionKey>API_TRANSACTION_KEY</transactionKey>
</merchantAuthentication>
<transactionRequest>
<transactionType>authCaptureTransaction</transactionType>
<amount>20.00</amount>
</transactionRequest>
<hostedPaymentSettings>
<setting>
<settingName>hostedPaymentBillingAddressOptions</settingName>
<settingValue>{"show": true, "required":true}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentButtonOptions</settingName>
<settingValue>{"text": "Pay"}</settingValue>
</setting>
<setting>
<settingName>hostedPaymentReturnOptions</settingName>
<settingValue>{"url":"https://www.mystore.com/good","urlText":"Continue","cancelUrl":"https://www.mystore.com/cancel","can...>
</setting>
</hostedPaymentSettings>
</getHostedPaymentPageRequest>
I was tried to get the payment page based on below link,
http://developer.authorize.net/api/reference/features/accept_hosted.html
Previously we were used the SIM & Direct Payment gateway in our application. I am looking same payment gateway option in AIM also. So we have decided to use the Accept Host Payment Page for our payment gateway transaction without IFRAME.
Please guide us to complete the payment gateway integration.
Thanks
Sundar
Thanks
Sundarrajan
07-21-2017 11:45 AM
It sound like your Java code is unable to make a connection to our sandbox endpoint. We do require a TLS 1.2 connection, so please ensure that your environment and code is configured appropriately.
Richard
07-21-2017 12:10 PM
Thanks Richard.
I am beginner of this process. Can you please suggest url which are related to configuration and JAVA code for TLS 1.2. It would help me to understand the basic concepts. I have few basic question about Accept Host PAymeny Page,
1. For sandbox & Production testing , do we really need to SSL connection
2. Can we use localhost url for Cancel/ Continue button (http://localhost:8808/xx/thankyou.jsp)
Thanks
Sundarrajan
07-21-2017 08:48 PM
Hello,
I don't think the SSL / TLS is your issue. You need to get the token value into your JSP by importing your class and calling your method.
See a working example, using a slightly modified version of the exact code you posted at : http://45.55.195.86:8080/accepthosted/
07-22-2017 03:49 AM - edited 07-22-2017 04:03 AM
07-22-2017 08:51 AM
Basically, the modifications are bolded below. The class name, in this case was changed from GetAnAcceptPaymentPage to GetPaymentPage, but that is arbitrary.
public class GetPaymentPage { public static String myToken; public static ANetApiResponse run(Double amount) { ApiOperationBase.setEnvironment(Environment.SANDBOX); MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ; merchantAuthenticationType.setName("YOUR_LOGIN"); merchantAuthenticationType.setTransactionKey("YOUR_TRANSACTION_KEY"); // ... if (response!=null) { if (response.getMessages().getResultCode() == MessageTypeEnum.OK) { system.out.println(response.getMessages().getMessage().get(0).getCode()); System.out.println(response.getMessages().getMessage().get(0).getText()); System.out.println(response.getToken()); myToken = response.getToken(); }
In your JSP, you would import the package_name.class, call
ANetApiResponse run with the amount to charge, which gets the token into myToken with
myToken = response.getToken();
<%@page import="com.nexwebsites.GetPaymentPage"%> <% GetPaymentPage.run(25.00); %> <form method="POST" target="payframe" action="https://test.authorize.net/payment/payment" id="DemoCheckoutForm" name="DemoCheckoutForm"> <input type="hidden" name="token" value="<%= GetPaymentPage.myToken%>" > <input type="submit" name="submit_b" value="Buy now" > </form> <iframe id="payframe" name="payframe"></iframe>
07-22-2017 09:19 AM - edited 07-22-2017 09:23 AM
Thank you again. I have tried the code same way what you have mentioned earlier, but i have got NULL response only. Please find the code which is used in our project for testing payment and suggest us what we need to modify the code. I am looking the code related Accept Hosted Payment PAge without IFRAME.
JAVA METHOD
private ANetApiResponse run(Double amount) {
ApiOperationBase.setEnvironment(Environment.SANDBOX);
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName("9aAp6DGQ5xxx");
merchantAuthenticationType.setTransactionKey("94Fxv33At5u94xxx");
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
// Create the payment transaction request
TransactionRequestType txnRequest = new TransactionRequestType();
txnRequest.setTransactionType(TransactionTypeEnum.AUTH_ONLY_TRANSACTION.value());
txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
SettingType setting1 = new SettingType();
setting1.setSettingName("hostedPaymentButtonOptions");
setting1.setSettingValue("{\"text\": \"Pay\"}");
SettingType setting2 = new SettingType();
setting2.setSettingName("hostedPaymentOrderOptions");
setting2.setSettingValue("{\"show\": false}");
SettingType setting3 = new SettingType();
setting3.setSettingName("hostedPaymentReturnOptions");
setting3.setSettingValue("{\"showReceipt\" : false, \"url\":\"http://localhost:8080/xxx/thankyou.jsp\", \"urlText\": \"Continue\", \"cancelUrl\": \"http://localhost:8080/xxx/order_now.jsp\", \"cancelUrlText\": \"Cancel\"}");
ArrayOfSetting alist = new ArrayOfSetting();
alist.getSetting().add(setting1);
alist.getSetting().add(setting2);
alist.getSetting().add(setting3);
GetHostedPaymentPageRequest apiRequest = new GetHostedPaymentPageRequest();
apiRequest.setTransactionRequest(txnRequest);
apiRequest.setHostedPaymentSettings(alist);
GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
controller.execute();
GetHostedPaymentPageResponse response = new GetHostedPaymentPageResponse();
response = controller.getApiResponse();
if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getMessages().getMessage().get(0).getCode());
System.out.println(response.getMessages().getMessage().get(0).getText());
System.out.println(response.getToken());
}
else
{
System.out.println("Failed to get hosted payment page: " + response.getMessages().getResultCode());
}
}
return response;
}
JSP Code,
<form method="POST" target="payframe" action="https://test.authorize.net/payment/payment" id="DemoCheckoutForm" name="DemoCheckoutForm">
<input type="hidden" name="token" value="<%= token%>" >
<input type="submit" name="submit_b" value="Buy now" >
</form>
Thanks
Sundar
07-23-2017 09:13 AM
There isn't any difference between the iframe and the modal version in terms of the Java.
If you look at the modifications posted above closely, you should be able to get it, they are about as simple as can be.
The example has been updated to demonstrate the modal version at : http://45.55.195.86:8080/accepthosted/modal.jsp
07-23-2017 10:58 AM - edited 07-23-2017 10:59 AM