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

Raisely Enrichment Service Updates #151

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ public void enrich(CrmDonation crmDonation) throws Exception {
String donationId = parseDonationId(crmDonation.description);
RaiselyClient.Donation raiselyDonation = raiselyClient.getDonation(donationId);

if (raiselyDonation == null || raiselyDonation.items == null || raiselyDonation.items.size() <= 1) {
// not a split transaction -- return the original
if (raiselyDonation == null || raiselyDonation.items == null || raiselyDonation.items.isEmpty()) {
// return the original
} else {
// TODO: Are there other types of items? Could there be a ticket + products + donation?
List<RaiselyClient.DonationItem> donationItems = raiselyDonation.items.stream().filter(i -> !"ticket".equalsIgnoreCase(i.type)).toList();
List<RaiselyClient.DonationItem> ticketItems = raiselyDonation.items.stream().filter(i -> "ticket".equalsIgnoreCase(i.type)).toList();
if (ticketItems.isEmpty()) {
// donations only, but this should never happen?
// donations only
crmDonation.transactionType = EnvironmentConfig.TransactionType.DONATION;
crmDonation.amount = calculateTotalAmount(donationItems);
} else if (donationItems.isEmpty()) {
// tickets only
crmDonation.transactionType = EnvironmentConfig.TransactionType.TICKET;
} else if (donationItems.size() > 1 || ticketItems.size() > 1) {
env.logJobWarn("Raisely donation {} had multiple donations and/or tickets; expected one of each, so skipping out of caution", donationId);
crmDonation.amount = calculateTotalAmount(ticketItems);
} else {
// one of each -- let the ticket be the primary and donation secondary

// multiple of each -- let the ticket be the primary and donation secondary
crmDonation.transactionType = EnvironmentConfig.TransactionType.TICKET;
// if fees are covered, stick them on the TICKET, not the DONATION
double ticketAmount = calculateTotalAmount(ticketItems);
double donationAmount = calculateTotalAmount(donationItems);
double coveredFee = raiselyDonation.feeCovered ? (raiselyDonation.fee / 100.0) : 0.0;
crmDonation.amount = (ticketItems.get(0).amount / 100.0) + coveredFee;
crmDonation.amount = ticketAmount + coveredFee;

// TODO: This will have the same Stripe IDs! For most clients, this won't work, since we skip processing
// gifts if their Stripe ID already exists in the CRM. Talking to DR AU about how to handle. Nuke the IDs
Expand All @@ -83,7 +83,7 @@ public void enrich(CrmDonation crmDonation) throws Exception {
clonedCrmDonation.contact.crmRawObject = crmContactRawObject;

clonedCrmDonation.transactionType = EnvironmentConfig.TransactionType.DONATION;
clonedCrmDonation.amount = donationItems.get(0).amount / 100.0;
clonedCrmDonation.amount = donationAmount;
// Downstream, we need a notion of parent/child to handle secondary events within the CrmServices.
clonedCrmDonation.parent = crmDonation;
crmDonation.children.add(clonedCrmDonation);
Expand All @@ -92,6 +92,13 @@ public void enrich(CrmDonation crmDonation) throws Exception {
}

//HELPERS
protected double calculateTotalAmount(List<RaiselyClient.DonationItem> items) {
double totalAmount = 0.0;
for (RaiselyClient.DonationItem item : items) {
totalAmount += item.amount / 100.0;
}
return totalAmount;
}

protected String parseDonationId(String description){
Pattern r = Pattern.compile("Donation \\((\\d+)\\).*");
Expand Down
Loading