javagrailsauthorize.netaccept.js

getting connect timeout when sending request to authorize.net from deployed app(Hetzner)?


we have a grails 4.0.10 app. we have integrated authorize.net for accepting payments via credit card. I have used accept.js library.

the part of code that sends request to authorize.net to charge credit card is as follows

        def descriptor = params['dataDescriptor']
        def value = params['dataValue']


        String firstName = params[AuthNetField.X_FIRST_NAME.fieldName]
        String lastName = params[AuthNetField.X_LAST_NAME.fieldName]
        String address = params[AuthNetField.X_ADDRESS.fieldName]
        String city = params[AuthNetField.X_CITY.fieldName]
        String state = params[AuthNetField.X_STATE.fieldName]
        String zip = params[AuthNetField.X_ZIP.fieldName]
        String country = params[AuthNetField.X_COUNTRY.fieldName]
        String phone = params[AuthNetField.X_PHONE.fieldName]
        String email = params[AuthNetField.X_EMAIL.fieldName]

        String apiLoginId = grailsApplication.config.net.authorize.apiLoginId


        if (grailsApplication.config.net.authorize.environment == net.authorize.Environment.PRODUCTION){
            ApiOperationBase.setEnvironment(Environment.PRODUCTION);
        }
        else{
            ApiOperationBase.setEnvironment(Environment.SANDBOX);
        }

        String transactionKey = grailsApplication.config.net.authorize.transactionKey


        MerchantAuthenticationType merchantAuthenticationType  = new MerchantAuthenticationType() ;
        merchantAuthenticationType.setName(apiLoginId);
        merchantAuthenticationType.setTransactionKey(transactionKey);
        ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);

        // Populate the payment data
        PaymentType paymentType = new PaymentType();
        OpaqueDataType OpaqueData = new OpaqueDataType();
        OpaqueData.setDataDescriptor(descriptor);
        OpaqueData.setDataValue(value);
        paymentType.setOpaqueData(OpaqueData);


        CustomerDataType cdt = new CustomerDataType()
        cdt.setEmail(email)

        CustomerAddressType customerType = new CustomerAddressType()
        customerType.setFirstName(firstName)
        customerType.setLastName(lastName)
        customerType.setAddress(address)
        customerType.setCity(city)
        customerType.setState(state)
        customerType.setZip(zip)
        customerType.setCountry(country)
        customerType.setPhoneNumber(phone)

        // Create the payment transaction request
        TransactionRequestType txnRequest = new TransactionRequestType();
        txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
        txnRequest.setPayment(paymentType);
        txnRequest.setBillTo(customerType)
        txnRequest.setCustomer(cdt)

        ArrayOfLineItem aol = new ArrayOfLineItem()


        itemizedOrderEntries.each { io ->

            def parts = io.split("<\\|>")

            LineItemType lit = new LineItemType()
            lit.setItemId(parts[0])
            lit.setName(parts[1])
            lit.setDescription(parts[2])
            lit.setQuantity(parts[3].toBigDecimal())
            lit.setUnitPrice(parts[4].toBigDecimal())
            lit.setTaxable(parts[5].toBoolean())


            aol.lineItem.add(lit)


        }


        txnRequest.setLineItems(aol)


        txnRequest.setAmount(total.setScale(2, RoundingMode.CEILING));


        // Make the API Request
        CreateTransactionRequest apiRequest = new CreateTransactionRequest();
        apiRequest.setTransactionRequest(txnRequest);
        CreateTransactionController controller = new CreateTransactionController(apiRequest);
        controller.execute();


        CreateTransactionResponse tresponse = controller.getApiResponse();

When the app is run locally it can connect to the authorize.net server.

But when the app is deplyed to remote server, we are using hetzner servers, i am getting connect timeout. I have pasted the error below.

2023-01-28 23:53:17.082 ERROR --- [pool-4-thread-1] net.authorize.util.HttpCallTask          : Http request execute failed: 'Connect to apitest.authorize.net:443 [apitest.authorize.net/198.241.206.22] failed: connect timed out'
2023-01-28 23:53:17.082  WARN --- [pool-4-thread-1] net.authorize.util.HttpCallTask          : Adding ErrorMessage: Code: 'org.apache.http.conn.ConnectTimeoutException', Text: 'Connect to apitest.authorize.net:443 [apitest.authorize.net/198.241.206.22] failed: connect timed out'
2023-01-28 23:53:17.083 ERROR --- [nio-8443-exec-3] n.a.a.controller.base.ApiOperationBase   : Invalid response:'net.authorize.api.contract.v1.ANetApiResponse@6744ad91'
2023-01-28 23:53:17.091 ERROR --- [nio-8443-exec-3] StackTrace                               : Full Stack Trace:

When i run the app locally in my system it can successfully connect to the authorize.net api but when i run it remotely i.e our web app is hosted at Hetzner server, it gives connect time out error.

do you know what is causing this connect timeout?

i dont seem to find the cause. i appreciate any guide.

Thanks

UPDATE:

As suggested by @roanjain i did curl request to sandbox api endpoint.

It took a few minutes and then outputted below

enter image description here

UPDATE 2:

I sent the same curl request from another server and it worked. So i think the issue is only with hetzner server.

enter image description here


Solution

  • Finally got it to work by moving server to another location. Initially i had server in Oregon. Hetzner confirmed that the ips at that location have mostly been blocked by authorize.net.