Skip to content

Commit a46ddc8

Browse files
authoredNov 16, 2023
Merge pull request #91 from starkbank/feature/split-and-split-receiver
Add Split and Split Receiver resources
2 parents a8d8eb4 + a62575e commit a46ddc8

11 files changed

+1792
-79
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1414

1515
## [Unreleased]
1616
### Added
17+
- Split resource
18+
- SplitReceiver resource
1719
- update function to Deposit resource
1820

1921
## [2.15.0] - 2023-09-18

‎README.md

+157-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Stark Bank Java SDK
23

34
Welcome to the Stark Bank Java SDK! This tool is made for Java
@@ -49,6 +50,8 @@ is as easy as sending a text message to your client!
4950
- [CorporateBalance](#get-your-corporatebalance): View your corporate balance
5051
- [CorporateTransactions](#query-corporatetransactions): View the transactions that have affected your corporate balance
5152
- [CorporateEnums](#corporate-enums): Query enums related to the corporate purchases, such as merchant categories, countries and card purchase methods
53+
- [Split](#query-splits): Split received Invoice payments between different receivers
54+
- [SplitReceiver](#create-splitreceivers): Receiver of an Invoice split
5255
- [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions
5356
- [WebhookEvents](#process-webhook-events): Manage webhook events
5457
- [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries
@@ -2481,15 +2484,168 @@ for (CardMethod method : methods) {
24812484
}
24822485
```
24832486

2487+
## Split
2488+
2489+
Split an Invoice between different receivers.
2490+
2491+
## Query Splits
2492+
2493+
You can get a list of created Splits given some filters.
2494+
2495+
```java
2496+
import com.starkbank.*;
2497+
import java.util.Map;
2498+
import java.util.HashMap;
2499+
2500+
Map<String, Object> params = new HashMap<>();
2501+
params.put("limit", 10);
2502+
2503+
Generator<Split> splits = Split.query(params);
2504+
2505+
for (Split split : splits) {
2506+
System.out.println(split);
2507+
}
2508+
```
2509+
2510+
## Get a Split
2511+
2512+
To get a single Split by its id, run:
2513+
2514+
```java
2515+
import com.starkbank.*;
2516+
2517+
Split split = Split.get("5155165527080960");
2518+
2519+
System.out.println(split);
2520+
```
2521+
2522+
## Query Split Logs
2523+
2524+
You can query Split Logs to check additional information.
2525+
2526+
```java
2527+
import com.starkbank.*;
2528+
import java.util.Map;
2529+
import java.util.HashMap;
2530+
2531+
Map<String, Object> params = new HashMap<>();
2532+
params.put("limit", 10);
2533+
2534+
Generator<Split.Log> logs = Split.Log.query(params);
2535+
2536+
for (Split.Log log : logs) {
2537+
System.out.println(log);
2538+
}
2539+
```
2540+
2541+
## Get a Split Log
2542+
2543+
You can also get a Split Log by specifying its id.
2544+
2545+
```java
2546+
import com.starkbank.*;
2547+
2548+
Split.Log log = Split.Log.get("5155165527080960");
2549+
2550+
System.out.println(log);
2551+
```
2552+
2553+
## Create SplitReceivers
2554+
2555+
You can create receivers to an Invoice Split by using the SplitReceiver resource.
2556+
2557+
```java
2558+
import com.starkbank.*;
2559+
import java.util.Map;
2560+
import java.util.List;
2561+
import java.util.HashMap;
2562+
import java.util.ArrayList;
2563+
2564+
Map<String, Object> data = new HashMap<>();
2565+
data.put("name", "Daenerys Targaryen Stormborn");
2566+
data.put("taxId", "594.739.480-42");
2567+
data.put("bankCode", "341");
2568+
data.put("branchCode", "2201");
2569+
data.put("accountNumber", "76543-8");
2570+
data.put("accountType", "salary");
2571+
2572+
SplitReceiver receiver = SplitReceiver.create(new SplitReceiver(data));
2573+
2574+
System.out.println(receiver);
2575+
```
2576+
2577+
## Query SplitReceivers
2578+
2579+
You can get a list of created SplitReceivers given some filters.
2580+
2581+
```java
2582+
import com.starkbank.*;
2583+
import java.util.Map;
2584+
import java.util.HashMap;
2585+
2586+
Map<String, Object> params = new HashMap<>();
2587+
params.put("limit", 10);
2588+
2589+
Generator<SplitReceiver> receivers = SplitReceiver.query(params);
2590+
2591+
for (SplitReceiver receiver : receivers) {
2592+
System.out.println(receiver);
2593+
}
2594+
```
2595+
2596+
## Get a SplitReceiver
2597+
2598+
To get a single SplitReceiver by its id, run:
2599+
2600+
```java
2601+
import com.starkbank.*;
2602+
2603+
SplitReceiver receiver = SplitReceiver.get("5155165527080960");
2604+
2605+
System.out.println(receiver);
2606+
```
2607+
2608+
## Query SplitReceiver Logs
2609+
2610+
You can query SplitReceiver Logs to check additional information.
2611+
2612+
```java
2613+
import com.starkbank.*;
2614+
import java.util.Map;
2615+
import java.util.HashMap;
2616+
2617+
Map<String, Object> params = new HashMap<>();
2618+
params.put("limit", 10);
2619+
2620+
Generator<SplitReceiver.Log> logs = SplitReceiver.Log.query(params);
2621+
2622+
for (Split.Log log : logs) {
2623+
System.out.println(log);
2624+
}
2625+
```
2626+
2627+
## Get a SplitReceiver Log
2628+
2629+
You can also get a SplitReceiver Log by specifying its id.
2630+
2631+
```java
2632+
import com.starkbank.*;
2633+
2634+
SplitReceiver.Log log = SplitReceiver.Log.get("5155165527080960");
2635+
2636+
System.out.println(log);
2637+
```
2638+
24842639
## Create a webhook subscription
24852640

24862641
To create a webhook subscription and be notified whenever an event occurs, run:
24872642

24882643
```java
24892644
import com.starkbank.*;
2645+
import java.util.Map;
24902646
import java.util.HashMap;
24912647

2492-
HashMap<String, Object> data = new HashMap<>();
2648+
Map<String, Object> data = new HashMap<>();
24932649
data.put("url", "https://winterfell.westeros.gov/events-from-stark-bank");
24942650
data.put("subscriptions", new String[]{"boleto", "boleto-payment", "transfer", "utility-payment", "tax-payment", "boleto-holmes", "brcode-payment", "deposit", "invoice"});
24952651
Webhook webhook = Webhook.create(data);

‎src/main/java/com/starkbank/Balance.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.starkbank;
22

3-
import com.starkbank.utils.Generator;
4-
import com.starkbank.utils.Resource;
53
import com.starkbank.utils.Rest;
4+
import com.starkbank.utils.Resource;
5+
import com.starkbank.utils.Generator;
66

7-
import java.util.ArrayList;
8-
import java.util.HashMap;
97
import java.util.List;
8+
import java.util.HashMap;
9+
import java.util.ArrayList;
1010

1111

1212
public final class Balance extends Resource {

‎src/main/java/com/starkbank/DictKey.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.starkbank;
22

3-
import com.starkbank.utils.Generator;
4-
import com.starkbank.utils.Resource;
53
import com.starkbank.utils.Rest;
4+
import com.starkbank.utils.Resource;
5+
import com.starkbank.utils.Generator;
66
import com.starkbank.utils.SubResource;
77

8-
import java.util.ArrayList;
9-
import java.util.HashMap;
10-
import java.util.List;
118
import java.util.Map;
9+
import java.util.List;
10+
import java.util.HashMap;
11+
import java.util.ArrayList;
1212

1313
public class DictKey extends Resource {
1414

‎src/main/java/com/starkbank/Invoice.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public final class Invoice extends Resource {
3030
* interest [number, default 0.0]: Invoice monthly interest for overdue payment in %. ex: 5.2
3131
* discounts [list of maps, default null]: list of maps with "percentage":number and "due":string pairs
3232
* rules [list of Invoice.Rules, default []]: list of Invoice.Rule objects for modifying invoice behavior. ex: [Invoice.Rule(key="allowedTaxIds", value=[ "012.345.678-90", "45.059.493/0001-73" ])]
33+
* splits [list of Splits, default []]: list of Splits objects to indicate payment receivers. ex: [Split(amount=141, receiverId="5706627130851328")]
3334
* tags [list of strings, default null]: list of strings for tagging
3435
* descriptions [list of maps, default null]: list of maps with "key":string and (optional) "value":string pairs
3536
* pdf [string]: public Invoice PDF URL. ex: "https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8"
@@ -59,6 +60,7 @@ public final class Invoice extends Resource {
5960
public List<Invoice.Description> descriptions;
6061
public List<Invoice.Discount> discounts;
6162
public List<Invoice.Rule> rules;
63+
public List<Split> splits;
6264
public String[] tags;
6365
public String pdf;
6466
public String link;
@@ -92,6 +94,7 @@ public final class Invoice extends Resource {
9294
* @param interest [number, default 0.0]: Invoice monthly interest for overdue payment in %. ex: 5.2
9395
* @param discounts [list of maps, default null]: list of maps with "percentage":number and "due":string or string pairs
9496
* @param rules [list of Invoice.Rules, default []]: list of Invoice.Rule objects for modifying invoice behavior. ex: [Invoice.Rule(key="allowedTaxIds", value=[ "012.345.678-90", "45.059.493/0001-73" ])]
97+
* @param splits [list of Splits, default []]: list of Splits objects to indicate payment receivers. ex: [Split(amount=141, receiverId="5706627130851328")]
9598
* @param tags [list of strings, default null]: list of strings for tagging
9699
* @param descriptions [list of maps, default null]: list of maps with "key":string and (optional) "value":string pairs
97100
* @param pdf [string]: public Invoice PDF URL. ex: "https://invoice.starkbank.com/pdf/d454fa4e524441c1b0c1a729457ed9d8"
@@ -109,10 +112,10 @@ public final class Invoice extends Resource {
109112
* @param updated [string]: creation datetime for the Invoice. ex: "2020-03-10 10:30:00.000000+00:00"
110113
*/
111114
public Invoice(Number amount, String due, String taxId, String name, Number expiration, Number fine,
112-
Number interest, List<Invoice.Description> descriptions, List<Invoice.Discount> discounts, List<Invoice.Rule> rules,
113-
String pdf, String link, String[] tags, Number nominalAmount, Number fineAmount, Number interestAmount,
114-
Number discountAmount, String id, String brcode, Integer fee, String[] transactionIds, String status,
115-
String created, String updated
115+
Number interest, List<Invoice.Description> descriptions, List<Invoice.Discount> discounts,
116+
List<Invoice.Rule> rules, List<Split> splits, String pdf, String link, String[] tags,
117+
Number nominalAmount, Number fineAmount, Number interestAmount, Number discountAmount, String id,
118+
String brcode, Integer fee, String[] transactionIds, String status, String created, String updated
116119
) {
117120
super(id);
118121
this.amount = amount;
@@ -124,6 +127,7 @@ public Invoice(Number amount, String due, String taxId, String name, Number expi
124127
this.interest = interest;
125128
this.discounts = discounts;
126129
this.rules = rules;
130+
this.splits = splits;
127131
this.tags = tags;
128132
this.descriptions = descriptions;
129133
this.pdf = pdf;
@@ -162,6 +166,7 @@ public Invoice(Number amount, String due, String taxId, String name, Number expi
162166
* descriptions [list of maps, default null]: list of maps with "key":string and (optional) "value":string pairs
163167
* discounts [list of maps, default null]: list of maps with "percentage":number and "due":string pairs
164168
* rules [list of Invoice.Rules, default []]: list of Invoice.Rule objects for modifying invoice behavior. ex: [Invoice.Rule(key="allowedTaxIds", value=[ "012.345.678-90", "45.059.493/0001-73" ])]
169+
* splits [list of Splits, default []]: list of Splits objects to indicate payment receivers. ex: [Split(amount=141, receiverId="5706627130851328")]
165170
* tags [list of strings, default null]: list of strings for tagging
166171
* <p>
167172
* Attributes (return-only):
@@ -193,6 +198,7 @@ public Invoice(Map<String, Object> data) throws Exception {
193198
this.discounts = parseDiscounts((List<Object>) dataCopy.remove("discounts"));
194199
this.tags = (String[]) dataCopy.remove("tags");
195200
this.rules = parseRules((List<Object>) dataCopy.remove("rules"));
201+
this.splits = parseSplit((List<Object>) dataCopy.remove("splits"));
196202
this.descriptions = parseDescriptions((List<Object>) dataCopy.remove("descriptions"));
197203
this.pdf = null;
198204
this.link = null;
@@ -1066,6 +1072,25 @@ private List<Invoice.Rule> parseRules(List<Object> rules) throws Exception {
10661072
return parsed;
10671073
}
10681074

1075+
private List<Split> parseSplit(List<Object> splits) throws Exception {
1076+
if (splits == null)
1077+
return null;
1078+
1079+
List<Split> parsed = new ArrayList<>();
1080+
if (splits.size() == 0 || splits.get(0) instanceof Split) {
1081+
for (Object split : splits) {
1082+
parsed.add((Split) split);
1083+
}
1084+
return parsed;
1085+
}
1086+
1087+
for (Object split : splits) {
1088+
Split splitObject = new Split((Map<String, Object>) split);
1089+
parsed.add(splitObject);
1090+
}
1091+
return parsed;
1092+
}
1093+
10691094
/**
10701095
* Invoice.Rule object
10711096
* <p>

0 commit comments

Comments
 (0)
Please sign in to comment.