Skip to content

Commit

Permalink
payment: Variable renaming + add ability to simulate CANCELED transac…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
sbrossie committed Mar 14, 2016
1 parent 1c82baf commit 86ebbcb
Showing 1 changed file with 21 additions and 11 deletions.
Expand Up @@ -68,9 +68,10 @@ public class MockPaymentProviderPlugin implements PaymentPluginApi {


public static final String PLUGIN_NAME = "__NO_OP__"; public static final String PLUGIN_NAME = "__NO_OP__";


private final AtomicBoolean makeNextInvoiceFailWithError = new AtomicBoolean(false); private final AtomicBoolean makeNextPaymentFailWithError = new AtomicBoolean(false);
private final AtomicBoolean makeNextInvoiceFailWithException = new AtomicBoolean(false); private final AtomicBoolean makeNextPaymentFailWithCancellation = new AtomicBoolean(false);
private final AtomicBoolean makeAllInvoicesFailWithError = new AtomicBoolean(false); private final AtomicBoolean makeNextPaymentFailWithException = new AtomicBoolean(false);
private final AtomicBoolean makeAllPaymentsFailWithError = new AtomicBoolean(false);
private final AtomicInteger makePluginWaitSomeMilliseconds = new AtomicInteger(0); private final AtomicInteger makePluginWaitSomeMilliseconds = new AtomicInteger(0);
private final AtomicReference<BigDecimal> overrideNextProcessedAmount = new AtomicReference<BigDecimal>(); private final AtomicReference<BigDecimal> overrideNextProcessedAmount = new AtomicReference<BigDecimal>();
private final AtomicReference<Currency> overrideNextProcessedCurrency = new AtomicReference<Currency>(); private final AtomicReference<Currency> overrideNextProcessedCurrency = new AtomicReference<Currency>();
Expand Down Expand Up @@ -194,9 +195,10 @@ public MockPaymentProviderPlugin(final Clock clock) {
} }


public void clear() { public void clear() {
makeNextInvoiceFailWithException.set(false); makeNextPaymentFailWithException.set(false);
makeAllInvoicesFailWithError.set(false); makeAllPaymentsFailWithError.set(false);
makeNextInvoiceFailWithError.set(false); makeNextPaymentFailWithError.set(false);
makeNextPaymentFailWithCancellation.set(false);
makePluginWaitSomeMilliseconds.set(0); makePluginWaitSomeMilliseconds.set(0);
overrideNextProcessedAmount.set(null); overrideNextProcessedAmount.set(null);
paymentMethods.clear(); paymentMethods.clear();
Expand All @@ -206,15 +208,19 @@ public void clear() {
} }


public void makeNextPaymentFailWithError() { public void makeNextPaymentFailWithError() {
makeNextInvoiceFailWithError.set(true); makeNextPaymentFailWithError.set(true);
}

public void makeNextPaymentFailWithCancellation() {
makeNextPaymentFailWithCancellation.set(true);
} }


public void makeNextPaymentFailWithException() { public void makeNextPaymentFailWithException() {
makeNextInvoiceFailWithException.set(true); makeNextPaymentFailWithException.set(true);
} }


public void makeAllInvoicesFailWithError(final boolean failure) { public void makeAllInvoicesFailWithError(final boolean failure) {
makeAllInvoicesFailWithError.set(failure); makeAllPaymentsFailWithError.set(failure);
} }


public void makePluginWaitSomeMilliseconds(final int milliseconds) { public void makePluginWaitSomeMilliseconds(final int milliseconds) {
Expand Down Expand Up @@ -368,7 +374,7 @@ private PaymentTransactionInfoPlugin getPaymentTransactionInfoPluginResult(final
} }
} }


if (makeNextInvoiceFailWithException.getAndSet(false)) { if (makeNextPaymentFailWithException.getAndSet(false)) {
throw new PaymentPluginApiException("", "test error"); throw new PaymentPluginApiException("", "test error");
} }


Expand All @@ -382,8 +388,12 @@ public boolean apply(final PluginProperty input) {
final PaymentPluginStatus status; final PaymentPluginStatus status;
if (paymentPluginStatusOverride != null && paymentPluginStatusOverride.getValue() != null) { if (paymentPluginStatusOverride != null && paymentPluginStatusOverride.getValue() != null) {
status = PaymentPluginStatus.valueOf(paymentPluginStatusOverride.getValue().toString()); status = PaymentPluginStatus.valueOf(paymentPluginStatusOverride.getValue().toString());
} else if (makeAllPaymentsFailWithError.get() || makeNextPaymentFailWithError.getAndSet(false)) {
status = PaymentPluginStatus.ERROR;
} else if (makeNextPaymentFailWithCancellation.getAndSet(false)) {
status = PaymentPluginStatus.CANCELED;
} else { } else {
status = (makeAllInvoicesFailWithError.get() || makeNextInvoiceFailWithError.getAndSet(false)) ? PaymentPluginStatus.ERROR : PaymentPluginStatus.PROCESSED; status = PaymentPluginStatus.PROCESSED;
} }
final String errorCode = status == PaymentPluginStatus.PROCESSED ? "" : GATEWAY_ERROR_CODE; final String errorCode = status == PaymentPluginStatus.PROCESSED ? "" : GATEWAY_ERROR_CODE;
final String error = status == PaymentPluginStatus.PROCESSED ? "" : GATEWAY_ERROR; final String error = status == PaymentPluginStatus.PROCESSED ? "" : GATEWAY_ERROR;
Expand Down

1 comment on commit 86ebbcb

@pierre
Copy link
Member

@pierre pierre commented on 86ebbcb Mar 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.