//
  // Run this sample from command line with:
  //                 java -jar target/ChargeCreditCard-jar-with-dependencies.jar
  //
  public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount) {

    // Common code to set for all requests
    ApiOperationBase.setEnvironment(Environment.SANDBOX);

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

    // Populate the payment data
    PaymentType paymentType = new PaymentType();
    BankAccountType bankAccountType = new BankAccountType();
    bankAccountType.setAccountType(BankAccountTypeEnum.CHECKING);
    bankAccountType.setRoutingNumber("125000024");
    bankAccountType.setAccountNumber("12345678");
    bankAccountType.setNameOnAccount("John Doe");
    paymentType.setBankAccount(bankAccountType);

    // Create the payment transaction request
    TransactionRequestType txnRequest = new TransactionRequestType();
    txnRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
    txnRequest.setPayment(paymentType);
    txnRequest.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));

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

    CreateTransactionResponse response = controller.getApiResponse();

    if (response != null) {

      // If API Response is ok, go ahead and check the transaction response
      if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {

        TransactionResponse result = response.getTransactionResponse();
        if (result.getResponseCode().equals("1")) {
          System.out.println(result.getResponseCode());
          System.out.println("Successful Debit Bank Transaction");
          System.out.println(result.getAuthCode());
          System.out.println(result.getTransId());
        } else {
          System.out.println("Failed Transaction: " + result.getResponseCode());
        }
      } else {
        System.out.println("Failed Transaction:  " + response.getMessages().getResultCode());
      }
    }
    return response;
  }
  public static ANetApiResponse run(String apiLoginId, String transactionKey) {
    ApiOperationBase.setEnvironment(Environment.SANDBOX);

    // Giving the merchant authentication information
    MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType();
    merchantAuthenticationType.setName(apiLoginId);
    merchantAuthenticationType.setTransactionKey(transactionKey);
    ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
    // Setting the payment
    OpaqueDataType op = new OpaqueDataType();
    op.setDataDescriptor("COMMON.APPLE.INAPP.PAYMENT");
    op.setDataValue(
        "eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxO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zNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0=");
    PaymentType paymentOne = new PaymentType();
    paymentOne.setOpaqueData(op);
    // Setting the transaction
    TransactionRequestType transactionRequest = new TransactionRequestType();
    transactionRequest.setAmount(new BigDecimal("131"));
    transactionRequest.setTransactionType(TransactionTypeEnum.AUTH_CAPTURE_TRANSACTION.value());
    transactionRequest.setPayment(paymentOne);
    // Making the api request
    CreateTransactionRequest apiRequest = new CreateTransactionRequest();
    apiRequest.setTransactionRequest(transactionRequest);
    // Creating the controller
    CreateTransactionController controller = new CreateTransactionController(apiRequest);
    controller.execute();
    // Getting the response
    CreateTransactionResponse response = controller.getApiResponse();
    if (response != null) {
      if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
        if (response.getTransactionResponse() != null) {
          TransactionResponse result = response.getTransactionResponse();
          System.out.println("Successful: Create an ApplePay Transaction");
          System.out.println("Response Code : " + result.getResponseCode());
          System.out.println("Transaction ID : " + result.getTransId());
          System.out.println("Auth code : " + result.getAuthCode());
        }
      } else {
        System.out.println("Failed: Create ApplePay  Transaction");
        if (!response.getMessages().getMessage().isEmpty())
          System.out.println(
              "Error: "
                  + response.getMessages().getMessage().get(0).getCode()
                  + "  "
                  + response.getMessages().getMessage().get(0).getText());

        if (response.getTransactionResponse() != null)
          if (!response.getTransactionResponse().getErrors().getError().isEmpty())
            System.out.println(
                "Transaction Error : "
                    + response.getTransactionResponse().getErrors().getError().get(0).getErrorCode()
                    + " "
                    + response
                        .getTransactionResponse()
                        .getErrors()
                        .getError()
                        .get(0)
                        .getErrorText());
      }
    }
    return response;
  }