From d7ce21f11d3d2c8d0d5a252235ccbdadeb20d3e6 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Mon, 3 Aug 2020 20:46:36 -0400 Subject: [PATCH] allow setting preferred plan when adding payment method --- .../src/main/java/bubble/model/account/Account.java | 6 ++---- .../java/bubble/model/bill/AccountPaymentMethod.java | 12 ++++++++++-- .../bill/AccountPaymentMethodsResource.java | 7 +++++++ .../V2020080302__add_account_preferred_plan_fk.sql | 2 ++ .../server/post_auth/ResourceMessages.properties | 1 + utils/cobbzilla-wizard | 2 +- 6 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 bubble-server/src/main/resources/db/migration/V2020080302__add_account_preferred_plan_fk.sql diff --git a/bubble-server/src/main/java/bubble/model/account/Account.java b/bubble-server/src/main/java/bubble/model/account/Account.java index 513521a2..7ed0d589 100644 --- a/bubble-server/src/main/java/bubble/model/account/Account.java +++ b/bubble-server/src/main/java/bubble/model/account/Account.java @@ -8,10 +8,7 @@ import bubble.dao.account.AccountInitializer; import bubble.model.app.AppData; import bubble.model.app.BubbleApp; import bubble.model.app.RuleDriver; -import bubble.model.bill.AccountPayment; -import bubble.model.bill.AccountPaymentMethod; -import bubble.model.bill.AccountPlan; -import bubble.model.bill.Bill; +import bubble.model.bill.*; import bubble.model.boot.ActivationRequest; import bubble.model.cloud.*; import bubble.model.cloud.notify.ReceivedNotification; @@ -198,6 +195,7 @@ public class Account extends IdentifiableBaseParentEntity implements TokenPrinci } @Column(length=UUID_MAXLEN) + @ECForeignKey(entity=BubblePlan.class, index=false, cascade=false) @Getter @Setter private String preferredPlan; public boolean hasPreferredPlan () { return !empty(preferredPlan); } diff --git a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java index ff9b2e13..68c77edd 100644 --- a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java +++ b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java @@ -6,6 +6,7 @@ package bubble.model.bill; import bubble.cloud.CloudServiceType; import bubble.cloud.payment.PaymentServiceDriver; +import bubble.dao.bill.BubblePlanDAO; import bubble.dao.cloud.CloudServiceDAO; import bubble.model.account.Account; import bubble.model.account.HasAccountNoName; @@ -102,6 +103,9 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount @Transient @Getter @Setter private transient Boolean requireValidatedEmail = null; public boolean requireValidatedEmail() { return requireValidatedEmail == null || requireValidatedEmail; } + @Transient @Getter @Setter private transient String preferredPlan; + public boolean hasPreferredPlan() { return !empty(preferredPlan); } + public ValidationResult validate(ValidationResult result, BubbleConfiguration configuration) { if (!hasPaymentMethodType()) { @@ -143,7 +147,7 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount if (empty(getPaymentInfo())) { result.addViolation("err.paymentInfo.required"); } else { - log.info("validate: starting validation of payment method with this.requireValidatedEmail="+requireValidatedEmail); + log.debug("validate: starting validation of payment method with this.requireValidatedEmail="+requireValidatedEmail); final PaymentValidationResult validationResult = paymentDriver.validate(this); if (validationResult.hasErrors()) { result.addAll(validationResult.getViolations()); @@ -153,7 +157,11 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount } } } - + if (hasPreferredPlan()) { + final BubblePlanDAO planDAO = configuration.getBean(BubblePlanDAO.class); + final BubblePlan plan = planDAO.findById(preferredPlan); + if (plan == null) result.addViolation("err.plan.notFound"); + } return result; } diff --git a/bubble-server/src/main/java/bubble/resources/bill/AccountPaymentMethodsResource.java b/bubble-server/src/main/java/bubble/resources/bill/AccountPaymentMethodsResource.java index db4742d4..e893d021 100644 --- a/bubble-server/src/main/java/bubble/resources/bill/AccountPaymentMethodsResource.java +++ b/bubble-server/src/main/java/bubble/resources/bill/AccountPaymentMethodsResource.java @@ -75,4 +75,11 @@ public class AccountPaymentMethodsResource extends AccountOwnedResource