Skip to content

Commit 3be4c8f

Browse files
Add merchant purchase, merchant session, merchant card and merchant installment
1 parent 85c4356 commit 3be4c8f

13 files changed

+1633
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1212
- PATCH version when backwards compatible bug **fixes** are implemented.
1313

1414
## [Unreleased]
15+
### Added
16+
- merchantSession, merchantCard, merchantInstallment and merchantPurchase resources
1517

1618
## [2.19.0] - 2024-09-17
1719
### Added

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ is as easy as sending a text message to your client!
5252
- [CorporateEnums](#corporate-enums): Query enums related to the corporate purchases, such as merchant categories, countries and card purchase methods
5353
- [Split](#query-splits): Split received Invoice payments between different receivers
5454
- [SplitReceiver](#create-splitreceivers): Receiver of an Invoice split
55+
- [MerchantSession](#merchant-session): The Merchant Session allows you to create a session prior to a purchase. Sessions are essential for defining the parameters of a purchase, including funding type, expiration, 3DS, and more.
56+
- [MerchantPurchase](#merchant-purchase): The Merchant Purchase section allows users to retrieve detailed information of the purchases.
5557
- [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions
5658
- [WebhookEvents](#process-webhook-events): Manage webhook events
5759
- [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries
@@ -2637,6 +2639,133 @@ SplitReceiver.Log log = SplitReceiver.Log.get("5155165527080960");
26372639
System.out.println(log);
26382640
```
26392641

2642+
## Merchant Session
2643+
2644+
The Merchant Session allows you to create a session prior to a purchase.
2645+
Sessions are essential for defining the parameters of a purchase, including funding type, expiration, 3DS, and more.
2646+
2647+
## Create a MerchantSession
2648+
2649+
```java
2650+
import com.starkbank.*;
2651+
import java.util.Map;
2652+
import java.util.List;
2653+
import java.util.HashMap;
2654+
import java.util.ArrayList;
2655+
2656+
Map<String, Object> data = new HashMap<>();
2657+
List<String> allowedFundingTypes = new ArrayList<>();
2658+
allowedFundingTypes.add("debit");
2659+
allowedFundingTypes.add("credit");
2660+
data.put("allowedFundingTypes", allowedFundingTypes);
2661+
2662+
List<Map<String, Object>> allowedInstallments = new ArrayList<>();
2663+
Map<String, Object> installment1 = new HashMap<>();
2664+
installment1.put("totalAmount", 0);
2665+
installment1.put("count", 1);
2666+
allowedInstallments.add(installment1);
2667+
2668+
Map<String, Object> installment2 = new HashMap<>();
2669+
installment2.put("totalAmount", 120);
2670+
installment2.put("count", 2);
2671+
allowedInstallments.add(installment2);
2672+
2673+
Map<String, Object> installment3 = new HashMap<>();
2674+
installment3.put("totalAmount", 180);
2675+
installment3.put("count", 12);
2676+
allowedInstallments.add(installment3);
2677+
2678+
data.put("allowedInstallments", allowedInstallments);
2679+
data.put("expiration", 3600);
2680+
data.put("challengeMode", "disabled");
2681+
2682+
data.put("tags", new String[]{"Stark", "Suit"});
2683+
2684+
MerchantSession.create(new MerchantSession(data));
2685+
2686+
System.out.println(log);
2687+
```
2688+
2689+
You can create a MerchantPurchase through a MerchantSession by passing its UUID.
2690+
**Note**: This method must be implemented in your front-end to ensure that sensitive card data does not pass through the back-end of the integration.
2691+
2692+
### Create a MerchantSession Purchase
2693+
2694+
```java
2695+
import com.starkbank.*;
2696+
import java.util.Map;
2697+
import java.util.HashMap;
2698+
2699+
Map<String, Object> purchaseData = new HashMap<>();
2700+
purchaseData.put("amount", 1000L);
2701+
purchaseData.put("cardExpiration", "2035-01");
2702+
purchaseData.put("cardNumber", "36490101441625");
2703+
purchaseData.put("cardSecurityCode", "123");
2704+
purchaseData.put("holderName", "Margaery Tyrell");
2705+
purchaseData.put("fundingType", "credit");
2706+
2707+
MerchantSession.Purchase purchase= MerchantSession.purchase(
2708+
merchantSession.uuid, new com.starkbank.MerchantSession.Purchase(purchaseData););
2709+
2710+
System.out.println(purchase);
2711+
```
2712+
2713+
### Query MerchantSessions
2714+
2715+
```java
2716+
import com.starkbank.*;
2717+
import java.util.Map;
2718+
import java.util.HashMap;
2719+
2720+
HashMap<String, Object> params = new HashMap<>();
2721+
params.put("limit", 10);
2722+
2723+
Generator<MerchantSession> sessions = MerchantSession.query(params);
2724+
2725+
for (MerchantSession session : sessions) {
2726+
System.out.println(session);
2727+
}
2728+
```
2729+
2730+
### Get a MerchantSession
2731+
2732+
```java
2733+
import com.starkbank.*;
2734+
2735+
MerchantSession retrievedSession = MerchantSession.get("5441927222657024");
2736+
System.out.println(retrievedSession);
2737+
```
2738+
2739+
## Merchant Purchase
2740+
2741+
The Merchant Purchase section allows users to retrieve detailed information of the purchases.
2742+
2743+
### Query MerchantPurchases
2744+
2745+
```java
2746+
import com.starkbank.*;
2747+
import java.util.Map;
2748+
import java.util.HashMap;
2749+
2750+
HashMap<String, Object> params = new HashMap<>();
2751+
params.put("limit", 10);
2752+
Generator<MerchantPurchase> merchantPurchases = MerchantPurchase.query(params);
2753+
2754+
for (MerchantPurchase purchase : merchantPurchases) {
2755+
System.out.println(purchase);
2756+
}
2757+
```
2758+
2759+
### Get a MerchantPurchase
2760+
2761+
```java
2762+
import com.starkbank.*;
2763+
2764+
MerchantPurchase retrievedPurchase = MerchantPurchase.get("5441927222657024");
2765+
2766+
System.out.println(retrievedPurchase);
2767+
```
2768+
26402769
## Create a webhook subscription
26412770

26422771
To create a webhook subscription and be notified whenever an event occurs, run:
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.starkbank;
2+
3+
import com.starkbank.utils.Generator;
4+
import com.starkbank.utils.Resource;
5+
import com.starkbank.utils.Rest;
6+
7+
import java.util.ArrayList;
8+
import java.util.HashMap;
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
13+
public class MerchantCard extends Resource {
14+
15+
/**
16+
# MerchantCard object
17+
Check out our API Documentation at https://starkbank.com/docs/api#merchant-card
18+
**/
19+
20+
static ClassData data = new ClassData(MerchantCard.class, "MerchantCard");
21+
22+
public String ending;
23+
public String fundingType;
24+
public String holderName;
25+
public String network;
26+
public String status;
27+
public List<String> tags;
28+
public String expiration;
29+
public String created;
30+
public String updated;
31+
32+
public MerchantCard(String id, String ending, String fundingType, String holderName, String network, String status, List<String> tags, String expiration, String created, String updated) {
33+
super(id);
34+
this.ending = ending;
35+
this.fundingType = fundingType;
36+
this.holderName = holderName;
37+
this.network = network;
38+
this.status = status;
39+
this.tags = tags;
40+
this.expiration = expiration;
41+
this.created = created;
42+
this.updated = updated;
43+
}
44+
45+
public static Generator<MerchantCard> query(Map<String, Object> params, User user) throws Exception {
46+
return Rest.getStream(data, params, user);
47+
}
48+
49+
public static Generator<MerchantCard> query(Map<String, Object> params) throws Exception {
50+
return MerchantCard.query(params, null);
51+
}
52+
53+
public static Generator<MerchantCard> query() throws Exception {
54+
return Rest.getStream(data, new HashMap<>(), null);
55+
}
56+
57+
public static MerchantCard get(String id, User user) throws Exception {
58+
return Rest.getId(data, id, user);
59+
}
60+
61+
public static MerchantCard get(String id) throws Exception {
62+
return MerchantCard.get(id, null);
63+
}
64+
65+
public static MerchantCard.Page page(Map<String, Object> params) throws Exception {
66+
return page(params, null);
67+
}
68+
69+
public static MerchantCard.Page page(User user) throws Exception {
70+
return page(new HashMap<>(), user);
71+
}
72+
73+
public static MerchantCard.Page page() throws Exception {
74+
return page(new HashMap<>(), null);
75+
}
76+
77+
78+
public static MerchantCard.Page page(Map<String, Object> params, User user) throws Exception {
79+
com.starkcore.utils.Page page = Rest.getPage(data, params, user);
80+
List<MerchantCard> MerchantCards = new ArrayList<>();
81+
for (com.starkcore.utils.SubResource MerchantCard: page.entities) {
82+
MerchantCards.add((MerchantCard) MerchantCard);
83+
}
84+
return new MerchantCard.Page(MerchantCards, page.cursor);
85+
}
86+
87+
public final static class Page {
88+
public List<MerchantCard> merchantCards;
89+
public String cursor;
90+
91+
public Page(List<MerchantCard> merchantCards, String cursor) {
92+
this.merchantCards = merchantCards;
93+
this.cursor = cursor;
94+
}
95+
}
96+
97+
public final static class Log extends Resource {
98+
static ClassData data = new ClassData(MerchantCard.Log.class, "MerchantCardLog");
99+
100+
public String created;
101+
public String type;
102+
public String[] errors;
103+
public MerchantCard card;
104+
105+
public Log(String created, String type, String[] errors, MerchantCard card, String id) {
106+
super(id);
107+
this.created = created;
108+
this.type = type;
109+
this.errors = errors;
110+
this.card = card;
111+
}
112+
113+
114+
public static MerchantCard.Log get(String id) throws Exception {
115+
return MerchantCard.Log.get(id, null);
116+
}
117+
118+
public static MerchantCard.Log get(String id, User user) throws Exception {
119+
return Rest.getId(data, id, user);
120+
}
121+
122+
public static Generator<MerchantCard.Log> query(Map<String, Object> params) throws Exception {
123+
return MerchantCard.Log.query(params, null);
124+
}
125+
126+
public static Generator<MerchantCard.Log> query(User user) throws Exception {
127+
return MerchantCard.Log.query(new HashMap<>(), user);
128+
}
129+
130+
public static Generator<MerchantCard.Log> query() throws Exception {
131+
return MerchantCard.Log.query(new HashMap<>(), null);
132+
}
133+
134+
public static Generator<MerchantCard.Log> query(Map<String, Object> params, User user) throws Exception {
135+
return Rest.getStream(data, params, user);
136+
}
137+
138+
public final static class Page {
139+
public List<MerchantCard.Log> logs;
140+
public String cursor;
141+
142+
public Page(List<MerchantCard.Log> logs, String cursor) {
143+
this.logs = logs;
144+
this.cursor = cursor;
145+
}
146+
}
147+
148+
public static MerchantCard.Log.Page page(Map<String, Object> params) throws Exception {
149+
return MerchantCard.Log.page(params, null);
150+
}
151+
152+
public static MerchantCard.Log.Page page(User user) throws Exception {
153+
return MerchantCard.Log.page(new HashMap<>(), user);
154+
}
155+
156+
public static MerchantCard.Log.Page page() throws Exception {
157+
return MerchantCard.Log.page(new HashMap<>(), null);
158+
}
159+
160+
public static MerchantCard.Log.Page page(Map<String, Object> params, User user) throws Exception {
161+
com.starkcore.utils.Page page = Rest.getPage(data, params, user);
162+
List<MerchantCard.Log> logs = new ArrayList<>();
163+
for (com.starkcore.utils.SubResource log: page.entities) {
164+
logs.add((MerchantCard.Log) log);
165+
}
166+
return new MerchantCard.Log.Page(logs, page.cursor);
167+
}
168+
169+
}
170+
171+
}

0 commit comments

Comments
 (0)