Skip to content

Commit

Permalink
Merge pull request #119 from hglohika/story/DNM-1109/add_support_for_…
Browse files Browse the repository at this point in the history
…php_disbursement

[DNM-1109] added support for php disbursement
  • Loading branch information
xen-HendryZheng authored Jul 21, 2022
2 parents e98fad6 + c99b046 commit 21178df
Show file tree
Hide file tree
Showing 18 changed files with 1,760 additions and 13 deletions.
148 changes: 136 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ This library is the abstraction of Xendit API for access from applications writt
- [Gradle](#gradle)
- [Usage](#usage)
- [Disbursement Services](#disbursement-services)
- [Create a disbursement](#create-a-disbursement)
- [Get banks with available disbursement service](#get-banks-with-available-disbursement-service)
- [Get a disbursement by external ID](#get-a-disbursement-by-external-id)
- [Get a disbursement by ID](#get-a-disbursement-by-id)
- [Create an IDR disbursement](#create-an-idr-disbursement)
- [Create a PHP disbursement](#create-a-php-disbursement)
- [Get banks with available IDR disbursement service](#get-banks-with-available-idr-disbursement-service)
- [Get disbursements channels](#get-disbursements-channels)
- [Get disbursements channels by channel category](#get-disbursement-channels-by-channel-category)
- [Get disbursements channels by channel code](#get-disbursement-channels-by-channel-code)
- [Get an IDR disbursement by external ID](#get-an-idr-disbursement-by-external-id)
- [Get a PHP disbursement by reference ID](#get-a-php-disbursement-by-reference-id)
- [Get an IDR disbursement by ID](#get-an-idr-disbursement-by-id)
- [Get a PHP disbursement by ID](#get-a-php-disbursement-by-id)
- [Invoice services](#invoice-services)
- [Create an invoice](#create-an-invoice)
- [Get an invoice by ID](#get-an-invoice-by-id)
Expand Down Expand Up @@ -135,7 +141,7 @@ More information: https://search.maven.org/artifact/com.xendit/xendit-java-lib
You need to use secret API key in order to use functionality in this library. The key can be obtained from your [Xendit Dashboard](https://dashboard.xendit.co/settings/developers#api-keys).

### Without Client
If you're only dealing with a single secret key, you can simply import the packages required for the products you're interacting with without the need to create a client.
If you're only dealing with a single secret key, you can simply import the packages required for the products you're interacting with without the need to create a client. Xendit Disbursement class is being used for IDR Disbursement.

There is another way to set secret key using **Xendit.Opt.setApiKey(")** which is recommended way to use instead of **Xendit.apiKey**.

Expand All @@ -151,7 +157,7 @@ public class Example {
}
```
### With Client
If you're dealing with multiple secret keys, it is recommended that you use **XenditClient**. This allows you to create as many clients as needed, each with their own individual key.
If you're dealing with multiple secret keys, it is recommended that you use **XenditClient**. This allows you to create as many clients as needed, each with their own individual key. Xendit Disbursement Client is being used for IDR Disbursements.
```java
import com.xendit.XenditClient;

Expand All @@ -168,7 +174,7 @@ public class Example {
}
}
```
Example: Create a disbursement
Example: Create an IDR disbursement

###### Without Client
```java
Expand Down Expand Up @@ -202,6 +208,7 @@ public class ExampleCreateDisbursement {
}
```
###### With Client
Xendit Disbursement Client is being used for IDR Disbursement.
```java
import com.xendit.exception.XenditException;
import com.xendit.XenditClient;
Expand Down Expand Up @@ -241,9 +248,9 @@ There are some examples provided for you [here](https://github.com/xendit/xendit

### Disbursement Services

#### Create a disbursement
#### Create an IDR disbursement

You can choose whether want to put the attributes as parameters or to put in inside a Map object.
You can choose whether want to put the attributes as parameters or to put in inside a Map object.

<table>
<tr>
Expand Down Expand Up @@ -288,7 +295,7 @@ Disbursement disbursement = Disbursement.create(params);
Disbursement disbursement = xenditClient.disbursement.create(params);
```

#### Get banks with available disbursement service
#### Get banks with available IDR disbursement service

```java
/* Without client */
Expand All @@ -297,7 +304,7 @@ AvailableBank[] banks = Disbursement.getAvailableBanks();
AvailableBank[] banks = xenditClient.disbursement.getAvailableBanks();
```

#### Get a disbursement by external ID
#### Get an IDR disbursement by external ID

```java
/* Without client */
Expand All @@ -306,7 +313,7 @@ Disbursement disbursement = Disbursement.getByExternalId("EXAMPLE_ID");
Disbursement disbursement = xenditClient.disbursement.getByExternalId("EXAMPLE_ID");
```

#### Get a disbursement by ID
#### Get an IDR disbursement by ID

```java
/* Without client */
Expand All @@ -315,6 +322,123 @@ Disbursement disbursement = Disbursement.getById("EXAMPLE_ID");
Disbursement disbursement = xenditClient.disbursement.getById("EXAMPLE_ID");
```

#### Create a PHP disbursement

You can choose whether want to put the attributes as parameters or to put in inside a Map object.

<table>
<tr>
<td>
<pre>
DisbursementPHP.createPHPDisbursement(
String xendit_idempotency_key,
String reference_id,
String currency,
String channel_code,
String account_name,
String account_number,
String description,
Integer amount,
ReceiptNotification receiptNotification,
Beneficiary beneficiary
);
ReceiptNotification receiptNotification = ReceiptNotification.builder()
.emailTo(new String[] { "[email protected]" })
.emailCC(new String[] { "[email protected]" })
.emailBcc(new String[] { "[email protected]" })
.build();
Beneficiary beneficiary =
Beneficiary.builder()
.type("test-type")
.givenNames("Test Name")
.middleName("Middle Name")
.surname("Sur Name")
.businessName("Test")
.streetLine1("Jl. 123")
.streetLine2("Jl. 456")
.city("Jakarta Selatan")
.province("DKI Jakarta")
.state("Test")
.country("Test")
.zipCode("12345")
.mobileNumber("123456789")
.phoneNumber("12345678")
.email("[email protected]")
.build();
</pre>
</td>
<td>
<pre>
DisbursementPHP.createPHPDisbursement(
Map&lt;String, String&gt; headers, Map&lt;String, Object&gt; params
);
</pre>
</td>
</tr>
</table>

```java
Map<String, Object> params = new HashMap<>();
Map<String, String> headers = new HashMap<>();
headers.put("xendit-idempotency-key", "xendit-idempotency-key");
params.put("reference_id", "reference_id_value");
params.put("currency", "PHP");
params.put("channel_code", "required_channel_code");
params.put("account_name", "John etc");
params.put("account_number", "123456");
params.put("description", "Disbursement description");
params.put("amount", 50000);
params.put("receipt_notification", receiptNotification);

/* Without client */
DisbursementPHP disbursement = DisbursementPHP.createPHPDisbursement(headers, params);

/* With client */
DisbursementPHP disbursement = xenditClient.disbursementPHP.createPHPDisbursement(headers, params);
```

#### Get disbursements Channels

```java
/* Without client */
DisbursementChannel[] disbursementChannels = DisbursementChannel.getDisbursementChannels();
/* With client */
DisbursementChannel[] disbursementChannels = xenditClient.disbursementPHP.getDisbursementChannels();
```
#### Get disbursement channels by channel category

```java
/* Without client */
DisbursementChannel[] disbursementChannels = DisbursementChannel.getByChannelCategory("channel-category");
/* With client */
DisbursementChannel[] disbursementChannels = xenditClient.disbursementPHP.getByChannelCategory("channel-category");
```
#### Get disbursement channels by channel code

```java
/* Without client */
DisbursementChannel[] disbursementChannels = DisbursementChannel.getByChannelCode("channel-code");
/* With client */
DisbursementChannel[] disbursementChannels = xenditClient.disbursementPHP.getByChannelCode("channel-code");
```
#### Get a PHP disbursement by reference ID

```java
/* Without client */
DisbursementPHP disbursement = DisbursementPHP.getPHPByReferenceId("EXAMPLE_ID");
/* With client */
DisbursementPHP disbursement = xenditClient.disbursementPHP.getPHPByReferenceId("EXAMPLE_ID");
```

#### Get a PHP disbursement by ID

```java
/* Without client */
DisbursementPHP disbursement = Disbursement.getPHPById("EXAMPLE_ID");
/* With client */
DisbursementPHP disbursement = xenditClient.disbursementPHP.getPHPById("EXAMPLE_ID");
```

[Back to top](#table-of-contents)

### Invoice services
Expand Down
2 changes: 1 addition & 1 deletion xendit-java-lib/src/main/java/com/xendit/Xendit.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String getXenditURL() {
}

public String getVersion() {
return "1.19.6";
return "1.20.0";
}
}
}
3 changes: 3 additions & 0 deletions xendit-java-lib/src/main/java/com/xendit/XenditClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.xendit.model.CustomerClient;
import com.xendit.model.DirectDebitPaymentClient;
import com.xendit.model.DisbursementClient;
import com.xendit.model.DisbursementPHPClient;
import com.xendit.model.EWalletClient;
import com.xendit.model.FixedVirtualAccountClient;
import com.xendit.model.InvoiceClient;
Expand All @@ -23,6 +24,7 @@ public class XenditClient {
public BalanceClient balance;
public PayoutClient payout;
public DisbursementClient disbursement;
public DisbursementPHPClient disbursementPHP;
public EWalletClient eWallet;
public QRCodeClient qrCode;
public CustomerClient customer;
Expand Down Expand Up @@ -70,6 +72,7 @@ private static void buildClient(Xendit.Option option, XenditClient xenditClient)
xenditClient.invoice = new InvoiceClient(option, Xendit.getRequestClient());
xenditClient.balance = new BalanceClient(option, Xendit.getRequestClient());
xenditClient.disbursement = new DisbursementClient(option, Xendit.getRequestClient());
xenditClient.disbursementPHP = new DisbursementPHPClient(option, Xendit.getRequestClient());
xenditClient.payout = new PayoutClient(option, Xendit.getRequestClient());
xenditClient.eWallet = new EWalletClient(option, Xendit.getRequestClient());
xenditClient.qrCode = new QRCodeClient(option, Xendit.getRequestClient());
Expand Down
54 changes: 54 additions & 0 deletions xendit-java-lib/src/main/java/com/xendit/model/Beneficiary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.xendit.model;

import com.google.gson.annotations.SerializedName;
import lombok.*;

@Getter
@Setter
@Builder
public class Beneficiary {
@SerializedName("type")
private String type;

@SerializedName("given_names")
private String givenNames;

@SerializedName("middle_name")
private String middleName;

@SerializedName("surname")
private String surname;

@SerializedName("business_name")
private String businessName;

@SerializedName("street_line1")
private String streetLine1;

@SerializedName("street_line2")
private String streetLine2;

@SerializedName("city")
private String city;

@SerializedName("province")
private String province;

@SerializedName("state")
private String state;

@SerializedName("country")
private String country;

@SerializedName("zip_code")
private String zipCode;

@SerializedName("mobile_number")
private String mobileNumber;

@SerializedName("phone_number")
private String phoneNumber;

@SerializedName("email")
private String email;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.xendit.model;

public class CurrencyEnum {
public enum CurrencyType {
PHP,
IDR
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import lombok.*;

/** Disbursement Class is being used for IDR Disbursements. */
@Getter
@Setter
@Builder
Expand Down
Loading

0 comments on commit 21178df

Please sign in to comment.