<commit_before>= Using the Kill Bill Java client

Kill Bill provides a https://github.com/killbill/killbill-client-java[Java client] that can be used to invoke Kill Bill's API methods. This document is aimed at providing a detailed walkthrough of how to set up this client and use it to execute Kill Bill API methods.

== Pre-requisites

* You have gone through the https://docs.killbill.io/latest/getting_started.html[Getting started] tutorial and have Kill Bill, Kaui and the database setup and running

* You have a tenant configured with API key `bob` and API secret `lazar`

== Setting up the Kill Bill Java client

The first step in setting up the Kill Bill Java client is to add the following Maven dependency related to the Kill Bill client to your POM file. (You can find out the latest version number of the library from the https://github.com/killbill/killbill-client-java[README] file)

[source,xml]
 <dependency>
  <groupId>org.kill-bill.billing</groupId>
  <artifactId>killbill-client-java</artifactId>
  <version>... release version ...</version>
 </dependency>
 
 
 
== Writing the Java code

Once the dependency is added, you can write code that invokes the Kill Bill APIs as shown below.
 
[source,java]
 int default_connection_timeout_sec = 10;
 int default_read_timeout_sec = 60;
 int default_request_timeout_sec = default_read_timeout_sec;
 String username = "admin";
 String password = "password";
 String apiKey = "bob";
 String apiSecret = "lazar";
 String serverHost = "localhost";
 int serverPort = 8080;
 String kbServerUrl = String.format("http://%s:%d", serverHost, serverPort);
 KillBillHttpClient killBillHttpClient = new KillBillHttpClient(kbServerUrl, username, password, apiKey,apiSecret, null, null, default_connection_timeout_sec * 1000, default_read_timeout_sec * 1000,default_request_timeout_sec * 1000);
 AccountApi accountApi = new AccountApi(killBillHttpClient);
 UUID accountId = UUID.fromString("<KEY>");
 String createdBy = "Kill Bill Client Tutorial";
 String reason = "Demonstrating Kill Bill Client";
 String comment = "Demonstrating Kill Bill Client";
 RequestOptions requestOptions =  RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build();
 ImmutableMap<String, String> NULL_PLUGIN_PROPERTIES = null;
 List<PaymentMethod> paymentMethods = accountApi.getPaymentMethodsForAccount(accountId, NULL_PLUGIN_PROPERTIES,requestOptions);
 logger.info("Payment methods=" + paymentMethods.size());


 * This code first declares and initializes some variables like `username`, `password` and so on. 
 
 * Next, a https://github.com/killbill/killbill-client-java/blob/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/KillBillHttpClient.java[KillBillHttpClient] instance is created using the variables declared earlier.  
 
 * After that, the code creates an https://github.com/killbill/killbill-client-java/tree/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/api/gen[AccountApi] instance using the `killBillHttpClient` object. `AccountApi` can be used to execute account related Kill Bill methods. Just like `AccountApi`, the https://github.com/killbill/killbill-client-java/tree/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/api/gen[org.killbill.billing.client.api.gen] package has other classes  like `PaymentMethodApi`, `OverDueApi` which can be used to invoke the corresponding API methods.
 
 * Next, the code declares and initializes some more variables like `createdBy`, `reason` and `comment`.
 
 * A https://github.com/killbill/killbill-client-java/blob/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/RequestOptions.java[RequestOptions] instance is then created using these variables.

* Finally, the code invokes the `AccountApi#getPaymentMethodsForAccount` method. This returns the payment methods corresponding to the specified `accountId`.

== Using the sample code

The complete source code used in this example is available at https://github.com/killbill/killbill-client-java-example[this] Github location. You can clone it in order to get started with your application. For detailed instructions on how to set up the code in Eclipse IDE, you can refer to our https://docs.killbill.io/latest/development.html#_setting_up_code_in_an_ide[development] document.

== Executing the code

In order to execute this code, you need to ensure Kill Bill is running (either on https://docs.killbill.io/latest/getting_started.html#_aws_one_click[AWS] or via https://docs.killbill.io/latest/getting_started.html#_docker[Docker] or in https://docs.killbill.io/latest/getting_started.html#_tomcat[Tomcat]) or https://docs.killbill.io/latest/development.html#_running_the_application[standalone] and execute the code specified above.

== TroubleShooting

In case you face an error in executing the code, you can take a look at the Kill Bill logs to obtain additional information about the error. The Kill Bill log files can be configured as explained https://docs.killbill.io/latest/development.html#_customizing_log_file_path[here]. It may also be useful to set a break point and debug the code as explained https://docs.killbill.io/latest/development.html#_setting_up_a_breakpoint_and_remote_debugging[here]. 
<commit_msg>Minor fixes<commit_after>= Using the Kill Bill Java client

Kill Bill provides a https://github.com/killbill/killbill-client-java[Java client] that can be used to invoke Kill Bill's API methods. This document is aimed at providing a detailed walkthrough of how to set up this client and use it to execute Kill Bill API methods.

== Pre-requisites

* You have gone through the https://docs.killbill.io/latest/getting_started.html[Getting started] tutorial and have Kill Bill, Kaui and the database setup and running

* You have a tenant configured with API key `bob` and API secret `lazar`

== Setting up the Kill Bill Java client

The first step in setting up the Kill Bill Java client is to add the following Maven dependency related to the Kill Bill client to your POM file. (You can find out the latest version number of the library from the https://github.com/killbill/killbill-client-java[README] file)

[source,xml]
 <dependency>
  <groupId>org.kill-bill.billing</groupId>
  <artifactId>killbill-client-java</artifactId>
  <version>... release version ...</version>
 </dependency>
 
 
 
== Writing the Java code

Once the dependency is added, you can write code that invokes the Kill Bill APIs as shown below.
 
[source,java]
 int default_connection_timeout_sec = 10;
 int default_read_timeout_sec = 60;
 int default_request_timeout_sec = default_read_timeout_sec;
 String username = "admin";
 String password = "password";
 String apiKey = "bob";
 String apiSecret = "lazar";
 String serverHost = "localhost";
 int serverPort = 8080;
 String kbServerUrl = String.format("http://%s:%d", serverHost, serverPort);
 KillBillHttpClient killBillHttpClient = new KillBillHttpClient(kbServerUrl, username, password, apiKey,apiSecret, null, null, default_connection_timeout_sec * 1000, default_read_timeout_sec * 1000,default_request_timeout_sec * 1000);
 AccountApi accountApi = new AccountApi(killBillHttpClient);
 UUID accountId = UUID.fromString("a21f1ca3-53ec-456b-8039-7170350c9c12");
 String createdBy = "Kill Bill Client Tutorial";
 String reason = "Demonstrating Kill Bill Client";
 String comment = "Demonstrating Kill Bill Client";
 RequestOptions requestOptions =  RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build();
 ImmutableMap<String, String> NULL_PLUGIN_PROPERTIES = null;
 List<PaymentMethod> paymentMethods = accountApi.getPaymentMethodsForAccount(accountId, NULL_PLUGIN_PROPERTIES,requestOptions);
 logger.info("Payment methods=" + paymentMethods.size());


 * This code first declares and initializes some variables like `username`, `password` and so on. 
 
 * Next, a https://github.com/killbill/killbill-client-java/blob/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/KillBillHttpClient.java[KillBillHttpClient] instance is created using the variables declared earlier.  
 
 * After that, the code creates an https://github.com/killbill/killbill-client-java/tree/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/api/gen[AccountApi] instance using the `killBillHttpClient` object. `AccountApi` can be used to execute account related Kill Bill methods. Just like `AccountApi`, the https://github.com/killbill/killbill-client-java/tree/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/api/gen[org.killbill.billing.client.api.gen] package has other classes  like `PaymentMethodApi`, `OverDueApi` which can be used to invoke the corresponding API methods.
 
 * Next, the code declares and initializes some more variables like `createdBy`, `reason` and `comment`.
 
 * A https://github.com/killbill/killbill-client-java/blob/9634a6d114ab71c868e7ef9ddc8a987cfec414ab/src/main/java/org/killbill/billing/client/RequestOptions.java[RequestOptions] instance is then created using these variables.

* Finally, the code invokes the `AccountApi#getPaymentMethodsForAccount` method. This returns the payment methods corresponding to the specified `accountId`.

== Executing the code

In order to execute this code, you need to ensure Kill Bill is running (either on https://docs.killbill.io/latest/getting_started.html#_aws_one_click[AWS] or via https://docs.killbill.io/latest/getting_started.html#_docker[Docker] or in https://docs.killbill.io/latest/getting_started.html#_tomcat[Tomcat]) or https://docs.killbill.io/latest/development.html#_running_the_application[standalone] and execute the code specified above.

== TroubleShooting

In case you face an error in executing the code, you can take a look at the Kill Bill logs to obtain additional information about the error. The Kill Bill log files can be configured as explained https://docs.killbill.io/latest/development.html#_customizing_log_file_path[here]. It may also be useful to set a break point and debug the code as explained https://docs.killbill.io/latest/development.html#_setting_up_a_breakpoint_and_remote_debugging[here]. 

== Using the sample code

The complete source code used in this example is available at https://github.com/killbill/killbill-client-java-example[this] Github location. You can clone it in order to get started with your application. For detailed instructions on how to set up the code in Eclipse IDE, you can refer to our https://docs.killbill.io/latest/development.html#_setting_up_code_in_an_ide[development] document.
{'fraction_non_alphanumeric': 0.08639671580518754, 'fraction_numerical': 0.022298936368725507, 'mean_word_length': 5.596307692307692, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 30, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4315959', 'n_tokens_mistral': 3321, 'n_tokens_neox': 3021, 'n_words': 997}