# Java

The IremboPay Java SDK is a robust and developer-friendly library designed to simplify the integration of payment functionality into your Java applications. With a comprehensive set of features, the SDK streamlines transaction management, enabling seamless payment processing within the IremboPay ecosystem. Whether you’re developing a new application or enhancing an existing one, the IremboPay Java SDK provides smooth integration, high performance, and a hassle-free development experience.

#### Installation <a href="#installation" id="installation"></a>

{% tabs %}
{% tab title="Maven" %}
{% code title="pom.xml" lineNumbers="true" %}

```xml
<dependencies>
    ....
    <dependency>
        <groupId>com.irembopay</groupId>
        <artifactId>irembopay-java-sdk</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>
```

{% endcode %}
{% endtab %}

{% tab title="Gradle" %}
{% code title="build.gradle" %}

```gradle
dependencies {
    implementation group: 'com.irembopay', name: 'irembopay-java-sdk', version: '1.0.0'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

**Install the package**

{% tabs %}
{% tab title="Maven" %}

```bash
  mvn install
```

{% endtab %}

{% tab title="Gradle" %}

```bash
gradle build
```

{% endtab %}
{% endtabs %}

Initialization

```java
import rw.irembo.payment.sdk.IremboPay;
import rw.irembo.payment.sdk.Invoice;
import rw.irembo.payment.sdk.IremboPay;
import rw.irembo.payment.sdk.models.*;
import rw.irembo.payment.sdk.util.*;
String secretKey = "yourSecretKey"
IremboPay iremboPay = new IremboPay(secretKey, Environment.SANDBOX);
```

## Invoice

### Create Invoice

```java
String transactionId="TST-1001477106";
String paymentAccountIdentifier = "07808652516";
Customer customer = new Customer();
customer.setFullName("Jixle Manzi");
customer.setPhoneNumber("0780000001");
customer.setEmail("user@email.com");
List<PaymentItem> paymentItems = new java.util.ArrayList<>(List.of());
PaymentItem paymentItem = new PaymentItem();
paymentItem.setCode("PC-aaf751b73f");
paymentItem.setQuantity(1);
paymentItem.setUnitAmount(2000);
paymentItems.add(paymentItem);
String description = "Invoice description";
Calendar calendar = Calendar.getInstance();
calendar.set(2025, Calendar.JULY, 27, 16, 24, 51);
Date expiryAt = calendar.getTime();
String language = "EN";
IremboPayResponse<Invoice> createdInvoice =  iremboPay.invoice.createInvoice(transactionId,paymentAccountIdentifier,customer,paymentItems,description,expiryAt,language);
System.out.println(createdInvoice);
```

### Create Batch Invoice

```java
List<String> invoiceNumbers = new ArrayList<>();
invoiceNumbers.add("880620445855");
invoiceNumbers.add("880620346771");
String transactionId = "TST-10015-Test";
String description = "Batch SDK test invoice creation";
IremboPayResponse<Invoice> createdBatchInvoice = iremboPay.invoice.createBatchInvoice(invoiceNumbers, transactionId, description);
System.out.println(createdInvoice);
```

### Get Invoice

```java
IremboPayResponse<Invoice> invoice = iremboPay.invoice.getInvoice("880628496284");
System.out.println(invoice);
```

### Update Invoice

```java
Calendar calendar = Calendar.getInstance();
calendar.set(2024, Calendar.JUNE, 28, 16, 24, 51);
Date expiryAt = calendar.getTime();
List<PaymentItem> paymentItems = new ArrayList<>();
PaymentItem paymentItem = new PaymentItem();
paymentItem.setUnitAmount(2000);
paymentItem.setCode("PC-aaf751b73f");
paymentItem.setQuantity(1);
paymentItems.add(paymentItem);
IremboPayResponse<Invoice> invoice = iremboPay.invoice.updateInvoice("880530633460",expiryAt,paymentItems);
System.out.println(invoice);
```

## Payment

### Initiate mobile money push payment

```java
String accountIdentifier = "0781110011"
String paymentProvider = "MTN";
String invoiceNumber = "870611420239";
String transactionReference = "MTN_001";
iremboPay.mobileMoney.initiate(accountIdentifier,paymentProvider,invoiceNumber,transactionReference);
```

### Payment Notifications

#### Verifying the signature <a href="#verifying-the-signature" id="verifying-the-signature"></a>

```java
String payload = "{\"key\": \"value\"}";
String signatureHeader = "signature_header_here";
boolean isValid = irembopay.signatureHelper.verifySignature(payload, signatureHeader);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://irembopay.gitbook.io/irembopay-api-docs/sdk/java.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
