Skip to content

Commit

Permalink
LC-169 Add ability to modify transactionrecordcustomdata from extensi…
Browse files Browse the repository at this point in the history
…ons (#831)
  • Loading branch information
pvyhnal-generalbytes authored Aug 15, 2023
1 parent 12ab6f4 commit a825117
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# buildscript - project id
projectGroup=com.generalbytes.batm.public
projectVersion=1.1.11
projectVersion=1.1.12

# buildscript - common dependency versions
bitrafaelVersion=1.0.44
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ public interface IExtensionContext {
*/
ITransactionDetails updateTransaction(String rid, Integer status, String detail, Set<String> tags) throws UpdateException;

/**
* @param rid remote transaction ID of the transaction to be updated
* @param status new status to be set or null to keep it unmodified
* @param detail detail message to be appended if there already is a detail set. Null to keep it unmodified
* @param customData custom data to be set to the transaction.
* This will replace existing custom data stored for the transaction.
* If you need to keep existing data obtain them first using {@link ITransactionDetails#getCustomData()}.
* Providing an empty map will remove all existing custom data.
* Null keeps the existing custom data unchanged.
* @return modified transaction details
* @throws UpdateException if the update was not successful
*/
ITransactionDetails updateTransaction(String rid, Integer status, String detail, Map<String, String> customData) throws UpdateException;

ITransactionDetails updateTransaction(String rid, Integer status, String detail) throws UpdateException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface ITransactionDetails {
Expand Down Expand Up @@ -303,4 +304,12 @@ public interface ITransactionDetails {
Set<String> getTags();

List<IBanknoteCounts> getBanknotes();

/**
* @return Custom data for the transaction.
* Saved when returned from {@link ITransactionListener#onTransactionCreated(ITransactionDetails)}
* or {@link ITransactionListener#onTransactionUpdated(ITransactionDetails)}
* or using {@link IExtensionContext#updateTransaction(String, Integer, String, Map)}.
*/
Map<String, String> getCustomData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public ITransactionDetails updateTransaction(String rid, Integer status, String
return null;
}

@Override
public ITransactionDetails updateTransaction(String rid, Integer status, String detail, Map<String, String> customData) throws UpdateException {
return null;
}

@Override
public Set<String> getTransactionTags(String organizationId) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ public Map<String, String> onTransactionCreated(ITransactionDetails transactionD
public Map<String, String> onTransactionUpdated(ITransactionDetails transactionDetails) {
log.info("Transaction updated; tags: {}", transactionDetails.getTags());
try {
String rid = transactionDetails.getRemoteTransactionId();

ITransactionDetails details = ctx.findTransactionByTransactionId(rid);
log.info("Transaction custom data: {}", details.getCustomData());
Map<String, String> customData = new HashMap<>(details.getCustomData());
customData.remove("ticket.previous.counter");
customData.put("ticket.footer", "Enjoy!");
ctx.updateTransaction(rid, null, null, customData);

String organizationId = ctx.findIdentityByIdentityId(transactionDetails.getIdentityPublicId()).getOrganization().getId();
log.info("Defined transaction tags: {}", ctx.getTransactionTags(organizationId));
Set<String> tags = Collections.singleton(transactionDetails.getCryptoCurrency());
ITransactionDetails updated = ctx.updateTransaction(transactionDetails.getRemoteTransactionId(), null, null, tags);
ITransactionDetails updated = ctx.updateTransaction(rid, null, null, tags);
log.info("Transaction updated; tags: {}", updated.getTags());
} catch (UpdateException e) {
log.error("", e);
Expand Down

0 comments on commit a825117

Please sign in to comment.