Browse Source

only issue a refund once

tags/v0.1.8
Jonathan Cobb 4 years ago
parent
commit
6e1bf8f8a7
7 changed files with 43 additions and 22 deletions
  1. +17
    -0
      bubble-server/src/main/java/bubble/dao/app/BubbleAppDAO.java
  2. +11
    -5
      bubble-server/src/main/java/bubble/dao/bill/AccountPlanDAO.java
  3. +6
    -0
      bubble-server/src/main/java/bubble/model/bill/AccountPlan.java
  4. +0
    -3
      bubble-server/src/main/java/bubble/resources/account/AccountOwnedResource.java
  5. +1
    -12
      bubble-server/src/main/java/bubble/resources/app/AppsResourceBase.java
  6. +7
    -1
      bubble-server/src/main/java/bubble/service/bill/StandardRefundService.java
  7. +1
    -1
      bubble-web

+ 17
- 0
bubble-server/src/main/java/bubble/dao/app/BubbleAppDAO.java View File

@@ -1,7 +1,10 @@
package bubble.dao.app;

import bubble.dao.account.AccountOwnedTemplateDAO;
import bubble.model.app.AppMatcher;
import bubble.model.app.AppRule;
import bubble.model.app.BubbleApp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@@ -9,6 +12,9 @@ import java.util.List;
@Repository
public class BubbleAppDAO extends AccountOwnedTemplateDAO<BubbleApp> {

@Autowired private AppMatcherDAO matcherDAO;
@Autowired private AppRuleDAO ruleDAO;

public List<BubbleApp> findByAccountAndEnabledAndTemplate(String account, Boolean enabled, Boolean template) {
if (enabled != null) {
if (template != null) {
@@ -22,4 +28,15 @@ public class BubbleAppDAO extends AccountOwnedTemplateDAO<BubbleApp> {
return findByField("account", account);
}

@Override public void delete(String uuid) {
final BubbleApp app = findByUuid(uuid);
for (AppMatcher m : matcherDAO.findByApp(app.getUuid())) {
matcherDAO.delete(m.getUuid());
}
for (AppRule r : ruleDAO.findByApp(app.getUuid())) {
ruleDAO.delete(r.getUuid());
}
super.delete(uuid);
}

}

+ 11
- 5
bubble-server/src/main/java/bubble/dao/bill/AccountPlanDAO.java View File

@@ -50,10 +50,11 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> {
return findByFields("account", account, "paymentMethod", paymentMethod, "deleted", null);
}

public List<AccountPlan> findByDeletedAndNotClosed() {
public List<AccountPlan> findByDeletedAndNotClosedAndNoRefundIssued() {
return list(criteria().add(and(
isNotNull("deleted"),
eq("closed", false)
eq("closed", false),
eq("refundIssued", false)
)));
}

@@ -130,9 +131,14 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> {
throw invalidEx("err.accountPlan.stopNetworkBeforeDeleting");
}
update(accountPlan.setDeleted(now()).setEnabled(false));
networkDAO.delete(accountPlan.getNetwork());
if (configuration.paymentsEnabled()) {
refundService.processRefunds();
if (accountPlan.getNetwork() == null && accountPlan.getDeletedNetwork() != null) {
log.warn("delete: network was supposed to be deleted, deleting it again: "+accountPlan.getDeletedNetwork());
networkDAO.delete(accountPlan.getDeletedNetwork());
} else {
networkDAO.delete(accountPlan.getNetwork());
if (configuration.paymentsEnabled()) {
refundService.processRefunds();
}
}
}



+ 6
- 0
bubble-server/src/main/java/bubble/model/bill/AccountPlan.java View File

@@ -116,6 +116,12 @@ public class AccountPlan extends IdentifiableBase implements HasAccount {
@Getter @Setter private String deletedNetwork;
public boolean hasDeletedNetwork() { return deletedNetwork != null; }

@ECSearchable @ECField(index=140) @Column(nullable=false)
@Getter @Setter private Boolean refundIssued = false;

@ECSearchable @ECField(index=150)
@Getter @Setter private String refundError;

// Fields below are used when creating a new plan, to also create the network associated with it
@Size(max=10000, message="err.description.length")
@Transient @Getter @Setter private transient String description;


+ 0
- 3
bubble-server/src/main/java/bubble/resources/account/AccountOwnedResource.java View File

@@ -171,13 +171,10 @@ public class AccountOwnedResource<E extends HasAccount, DAO extends AccountOwned

if (!canDelete(ctx, caller, found)) return forbidden();

cascadingDeletes(found);
getDao().delete(found.getUuid());
return ok(found);
}

protected void cascadingDeletes(E entity) {}

protected Account checkEditable(ContainerRequest ctx) {
final Account caller = userPrincipal(ctx);
if (caller.admin()) return caller;


+ 1
- 12
bubble-server/src/main/java/bubble/resources/app/AppsResourceBase.java View File

@@ -4,8 +4,6 @@ import bubble.dao.app.AppMatcherDAO;
import bubble.dao.app.AppRuleDAO;
import bubble.dao.app.BubbleAppDAO;
import bubble.model.account.Account;
import bubble.model.app.AppMatcher;
import bubble.model.app.AppRule;
import bubble.model.app.BubbleApp;
import bubble.resources.account.AccountOwnedTemplateResource;
import bubble.server.BubbleConfiguration;
@@ -39,20 +37,11 @@ public abstract class AppsResourceBase extends AccountOwnedTemplateResource<Bubb

final BubbleApp found = appDAO.findByAccountAndId(getAccountUuid(ctx), id);
if (found == null) return notFound(id);
cascadingDeletes(found);
appDAO.delete(found.getUuid());
return ok_empty();
}

@Override protected void cascadingDeletes(BubbleApp found) {
for (AppMatcher m : matcherDAO.findByApp(found.getUuid())) {
matcherDAO.delete(m.getUuid());
}
for (AppRule r : ruleDAO.findByApp(found.getUuid())) {
ruleDAO.delete(r.getUuid());
}
}

@Path("/{id}"+EP_RULES)
public AppRulesResource getRules(@Context ContainerRequest ctx,
@PathParam("id") String id) {


+ 7
- 1
bubble-server/src/main/java/bubble/service/bill/StandardRefundService.java View File

@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
import java.util.List;

import static java.util.concurrent.TimeUnit.HOURS;
import static org.cobbzilla.util.daemon.ZillaRuntime.shortError;

@Service @Slf4j
public class StandardRefundService extends SimpleDaemon implements RefundService {
@@ -35,15 +36,20 @@ public class StandardRefundService extends SimpleDaemon implements RefundService

@Override protected void process() {
// iterate over all account plans that have been deleted but not yet closed
final List<AccountPlan> pendingPlans = accountPlanDAO.findByDeletedAndNotClosed();
final List<AccountPlan> pendingPlans = accountPlanDAO.findByDeletedAndNotClosedAndNoRefundIssued();
for (AccountPlan accountPlan : pendingPlans) {
try {
final AccountPaymentMethod paymentMethod = paymentMethodDAO.findByUuid(accountPlan.getPaymentMethod());
final CloudService paymentCloud = cloudDAO.findByUuid(paymentMethod.getCloud());
final PaymentServiceDriver paymentDriver = paymentCloud.getPaymentDriver(configuration);
paymentDriver.refund(accountPlan.getUuid());

} catch (Exception e) {
log.error("process: error processing refund for AccountPlan: "+accountPlan.getUuid());
accountPlan.setRefundError(shortError(e));

} finally {
accountPlanDAO.update(accountPlan.setRefundIssued(true));
}
}
}


+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit f9134769f17da5b76d038974c75271f17fe88f9b
Subproject commit 702c0c4c2142cfa818c50b0c29af3bd7addc734e

Loading…
Cancel
Save