Search in sources :

Example 6 with PaymentPluginApiException

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

the class PaymentGatewayProcessor method buildFormDescriptor.

public HostedPaymentPageFormDescriptor buildFormDescriptor(final boolean shouldDispatch, final Account account, final UUID paymentMethodId, final Iterable<PluginProperty> customFields, final Iterable<PluginProperty> properties, final CallContext callContext, final InternalCallContext internalCallContext) throws PaymentApiException {
    final String pluginName = getPaymentMethodById(paymentMethodId, true, internalCallContext).getPluginName();
    final PaymentPluginApi plugin = getPaymentPluginApi(pluginName);
    if (shouldDispatch) {
        return dispatchWithExceptionHandling(account, pluginName, new Callable<PluginDispatcherReturnType<HostedPaymentPageFormDescriptor>>() {

            @Override
            public PluginDispatcherReturnType<HostedPaymentPageFormDescriptor> call() throws PaymentApiException {
                try {
                    final HostedPaymentPageFormDescriptor result = plugin.buildFormDescriptor(account.getId(), customFields, properties, callContext);
                    return PluginDispatcher.createPluginDispatcherReturnType(result == null ? new DefaultNoOpHostedPaymentPageFormDescriptor(account.getId()) : result);
                } catch (final RuntimeException e) {
                    throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, MoreObjects.firstNonNull(e.getMessage(), ""));
                } catch (final PaymentPluginApiException e) {
                    throw new PaymentApiException(e, ErrorCode.PAYMENT_PLUGIN_EXCEPTION, e.getErrorMessage());
                }
            }
        }, paymentPluginFormDispatcher);
    } else {
        try {
            return plugin.buildFormDescriptor(account.getId(), customFields, properties, callContext);
        } catch (final PaymentPluginApiException e) {
            throw new PaymentApiException(e, ErrorCode.PAYMENT_PLUGIN_EXCEPTION, e.getErrorMessage());
        }
    }
}
Also used : PaymentPluginApi(org.killbill.billing.payment.plugin.api.PaymentPluginApi) PluginDispatcherReturnType(org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType) DefaultNoOpHostedPaymentPageFormDescriptor(org.killbill.billing.payment.provider.DefaultNoOpHostedPaymentPageFormDescriptor) HostedPaymentPageFormDescriptor(org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor) DefaultNoOpHostedPaymentPageFormDescriptor(org.killbill.billing.payment.provider.DefaultNoOpHostedPaymentPageFormDescriptor) PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException)

Example 7 with PaymentPluginApiException

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

the class PaymentOperation method doOperation.

private OperationResult doOperation() throws PaymentApiException {
    try {
        //
        if (paymentStateContext.getOverridePluginOperationResult() == null) {
            final PaymentTransactionInfoPlugin paymentInfoPlugin = doCallSpecificOperationCallback();
            //
            if (paymentInfoPlugin == null) {
                throw new IllegalStateException("Payment plugin returned a null result");
            }
            paymentStateContext.setPaymentTransactionInfoPlugin(paymentInfoPlugin);
            return PaymentTransactionInfoPluginConverter.toOperationResult(paymentStateContext.getPaymentTransactionInfoPlugin());
        } else {
            final PaymentTransactionInfoPlugin paymentInfoPlugin = new DefaultNoOpPaymentInfoPlugin(paymentStateContext.getPaymentId(), paymentStateContext.getTransactionId(), paymentStateContext.getTransactionType(), paymentStateContext.getPaymentTransactionModelDao().getProcessedAmount(), paymentStateContext.getPaymentTransactionModelDao().getProcessedCurrency(), paymentStateContext.getPaymentTransactionModelDao().getEffectiveDate(), paymentStateContext.getPaymentTransactionModelDao().getCreatedDate(), buildPaymentPluginStatusFromOperationResult(paymentStateContext.getOverridePluginOperationResult()), null, null);
            paymentStateContext.setPaymentTransactionInfoPlugin(paymentInfoPlugin);
            return paymentStateContext.getOverridePluginOperationResult();
        }
    } catch (final PaymentPluginApiException e) {
        throw new PaymentApiException(e, ErrorCode.PAYMENT_PLUGIN_EXCEPTION, e.getErrorMessage());
    }
}
Also used : DefaultNoOpPaymentInfoPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin) PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException)

Example 8 with PaymentPluginApiException

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

the class TestPaymentApi method testCreatePurchaseWithControlPaymentPluginException.

@Test(groups = "slow")
public void testCreatePurchaseWithControlPaymentPluginException() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithException();
    final BigDecimal requestedAmount = BigDecimal.TEN;
    final String paymentExternalKey = "pay controle external key";
    ;
    final String transactionExternalKey = "txn control external key";
    try {
        paymentApi.createPurchaseWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), CONTROL_PLUGIN_OPTIONS, callContext);
        fail();
    } catch (PaymentApiException e) {
        assertTrue(e.getCause() instanceof PaymentPluginApiException);
    }
}
Also used : PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 9 with PaymentPluginApiException

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

the class MockPaymentProviderPlugin method refundPayment.

@Override
public PaymentTransactionInfoPlugin refundPayment(final UUID kbAccountId, final UUID kbPaymentId, final UUID kbTransactionId, final UUID kbPaymentMethodId, final BigDecimal refundAmount, final Currency currency, final Iterable<PluginProperty> properties, final CallContext context) throws PaymentPluginApiException {
    final InternalPaymentInfo info = payments.get(kbPaymentId.toString());
    if (info == null) {
        throw new PaymentPluginApiException("", String.format("No payment found for payment id %s (plugin %s)", kbPaymentId.toString(), PLUGIN_NAME));
    }
    BigDecimal maxAmountRefundable = info.getCaptureAmount().add(info.getPurchasedAmount());
    if (maxAmountRefundable.compareTo(info.getRefundAmount()) < 0) {
        throw new PaymentPluginApiException("", String.format("Refund amount of %s for payment id %s is bigger than the payment amount %s (plugin %s)", refundAmount, kbPaymentId.toString(), maxAmountRefundable, PLUGIN_NAME));
    }
    return getPaymentTransactionInfoPluginResult(kbPaymentId, kbTransactionId, TransactionType.REFUND, refundAmount, currency, properties);
}
Also used : PaymentPluginApiException(org.killbill.billing.payment.plugin.api.PaymentPluginApiException) BigDecimal(java.math.BigDecimal)

Aggregations

PaymentPluginApiException (org.killbill.billing.payment.plugin.api.PaymentPluginApiException)9 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)5 BigDecimal (java.math.BigDecimal)4 PaymentPluginApi (org.killbill.billing.payment.plugin.api.PaymentPluginApi)4 DefaultPaymentMethod (org.killbill.billing.payment.api.DefaultPaymentMethod)3 UUID (java.util.UUID)2 AccountApiException (org.killbill.billing.account.api.AccountApiException)2 PaymentMethod (org.killbill.billing.payment.api.PaymentMethod)2 PaymentMethodModelDao (org.killbill.billing.payment.dao.PaymentMethodModelDao)2 PluginDispatcherReturnType (org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType)2 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)2 Test (org.testng.annotations.Test)2 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Currency (org.killbill.billing.catalog.api.Currency)1 PaymentMethodPlugin (org.killbill.billing.payment.api.PaymentMethodPlugin)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1 HostedPaymentPageFormDescriptor (org.killbill.billing.payment.plugin.api.HostedPaymentPageFormDescriptor)1