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());
}
}
}
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());
}
}
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);
}
}
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);
}
Aggregations