killbill-memoizeit

Details

diff --git a/payment/src/main/java/org/killbill/billing/payment/api/DefaultPaymentGatewayApi.java b/payment/src/main/java/org/killbill/billing/payment/api/DefaultPaymentGatewayApi.java
index b4eb5c2..39117a5 100644
--- a/payment/src/main/java/org/killbill/billing/payment/api/DefaultPaymentGatewayApi.java
+++ b/payment/src/main/java/org/killbill/billing/payment/api/DefaultPaymentGatewayApi.java
@@ -124,9 +124,9 @@ public class DefaultPaymentGatewayApi extends DefaultApiBase implements PaymentG
             final T result = callback.doPaymentGatewayApiOperation(priorCallResult.getAdjustedPluginProperties());
             controlPluginRunner.executePluginOnSuccessCalls(account,
                                                             paymentMethodId,
-                                                            null, null, null, null,
+                                                            null, null, null, null, null,
                                                             PaymentApiType.HPP, null, HPPType.BUILD_FORM_DESCRIPTOR,
-                                                            null, null, true, paymentControlPluginNames, priorCallResult.getAdjustedPluginProperties(), callContext);
+                                                            null, null, null, null, true, paymentControlPluginNames, priorCallResult.getAdjustedPluginProperties(), callContext);
             return result;
         } catch (final PaymentApiException e) {
             controlPluginRunner.executePluginOnFailureCalls(account,
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/ControlPluginRunner.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/ControlPluginRunner.java
index da94cfd..41c37a2 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/ControlPluginRunner.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/ControlPluginRunner.java
@@ -68,7 +68,7 @@ public class ControlPluginRunner {
                                                              final HPPType hppType,
                                                              final BigDecimal amount,
                                                              final Currency currency,
-                                                             final boolean  isApiPayment,
+                                                             final boolean isApiPayment,
                                                              final List<String> paymentControlPluginNames,
                                                              final Iterable<PluginProperty> pluginProperties,
                                                              final CallContext callContext) throws PaymentControlApiException {
@@ -124,34 +124,39 @@ public class ControlPluginRunner {
         return prevResult;
     }
 
-
     public OnSuccessPaymentControlResult executePluginOnSuccessCalls(final Account account,
-                                            final UUID paymentMethodId,
-                                            final UUID paymentAttemptId,
-                                            final UUID paymentId,
-                                            final String paymentExternalKey,
-                                            final String paymentTransactionExternalKey,
-                                            final PaymentApiType paymentApiType,
-                                            final TransactionType transactionType,
-                                            final HPPType hppType,
-                                            final BigDecimal amount,
-                                            final Currency currency,
-                                            final boolean  isApiPayment,
-                                            final List<String> paymentControlPluginNames,
-                                            final Iterable<PluginProperty> pluginProperties,
-                                            final CallContext callContext) {
+                                                                     final UUID paymentMethodId,
+                                                                     final UUID paymentAttemptId,
+                                                                     final UUID paymentId,
+                                                                     final String paymentExternalKey,
+                                                                     final UUID transactionId,
+                                                                     final String paymentTransactionExternalKey,
+                                                                     final PaymentApiType paymentApiType,
+                                                                     final TransactionType transactionType,
+                                                                     final HPPType hppType,
+                                                                     final BigDecimal amount,
+                                                                     final Currency currency,
+                                                                     final BigDecimal processedAmount,
+                                                                     final Currency processedCurrency,
+                                                                     final boolean isApiPayment,
+                                                                     final List<String> paymentControlPluginNames,
+                                                                     final Iterable<PluginProperty> pluginProperties,
+                                                                     final CallContext callContext) {
 
         final PaymentControlContext inputPaymentControlContext = new DefaultPaymentControlContext(account,
                                                                                                   paymentMethodId,
                                                                                                   paymentAttemptId,
                                                                                                   paymentId,
                                                                                                   paymentExternalKey,
+                                                                                                  transactionId,
                                                                                                   paymentTransactionExternalKey,
                                                                                                   paymentApiType,
                                                                                                   transactionType,
                                                                                                   hppType,
                                                                                                   amount,
                                                                                                   currency,
+                                                                                                  processedAmount,
+                                                                                                  processedCurrency,
                                                                                                   isApiPayment,
                                                                                                   callContext);
         Iterable<PluginProperty> inputPluginProperties = pluginProperties;
@@ -174,7 +179,6 @@ public class ControlPluginRunner {
         return new DefaultOnSuccessPaymentControlResult(inputPluginProperties);
     }
 
-
     public OnFailurePaymentControlResult executePluginOnFailureCalls(final Account account,
                                                                      final UUID paymentMethodId,
                                                                      final UUID paymentAttemptId,
@@ -186,7 +190,7 @@ public class ControlPluginRunner {
                                                                      final HPPType hppType,
                                                                      final BigDecimal amount,
                                                                      final Currency currency,
-                                                                     final boolean  isApiPayment,
+                                                                     final boolean isApiPayment,
                                                                      final List<String> paymentControlPluginNames,
                                                                      final Iterable<PluginProperty> pluginProperties,
                                                                      final CallContext callContext) {
@@ -232,9 +236,6 @@ public class ControlPluginRunner {
         return new DefaultFailureCallResult(candidate, inputPluginProperties);
     }
 
-
-
-
     public static class DefaultPaymentControlContext extends DefaultCallContext implements PaymentControlContext {
 
         private final Account account;
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/OperationControlCallback.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/OperationControlCallback.java
index f2458e8..a1e8928 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/control/OperationControlCallback.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/control/OperationControlCallback.java
@@ -200,18 +200,22 @@ public abstract class OperationControlCallback extends OperationCallbackBase<Pay
     }
 
     protected void executePluginOnSuccessCalls(final List<String> paymentControlPluginNames, final PaymentControlContext paymentControlContext) {
-
+        // Values that were obtained/chnaged after the payment call was made (paymentId, processedAmount, processedCurrency,... needs to be extracted from the paymentControlContext)
+        // paymentId, paymentExternalKey, transactionAmount, transaction currency are extracted from  paymentControlContext which was update from the operation result.
         final OnSuccessPaymentControlResult result = controlPluginRunner.executePluginOnSuccessCalls(paymentStateContext.getAccount(),
-                                                                                                     paymentControlContext.getPaymentMethodId(),
+                                                                                                     paymentStateContext.getPaymentMethodId(),
                                                                                                      paymentStateControlContext.getAttemptId(),
-                                                                                                     paymentStateContext.getPaymentId(),
-                                                                                                     paymentStateContext.getPaymentExternalKey(),
+                                                                                                     paymentControlContext.getPaymentId(),
+                                                                                                     paymentControlContext.getPaymentExternalKey(),
+                                                                                                     paymentControlContext.getTransactionId(),
                                                                                                      paymentStateContext.getPaymentTransactionExternalKey(),
                                                                                                      PaymentApiType.PAYMENT_TRANSACTION,
                                                                                                      paymentStateContext.getTransactionType(),
                                                                                                      null,
                                                                                                      paymentControlContext.getAmount(),
                                                                                                      paymentControlContext.getCurrency(),
+                                                                                                     paymentControlContext.getProcessedAmount(),
+                                                                                                     paymentControlContext.getProcessedCurrency(),
                                                                                                      paymentStateControlContext.isApiPayment(),
                                                                                                      paymentControlPluginNames,
                                                                                                      paymentStateContext.getProperties(),
diff --git a/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java b/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java
index 0484897..8510301 100644
--- a/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java
+++ b/payment/src/main/java/org/killbill/billing/payment/invoice/InvoicePaymentControlPluginApi.java
@@ -33,6 +33,7 @@ import org.killbill.billing.ObjectType;
 import org.killbill.billing.account.api.Account;
 import org.killbill.billing.callcontext.InternalCallContext;
 import org.killbill.billing.callcontext.InternalTenantContext;
+import org.killbill.billing.control.plugin.api.PaymentApiType;
 import org.killbill.billing.invoice.api.Invoice;
 import org.killbill.billing.invoice.api.InvoiceApiException;
 import org.killbill.billing.invoice.api.InvoiceInternalApi;
@@ -114,7 +115,9 @@ public final class InvoicePaymentControlPluginApi implements PaymentControlPlugi
 
     @Override
     public PriorPaymentControlResult priorCall(final PaymentControlContext paymentControlContext, final Iterable<PluginProperty> pluginProperties) throws PaymentControlApiException {
+
         final TransactionType transactionType = paymentControlContext.getTransactionType();
+        Preconditions.checkArgument(paymentControlContext.getPaymentApiType() == PaymentApiType.PAYMENT_TRANSACTION);
         Preconditions.checkArgument(transactionType == TransactionType.PURCHASE ||
                                     transactionType == TransactionType.REFUND ||
                                     transactionType == TransactionType.CHARGEBACK);