Skip to content

Commit

Permalink
Quickbooks integration
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyrsy committed Sep 27, 2021
1 parent 6a57b2a commit b88bbe9
Show file tree
Hide file tree
Showing 9 changed files with 706 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<artifactId>hubspot-java-client</artifactId>
<version>2.1.0-SNAPSHOT</version>
</dependency>

<!--Temp-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>

</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/impactupgrade/nucleus/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.impactupgrade.nucleus;

import com.impactupgrade.nucleus.controller.AccountingController;
import com.impactupgrade.nucleus.controller.BackupController;
import com.impactupgrade.nucleus.controller.CrmController;
import com.impactupgrade.nucleus.controller.DonationFormController;
Expand Down Expand Up @@ -76,6 +77,7 @@ public void start() throws Exception {
apiConfig.register(stripeController());
apiConfig.register(twilioController());
apiConfig.register(mailchimpController());
apiConfig.register(accountingController());

registerAPIControllers(apiConfig);

Expand Down Expand Up @@ -132,8 +134,10 @@ public void registerServlets(ServletContextHandler context) throws Exception {}
protected StripeController stripeController() { return new StripeController(envFactory()); }
protected TwilioController twilioController() { return new TwilioController(envFactory()); }
protected MailchimpController mailchimpController() { return new MailchimpController(envFactory()); }
protected AccountingController accountingController() { return new AccountingController(envFactory()); }

public static void main(String... args) throws Exception {
new App().start();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.impactupgrade.nucleus.controller;

import com.impactupgrade.nucleus.environment.Environment;
import com.impactupgrade.nucleus.environment.EnvironmentFactory;
import com.impactupgrade.nucleus.model.PaymentGatewayDeposit;
import com.impactupgrade.nucleus.security.SecurityUtil;
import com.impactupgrade.nucleus.service.segment.PaymentGatewayService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Path("/accounting")
public class AccountingController {

private static final Logger log = LogManager.getLogger(AccountingController.class);
private static final String DATE_FORMAT = "yyyy-MM-dd";

protected final EnvironmentFactory environmentFactory;

public AccountingController(EnvironmentFactory environmentFactory) {
this.environmentFactory = environmentFactory;
}

@Path("/sync-transactions")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response syncTransactions(
@FormParam("start_date") String start,
@FormParam("end_date") String end,
@Context HttpServletRequest request
) throws Exception {

Environment environment = environmentFactory.init(request);
SecurityUtil.verifyApiKey(environment);

Date startDate = new SimpleDateFormat(DATE_FORMAT).parse(start);
Date endDate = new SimpleDateFormat(DATE_FORMAT).parse(end);

Runnable runnable = () -> {
// Get all payment services available (Stripe is it you?)
List<PaymentGatewayService> paymentGatewayServices = environment.allPaymentGatewayServices();

if (CollectionUtils.isEmpty(paymentGatewayServices)) {
log.info("Payment Services not defined for environment! Returning...");
return;
}

List<PaymentGatewayDeposit> deposits = new ArrayList<>();

try {
for (PaymentGatewayService paymentGatewayService : paymentGatewayServices) {
String serviceName = paymentGatewayService.name();
log.info("Payment service '{}' running...", serviceName);
deposits.addAll(paymentGatewayService.getDeposits(startDate, endDate));
log.info("Payment service '{}' done.", serviceName);
}
} catch (Exception e) {
log.error("Failed to get deposits! {}", e.getMessage());
return;
}

environment.accountingService().addDeposits(deposits);
};

// Away from the main thread
new Thread(runnable).start();

return Response.ok().build();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.impactupgrade.nucleus.client.SfdcClient;
import com.impactupgrade.nucleus.client.SfdcMetadataClient;
import com.impactupgrade.nucleus.client.StripeClient;
import com.impactupgrade.nucleus.service.logic.AccountingService;
import com.impactupgrade.nucleus.service.logic.ContactService;
import com.impactupgrade.nucleus.service.logic.DonationService;
import com.impactupgrade.nucleus.service.logic.MessagingService;
import com.impactupgrade.nucleus.service.segment.AccountingPlatformService;
import com.impactupgrade.nucleus.service.segment.CrmService;
import com.impactupgrade.nucleus.service.segment.EmailPlatformService;
import com.impactupgrade.nucleus.service.segment.PaymentGatewayService;
Expand Down Expand Up @@ -100,6 +102,7 @@ public void setOtherContext(MultivaluedMap<String, String> otherContext) {
public DonationService donationService() { return new DonationService(this); }
public ContactService contactService() { return new ContactService(this); }
public MessagingService messagingService() { return new MessagingService(this); }
public AccountingService accountingService() { return new AccountingService(this); }

// segment services

Expand Down Expand Up @@ -145,6 +148,10 @@ public List<EmailPlatformService> allEmailPlatformServices() {
return segmentServices(EmailPlatformService.class);
}

public List<AccountingPlatformService> allAccountingPlatformServices() {
return segmentServices(AccountingPlatformService.class);
}

private <T extends SegmentService> T segmentService(final String name, Class<T> clazz) {
ServiceLoader<T> loader = java.util.ServiceLoader.load(clazz);
T segmentService = loader.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public static class Platform {
// if basic auth
public String username = "";
public String password = "";

// if OAuth
public String clientId = "";
public String clientSecret = "";
public String tokenServerUrl = "";

public String accessToken = "";
public String refreshToken = "";
}

public Platform stripe = new Platform();
Expand Down Expand Up @@ -170,6 +178,13 @@ public static class Recaptcha {
public String siteSecret = "";
}

public static class QuickBooks extends Platform {
public String realmId = "";
public String apiBaseUrl = "";
}

public QuickBooks quickbooks = new QuickBooks();

public MetadataKeys metadataKeys = new MetadataKeys();

public static class MetadataKeys {
Expand Down
Loading

0 comments on commit b88bbe9

Please sign in to comment.