@@ -8,10 +8,7 @@ import bubble.dao.account.AccountInitializer; | |||||
import bubble.model.app.AppData; | import bubble.model.app.AppData; | ||||
import bubble.model.app.BubbleApp; | import bubble.model.app.BubbleApp; | ||||
import bubble.model.app.RuleDriver; | 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.boot.ActivationRequest; | ||||
import bubble.model.cloud.*; | import bubble.model.cloud.*; | ||||
import bubble.model.cloud.notify.ReceivedNotification; | import bubble.model.cloud.notify.ReceivedNotification; | ||||
@@ -198,6 +195,7 @@ public class Account extends IdentifiableBaseParentEntity implements TokenPrinci | |||||
} | } | ||||
@Column(length=UUID_MAXLEN) | @Column(length=UUID_MAXLEN) | ||||
@ECForeignKey(entity=BubblePlan.class, index=false, cascade=false) | |||||
@Getter @Setter private String preferredPlan; | @Getter @Setter private String preferredPlan; | ||||
public boolean hasPreferredPlan () { return !empty(preferredPlan); } | public boolean hasPreferredPlan () { return !empty(preferredPlan); } | ||||
@@ -6,6 +6,7 @@ package bubble.model.bill; | |||||
import bubble.cloud.CloudServiceType; | import bubble.cloud.CloudServiceType; | ||||
import bubble.cloud.payment.PaymentServiceDriver; | import bubble.cloud.payment.PaymentServiceDriver; | ||||
import bubble.dao.bill.BubblePlanDAO; | |||||
import bubble.dao.cloud.CloudServiceDAO; | import bubble.dao.cloud.CloudServiceDAO; | ||||
import bubble.model.account.Account; | import bubble.model.account.Account; | ||||
import bubble.model.account.HasAccountNoName; | import bubble.model.account.HasAccountNoName; | ||||
@@ -102,6 +103,9 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount | |||||
@Transient @Getter @Setter private transient Boolean requireValidatedEmail = null; | @Transient @Getter @Setter private transient Boolean requireValidatedEmail = null; | ||||
public boolean requireValidatedEmail() { return requireValidatedEmail == null || requireValidatedEmail; } | 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) { | public ValidationResult validate(ValidationResult result, BubbleConfiguration configuration) { | ||||
if (!hasPaymentMethodType()) { | if (!hasPaymentMethodType()) { | ||||
@@ -143,7 +147,7 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount | |||||
if (empty(getPaymentInfo())) { | if (empty(getPaymentInfo())) { | ||||
result.addViolation("err.paymentInfo.required"); | result.addViolation("err.paymentInfo.required"); | ||||
} else { | } 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); | final PaymentValidationResult validationResult = paymentDriver.validate(this); | ||||
if (validationResult.hasErrors()) { | if (validationResult.hasErrors()) { | ||||
result.addAll(validationResult.getViolations()); | 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; | return result; | ||||
} | } | ||||
@@ -75,4 +75,11 @@ public class AccountPaymentMethodsResource extends AccountOwnedResource<AccountP | |||||
return false; | return false; | ||||
} | } | ||||
@Override protected Object daoCreate(AccountPaymentMethod apm) { | |||||
if (apm.hasPreferredPlan()) { | |||||
final Account account = accountDAO.findByUuid(apm.getAccount()); | |||||
accountDAO.update(account.setPreferredPlan(apm.getPreferredPlan())); | |||||
} | |||||
return super.daoCreate(apm); | |||||
} | |||||
} | } |
@@ -0,0 +1,2 @@ | |||||
ALTER TABLE ONLY account ADD CONSTRAINT account_fk_preferred_plan FOREIGN KEY (preferred_plan) REFERENCES bubble_plan(uuid); |
@@ -762,6 +762,7 @@ err.paymentService.notFound=Payment service is invalid | |||||
err.parent.notFound=Parent account does not exist | err.parent.notFound=Parent account does not exist | ||||
err.path.length=Path is too long | err.path.length=Path is too long | ||||
err.plan.required=Plan is required | err.plan.required=Plan is required | ||||
err.plan.notFound=Plan not found | |||||
err.plan.planMaxAccountLimit=No more accounts can be created. Please upgrade your plan to create more accounts. | err.plan.planMaxAccountLimit=No more accounts can be created. Please upgrade your plan to create more accounts. | ||||
err.price.invalid=Price is invalid | err.price.invalid=Price is invalid | ||||
err.price.length=Price is too long | err.price.length=Price is too long | ||||
@@ -1 +1 @@ | |||||
Subproject commit 121fc1cc39ff487d74f9000658ba9138e18e9267 | |||||
Subproject commit 7937eb3f39cfbc026275ed381b89ce4dd7b16d23 |