Skip to content

Commit

Permalink
Add merchant purchase, merchant session, merchant card and merchant i…
Browse files Browse the repository at this point in the history
…nstallment
  • Loading branch information
jonasborges-stark committed Feb 11, 2025
1 parent 85c4356 commit e5ea358
Show file tree
Hide file tree
Showing 13 changed files with 1,622 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
- PATCH version when backwards compatible bug **fixes** are implemented.

## [Unreleased]
### Added
- merchantSession, merchantCard, merchantInstallment and merchantPurchase resources

## [2.19.0] - 2024-09-17
### Added
Expand Down
129 changes: 129 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ is as easy as sending a text message to your client!
- [CorporateEnums](#corporate-enums): Query enums related to the corporate purchases, such as merchant categories, countries and card purchase methods
- [Split](#query-splits): Split received Invoice payments between different receivers
- [SplitReceiver](#create-splitreceivers): Receiver of an Invoice split
- [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.
- [MerchantPurchase](#merchant-purchase): The Merchant Purchase section allows users to retrieve detailed information of the purchases.
- [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions
- [WebhookEvents](#process-webhook-events): Manage webhook events
- [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries
Expand Down Expand Up @@ -2637,6 +2639,133 @@ SplitReceiver.Log log = SplitReceiver.Log.get("5155165527080960");
System.out.println(log);
```

## 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.

## Create a MerchantSession

```java
import com.starkbank.*;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;

Map<String, Object> data = new HashMap<>();
List<String> allowedFundingTypes = new ArrayList<>();
allowedFundingTypes.add("debit");
allowedFundingTypes.add("credit");
data.put("allowedFundingTypes", allowedFundingTypes);

List<Map<String, Object>> allowedInstallments = new ArrayList<>();
Map<String, Object> installment1 = new HashMap<>();
installment1.put("totalAmount", 0);
installment1.put("count", 1);
allowedInstallments.add(installment1);

Map<String, Object> installment2 = new HashMap<>();
installment2.put("totalAmount", 120);
installment2.put("count", 2);
allowedInstallments.add(installment2);

Map<String, Object> installment3 = new HashMap<>();
installment3.put("totalAmount", 180);
installment3.put("count", 12);
allowedInstallments.add(installment3);

data.put("allowedInstallments", allowedInstallments);
data.put("expiration", 3600);
data.put("challengeMode", "disabled");

data.put("tags", new String[]{"Stark", "Suit"});

MerchantSession.create(new MerchantSession(data));

System.out.println(log);
```

You can create a MerchantPurchase through a MerchantSession by passing its UUID.
**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.

### Create a MerchantSesssion Purchase

```java
import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

Map<String, Object> purchaseData = new HashMap<>();
purchaseData.put("amount", 1000L);
purchaseData.put("cardExpiration", "2035-01");
purchaseData.put("cardNumber", "36490101441625");
purchaseData.put("cardSecurityCode", "123");
purchaseData.put("holderName", "Margaery Tyrell");
purchaseData.put("fundingType", "credit");

MerchantSession.Purchase purchase= MerchantSession.purchase(
merchantSession.uuid, new com.starkbank.MerchantSession.Purchase(purchaseData););

System.out.println(purchase);
```

### Query MerchantSessions

```java
import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);

Generator<MerchantSession> sessions = MerchantSession.query(params);

for (MerchantSession session : sessions) {
System.out.println(session);
}
```

### Get a MerchantSession

```java
import com.starkbank.*;

MerchantSession retrievedSession = MerchantSession.get("5441927222657024");
System.out.println(retrievedSession);
```

## Merchant Purchase

The Merchant Purchase section allows users to retrieve detailed information of the purchases.

### Query MerchantPurchases

```java
import com.starkbank.*;
import java.util.Map;
import java.util.HashMap;

HashMap<String, Object> params = new HashMap<>();
params.put("limit", 10);
Generator<MerchantPurchase> merchantPurchases = MerchantPurchase.query(params);

for (MerchantPurchase purchase : merchantPurchases) {
System.out.println(purchase);
}
```

### Get a MerchantPurchase

```java
import com.starkbank.*;

MerchantPurchase retrievedPurchase = MerchantPurchase.get("5441927222657024");

System.out.println(retrievedPurchase);
```

## Create a webhook subscription

To create a webhook subscription and be notified whenever an event occurs, run:
Expand Down
170 changes: 170 additions & 0 deletions src/main/java/com/starkbank/MerchantCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package com.starkbank;

import com.starkbank.utils.Generator;
import com.starkbank.utils.Resource;
import com.starkbank.utils.Rest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MerchantCard extends Resource {

/**
# MerchantCard object
Check out our API Documentation at https://starkbank.com/docs/api#merchant-card
**/

static ClassData data = new ClassData(MerchantCard.class, "MerchantCard");

public String ending;
public String fundingType;
public String holderName;
public String network;
public String status;
public List<String> tags;
public String expiration;
public String created;
public String updated;

public MerchantCard(String id, String ending, String fundingType, String holderName, String network, String status, List<String> tags, String expiration, String created, String updated) {
super(id);
this.ending = ending;
this.fundingType = fundingType;
this.holderName = holderName;
this.network = network;
this.status = status;
this.tags = tags;
this.expiration = expiration;
this.created = created;
this.updated = updated;
}

public static Generator<MerchantCard> query(Map<String, Object> params, User user) throws Exception {
return Rest.getStream(data, params, user);
}

public static Generator<MerchantCard> query(Map<String, Object> params) throws Exception {
return MerchantCard.query(params, null);
}

public static Generator<MerchantCard> query() throws Exception {
return Rest.getStream(data, new HashMap<>(), null);
}

public static MerchantCard get(String id, User user) throws Exception {
return Rest.getId(data, id, user);
}

public static MerchantCard get(String id) throws Exception {
return MerchantCard.get(id, null);
}

public static MerchantCard.Page page(Map<String, Object> params) throws Exception {
return page(params, null);
}

public static MerchantCard.Page page(User user) throws Exception {
return page(new HashMap<>(), user);
}

public static MerchantCard.Page page() throws Exception {
return page(new HashMap<>(), null);
}


public static MerchantCard.Page page(Map<String, Object> params, User user) throws Exception {
com.starkcore.utils.Page page = Rest.getPage(data, params, user);
List<MerchantCard> MerchantCards = new ArrayList<>();
for (com.starkcore.utils.SubResource MerchantCard: page.entities) {
MerchantCards.add((MerchantCard) MerchantCard);
}
return new MerchantCard.Page(MerchantCards, page.cursor);
}

public final static class Page {
public List<MerchantCard> merchantCards;
public String cursor;

public Page(List<MerchantCard> merchantCards, String cursor) {
this.merchantCards = merchantCards;
this.cursor = cursor;
}
}

public final static class Log extends Resource {
static ClassData data = new ClassData(MerchantCard.Log.class, "MerchantCardLog");

public String created;
public String type;
public String[] errors;
public MerchantCard merchantCard;

public Log(String created, String type, String[] errors, MerchantCard merchantCard, String id) {
super(id);
this.created = created;
this.type = type;
this.errors = errors;
this.merchantCard = merchantCard;
}


public static MerchantCard.Log get(String id) throws Exception {
return MerchantCard.Log.get(id, null);
}

public static MerchantCard.Log get(String id, User user) throws Exception {
return Rest.getId(data, id, user);
}

public static Generator<MerchantCard.Log> query(Map<String, Object> params) throws Exception {
return MerchantCard.Log.query(params, null);
}

public static Generator<MerchantCard.Log> query(User user) throws Exception {
return MerchantCard.Log.query(new HashMap<>(), user);
}

public static Generator<MerchantCard.Log> query() throws Exception {
return MerchantCard.Log.query(new HashMap<>(), null);
}

public static Generator<MerchantCard.Log> query(Map<String, Object> params, User user) throws Exception {
return Rest.getStream(data, params, user);
}

public final static class Page {
public List<MerchantCard.Log> logs;
public String cursor;

public Page(List<MerchantCard.Log> logs, String cursor) {
this.logs = logs;
this.cursor = cursor;
}
}

public static MerchantCard.Log.Page page(Map<String, Object> params) throws Exception {
return MerchantCard.Log.page(params, null);
}

public static MerchantCard.Log.Page page(User user) throws Exception {
return MerchantCard.Log.page(new HashMap<>(), user);
}

public static MerchantCard.Log.Page page() throws Exception {
return MerchantCard.Log.page(new HashMap<>(), null);
}

public static MerchantCard.Log.Page page(Map<String, Object> params, User user) throws Exception {
com.starkcore.utils.Page page = Rest.getPage(data, params, user);
List<MerchantCard.Log> logs = new ArrayList<>();
for (com.starkcore.utils.SubResource log: page.entities) {
logs.add((MerchantCard.Log) log);
}
return new MerchantCard.Log.Page(logs, page.cursor);
}

}

}
Loading

0 comments on commit e5ea358

Please sign in to comment.