From 109f45b02ae817349b54b47a8fea23447e3e5a81 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 16 Jan 2020 20:01:48 -0500 Subject: [PATCH] fix delegate caching for payments --- .../bubble/model/bill/AccountPaymentMethod.java | 13 +++++++------ .../bubble/model/cloud/notify/NotificationType.java | 6 ++++++ .../payment/PaymentMethodClaimNotification.java | 2 +- .../PaymentMethodValidationNotification.java | 5 +++-- .../bubble/service/notify/NotificationService.java | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) 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 acb36fe9..59076280 100644 --- a/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java +++ b/bubble-server/src/main/java/bubble/model/bill/AccountPaymentMethod.java @@ -8,6 +8,7 @@ import bubble.model.account.HasAccountNoName; import bubble.model.cloud.CloudService; import bubble.notify.payment.PaymentValidationResult; import bubble.server.BubbleConfiguration; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -20,13 +21,9 @@ import org.cobbzilla.wizard.model.entityconfig.annotations.*; import org.cobbzilla.wizard.validation.ValidationResult; import org.hibernate.annotations.Type; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; +import javax.persistence.*; -import static org.cobbzilla.util.daemon.ZillaRuntime.bool; -import static org.cobbzilla.util.daemon.ZillaRuntime.empty; +import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.reflect.ReflectionUtil.copy; import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENCRYPTED_STRING; import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENC_PAD; @@ -135,4 +132,8 @@ public class AccountPaymentMethod extends IdentifiableBase implements HasAccount return result; } + + @JsonIgnore @Transient public String getCacheKey () { + return hashOf(getUuid(), account, cloud, paymentMethodType, paymentInfo); + } } diff --git a/bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java b/bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java index a85b12f8..26c19df0 100644 --- a/bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java +++ b/bubble-server/src/main/java/bubble/model/cloud/notify/NotificationType.java @@ -131,4 +131,10 @@ public enum NotificationType { : die("toResponse: no responseClass defined for "+this.name()); } + public boolean canReturnCachedResponse() { + // payment validation requests are never cached, because the response depends on data outside the message + // specifically, if the user does not have any validated email address, an error is returned + // but an identical notification can later return a different response, after the email has been validated + return this != payment_driver_validate; + } } diff --git a/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodClaimNotification.java b/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodClaimNotification.java index e306e42c..6b749bca 100644 --- a/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodClaimNotification.java +++ b/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodClaimNotification.java @@ -35,5 +35,5 @@ public class PaymentMethodClaimNotification extends SynchronousNotification { } @JsonIgnore @Transient @Getter(lazy=true) private final String cacheKey - = hashOf(hasPaymentMethod() ? paymentMethod.getUuid() : null, hasAccountPlan() ? accountPlan.getUuid() : null, cloud); + = hashOf(hasPaymentMethod() ? paymentMethod.getCacheKey() : null, hasAccountPlan() ? accountPlan.getUuid() : null, cloud); } diff --git a/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodValidationNotification.java b/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodValidationNotification.java index c19b3009..4a8001d2 100644 --- a/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodValidationNotification.java +++ b/bubble-server/src/main/java/bubble/notify/payment/PaymentMethodValidationNotification.java @@ -8,18 +8,19 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; import javax.persistence.Transient; import static org.cobbzilla.util.daemon.ZillaRuntime.hashOf; -@NoArgsConstructor @AllArgsConstructor @Accessors(chain=true) +@NoArgsConstructor @AllArgsConstructor @Accessors(chain=true) @Slf4j public class PaymentMethodValidationNotification extends SynchronousNotification { @Getter @Setter private String cloud; @Getter @Setter private AccountPaymentMethod paymentMethod; @JsonIgnore @Transient @Getter(lazy=true) private final String cacheKey - = hashOf(cloud, paymentMethod != null ? paymentMethod.getUuid() : null); + = hashOf(cloud, paymentMethod != null ? paymentMethod.getCacheKey() : null); } diff --git a/bubble-server/src/main/java/bubble/service/notify/NotificationService.java b/bubble-server/src/main/java/bubble/service/notify/NotificationService.java index 32b05084..d5c98395 100644 --- a/bubble-server/src/main/java/bubble/service/notify/NotificationService.java +++ b/bubble-server/src/main/java/bubble/service/notify/NotificationService.java @@ -129,7 +129,7 @@ public class NotificationService { SynchronousNotification activeNotification; synchronized (syncRequestCache) { activeNotification = syncRequestCache.get(cacheKey); - if (activeNotification == null) { + if (activeNotification == null || !type.canReturnCachedResponse()) { // no one else is calling, we are the activeNotification syncRequestCache.put(cacheKey, notification); activeNotification = notification;