cancel
Showing results for 
Search instead for 
Did you mean: 

Getting null value - Accept Hosted Authorize Net Integration issue

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

 

sundar2508
Member
12 REPLIES 12
Thanks. Whatever it is but i have got null response only for posted code. Can you please suggest/ advice for code changes to get the form token correctly. Then only i can continue further to complete the payment transaction.

I have already given you the whole kit and caboodle in order to achieve what you would like. If you can't see it, then you should start with the basics of your chosen programming language. There are many free resources available online.

 

For this particular, simple purpose of getting an Accept Payment page, or any purpose for that matter, you don't need to use the SDK. It is very easy, just make a getHostedPaymentPageRequest API call with the XML that you already have. Basically the only variable is "amount", and you could even hard code that, if you had to. Then just parse the response and populate the form 's "token" input value with the token.

 

If you are implementing this functionality in a real ecommerce application and not just for fun or to learn, then you really should have a certified developer hook it up for you. It would be well worth the investment. Contact us for more information.

Powered by NexWebSites.com -
Certified Authorize.net developers

Thank you again.  I have tried with other language also but we are expecting the JAVA api for our project.  I have investigated the code again but i have got below error. Can you please suggest to continue further.

 GetHostedPaymentPageController controller = new GetHostedPaymentPageController(apiRequest);
        controller.execute(); === getting error this line.

"Environment not set. Set environment using setter or use overloaded method to pass appropriate environment"

 

Thanks

Sundar