Skip to content

How to use sdk-java in android.  #177

Open
@patelbansari

Description

@patelbansari

I'm using the below dependency to use sdk-java in android.

    implementation 'net.authorize:anet-java-sdk:2.0.1'
    implementation('javax.xml.bind:jaxb-api:2.3.0')
    implementation('javax.activation:activation:1.1')
    implementation('org.glassfish.jaxb:jaxb-runtime:2.3.0')
    implementation 'org.apache.logging.log4j:log4j-api:2.3'

After a successful build, I tried to run the below code with sandbox details.

    ApiOperationBase.setEnvironment(Environment.SANDBOX)

    // Create object with merchant authentication details

    // Create object with merchant authentication details
    val merchantAuthenticationType = MerchantAuthenticationType()
    merchantAuthenticationType.setName("my_login_id")
    merchantAuthenticationType.setTransactionKey("my_trans_key")
    // Set the request to operate in either the sandbox or production environment

    // Populate the payment data

    // Populate the payment data
    val creditCard = CreditCardType()
    creditCard.setCardNumber("4111111111111111")
    creditCard.setExpirationDate("1220")
    val paymentType = PaymentType()
    paymentType.setCreditCard(creditCard)

    // Set payment profile data

    // Set payment profile data
    val customerPaymentProfileType = CustomerPaymentProfileType()
    customerPaymentProfileType.setCustomerType(CustomerTypeEnum.INDIVIDUAL)
    customerPaymentProfileType.setPayment(paymentType)

    // Set customer profile data

    // Set customer profile data
    val customerProfileType = CustomerProfileType()
    customerProfileType.setMerchantCustomerId("M_test@example.com")
    customerProfileType.setDescription("Profile description for test@example.com")
    customerProfileType.setEmail("test@example.com")
    customerProfileType.getPaymentProfiles().add(customerPaymentProfileType)

    // Create the API request and set the parameters for this specific request

    // Create the API request and set the parameters for this specific request
    val apiRequest = CreateCustomerProfileRequest()
    apiRequest.setMerchantAuthentication(merchantAuthenticationType)
    apiRequest.setProfile(customerProfileType)
    apiRequest.setValidationMode(ValidationModeEnum.TEST_MODE)

    // Call the controller

    // Call the controller
    val controller =
        CreateCustomerProfileController(apiRequest)
    controller.execute()

    // Get the response

    // Get the response
    var response: CreateCustomerProfileResponse
    response = controller.getApiResponse()
    Log.e("",""+controller.getErrorResponse())
    // Parse the response to determine results

    // Parse the response to determine results
    if (response != null) {
        // If API Response is OK, go ahead and check the transaction response
        if (response.getMessages().getResultCode() === MessageTypeEnum.OK) {
            Log.e("",response.getCustomerProfileId())
            if (!response.getCustomerPaymentProfileIdList().getNumericString().isEmpty()) {
                Log.e("",
                    response.getCustomerPaymentProfileIdList().getNumericString().get(0)
                )
            }
            if (!response.customerShippingAddressIdList.getNumericString().isEmpty()) {
                Log.e("",
                    response.getCustomerShippingAddressIdList().getNumericString().get(0)
                )
            }
            if (!response.getValidationDirectResponseList().getString().isEmpty()) {
                Log.e("",
                    response.getValidationDirectResponseList().getString().get(0)
                )
            }
        } else {
            Log.e("",
                "Failed to create customer profile:  " + response.getMessages().getResultCode()
            )
        }
    } else {
        // Display the error code and message when response is null
        val errorResponse: ANetApiResponse = controller.getErrorResponse()
        Log.e("","Failed to get response")
        if (!errorResponse.getMessages().getMessage().isEmpty()) {
            Log.e("",
                "Error: " + errorResponse.getMessages().getMessage().get(0).getCode()
                    .toString() + " \n" + errorResponse.getMessages().getMessage().get(0)
                    .getText()
            )
        }
    }`

after run this code my app is getting crash with controller.getApiResponse() must not be null.
So i debugged the code and found one exception that is java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Image; in HttpUtility.java class with postData method.

Does anyone have an idea about this?

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