Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LC-169 Add ability to modify transactionrecordcustomdata from extensions #831

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9
projectVersion=1.1.10

# 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