Search in sources :

Example 1 with PaymentPluginStatus

use of org.killbill.billing.payment.plugin.api.PaymentPluginStatus in project killbill by killbill.

the class MockPaymentProviderPlugin method getPaymentTransactionInfoPluginResult.

private PaymentTransactionInfoPlugin getPaymentTransactionInfoPluginResult(final UUID kbPaymentId, final UUID kbTransactionId, final TransactionType type, @Nullable final BigDecimal amount, @Nullable final Currency currency, final Iterable<PluginProperty> pluginProperties) throws PaymentPluginApiException {
    if (makePluginWaitSomeMilliseconds.get() > 0) {
        try {
            Thread.sleep(makePluginWaitSomeMilliseconds.get());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new PaymentPluginApiException("An Interruption occurred while the Thread was sleeping.", e);
        }
    }
    if (makeNextPaymentFailWithException.getAndSet(false)) {
        throw new PaymentPluginApiException("", "test error");
    }
    final PluginProperty paymentPluginStatusOverride = Iterables.tryFind(pluginProperties, new Predicate<PluginProperty>() {

        @Override
        public boolean apply(final PluginProperty input) {
            return PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE.equals(input.getKey());
        }
    }).orNull();
    final PaymentPluginStatus status;
    if (paymentPluginStatusOverride != null && paymentPluginStatusOverride.getValue() != null) {
        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 if (makeNextPaymentPending.getAndSet(false)) {
        status = PaymentPluginStatus.PENDING;
    } else if (makeNextPaymentUnknown.getAndSet(false)) {
        status = PaymentPluginStatus.UNDEFINED;
    } else {
        status = PaymentPluginStatus.PROCESSED;
    }
    final String errorCode = status == PaymentPluginStatus.PROCESSED ? "" : GATEWAY_ERROR_CODE;
    final String error = status == PaymentPluginStatus.PROCESSED ? "" : GATEWAY_ERROR;
    InternalPaymentInfo info = payments.get(kbPaymentId.toString());
    if (info == null) {
        info = new InternalPaymentInfo();
        payments.put(kbPaymentId.toString(), info);
    }
    final BigDecimal overrideNextProcessedAmount = this.overrideNextProcessedAmount.getAndSet(null);
    final BigDecimal processedAmount = overrideNextProcessedAmount != null ? overrideNextProcessedAmount : amount;
    Currency processedCurrency = overrideNextProcessedCurrency.getAndSet(null);
    if (processedCurrency == null) {
        processedCurrency = currency;
    }
    final PaymentTransactionInfoPlugin result = new DefaultNoOpPaymentInfoPlugin(kbPaymentId, kbTransactionId, type, processedAmount, processedCurrency, clock.getUTCNow(), clock.getUTCNow(), status, errorCode, error, null, null, ImmutableList.<PluginProperty>copyOf(pluginProperties));
    List<PaymentTransactionInfoPlugin> existingTransactions = paymentTransactions.get(kbPaymentId.toString());
    if (existingTransactions == null) {
        existingTransactions = new ArrayList<PaymentTransactionInfoPlugin>();
        paymentTransactions.put(kbPaymentId.toString(), existingTransactions);
    }
    final Iterator<PaymentTransactionInfoPlugin> iterator = existingTransactions.iterator();
    while (iterator.hasNext()) {
        final PaymentTransactionInfoPlugin existingTransaction = iterator.next();
        if (existingTransaction.getKbTransactionPaymentId().equals(kbTransactionId)) {
            info.addAmount(type, existingTransaction.getAmount().negate());
            iterator.remove();
        }
    }
    existingTransactions.add(result);
    info.addAmount(type, result.getAmount());
    return result;
}
Also used : PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) BigDecimal(java.math.BigDecimal) Predicate(com.google.common.base.Predicate) PaymentPluginStatus(org.killbill.billing.payment.plugin.api.PaymentPluginStatus) PluginProperty(org.killbill.billing.payment.api.PluginProperty) Currency(org.killbill.billing.catalog.api.Currency) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)

Example 2 with PaymentPluginStatus

use of org.killbill.billing.payment.plugin.api.PaymentPluginStatus in project killbill by killbill.

the class TestDefaultNoOpPaymentInfoPlugin method testEquals.

@Test(groups = "fast")
public void testEquals() throws Exception {
    final UUID kbPaymentId = UUID.randomUUID();
    final UUID kbTransactionId = UUID.randomUUID();
    final BigDecimal amount = new BigDecimal("1.394810E-3");
    final DateTime effectiveDate = clock.getUTCNow().plusDays(1);
    final DateTime createdDate = clock.getUTCNow();
    final PaymentPluginStatus status = PaymentPluginStatus.UNDEFINED;
    final String error = UUID.randomUUID().toString();
    final DefaultNoOpPaymentInfoPlugin info = new DefaultNoOpPaymentInfoPlugin(kbPaymentId, kbTransactionId, TransactionType.PURCHASE, amount, Currency.USD, effectiveDate, createdDate, status, error, null);
    Assert.assertEquals(info, info);
    final DefaultNoOpPaymentInfoPlugin sameInfo = new DefaultNoOpPaymentInfoPlugin(kbPaymentId, kbTransactionId, TransactionType.PURCHASE, amount, Currency.USD, effectiveDate, createdDate, status, error, null);
    Assert.assertEquals(sameInfo, info);
    final DefaultNoOpPaymentInfoPlugin otherInfo = new DefaultNoOpPaymentInfoPlugin(kbPaymentId, kbTransactionId, TransactionType.PURCHASE, amount, Currency.USD, effectiveDate, createdDate, status, UUID.randomUUID().toString(), null);
    Assert.assertNotEquals(otherInfo, info);
}
Also used : PaymentPluginStatus(org.killbill.billing.payment.plugin.api.PaymentPluginStatus) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)2 PaymentPluginStatus (org.killbill.billing.payment.plugin.api.PaymentPluginStatus)2 Predicate (com.google.common.base.Predicate)1 UUID (java.util.UUID)1 DateTime (org.joda.time.DateTime)1 Currency (org.killbill.billing.catalog.api.Currency)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1 PaymentPluginApiException (org.killbill.billing.payment.plugin.api.PaymentPluginApiException)1 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)1 Test (org.testng.annotations.Test)1